enterprise.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="p-4">
  3. <!-- <GrowCard :loading="loading" class="enter-y" /> -->
  4. <BasicTable @register="registerTable" :loading="loading">
  5. <template #toolbar>
  6. <a-button type="primary" @click="handleExport">导出数据</a-button>
  7. </template>
  8. </BasicTable>
  9. <!-- <div class="md:flex enter-y">
  10. <div class="md:w-1/2 enter-y">
  11. <Card class="w-full">
  12. <VisitAnalysisBar :loading="loading" />
  13. </Card>
  14. </div>
  15. <div class="!md:mx-2"></div>
  16. <Card class="md:w-1/2 enter-y">
  17. <VisitAnalysis :loading="loading" />
  18. </Card>
  19. </div>
  20. <div class="md:flex enter-y mt-4">
  21. <Card class="md:w-1/2 md:w-full"> </Card>
  22. </div> -->
  23. </div>
  24. </template>
  25. <script lang="ts" setup>
  26. import { ref } from 'vue';
  27. import { BasicTable, useTable, BasicColumn, FormProps } from '/@/components/Table';
  28. // import { useI18n } from '/@/hooks/web/useI18n';
  29. // import GrowCard from './components/GrowCard.vue';
  30. import {
  31. liveRoomStaticsApi,
  32. // bulletChatStaticsApi,
  33. companyChatExportApi,
  34. } from '/@/api/dashboard/analysis';
  35. import { ListApi as ListCorporationApi } from '/@/api/corporation/list';
  36. import { listRoomsApi } from '/@/api/scene/list';
  37. import { ListApi as ListLiveApi } from '/@/api/scene/live';
  38. import { dateUtil, formatToDate } from '/@/utils/dateUtil';
  39. const loading = ref(true);
  40. // const { t } = useI18n();
  41. const today = formatToDate(dateUtil(new Date()));
  42. const priorDate = formatToDate(dateUtil(new Date().setDate(new Date().getDate() - 30)));
  43. const columns: BasicColumn[] = [
  44. {
  45. title: '企业名称',
  46. dataIndex: 'companyName',
  47. width: 120,
  48. },
  49. {
  50. title: '房间名称',
  51. dataIndex: 'liveRoomName',
  52. width: 120,
  53. },
  54. {
  55. title: '直播场景名称',
  56. dataIndex: 'brandName',
  57. width: 120,
  58. },
  59. {
  60. title: '主持人',
  61. dataIndex: 'anchorName',
  62. width: 120,
  63. },
  64. {
  65. title: '总观看人数',
  66. dataIndex: 'spectatorNum',
  67. // sorter: true,
  68. width: 120,
  69. },
  70. {
  71. title: '总直播时长(min)',
  72. dataIndex: 'duration',
  73. // sorter: true,
  74. width: 120,
  75. },
  76. {
  77. title: '总分享数',
  78. dataIndex: 'shareNum',
  79. // sorter: true,
  80. width: 120,
  81. },
  82. ];
  83. const searchForm: Partial<FormProps> = {
  84. labelWidth: 100,
  85. schemas: [
  86. {
  87. field: 'companyId',
  88. label: '请选择企业',
  89. component: 'ApiSelect',
  90. required: false,
  91. componentProps: {
  92. api: ListCorporationApi,
  93. resultField: 'list',
  94. labelField: 'name',
  95. valueField: 'id',
  96. immediate: false,
  97. showSearch: true,
  98. optionFilterProp: 'label',
  99. // onChange: function (_, opt) {
  100. // // Reflect.set(modalRecord, 'shippingName', opt.label);
  101. // },
  102. params: {
  103. page: 1,
  104. limit: 1000,
  105. },
  106. },
  107. colProps: {
  108. lg: 24,
  109. md: 24,
  110. xl: 12,
  111. xxl: 12,
  112. // xl: 5,
  113. // xxl: 12,
  114. },
  115. },
  116. {
  117. field: 'liveRoomId',
  118. label: '请选择房间',
  119. component: 'ApiSelect',
  120. colProps: {
  121. lg: 24,
  122. md: 24,
  123. xl: 12,
  124. xxl: 12,
  125. },
  126. componentProps: {
  127. api: listRoomsApi,
  128. resultField: 'list',
  129. labelField: 'name',
  130. valueField: 'id',
  131. immediate: false,
  132. showSearch: true,
  133. optionFilterProp: 'label',
  134. // onChange: function (_, opt) {
  135. // // Reflect.set(modalRecord, 'shippingName', opt.label);
  136. // },
  137. params: {
  138. page: 1,
  139. limit: 1000,
  140. state: 103,
  141. },
  142. },
  143. },
  144. {
  145. field: 'brandId',
  146. label: '请选择直播场景',
  147. labelWidth: 130,
  148. component: 'ApiSelect',
  149. colProps: {
  150. lg: 24,
  151. md: 24,
  152. xl: 12,
  153. xxl: 12,
  154. },
  155. componentProps: {
  156. api: ListLiveApi,
  157. resultField: 'list',
  158. labelField: 'name',
  159. valueField: 'id',
  160. immediate: false,
  161. showSearch: true,
  162. optionFilterProp: 'label',
  163. params: {
  164. page: 1,
  165. limit: 1000,
  166. },
  167. },
  168. },
  169. {
  170. field: 'time',
  171. label: '时间段',
  172. defaultValue: [priorDate, today],
  173. component: 'RangePicker',
  174. colProps: {
  175. lg: 24,
  176. md: 24,
  177. xl: 12,
  178. xxl: 12,
  179. },
  180. componentProps: {
  181. format: 'YYYY-MM-DD',
  182. // placeholder: ['开始时间', '结束时间'],
  183. // showTime: { format: 'HH:mm:ss' },
  184. disabledDate(current) {
  185. // console.log('current', current, date);
  186. return current && current > dateUtil().endOf('day');
  187. },
  188. },
  189. rules: [
  190. {
  191. required: true,
  192. // @ts-ignore
  193. validator: async (rule, value) => {
  194. if (!value) {
  195. return Promise.reject('请选择时间段');
  196. }
  197. const days = Math.abs(value[1].diff(value[0], 'days'));
  198. console.log('days', days);
  199. if (days > 30) {
  200. return Promise.reject('选择时间段应小于30天');
  201. }
  202. if (days < 1) {
  203. return Promise.reject('至少选择2天以上');
  204. }
  205. return Promise.resolve();
  206. },
  207. trigger: 'change',
  208. },
  209. ],
  210. },
  211. ],
  212. resetFunc: handleReset,
  213. };
  214. const searchInfo = ref({
  215. liveRoomId: '',
  216. companyId: '',
  217. brandId: '',
  218. limit: 20,
  219. page: 1,
  220. time: [priorDate, today],
  221. });
  222. const [registerTable] = useTable({
  223. title: '',
  224. columns: columns,
  225. useSearchForm: true,
  226. formConfig: searchForm,
  227. api: liveRoomStaticsApi,
  228. beforeFetch: (data) => {
  229. console.log('beforeFetch', data);
  230. data.time = data.time.map((item) => formatToDate(item));
  231. searchInfo.value = data;
  232. return data;
  233. },
  234. afterFetch: function (data) {
  235. console.log('data', data);
  236. return data;
  237. },
  238. searchInfo: searchInfo,
  239. handleSearchInfoFn(data) {
  240. searchInfo.value = Object.assign(searchInfo.value, data);
  241. console.log(searchInfo.value);
  242. },
  243. });
  244. async function handleExport() {
  245. const data = await companyChatExportApi(searchInfo.value);
  246. const downloadBlob = new Blob([data], {
  247. type: 'application/msexcel',
  248. });
  249. const url = URL.createObjectURL(downloadBlob);
  250. const a: HTMLAnchorElement = document.createElement('a');
  251. document.body.appendChild(a);
  252. a.style.display = 'none';
  253. a.href = url;
  254. const name = new Date().getTime();
  255. a.download = `${name}.csv`;
  256. a.click();
  257. window.URL.revokeObjectURL(url);
  258. }
  259. async function handleReset() {
  260. searchInfo.value = {
  261. liveRoomId: '',
  262. companyId: '',
  263. brandId: '',
  264. limit: 20,
  265. page: 1,
  266. time: [priorDate, today],
  267. };
  268. }
  269. </script>