|
@@ -50,8 +50,8 @@ const gridOptions = reactive({
|
|
|
tools: 'toolbar_buttons',
|
|
|
},
|
|
|
},
|
|
|
- columns: tableColumns.value,
|
|
|
- data: []
|
|
|
+ columns: tableColumns,
|
|
|
+ data: tableData,
|
|
|
});
|
|
|
|
|
|
// 分页
|
|
@@ -85,9 +85,57 @@ async function fetchMainData(taskIds, resetPage = false) {
|
|
|
});
|
|
|
gridOptions.data = response.data;
|
|
|
gridOptions.pagerConfig.total = response.total;
|
|
|
- return response.data;
|
|
|
+
|
|
|
+ if (response.data && response.data.length > 0) {
|
|
|
+ const dynamicColumns = [];
|
|
|
+ const regex1 = /\d{2}-\d{2}/;
|
|
|
+ const regex2 = /\d{4}-\d{2}-\d{2}/;
|
|
|
+ const regex3 = /\d{4}-\d{2}/
|
|
|
+ const middleKeywords = ['~', '截止', '近90天平台退货率', '余额'];
|
|
|
+
|
|
|
+ const allColumns = new Set();
|
|
|
+ response.data.forEach(row => {
|
|
|
+ for (const key in row) {
|
|
|
+ if (regex1.test(key) || middleKeywords.some(kw => key.includes(kw))) {
|
|
|
+ allColumns.add(key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ const firstColumns = [];
|
|
|
+ const middleColumns = [];
|
|
|
+ const lastColumns = [];
|
|
|
+
|
|
|
+ allColumns.forEach(key => {
|
|
|
+ const column = {
|
|
|
+ field: key,
|
|
|
+ title: key, // 使用字段名作为列标题
|
|
|
+ minWidth: key.includes('~') ? 90 : key.includes('截止')? 90 :regex2.test(key) ? 81 : 70,
|
|
|
+ align: 'center',
|
|
|
+ formatter: formatEmptyCell,
|
|
|
+ };
|
|
|
+ if (middleKeywords.some(kw => key.includes(kw))) {
|
|
|
+ middleColumns.push(column);
|
|
|
+ }
|
|
|
+ else if (regex3.test(key) &&!regex2.test(key)) {
|
|
|
+ lastColumns.push(column);
|
|
|
+ }
|
|
|
+ else if (regex1.test(key)) {
|
|
|
+ firstColumns.push(column);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ dynamicColumns.push(...firstColumns, ...middleColumns, ...lastColumns);
|
|
|
+
|
|
|
+ tableColumns.value = [
|
|
|
+ ...universal,
|
|
|
+ ...dynamicColumns,
|
|
|
+ ];
|
|
|
+ }
|
|
|
} catch (error) {
|
|
|
console.error('Error fetching task data:', error);
|
|
|
+ // 这里可以添加一个用户友好的错误提示,例如:
|
|
|
+ // showAlert('获取数据失败,请稍后重试。');
|
|
|
} finally {
|
|
|
gridOptions.loading = false;
|
|
|
}
|
|
@@ -95,7 +143,7 @@ async function fetchMainData(taskIds, resetPage = false) {
|
|
|
|
|
|
// 监测 taskIds 变化
|
|
|
watch(() => props.taskIds, (newTaskIds) => {
|
|
|
- loadData();
|
|
|
+ fetchMainData(newTaskIds, true)
|
|
|
});
|
|
|
|
|
|
// 监测 dayDate 变化
|
|
@@ -105,9 +153,9 @@ watch(() => props.dayDate, (newDayDate) => {
|
|
|
const {dailyStartDate, dailyTime} = newDayDate;
|
|
|
dayStartDate.value = dailyStartDate;
|
|
|
dayEndDate.value = dailyTime;
|
|
|
- // loadData();
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
// 监测 weekDate 变化
|
|
|
watch(() => props.weekDate, (newWeekDate) => {
|
|
|
if (newWeekDate) {
|
|
@@ -115,7 +163,7 @@ watch(() => props.weekDate, (newWeekDate) => {
|
|
|
const {weekStartDate, weekEndDate} = newWeekDate;
|
|
|
weekStart.value = weekStartDate;
|
|
|
weekEnd.value = weekEndDate;
|
|
|
- loadData();
|
|
|
+ fetchMainData(props.taskIds)
|
|
|
}
|
|
|
});
|
|
|
// 监测 monthDate 变化
|
|
@@ -125,41 +173,9 @@ watch(() => props.monthDate, (newMonthDate) => {
|
|
|
const {startDate, endDate} = newMonthDate;
|
|
|
monthStartDate.value = startDate;
|
|
|
monthEndDate.value = endDate;
|
|
|
- // loadData();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
-const fetchColumnNames = (data) => {
|
|
|
- if (data && data.length > 0) {
|
|
|
- const dynamicColumns = [];
|
|
|
- const allColumns = new Set();
|
|
|
- // 遍历所有数据行以获取所有列名
|
|
|
- data.forEach(row => {
|
|
|
- Object.keys(row).forEach(key => {
|
|
|
- if (/\d{2}-\d{2}的/.test(key) || key.includes('余额币种') || key.includes('退货率')) {
|
|
|
- allColumns.add(key);
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- allColumns.forEach(key => {
|
|
|
- dynamicColumns.push({
|
|
|
- field: key,
|
|
|
- title: key, // 使用字段名作为列标题
|
|
|
- minWidth: key.includes('~') ? 90 : /\d{4}-\d{2}-\d{2}/.test(key) ? 81 : 70,
|
|
|
- align: 'center',
|
|
|
- formatter: formatEmptyCell,
|
|
|
- })
|
|
|
- });
|
|
|
- tableColumns.value = [
|
|
|
- ...universal,
|
|
|
- ...dynamicColumns
|
|
|
- ];
|
|
|
- }else {
|
|
|
- tableData.value = [];
|
|
|
- gridOptions.pagerConfig.total = 0;
|
|
|
- }
|
|
|
-};
|
|
|
-
|
|
|
const cellStyle = () => {
|
|
|
return {
|
|
|
fontSize: '12px',
|
|
@@ -184,15 +200,6 @@ const cellStyleHandler = ({column}) => {
|
|
|
return {fontSize: '12px'};
|
|
|
};
|
|
|
|
|
|
-// 加载数据
|
|
|
-async function loadData() {
|
|
|
- const data = await fetchMainData(props.taskIds,true);
|
|
|
- fetchColumnNames(data);
|
|
|
- tableData.value = data;
|
|
|
- gridOptions.columns = tableColumns.value;
|
|
|
- gridOptions.data = tableData.value;
|
|
|
-}
|
|
|
-
|
|
|
async function handleExport() {
|
|
|
try {
|
|
|
gridOptions.loading = true;
|