index.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['menu.dashboard', 'menu.dashboard.dailyLog']" />
  4. <a-card class="general-card" :title="$t('menu.dashboard.dailyLog')">
  5. <a-row>
  6. <a-col :flex="1">
  7. <a-form :model="formModel" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
  8. label-align="left">
  9. <a-row :gutter="16">
  10. <a-col :span="8">
  11. <a-form-item field="query_date" :label="$t('searchTable.form.report_date')">
  12. <a-range-picker v-model="formModel.query_date" style="width: 100%"
  13. @change="search" />
  14. </a-form-item>
  15. </a-col>
  16. </a-row>
  17. </a-form>
  18. </a-col>
  19. <a-divider style="height: 32px" direction="vertical" />
  20. <a-col :flex="'86px'" style="text-align: right">
  21. <a-space direction="vertical" :size="18">
  22. <a-button type="primary" @click="search">
  23. <template #icon>
  24. <icon-search />
  25. </template>
  26. {{ $t('searchTable.form.search') }}
  27. </a-button>
  28. </a-space>
  29. </a-col>
  30. </a-row>
  31. <a-divider style="margin-top: 0" />
  32. <a-row style="margin-bottom: 16px">
  33. <a-col :span="12"> </a-col>
  34. <a-col :span="12" style="
  35. display: flex;
  36. align-items: center;
  37. justify-content: end;
  38. ">
  39. <a-tooltip :content="$t('searchTable.actions.refresh')">
  40. <div class="action-icon" @click="search"><icon-refresh size="18" /></div>
  41. </a-tooltip>
  42. <a-dropdown @select="handleSelectDensity">
  43. <a-tooltip :content="$t('searchTable.actions.density')">
  44. <div class="action-icon"><icon-line-height size="18" /></div>
  45. </a-tooltip>
  46. <template #content>
  47. <a-doption v-for="item in densityList" :key="item.value" :value="item.value"
  48. :class="{ active: item.value === size }">
  49. <span>{{ item.name }}</span>
  50. </a-doption>
  51. </template>
  52. </a-dropdown>
  53. <a-tooltip :content="$t('searchTable.actions.columnSetting')">
  54. <a-popover trigger="click" position="bl" @popup-visible-change="popupVisibleChange">
  55. <div class="action-icon"><icon-settings size="18" /></div>
  56. <template #content>
  57. <div id="tableSetting">
  58. <div v-for="(item, index) in showColumns" :key="item.dataIndex" class="setting">
  59. <div style="
  60. margin-right: 4px;
  61. cursor: move;
  62. ">
  63. <icon-drag-arrow />
  64. </div>
  65. <div>
  66. <a-checkbox v-model="item.checked" @change="
  67. handleChange(
  68. $event,
  69. item as TableColumnData,
  70. index
  71. )
  72. ">
  73. </a-checkbox>
  74. </div>
  75. <div class="title">
  76. {{
  77. item.title === '#'
  78. ? '序列号'
  79. : item.title
  80. }}
  81. </div>
  82. </div>
  83. </div>
  84. </template>
  85. </a-popover>
  86. </a-tooltip>
  87. </a-col>
  88. </a-row>
  89. <a-table row-key="id" :loading="loading" :pagination="pagination" :summary="true" summary-text="汇总"
  90. :columns="(cloneColumns as TableColumnData[])" :scroll="scroll" :scrollbar="scrollbar"
  91. :data="renderData" :bordered="{ headerCell: true }" :size="size" :load-more="loadMore"
  92. @page-change="onPageChange" @page-size-change="onPageSizeChange">
  93. <template #index="{ rowIndex }">
  94. {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
  95. </template>
  96. <template #xAxis="{ record }">
  97. <template v-if="record.isLeaf">
  98. {{ record.accountName }}
  99. </template>
  100. <template v-else>
  101. {{ dayjs(record.log_date).format('YYYY-MM-DD') }}
  102. </template>
  103. </template>
  104. <template #total_count="{ record }">
  105. <a-popover v-if="record.total_count > 0" popup-container="body" trigger="click">
  106. <a-tag color="green">{{ record.total_count }}</a-tag>
  107. <template #content>
  108. <CategoriesPercent total_key="total" :record="record" />
  109. </template>
  110. </a-popover>
  111. </template>
  112. <template #parse_total_count="{ record }">
  113. <a-popover v-if="record.parse_total_count > 0" popup-container="body" trigger="click">
  114. <a-tag color="green">{{ record.parse_total_count }}</a-tag>
  115. <template #content>
  116. <CategoriesPercent total_key="parse_total" :record="record" />
  117. </template>
  118. </a-popover>
  119. </template>
  120. <template #jd_parse_total_count="{ record }">
  121. <a-popover v-if="record.jd_parse_total_count > 0" popup-container="body" trigger="click">
  122. <a-tag color="green">{{ record.jd_parse_total_count }}</a-tag>
  123. <template #content>
  124. <CategoriesPercent total_key="jd_parse_total" :record="record" />
  125. </template>
  126. </a-popover>
  127. </template>
  128. <template #coupon_total_count="{ record }">
  129. <a-popover v-if="record.coupon_total_count > 0" popup-container="body" trigger="click">
  130. <a-tag color="green">{{ record.coupon_total_count }}</a-tag>
  131. <template #content>
  132. <CategoriesPercent total_key="coupon_total" :record="record" />
  133. </template>
  134. </a-popover>
  135. </template>
  136. <template #tool_total_count="{ record }">
  137. <a-popover v-if="record.tool_total_count > 0" popup-container="body" trigger="click">
  138. <a-tag color="green">{{ record.tool_total_count }}</a-tag>
  139. <template #content>
  140. <CategoriesPercent total_key="tool_total" :record="record" />
  141. </template>
  142. </a-popover>
  143. </template>
  144. <template #summary-cell="{ column, record }">
  145. <template v-if="column.slotName == 'total_count'">
  146. <a-tag v-if="record.total_count > 0" color="green">{{ record.total_count }}</a-tag>
  147. </template>
  148. <template v-else-if="column.slotName == 'parse_total_count'">
  149. <a-tag v-if="record.parse_total_count > 0" color="green">
  150. {{ record.parse_total_count }}</a-tag>
  151. </template>
  152. <template v-else-if="column.slotName == 'coupon_total_count'">
  153. <a-tag v-if="record.coupon_total_count > 0" color="green">
  154. {{ record.coupon_total_count }}</a-tag>
  155. </template>
  156. <template v-else-if="column.slotName == 'jd_parse_total_count'">
  157. <a-tag v-if="record.jd_parse_total_count > 0" color="green">
  158. {{ record.jd_parse_total_count }}</a-tag>
  159. </template>
  160. <template v-else>
  161. <div>{{ toAmount(record[column.dataIndex]) }}</div>
  162. </template>
  163. </template>
  164. </a-table>
  165. </a-card>
  166. </div>
  167. </template>
  168. <script lang="ts" setup>
  169. import { useRouter } from 'vue-router';
  170. import { computed, ref, reactive, watch, nextTick } from 'vue';
  171. import { useI18n } from 'vue-i18n';
  172. import dayjs from 'dayjs';
  173. import useLoading from '@/hooks/loading';
  174. import { queryDailyLog, DailyLogRecord, DailyLogParams } from '@/api/app';
  175. import { Pagination } from '@/types/global';
  176. import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
  177. import type { TableData, TableColumnData } from '@arco-design/web-vue/es/table/interface';
  178. import cloneDeep from 'lodash/cloneDeep';
  179. import Sortable from 'sortablejs';
  180. import CategoriesPercent from './components/categories-percent.vue';
  181. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  182. type Column = TableColumnData & { checked?: true };
  183. const generateFormModel = () => {
  184. return {
  185. accountName: 'all',
  186. current: 1,
  187. pageSize: 31,
  188. sort: 'log_date',
  189. order: 'descending'
  190. };
  191. };
  192. const router = useRouter();
  193. const { loading, setLoading } = useLoading(true);
  194. const { t } = useI18n();
  195. const renderData = ref<DailyLogRecord[]>([]);
  196. const formModel = ref(generateFormModel());
  197. const cloneColumns = ref<Column[]>([]);
  198. const showColumns = ref<Column[]>([]);
  199. const size = ref<SizeProps>('medium');
  200. const scrollbar = ref(true);
  201. const scroll = {
  202. x: '100%',
  203. y: '100%',
  204. maxHeight: 'calc( 100vh - 420px)',
  205. };
  206. const basePagination: Pagination = {
  207. current: 1,
  208. pageSize: 31,
  209. };
  210. const pagination = reactive({
  211. ...basePagination,
  212. showTotal: true,
  213. showJumper: true,
  214. showMore: true,
  215. showPageSize: true,
  216. pageSizeOptions: [10, 20, 30, 31, 50, 100, 200],
  217. sizePageSize: true,
  218. });
  219. const densityList = computed(() => [
  220. {
  221. name: t('searchTable.size.mini'),
  222. value: 'mini',
  223. },
  224. {
  225. name: t('searchTable.size.small'),
  226. value: 'small',
  227. },
  228. {
  229. name: t('searchTable.size.medium'),
  230. value: 'medium',
  231. },
  232. {
  233. name: t('searchTable.size.large'),
  234. value: 'large',
  235. },
  236. ]);
  237. const toAmount = (val: any): any => {
  238. console.log(val);
  239. if (typeof val === 'number' && !Number.isNaN(val)) {
  240. return parseFloat(val.toFixed(2));
  241. }
  242. return val;
  243. }
  244. const columns = computed<TableColumnData[]>(() => [
  245. {
  246. title: '日期',
  247. dataIndex: 'xAxis',
  248. slotName: 'xAxis',
  249. width: 250,
  250. fixed: 'left',
  251. },
  252. {
  253. title: '转链API调用',
  254. children: [
  255. {
  256. title: '调用',
  257. slotName: 'parse_total_count',
  258. dataIndex: 'parse_total_count',
  259. width: 100,
  260. align: 'right'
  261. },
  262. {
  263. title: '成功',
  264. dataIndex: 'parse_success_count',
  265. width: 100,
  266. align: 'right'
  267. },
  268. {
  269. title: '成功(%)',
  270. dataIndex: 'parse_success_percentage',
  271. width: 90,
  272. align: 'right'
  273. },
  274. {
  275. title: '放弃',
  276. dataIndex: 'parse_abandon_count',
  277. width: 100,
  278. align: 'right'
  279. },
  280. {
  281. title: '放弃(%)',
  282. dataIndex: 'parse_abandon_percentage',
  283. width: 90,
  284. align: 'right'
  285. },
  286. ]
  287. },
  288. {
  289. title: '优惠券API调用',
  290. children: [
  291. {
  292. title: '调用',
  293. slotName: 'coupon_total_count',
  294. dataIndex: 'coupon_total_count',
  295. width: 100,
  296. align: 'right'
  297. },
  298. {
  299. title: '成功',
  300. dataIndex: 'coupon_success_count',
  301. width: 100,
  302. align: 'right'
  303. },
  304. {
  305. title: '成功(%)',
  306. dataIndex: 'coupon_success_percentage',
  307. width: 90,
  308. align: 'right'
  309. },
  310. {
  311. title: '放弃',
  312. dataIndex: 'coupon_abandon_count',
  313. width: 100,
  314. align: 'right'
  315. },
  316. {
  317. title: '放弃(%)',
  318. dataIndex: 'coupon_abandon_percentage',
  319. width: 90,
  320. align: 'right'
  321. },
  322. ]
  323. },
  324. {
  325. title: '京东转链API调用',
  326. children: [
  327. {
  328. title: '调用',
  329. slotName: 'jd_parse_total_count',
  330. dataIndex: 'jd_parse_total_count',
  331. width: 100,
  332. align: 'right'
  333. },
  334. {
  335. title: '成功',
  336. dataIndex: 'jd_parse_success_count',
  337. width: 100,
  338. align: 'right'
  339. },
  340. {
  341. title: '成功(%)',
  342. dataIndex: 'jd_parse_success_percentage',
  343. width: 90,
  344. align: 'right'
  345. },
  346. {
  347. title: '放弃',
  348. dataIndex: 'jd_parse_abandon_count',
  349. width: 100,
  350. align: 'right'
  351. },
  352. {
  353. title: '放弃(%)',
  354. dataIndex: 'jd_parse_abandon_percentage',
  355. width: 90,
  356. align: 'right'
  357. },
  358. ]
  359. },
  360. {
  361. title: '工具API调用',
  362. children: [
  363. {
  364. title: '调用',
  365. dataIndex: 'tool_total_count',
  366. slotName: 'tool_total_count',
  367. width: 100,
  368. align: 'right'
  369. },
  370. {
  371. title: '成功',
  372. dataIndex: 'tool_success_count',
  373. width: 100,
  374. align: 'right'
  375. },
  376. {
  377. title: '成功(%)',
  378. dataIndex: 'tool_success_percentage',
  379. width: 90,
  380. align: 'right'
  381. },
  382. {
  383. title: '放弃',
  384. dataIndex: 'tool_abandon_count',
  385. width: 100,
  386. align: 'right'
  387. },
  388. {
  389. title: '放弃(%)',
  390. dataIndex: 'tool_abandon_percentage',
  391. width: 90,
  392. align: 'right'
  393. },
  394. ]
  395. },
  396. {
  397. title: '第三方API调用',
  398. children: [
  399. {
  400. title: '调用',
  401. dataIndex: 'total_count',
  402. slotName: 'total_count',
  403. width: 100,
  404. align: 'right'
  405. },
  406. {
  407. title: '成功',
  408. dataIndex: 'success_count',
  409. width: 100,
  410. align: 'right'
  411. },
  412. {
  413. title: '成功(%)',
  414. dataIndex: 'success_percentage',
  415. width: 90,
  416. align: 'right'
  417. },
  418. {
  419. title: '放弃',
  420. dataIndex: 'abandon_count',
  421. width: 100,
  422. align: 'right'
  423. },
  424. {
  425. title: '放弃(%)',
  426. dataIndex: 'abandon_percentage',
  427. width: 90,
  428. align: 'right'
  429. },
  430. ]
  431. },
  432. ]);
  433. const onPageSizeChange = (current: number) => {
  434. basePagination.pageSize = current;
  435. pagination.pageSize = current;
  436. fetchData({
  437. ...basePagination,
  438. ...formModel.value,
  439. current: 1,
  440. });
  441. };
  442. const fetchData = async (
  443. params: DailyLogParams = {
  444. accountName: 'all',
  445. pageSize: basePagination.pageSize,
  446. current: 1,
  447. sort: 'log_date',
  448. order: 'descending'
  449. }
  450. ) => {
  451. setLoading(true);
  452. try {
  453. const { data } = await queryDailyLog(params);
  454. console.log(data);
  455. if (!data) return;
  456. // const { data } = await queryDailyLog(params);
  457. renderData.value = data.list;
  458. pagination.current = data.page;
  459. pagination.total = data.count;
  460. console.log(data)
  461. } catch (err) {
  462. console.log(err)
  463. // you can report use errorHandler or other
  464. } finally {
  465. setLoading(false);
  466. }
  467. };
  468. const loadMore = async (row: TableData, done: (data: TableData[]) => void) => {
  469. setLoading(true);
  470. try {
  471. const params: DailyLogParams = {
  472. query_date: [row.log_date, row.log_date],
  473. current: 1, pageSize: 999, sort: 'id', order: 'descending'
  474. };
  475. const { data } = await queryDailyLog(params);
  476. console.log(data);
  477. if (!data) return;
  478. const list: TableData[] = data.list.map((item: DailyLogRecord) => ({
  479. ...item,
  480. isLeaf: true
  481. }));
  482. done(list);
  483. } catch (err) {
  484. console.log(err)
  485. } finally {
  486. setLoading(false);
  487. }
  488. };
  489. const changeItem = async (
  490. data: DailyLogRecord
  491. ) => {
  492. router.push({ name: 'updateCookies' });
  493. };
  494. const search = () => {
  495. fetchData({
  496. ...basePagination,
  497. ...formModel.value,
  498. } as unknown as DailyLogParams);
  499. };
  500. const onPageChange = (current: number) => {
  501. fetchData({
  502. ...basePagination,
  503. ...formModel.value,
  504. current
  505. });
  506. };
  507. fetchData();
  508. const reset = () => {
  509. formModel.value = generateFormModel();
  510. };
  511. const handleSelectDensity = (
  512. val: string | number | Record<string, any> | undefined,
  513. e: Event
  514. ) => {
  515. size.value = val as SizeProps;
  516. };
  517. const handleChange = (
  518. checked: boolean | (string | boolean | number)[],
  519. column: Column,
  520. index: number
  521. ) => {
  522. if (!checked) {
  523. cloneColumns.value = showColumns.value.filter(
  524. (item) => item.dataIndex !== column.dataIndex
  525. );
  526. } else {
  527. cloneColumns.value.splice(index, 0, column);
  528. }
  529. };
  530. const exchangeArray = <T extends Array<any>>(
  531. array: T,
  532. beforeIdx: number,
  533. newIdx: number,
  534. isDeep = false
  535. ): T => {
  536. const newArray = isDeep ? cloneDeep(array) : array;
  537. if (beforeIdx > -1 && newIdx > -1) {
  538. // 先替换后面的,然后拿到替换的结果替换前面的
  539. newArray.splice(
  540. beforeIdx,
  541. 1,
  542. newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
  543. );
  544. }
  545. return newArray;
  546. };
  547. const popupVisibleChange = (val: boolean) => {
  548. if (val) {
  549. nextTick(() => {
  550. const el = document.getElementById('tableSetting') as HTMLElement;
  551. const sortable = new Sortable(el, {
  552. onEnd(e: any) {
  553. const { oldIndex, newIndex } = e;
  554. exchangeArray(cloneColumns.value, oldIndex, newIndex);
  555. exchangeArray(showColumns.value, oldIndex, newIndex);
  556. },
  557. });
  558. });
  559. }
  560. };
  561. watch(
  562. () => columns.value,
  563. (val) => {
  564. cloneColumns.value = cloneDeep(val);
  565. cloneColumns.value.forEach((item, index) => {
  566. item.checked = true;
  567. });
  568. showColumns.value = cloneDeep(cloneColumns.value);
  569. },
  570. { deep: true, immediate: true }
  571. );
  572. </script>
  573. <script lang="ts">
  574. export default {
  575. name: 'SearchTable',
  576. };
  577. </script>
  578. <style scoped lang="less">
  579. .container {
  580. padding: 0 20px 20px 20px;
  581. }
  582. :deep(.arco-table-th) {
  583. &:last-child {
  584. .arco-table-th-item-title {
  585. margin-left: 16px;
  586. }
  587. }
  588. }
  589. .action-icon {
  590. margin-left: 12px;
  591. cursor: pointer;
  592. }
  593. .active {
  594. color: #0960bd;
  595. background-color: #e3f4fc;
  596. }
  597. .setting {
  598. display: flex;
  599. align-items: center;
  600. width: 200px;
  601. .title {
  602. margin-left: 12px;
  603. cursor: pointer;
  604. }
  605. }
  606. </style>