index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <div class="p-4">
  3. <!-- <GrowCard :loading="loading" class="enter-y" /> -->
  4. <BasicTable @register="registerTable">
  5. <template #headerTop>
  6. <div class="md:flex enter-y">
  7. <div class="md:w-1/2 enter-y">
  8. <Card class="w-full">
  9. <VisitAnalysisBar
  10. :loading="loading"
  11. :viewStatics="viewStaticsData"
  12. :shareStatics="shareStaticsData"
  13. />
  14. </Card>
  15. </div>
  16. <div class="!md:mx-2"></div>
  17. <Card class="md:w-1/2 enter-y">
  18. <!-- <VisitAnalysis :loading="loading" /> -->
  19. <VisitAnalysis
  20. :loading="loading"
  21. :bulletChatAmounts="bulletChatAmountsData"
  22. :userAmount="userAmountData"
  23. />
  24. </Card>
  25. </div>
  26. </template>
  27. <template #toolbar>
  28. <a-button type="primary" @click="handleExport">导出数据</a-button>
  29. </template>
  30. </BasicTable>
  31. <!-- <div class="md:flex enter-y">
  32. <div class="md:w-1/2 enter-y">
  33. <Card class="w-full">
  34. <VisitAnalysisBar :loading="loading" />
  35. </Card>
  36. </div>
  37. <div class="!md:mx-2"></div>
  38. <Card class="md:w-1/2 enter-y">
  39. <VisitAnalysis :loading="loading" />
  40. </Card>
  41. </div>
  42. <div class="md:flex enter-y mt-4">
  43. <Card class="md:w-1/2 md:w-full"> </Card>
  44. </div> -->
  45. </div>
  46. </template>
  47. <script lang="ts" setup>
  48. import { onMounted, ref } from 'vue';
  49. import { BasicTable, useTable, BasicColumn, FormProps } from '/@/components/Table';
  50. // import { useI18n } from '/@/hooks/web/useI18n';
  51. // import GrowCard from './components/GrowCard.vue';
  52. import { Card } from 'ant-design-vue';
  53. import VisitAnalysis from './components/VisitAnalysis.vue';
  54. import VisitAnalysisBar from './components/VisitAnalysisBar.vue';
  55. import {
  56. bulletChatApi,
  57. userStaticsApi,
  58. bulletChatStaticsApi,
  59. bulletChatExportApi,
  60. } from '/@/api/dashboard/analysis';
  61. import { listRoomsApi } from '/@/api/scene/list';
  62. import { dateUtil, formatToDate } from '/@/utils/dateUtil';
  63. import { StaticItemType } from '/@/api/dashboard/model';
  64. const today = formatToDate(dateUtil(new Date()));
  65. const priorDate = formatToDate(dateUtil(new Date().setDate(new Date().getDate() - 30)));
  66. const loading = ref(true);
  67. // UserStaticsModel
  68. const viewStaticsData = ref<StaticItemType[]>([]);
  69. const shareStaticsData = ref<StaticItemType[]>([]);
  70. const bulletChatAmountsData = ref<StaticItemType[]>([]);
  71. const userAmountData = ref<StaticItemType[]>([]);
  72. // const { t } = useI18n();
  73. const columns: BasicColumn[] = [
  74. {
  75. title: '微信昵称',
  76. dataIndex: 'nickName',
  77. width: 120,
  78. },
  79. {
  80. title: '手机号',
  81. dataIndex: 'userName',
  82. width: 120,
  83. },
  84. {
  85. title: '房间名称',
  86. dataIndex: 'liveRoomName',
  87. width: 120,
  88. },
  89. {
  90. title: '在线时长(min)',
  91. dataIndex: 'duration',
  92. width: 120,
  93. },
  94. {
  95. title: '留言条数',
  96. dataIndex: 'bulletChatAmount',
  97. width: 120,
  98. },
  99. {
  100. title: '留言内容',
  101. dataIndex: 'bulletChatContents',
  102. width: 320,
  103. },
  104. ];
  105. const searchForm: Partial<FormProps> = {
  106. labelWidth: 100,
  107. schemas: [
  108. {
  109. field: 'liveRoomId',
  110. label: '全部房间',
  111. component: 'ApiSelect',
  112. // required: true,
  113. colProps: {
  114. xl: 5,
  115. xxl: 5,
  116. },
  117. componentProps: {
  118. api: listRoomsApi,
  119. labelField: 'name',
  120. resultField: 'list',
  121. valueField: 'id',
  122. immediate: false,
  123. showSearch: true,
  124. optionFilterProp: 'label',
  125. params: {
  126. page: 1,
  127. limit: 1000,
  128. },
  129. },
  130. },
  131. {
  132. field: 'time',
  133. label: '时间段',
  134. component: 'RangePicker',
  135. defaultValue: [priorDate, today],
  136. colProps: {
  137. xl: 16,
  138. xxl: 16,
  139. },
  140. componentProps: {
  141. format: 'YYYY-MM-DD',
  142. showTime: false,
  143. disabledDate(current) {
  144. // console.log('current', current, date);
  145. return current && current > dateUtil().endOf('day');
  146. },
  147. // onChange: (value) => {
  148. // console.log('onchange', value);
  149. // },
  150. },
  151. },
  152. ],
  153. resetFunc: handleReset,
  154. };
  155. const searchInfo = ref({
  156. liveRoomId: '',
  157. limit: 20,
  158. page: 1,
  159. time: [priorDate, today],
  160. });
  161. const [registerTable] = useTable({
  162. title: '房间留言状态',
  163. columns: columns,
  164. useSearchForm: true,
  165. formConfig: searchForm,
  166. immediate: true,
  167. api: bulletChatApi,
  168. beforeFetch: (data) => {
  169. console.log('beforeFetch', data);
  170. data.time = data.time.map((item) => formatToDate(item));
  171. handleStatic(data);
  172. searchInfo.value = data;
  173. return data;
  174. },
  175. afterFetch: function (data) {
  176. console.log('afterFetch', arguments);
  177. return data;
  178. },
  179. searchInfo: searchInfo,
  180. handleSearchInfoFn(data) {
  181. searchInfo.value = Object.assign(searchInfo.value, data);
  182. console.log(searchInfo.value);
  183. },
  184. });
  185. onMounted(() => {
  186. handleStatic();
  187. });
  188. async function handleStatic(search?: any) {
  189. try {
  190. loading.value = true;
  191. const searchInfoParams = search || searchInfo.value;
  192. const sData = await userStaticsApi(searchInfoParams);
  193. const bData = await bulletChatStaticsApi(searchInfoParams);
  194. console.log('sData', sData);
  195. console.log('bData', sData);
  196. viewStaticsData.value = sData.viewStatics;
  197. shareStaticsData.value = sData.shareStatics;
  198. userAmountData.value = bData.userAmount;
  199. bulletChatAmountsData.value = bData.bulletChatAmounts;
  200. loading.value = false;
  201. } catch (error) {
  202. loading.value = false;
  203. }
  204. }
  205. async function handleExport() {
  206. const data = await bulletChatExportApi(searchInfo.value);
  207. const downloadBlob = new Blob([data], {
  208. type: 'application/msexcel',
  209. });
  210. const url = URL.createObjectURL(downloadBlob);
  211. const a: HTMLAnchorElement = document.createElement('a');
  212. document.body.appendChild(a);
  213. a.style.display = 'none';
  214. a.href = url;
  215. const name = new Date().getTime();
  216. a.download = `${name}.csv`;
  217. a.click();
  218. window.URL.revokeObjectURL(url);
  219. }
  220. async function handleReset() {
  221. searchInfo.value = {
  222. liveRoomId: '',
  223. limit: 20,
  224. page: 1,
  225. time: [priorDate, today],
  226. };
  227. }
  228. // setTimeout(() => {
  229. // loading.value = false;
  230. // }, 1500);
  231. </script>