enterprise.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. width: 120,
  68. },
  69. {
  70. title: '总直播时长',
  71. dataIndex: 'duration',
  72. width: 120,
  73. },
  74. {
  75. title: '总分享人数',
  76. dataIndex: 'shareNum',
  77. width: 120,
  78. },
  79. ];
  80. const searchForm: Partial<FormProps> = {
  81. labelWidth: 100,
  82. schemas: [
  83. {
  84. field: 'companyId',
  85. label: '请选择企业',
  86. component: 'ApiSelect',
  87. required: false,
  88. componentProps: {
  89. api: ListCorporationApi,
  90. resultField: 'list',
  91. labelField: 'name',
  92. valueField: 'id',
  93. immediate: false,
  94. showSearch: true,
  95. optionFilterProp: 'label',
  96. // onChange: function (_, opt) {
  97. // // Reflect.set(modalRecord, 'shippingName', opt.label);
  98. // },
  99. params: {
  100. page: 1,
  101. limit: 1000,
  102. },
  103. },
  104. colProps: {
  105. lg: 24,
  106. md: 24,
  107. xl: 12,
  108. xxl: 12,
  109. // xl: 5,
  110. // xxl: 12,
  111. },
  112. },
  113. {
  114. field: 'liveRoomId',
  115. label: '请选择房间',
  116. component: 'ApiSelect',
  117. colProps: {
  118. lg: 24,
  119. md: 24,
  120. xl: 12,
  121. xxl: 12,
  122. },
  123. componentProps: {
  124. api: listRoomsApi,
  125. resultField: 'list',
  126. labelField: 'name',
  127. valueField: 'id',
  128. immediate: false,
  129. showSearch: true,
  130. optionFilterProp: 'label',
  131. // onChange: function (_, opt) {
  132. // // Reflect.set(modalRecord, 'shippingName', opt.label);
  133. // },
  134. params: {
  135. page: 1,
  136. limit: 1000,
  137. },
  138. },
  139. },
  140. {
  141. field: 'brandId',
  142. label: '请选择直播场景',
  143. labelWidth: 130,
  144. component: 'ApiSelect',
  145. colProps: {
  146. lg: 24,
  147. md: 24,
  148. xl: 12,
  149. xxl: 12,
  150. },
  151. componentProps: {
  152. api: ListLiveApi,
  153. resultField: 'list',
  154. labelField: 'sceneName',
  155. valueField: 'id',
  156. immediate: false,
  157. showSearch: true,
  158. optionFilterProp: 'label',
  159. params: {
  160. page: 1,
  161. limit: 1000,
  162. },
  163. },
  164. },
  165. {
  166. field: 'time',
  167. label: '时间段',
  168. defaultValue: [priorDate, today],
  169. component: 'RangePicker',
  170. colProps: {
  171. lg: 24,
  172. md: 24,
  173. xl: 12,
  174. xxl: 12,
  175. },
  176. componentProps: {
  177. format: 'YYYY-MM-DD',
  178. // placeholder: ['开始时间', '结束时间'],
  179. // showTime: { format: 'HH:mm:ss' },
  180. disabledDate(current) {
  181. // console.log('current', current, date);
  182. return current && current > dateUtil().endOf('day');
  183. },
  184. },
  185. },
  186. ],
  187. resetFunc: handleReset,
  188. };
  189. const searchInfo = ref({
  190. liveRoomId: '',
  191. companyId: '',
  192. brandId: '',
  193. limit: 20,
  194. page: 1,
  195. time: [priorDate, today],
  196. });
  197. const [registerTable] = useTable({
  198. title: '',
  199. columns: columns,
  200. useSearchForm: true,
  201. formConfig: searchForm,
  202. api: liveRoomStaticsApi,
  203. beforeFetch: (data) => {
  204. console.log('beforeFetch', data);
  205. data.time = data.time.map((item) => formatToDate(item));
  206. searchInfo.value = data;
  207. return data;
  208. },
  209. afterFetch: function (data) {
  210. console.log('data', data);
  211. return data;
  212. },
  213. searchInfo: searchInfo,
  214. });
  215. async function handleExport() {
  216. const data = await companyChatExportApi(searchInfo.value);
  217. const downloadBlob = new Blob([data], {
  218. type: 'application/msexcel',
  219. });
  220. const url = URL.createObjectURL(downloadBlob);
  221. const a: HTMLAnchorElement = document.createElement('a');
  222. document.body.appendChild(a);
  223. a.style.display = 'none';
  224. a.href = url;
  225. const name = new Date().getTime();
  226. a.download = `${name}.csv`;
  227. a.click();
  228. window.URL.revokeObjectURL(url);
  229. }
  230. async function handleReset() {
  231. searchInfo.value = {
  232. liveRoomId: '',
  233. companyId: '',
  234. brandId: '',
  235. limit: 20,
  236. page: 1,
  237. time: [priorDate, today],
  238. };
  239. }
  240. </script>