| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- <template>
- <div class="container">
- <Breadcrumb :items="['menu.taobao', 'menu.taobao.list']" />
- <a-card class="general-card" :title="$t('menu.taobao.list')">
- <a-row style="margin-bottom: 16px">
- <a-col :span="12">
- </a-col>
- <a-col :span="12" style="display: flex; align-items: center; justify-content: end">
- <a-tooltip :content="$t('searchTable.actions.refresh')">
- <div class="action-icon" @click="search"><icon-refresh size="18" /></div>
- </a-tooltip>
- <a-dropdown @select="handleSelectDensity">
- <a-tooltip :content="$t('searchTable.actions.density')">
- <div class="action-icon"><icon-line-height size="18" /></div>
- </a-tooltip>
- <template #content>
- <a-doption v-for="item in densityList" :key="item.value" :value="item.value"
- :class="{ active: item.value === size }">
- <span>{{ item.name }}</span>
- </a-doption>
- </template>
- </a-dropdown>
- <a-tooltip :content="$t('searchTable.actions.columnSetting')">
- <a-popover trigger="click" position="bl" @popup-visible-change="popupVisibleChange">
- <div class="action-icon"><icon-settings size="18" /></div>
- <template #content>
- <div id="tableSetting">
- <div v-for="(item, index) in showColumns" :key="item.dataIndex" class="setting">
- <div style="margin-right: 4px; cursor: move">
- <icon-drag-arrow />
- </div>
- <div>
- <a-checkbox v-model="item.checked" @change="
- handleChange($event, item as TableColumnData, index)
- ">
- </a-checkbox>
- </div>
- <div class="title">
- {{ item.title === '#' ? '序列号' : item.title }}
- </div>
- </div>
- </div>
- </template>
- </a-popover>
- </a-tooltip>
- </a-col>
- </a-row>
-
- <a-table row-key="id" :loading="loading" :pagination="pagination" :columns="(cloneColumns as TableColumnData[])"
- :data="renderData" :bordered="false" :size="size" @page-change="onPageChange" :load-more="loadMore">
- <template #index="{ rowIndex }">
- {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
- </template>
- <template #xAxis="{ record }">
- <template v-if="record.isLeaf">
- {{ record.accountName }}
- </template>
- <template v-else>
- {{ dayjs(record.log_date).format('YYYY-MM-DD') }}
- </template>
- </template>
-
- </a-table>
- </a-card>
- </div>
- </template>
-
- <script lang="ts" setup>
- import { useRouter } from 'vue-router';
- import { computed, ref, reactive, watch, nextTick } from 'vue';
- import { useI18n } from 'vue-i18n';
- import dayjs from 'dayjs';
- import useLoading from '@/hooks/loading';
- import { queryDailyLog, DailyLogRecord, DailyLogParams } from '@/api/taobao';
- import { Pagination } from '@/types/global';
- import type { SelectOptionData } from '@arco-design/web-vue/es/select/interface';
- import type { TableData, TableColumnData } from '@arco-design/web-vue/es/table/interface';
- import cloneDeep from 'lodash/cloneDeep';
- import Sortable from 'sortablejs';
-
- type SizeProps = 'mini' | 'small' | 'medium' | 'large';
- type Column = TableColumnData & { checked?: true };
-
- const generateFormModel = () => {
- return {
- accountName: 'all',
- current: 1, pageSize: 20, sort: 'log_date', order: 'descending'
-
- };
- };
- const router = useRouter();
-
- const { loading, setLoading } = useLoading(true);
- const { t } = useI18n();
- const renderData = ref<DailyLogRecord[]>([]);
- const formModel = ref(generateFormModel());
- const cloneColumns = ref<Column[]>([]);
- const showColumns = ref<Column[]>([]);
-
- const size = ref<SizeProps>('medium');
-
- const basePagination: Pagination = {
- current: 1,
- pageSize: 20,
- };
- const pagination = reactive({
- ...basePagination,
- });
- const densityList = computed(() => [
- {
- name: t('searchTable.size.mini'),
- value: 'mini',
- },
- {
- name: t('searchTable.size.small'),
- value: 'small',
- },
- {
- name: t('searchTable.size.medium'),
- value: 'medium',
- },
- {
- name: t('searchTable.size.large'),
- value: 'large',
- },
- ]);
-
- const columns = computed<TableColumnData[]>(() => [
- {
- title: '日期',
- slotName: 'xAxis',
- },
- {
- title: 'API调用数',
- dataIndex: 'total_count',
- },
- {
- title: '转链成功数',
- dataIndex: 'success_count',
- },
- {
- title: '转链成功率 %',
- dataIndex: 'success_percentage',
- slotName: 'success_percentage',
- },
- {
- title: '放弃转链数',
- dataIndex: 'abandon_count',
- slotName: 'abandon_count',
- },
- {
- title: '放弃转链 %',
- dataIndex: 'abandon_percentage',
- slotName: 'abandon_percentage',
- },
- {
- title: '最后更新',
- dataIndex: 'last_time',
- },
- ]);
-
- const fetchData = async (
- params: DailyLogParams = {
- // query_date: [row.report_date, row.report_date],
- accountName: 'all',
- current: 1, pageSize: 20, sort: 'log_date', order: 'descending'
- }
- ) => {
- setLoading(true);
- try {
-
- const { data } = await queryDailyLog(params);
- console.log(data);
- if (!data) return;
- // const { data } = await queryDailyLog(params);
- renderData.value = data.list;
- pagination.current = data.page;
- pagination.total = data.count;
- console.log(data)
- } catch (err) {
-
- console.log(err)
- // you can report use errorHandler or other
- } finally {
- setLoading(false);
- }
- };
-
- const loadMore = async (row: TableData, done: (data: TableData[]) => void) => {
- setLoading(true);
- try {
-
- const params: DailyLogParams = {
- query_date: [row.log_date, row.log_date],
- current: 1, pageSize: 999, sort: 'id', order: 'descending'
- };
-
- const { data } = await queryDailyLog(params);
- console.log(data);
- if (!data) return;
-
- const list: TableData[] = data.list.map((item: DailyLogRecord) => ({
- ...item,
- isLeaf: true
- }));
- done(list);
- } catch (err) {
- console.log(err)
- } finally {
- setLoading(false);
- }
- };
-
-
-
-
- const changeItem = async (
- data: DailyLogRecord
- ) => {
- router.push({ name: 'updateCookies' });
- };
-
-
-
- const search = () => {
- fetchData({
- ...basePagination,
- ...formModel.value,
- } as unknown as DailyLogParams);
- };
- const onPageChange = (current: number) => {
- fetchData({
- ...basePagination,
- ...formModel.value,
- current
- });
- };
-
- fetchData();
- const reset = () => {
- formModel.value = generateFormModel();
- };
-
- const handleSelectDensity = (
- val: string | number | Record<string, any> | undefined,
- e: Event
- ) => {
- size.value = val as SizeProps;
- };
-
- const handleChange = (
- checked: boolean | (string | boolean | number)[],
- column: Column,
- index: number
- ) => {
- if (!checked) {
- cloneColumns.value = showColumns.value.filter(
- (item) => item.dataIndex !== column.dataIndex
- );
- } else {
- cloneColumns.value.splice(index, 0, column);
- }
- };
-
- const exchangeArray = <T extends Array<any>>(
- array: T,
- beforeIdx: number,
- newIdx: number,
- isDeep = false
- ): T => {
- const newArray = isDeep ? cloneDeep(array) : array;
- if (beforeIdx > -1 && newIdx > -1) {
- // 先替换后面的,然后拿到替换的结果替换前面的
- newArray.splice(
- beforeIdx,
- 1,
- newArray.splice(newIdx, 1, newArray[beforeIdx]).pop()
- );
- }
- return newArray;
- };
-
- const popupVisibleChange = (val: boolean) => {
- if (val) {
- nextTick(() => {
- const el = document.getElementById('tableSetting') as HTMLElement;
- const sortable = new Sortable(el, {
- onEnd(e: any) {
- const { oldIndex, newIndex } = e;
- exchangeArray(cloneColumns.value, oldIndex, newIndex);
- exchangeArray(showColumns.value, oldIndex, newIndex);
- },
- });
- });
- }
- };
-
- watch(
- () => columns.value,
- (val) => {
- cloneColumns.value = cloneDeep(val);
- cloneColumns.value.forEach((item, index) => {
- item.checked = true;
- });
- showColumns.value = cloneDeep(cloneColumns.value);
- },
- { deep: true, immediate: true }
- );
- </script>
-
- <script lang="ts">
- export default {
- name: 'SearchTable',
- };
- </script>
-
- <style scoped lang="less">
- .container {
- padding: 0 20px 20px 20px;
- }
-
- :deep(.arco-table-th) {
- &:last-child {
- .arco-table-th-item-title {
- margin-left: 16px;
- }
- }
- }
-
- .action-icon {
- margin-left: 12px;
- cursor: pointer;
- }
-
- .active {
- color: #0960bd;
- background-color: #e3f4fc;
- }
-
- .setting {
- display: flex;
- align-items: center;
- width: 200px;
-
- .title {
- margin-left: 12px;
- cursor: pointer;
- }
- }
- </style>
-
|