index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. ellipsis: true,
  79. customRender: ({ record }) => {
  80. const { nickName } = record;
  81. return nickName?.length ? nickName : ' -- ';
  82. },
  83. },
  84. {
  85. title: '手机号',
  86. dataIndex: 'userName',
  87. width: 120,
  88. },
  89. {
  90. title: '房间名称',
  91. dataIndex: 'liveRoomName',
  92. width: 120,
  93. },
  94. {
  95. title: '在线时长(min)',
  96. dataIndex: 'duration',
  97. width: 120,
  98. },
  99. {
  100. title: '留言条数',
  101. dataIndex: 'bulletChatAmount',
  102. width: 120,
  103. },
  104. {
  105. title: '留言内容',
  106. dataIndex: 'bulletChatContents',
  107. width: 320,
  108. },
  109. ];
  110. const searchForm: Partial<FormProps> = {
  111. labelWidth: 100,
  112. schemas: [
  113. {
  114. field: 'liveRoomId',
  115. label: '全部房间',
  116. component: 'ApiSelect',
  117. // required: true,
  118. colProps: {
  119. xl: 5,
  120. xxl: 5,
  121. },
  122. componentProps: {
  123. api: listRoomsApi,
  124. labelField: 'name',
  125. resultField: 'list',
  126. valueField: 'id',
  127. immediate: false,
  128. showSearch: true,
  129. optionFilterProp: 'label',
  130. params: {
  131. page: 1,
  132. limit: 1000,
  133. },
  134. },
  135. },
  136. {
  137. field: 'time',
  138. label: '时间段',
  139. component: 'RangePicker',
  140. defaultValue: [priorDate, today],
  141. colProps: {
  142. xl: 16,
  143. xxl: 16,
  144. },
  145. componentProps: {
  146. format: 'YYYY-MM-DD',
  147. showTime: false,
  148. disabledDate(current) {
  149. // console.log('current', current, date);
  150. return current && current > dateUtil().endOf('day');
  151. },
  152. // onChange: (value) => {
  153. // console.log('onchange', value);
  154. // },
  155. },
  156. rules: [
  157. {
  158. required: true,
  159. // @ts-ignore
  160. validator: async (rule, value) => {
  161. if (!value) {
  162. return Promise.reject('请选择时间段');
  163. }
  164. const days = Math.abs(value[1].diff(value[0], 'days'));
  165. console.log('days', days);
  166. if (days > 30) {
  167. return Promise.reject('请选择小于一个月');
  168. }
  169. if (days < 1) {
  170. return Promise.reject('至少选择2天以上');
  171. }
  172. return Promise.resolve();
  173. },
  174. trigger: 'change',
  175. },
  176. ],
  177. },
  178. ],
  179. resetFunc: handleReset,
  180. };
  181. const searchInfo = ref({
  182. liveRoomId: '',
  183. limit: 20,
  184. page: 1,
  185. time: [priorDate, today],
  186. });
  187. const [registerTable] = useTable({
  188. title: '房间留言状态',
  189. columns: columns,
  190. useSearchForm: true,
  191. formConfig: searchForm,
  192. immediate: true,
  193. api: bulletChatApi,
  194. beforeFetch: (data) => {
  195. console.log('beforeFetch', data);
  196. data.time = data.time.map((item) => formatToDate(item));
  197. handleStatic(data);
  198. searchInfo.value = data;
  199. return data;
  200. },
  201. afterFetch: function (data) {
  202. console.log('afterFetch', arguments);
  203. return data;
  204. },
  205. searchInfo: searchInfo,
  206. handleSearchInfoFn(data) {
  207. searchInfo.value = Object.assign(searchInfo.value, data);
  208. console.log(searchInfo.value);
  209. return;
  210. },
  211. });
  212. onMounted(() => {
  213. handleStatic();
  214. });
  215. async function handleStatic(search?: any) {
  216. try {
  217. loading.value = true;
  218. const searchInfoParams = search || searchInfo.value;
  219. const sData = await userStaticsApi(searchInfoParams);
  220. const bData = await bulletChatStaticsApi(searchInfoParams);
  221. console.log('sData', sData);
  222. console.log('bData', sData);
  223. viewStaticsData.value = sData.viewStatics;
  224. shareStaticsData.value = sData.shareStatics;
  225. userAmountData.value = bData.userAmount;
  226. bulletChatAmountsData.value = bData.bulletChatAmounts;
  227. loading.value = false;
  228. } catch (error) {
  229. loading.value = false;
  230. }
  231. }
  232. async function handleExport() {
  233. const data = await bulletChatExportApi(searchInfo.value);
  234. const downloadBlob = new Blob([data], {
  235. type: 'application/msexcel',
  236. });
  237. const url = URL.createObjectURL(downloadBlob);
  238. const a: HTMLAnchorElement = document.createElement('a');
  239. document.body.appendChild(a);
  240. a.style.display = 'none';
  241. a.href = url;
  242. const name = new Date().getTime();
  243. a.download = `${name}.csv`;
  244. a.click();
  245. window.URL.revokeObjectURL(url);
  246. }
  247. async function handleReset() {
  248. searchInfo.value = {
  249. liveRoomId: '',
  250. limit: 20,
  251. page: 1,
  252. time: [priorDate, today],
  253. };
  254. }
  255. // setTimeout(() => {
  256. // loading.value = false;
  257. // }, 1500);
  258. </script>