all.vue 23 KB

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