refactor: 分页响应数据结构调整
This commit is contained in:
@@ -51,14 +51,20 @@ function isDashboard(route: RouteLocationMatched) {
|
||||
function handleLink(item: any) {
|
||||
const { redirect, path } = item;
|
||||
if (redirect) {
|
||||
router.push(redirect).catch((err) => {
|
||||
console.warn(err);
|
||||
});
|
||||
router.push(redirect).then(
|
||||
() => {},
|
||||
(err) => {
|
||||
console.warn(err);
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
router.push(pathCompile(path)).catch((err) => {
|
||||
console.warn(err);
|
||||
});
|
||||
router.push(pathCompile(path)).then(
|
||||
() => {},
|
||||
(err) => {
|
||||
console.warn(err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
watch(
|
||||
|
||||
@@ -509,24 +509,29 @@ function handleDelete(id?: number | string) {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
})
|
||||
.then(function () {
|
||||
}).then(
|
||||
function () {
|
||||
if (props.contentConfig.deleteAction) {
|
||||
props.contentConfig
|
||||
.deleteAction(ids)
|
||||
.then(() => {
|
||||
props.contentConfig.deleteAction(ids).then(
|
||||
() => {
|
||||
ElMessage.success("删除成功");
|
||||
removeIds.value = [];
|
||||
// 清空选中项
|
||||
tableRef.value?.clearSelection();
|
||||
handleRefresh(true);
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
() => {
|
||||
// 交由全局错误处理
|
||||
}
|
||||
);
|
||||
} else {
|
||||
ElMessage.error("未配置deleteAction");
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
() => {
|
||||
// 用户取消
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// 导出表单
|
||||
@@ -591,14 +596,14 @@ function handleExports() {
|
||||
worksheet.columns = columns;
|
||||
if (exportsFormData.origin === ExportsOriginEnum.REMOTE) {
|
||||
if (props.contentConfig.exportsAction) {
|
||||
props.contentConfig.exportsAction(lastFormData).then((res) => {
|
||||
worksheet.addRows(res);
|
||||
workbook.xlsx
|
||||
.writeBuffer()
|
||||
.then((buffer) => {
|
||||
props.contentConfig.exportsAction(lastFormData).then((data) => {
|
||||
worksheet.addRows(data);
|
||||
workbook.xlsx.writeBuffer().then(
|
||||
(buffer) => {
|
||||
saveXlsx(buffer, filename as string);
|
||||
})
|
||||
.catch((error) => console.log(error));
|
||||
},
|
||||
(error) => console.log(error)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
ElMessage.error("未配置exportsAction");
|
||||
@@ -607,12 +612,12 @@ function handleExports() {
|
||||
worksheet.addRows(
|
||||
exportsFormData.origin === ExportsOriginEnum.SELECTED ? selectionData.value : pageData.value
|
||||
);
|
||||
workbook.xlsx
|
||||
.writeBuffer()
|
||||
.then((buffer) => {
|
||||
workbook.xlsx.writeBuffer().then(
|
||||
(buffer) => {
|
||||
saveXlsx(buffer, filename as string);
|
||||
})
|
||||
.catch((error) => console.log(error));
|
||||
},
|
||||
(error) => console.log(error)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -710,9 +715,8 @@ function handleImports() {
|
||||
if (ev.target !== null && ev.target.result !== null) {
|
||||
const result = ev.target.result as ArrayBuffer;
|
||||
// 从 buffer 中加载并解析数据
|
||||
workbook.xlsx
|
||||
.load(result)
|
||||
.then((workbook) => {
|
||||
workbook.xlsx.load(result).then(
|
||||
(workbook) => {
|
||||
// 解析后的数据
|
||||
const data = [];
|
||||
// 获取第一个worksheet内容
|
||||
@@ -745,14 +749,14 @@ function handleImports() {
|
||||
handleCloseImportModal();
|
||||
handleRefresh(true);
|
||||
});
|
||||
})
|
||||
.catch((error) => console.log(error));
|
||||
},
|
||||
(error) => console.log(error)
|
||||
);
|
||||
} else {
|
||||
ElMessage.error("读取文件失败");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// 操作人"
|
||||
function handleToolbar(name: string) {
|
||||
switch (name) {
|
||||
@@ -864,17 +868,21 @@ function fetchPageData(formData: IObject = {}, isRestart = false) {
|
||||
? {
|
||||
[request.pageName]: pagination.currentPage,
|
||||
[request.limitName]: pagination.pageSize,
|
||||
...getFilterParams(),
|
||||
...formData,
|
||||
}
|
||||
: {
|
||||
...getFilterParams(),
|
||||
...formData,
|
||||
}
|
||||
: formData
|
||||
)
|
||||
.then((data) => {
|
||||
if (showPagination) {
|
||||
const pageResult = Array.isArray(data) ? { data, page: null } : data;
|
||||
pagination.total = pageResult.page?.total ?? 0;
|
||||
pageData.value = pageResult.data ?? [];
|
||||
const pageResult = Array.isArray(data) ? { list: data, total: 0 } : data;
|
||||
pagination.total = pageResult?.total ?? 0;
|
||||
pageData.value = pageResult?.list ?? [];
|
||||
} else {
|
||||
pageData.value = Array.isArray(data) ? data : (data.data ?? []);
|
||||
pageData.value = Array.isArray(data) ? data : (data?.list ?? data?.data ?? []);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
|
||||
@@ -4,6 +4,7 @@ import type PageContent from "./PageContent.vue";
|
||||
import type PageModal from "./PageModal.vue";
|
||||
import type PageSearch from "./PageSearch.vue";
|
||||
import type { CSSProperties } from "vue";
|
||||
import type { PageResult } from "@/types/api/common";
|
||||
|
||||
export type PageSearchInstance = InstanceType<typeof PageSearch>;
|
||||
export type PageContentInstance = InstanceType<typeof PageContent>;
|
||||
@@ -78,7 +79,7 @@ export interface IContentConfig<TQuery = any, TItem = any> {
|
||||
pageName: string;
|
||||
limitName: string;
|
||||
};
|
||||
// 分页接口统一返回 PageResult { data, page }
|
||||
// 分页接口统一返回 PageResult { list, total }
|
||||
// 修改属性的网络请求函数(需返回promise)
|
||||
modifyAction?: (data: {
|
||||
[key: string]: any;
|
||||
|
||||
@@ -27,15 +27,15 @@ const props = defineProps({
|
||||
function handleClipboard() {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
// 使用 Clipboard API
|
||||
navigator.clipboard
|
||||
.writeText(props.text)
|
||||
.then(() => {
|
||||
navigator.clipboard.writeText(props.text).then(
|
||||
() => {
|
||||
ElMessage.success("Copy successfully");
|
||||
})
|
||||
.catch((error) => {
|
||||
},
|
||||
(error) => {
|
||||
ElMessage.warning("Copy failed");
|
||||
console.log("[CopyButton] Copy failed", error);
|
||||
});
|
||||
}
|
||||
);
|
||||
} else {
|
||||
// 兼容性处理(useClipboard 有兼容性问题)
|
||||
const input = document.createElement("input");
|
||||
@@ -44,19 +44,18 @@ function handleClipboard() {
|
||||
input.setAttribute("value", props.text);
|
||||
document.body.appendChild(input);
|
||||
input.select();
|
||||
let successful = false;
|
||||
try {
|
||||
const successful = document.execCommand("copy");
|
||||
if (successful) {
|
||||
ElMessage.success("Copy successfully!");
|
||||
} else {
|
||||
ElMessage.warning("Copy failed!");
|
||||
}
|
||||
} catch (err) {
|
||||
ElMessage.error("Copy failed.");
|
||||
console.log("[CopyButton] Copy failed.", err);
|
||||
successful = document.execCommand("copy");
|
||||
} finally {
|
||||
document.body.removeChild(input);
|
||||
}
|
||||
|
||||
if (successful) {
|
||||
ElMessage.success("Copy successfully!");
|
||||
} else {
|
||||
ElMessage.warning("Copy failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -261,9 +261,9 @@ function fetchPageData(isRestart = false) {
|
||||
}
|
||||
props.selectConfig
|
||||
.indexAction(queryParams)
|
||||
.then((res) => {
|
||||
total.value = res.page?.total ?? 0;
|
||||
pageData.value = res.data ?? [];
|
||||
.then((data) => {
|
||||
total.value = data.total ?? 0;
|
||||
pageData.value = data.list ?? [];
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
|
||||
@@ -172,13 +172,14 @@ function handleUpload(options: UploadRequestOptions) {
|
||||
if (fileItem) {
|
||||
fileItem.percentage = percent;
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
resolve(res);
|
||||
})
|
||||
.catch((err) => {
|
||||
}).then(
|
||||
(data) => {
|
||||
resolve(data);
|
||||
},
|
||||
(err) => {
|
||||
reject(err);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -156,13 +156,14 @@ function handleUpload(options: UploadRequestOptions) {
|
||||
formData.append(key, props.data[key]);
|
||||
});
|
||||
|
||||
FileAPI.upload(formData)
|
||||
.then((data) => {
|
||||
FileAPI.upload(formData).then(
|
||||
(data) => {
|
||||
resolve(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
},
|
||||
(error) => {
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -137,13 +137,14 @@ function handleUpload(options: UploadRequestOptions) {
|
||||
formData.append(key, props.data[key]);
|
||||
});
|
||||
|
||||
FileAPI.upload(formData)
|
||||
.then((data) => {
|
||||
FileAPI.upload(formData).then(
|
||||
(data) => {
|
||||
resolve(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
},
|
||||
(error) => {
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -64,9 +64,9 @@ const editorConfig = ref<Partial<IEditorConfig>>({
|
||||
uploadImage: {
|
||||
customUpload(file: File, insertFn: InsertFnType) {
|
||||
// 上传图片
|
||||
FileAPI.uploadFile(file).then((res) => {
|
||||
FileAPI.uploadFile(file).then((data) => {
|
||||
// 插入图片
|
||||
insertFn(res.url, res.name, res.url);
|
||||
insertFn(data.url, data.name, data.url);
|
||||
});
|
||||
},
|
||||
} as any,
|
||||
|
||||
Reference in New Issue
Block a user