修复:完善基础资料页异步与提交保护
This commit is contained in:
@@ -32,7 +32,7 @@
|
||||
|
||||
<el-alert v-if="loadError" :title="loadError" type="error" :closable="false" show-icon class="mb8" />
|
||||
<el-table v-loading="loading" empty-text="暂无数据" :data="customerList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" :selectable="isRowSelectable" width="55" align="center" />
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column label="客户ID" prop="customerId" align="center" />
|
||||
<el-table-column label="客户编码" prop="customerCode" align="center" :show-overflow-tooltip="true" />
|
||||
<el-table-column label="客户名称" prop="customerName" align="center" :show-overflow-tooltip="true" />
|
||||
@@ -46,7 +46,7 @@
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-if="proxy.$auth.hasPermiAnd(['master:customer:query', 'master:customer:edit'])"
|
||||
link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['master:customer:edit']"
|
||||
link type="primary" icon="Edit" :disabled="detailLoading" @click="handleUpdate(scope.row)" v-hasPermi="['master:customer:edit']"
|
||||
>修改</el-button>
|
||||
<el-button
|
||||
v-if="scope.row.canRemove === true"
|
||||
@@ -61,7 +61,16 @@
|
||||
v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList"
|
||||
/>
|
||||
|
||||
<el-dialog v-model="open" :title="title" width="min(520px, 92vw)" append-to-body>
|
||||
<el-dialog
|
||||
v-model="open"
|
||||
:title="title"
|
||||
width="min(520px, 92vw)"
|
||||
append-to-body
|
||||
:close-on-click-modal="!submitLoading"
|
||||
:close-on-press-escape="!submitLoading"
|
||||
:show-close="!submitLoading"
|
||||
:before-close="handleDialogBeforeClose"
|
||||
>
|
||||
<el-alert v-if="formError" :title="formError" type="error" :closable="false" show-icon class="mb8" />
|
||||
<el-form ref="customerRef" :model="form" :rules="rules" label-width="90px">
|
||||
<el-form-item label="客户编码" prop="customerCode">
|
||||
@@ -96,7 +105,8 @@ import { addCustomer, delCustomer, getCustomer, listCustomer, updateCustomer } f
|
||||
const { proxy } = getCurrentInstance();
|
||||
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
|
||||
const customerList = ref([]);
|
||||
const ids = ref([]);
|
||||
const selectedIds = ref([]);
|
||||
const removableIds = ref([]);
|
||||
const loading = ref(false);
|
||||
const detailLoading = ref(false);
|
||||
const submitLoading = ref(false);
|
||||
@@ -107,6 +117,8 @@ const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
const title = ref("");
|
||||
let listGeneration = 0;
|
||||
let detailGeneration = 0;
|
||||
|
||||
function validateRequiredText(rule, value, callback) {
|
||||
if (typeof value !== "string" || value.trim() === "") {
|
||||
@@ -127,17 +139,36 @@ const data = reactive({
|
||||
});
|
||||
const { form, queryParams, rules } = toRefs(data);
|
||||
|
||||
function isCurrentListRequest(listContext) {
|
||||
return listContext.generation === listGeneration;
|
||||
}
|
||||
|
||||
function getList() {
|
||||
const listContext = {
|
||||
generation: ++listGeneration,
|
||||
query: { ...queryParams.value }
|
||||
};
|
||||
loading.value = true;
|
||||
loadError.value = "";
|
||||
listCustomer(queryParams.value).then((response) => {
|
||||
listCustomer(listContext.query).then((response) => {
|
||||
if (!isCurrentListRequest(listContext)) {
|
||||
return;
|
||||
}
|
||||
customerList.value = response.rows;
|
||||
total.value = response.total;
|
||||
}).catch(() => {
|
||||
if (!isCurrentListRequest(listContext)) {
|
||||
return;
|
||||
}
|
||||
customerList.value = [];
|
||||
total.value = 0;
|
||||
loadError.value = "客户列表加载失败,请稍后重试";
|
||||
}).finally(() => { loading.value = false; });
|
||||
}).finally(() => {
|
||||
if (!isCurrentListRequest(listContext)) {
|
||||
return;
|
||||
}
|
||||
loading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function reset() {
|
||||
@@ -145,26 +176,54 @@ function reset() {
|
||||
form.value = { customerId: undefined, customerCode: "", customerName: "", status: "0", remark: "" };
|
||||
proxy.resetForm("customerRef");
|
||||
}
|
||||
function cancel() { open.value = false; reset(); }
|
||||
function invalidateDetailRequest() {
|
||||
detailGeneration += 1;
|
||||
detailLoading.value = false;
|
||||
}
|
||||
function isCurrentDetailRequest(detailContext) {
|
||||
return detailContext.generation === detailGeneration;
|
||||
}
|
||||
function cancel() {
|
||||
if (submitLoading.value) return;
|
||||
invalidateDetailRequest();
|
||||
open.value = false;
|
||||
reset();
|
||||
}
|
||||
function handleDialogBeforeClose(done) {
|
||||
if (submitLoading.value) return;
|
||||
invalidateDetailRequest();
|
||||
reset();
|
||||
done();
|
||||
}
|
||||
function handleQuery() { queryParams.value.pageNum = 1; getList(); }
|
||||
function resetQuery() { proxy.resetForm("queryRef"); handleQuery(); }
|
||||
function isRowSelectable(row) {
|
||||
return row.canRemove === true;
|
||||
}
|
||||
function handleSelectionChange(selection) {
|
||||
ids.value = selection
|
||||
selectedIds.value = selection.map((item) => item.customerId);
|
||||
removableIds.value = selection
|
||||
.filter((item) => item.canRemove === true)
|
||||
.map((item) => item.customerId);
|
||||
single.value = ids.value.length !== 1;
|
||||
multiple.value = ids.value.length === 0;
|
||||
single.value = selectedIds.value.length !== 1;
|
||||
multiple.value = removableIds.value.length === 0;
|
||||
}
|
||||
function handleAdd() {
|
||||
invalidateDetailRequest();
|
||||
reset();
|
||||
title.value = "新增客户";
|
||||
open.value = true;
|
||||
}
|
||||
function handleAdd() { reset(); title.value = "新增客户"; open.value = true; }
|
||||
|
||||
function handleUpdate(row = {}) {
|
||||
reset();
|
||||
const customerId = row.customerId || ids.value[0];
|
||||
const customerId = row.customerId || selectedIds.value[0];
|
||||
const detailContext = {
|
||||
generation: ++detailGeneration,
|
||||
resourceId: customerId
|
||||
};
|
||||
detailLoading.value = true;
|
||||
getCustomer(customerId).then((response) => {
|
||||
getCustomer(detailContext.resourceId).then((response) => {
|
||||
if (!isCurrentDetailRequest(detailContext)) {
|
||||
return;
|
||||
}
|
||||
const detail = response.data;
|
||||
form.value = {
|
||||
customerId: detail.customerId,
|
||||
@@ -176,8 +235,16 @@ function handleUpdate(row = {}) {
|
||||
title.value = "修改客户";
|
||||
open.value = true;
|
||||
}).catch(() => {
|
||||
if (!isCurrentDetailRequest(detailContext)) {
|
||||
return;
|
||||
}
|
||||
loadError.value = "客户详情加载失败,请稍后重试";
|
||||
}).finally(() => { detailLoading.value = false; });
|
||||
}).finally(() => {
|
||||
if (!isCurrentDetailRequest(detailContext)) {
|
||||
return;
|
||||
}
|
||||
detailLoading.value = false;
|
||||
});
|
||||
}
|
||||
|
||||
function afterSubmit(response) {
|
||||
@@ -217,7 +284,7 @@ function submitUpdate() {
|
||||
});
|
||||
}
|
||||
function handleDelete(row) {
|
||||
const targetIds = row?.customerId ? (row.canRemove === true ? [row.customerId] : []) : ids.value;
|
||||
const targetIds = row?.customerId ? (row.canRemove === true ? [row.customerId] : []) : removableIds.value;
|
||||
if (!targetIds.length) { proxy.$modal.msgWarning("请选择允许删除的客户"); return; }
|
||||
proxy.$modal.confirm(`是否确认删除客户编号为“${targetIds.join(",")}”的数据项?`).then(() =>
|
||||
delCustomer(targetIds.join(","))
|
||||
|
||||
Reference in New Issue
Block a user