Merge pull request #914 from xinnan-tech/web-table-loading

Web table loading
This commit is contained in:
Sakura-RanChen
2025-04-21 11:40:47 +08:00
committed by GitHub
6 changed files with 224 additions and 79 deletions
@@ -77,7 +77,12 @@
</div> </div>
<div style="display: flex;justify-content: center;"> <div style="display: flex;justify-content: center;">
<el-button type="primary" @click="confirm" class="save-btn"> <el-button
type="primary"
@click="confirm"
class="save-btn"
:loading="saving"
:disabled="saving">
保存 保存
</el-button> </el-button>
</div> </div>
@@ -94,6 +99,7 @@ export default {
}, },
data() { data() {
return { return {
saving: false,
providers: [], providers: [],
dialogVisible: false, dialogVisible: false,
providersLoaded: false, providersLoaded: false,
@@ -175,6 +181,7 @@ export default {
}, },
handleClose() { handleClose() {
this.saving = false;
this.$emit('update:visible', false); this.$emit('update:visible', false);
}, },
initDynamicConfig() { initDynamicConfig() {
@@ -185,8 +192,11 @@ export default {
this.formData.configJson = newConfig; this.formData.configJson = newConfig;
}, },
confirm() { confirm() {
this.saving = true;
if (!this.formData.supplier) { if (!this.formData.supplier) {
this.$message.error('请选择供应器'); this.$message.error('请选择供应器');
this.saving = false;
return; return;
} }
@@ -206,11 +216,18 @@ export default {
} }
}; };
this.$emit('confirm', submitData); try {
this.$emit('update:visible', false); this.$emit('confirm', submitData);
this.resetForm(); this.$emit('update:visible', false);
this.resetForm();
} catch (e) {
console.error(e);
} finally {
this.saving = false;
}
}, },
resetForm() { resetForm() {
this.saving = false;
this.formData = { this.formData = {
modelName: '', modelName: '',
modelCode: '', modelCode: '',
@@ -76,7 +76,12 @@
</div> </div>
<div style="display: flex;justify-content: center;"> <div style="display: flex;justify-content: center;">
<el-button type="primary" @click="handleSave" class="save-btn"> <el-button
type="primary"
@click="handleSave"
class="save-btn"
:loading="saving"
:disabled="saving">
保存 保存
</el-button> </el-button>
</div> </div>
@@ -102,6 +107,7 @@ export default {
dialogVisible: this.visible, dialogVisible: this.visible,
providers: [], providers: [],
providersLoaded: false, providersLoaded: false,
saving: false,
allProvidersData: null, allProvidersData: null,
pendingProviderType: null, pendingProviderType: null,
pendingModelData: null, pendingModelData: null,
@@ -195,6 +201,8 @@ export default {
} }
}, },
handleSave() { handleSave() {
this.saving = true; // 开始保存加载
const provideCode = this.form.configJson.type; const provideCode = this.form.configJson.type;
const formData = { const formData = {
id: this.modelData.id, id: this.modelData.id,
@@ -209,8 +217,19 @@ export default {
...this.form.configJson, ...this.form.configJson,
} }
}; };
this.$emit("save", { provideCode, formData });
this.dialogVisible = false; this.$emit("save", {
provideCode,
formData,
done: () => {
this.saving = false; // 保存完成后回调
}
});
// 如果父组件不处理done回调,3秒后自动关闭加载状态
setTimeout(() => {
this.saving = false;
}, 3000);
}, },
loadProviders() { loadProviders() {
if (this.providersLoaded) return; if (this.providersLoaded) return;
@@ -40,7 +40,12 @@
</el-form> </el-form>
<div class="dialog-footer"> <div class="dialog-footer">
<el-button type="primary" @click="submit" class="save-btn"> <el-button
type="primary"
@click="submit"
class="save-btn"
:loading="saving"
:disabled="saving">
保存 保存
</el-button> </el-button>
<el-button @click="cancel" class="cancel-btn"> <el-button @click="cancel" class="cancel-btn">
@@ -76,6 +81,7 @@ export default {
data() { data() {
return { return {
dialogKey: Date.now(), dialogKey: Date.now(),
saving: false,
valueTypeOptions: [ valueTypeOptions: [
{ value: 'string', label: '字符串(string)' }, { value: 'string', label: '字符串(string)' },
{ value: 'number', label: '数字(number)' }, { value: 'number', label: '数字(number)' },
@@ -100,11 +106,22 @@ export default {
submit() { submit() {
this.$refs.form.validate((valid) => { this.$refs.form.validate((valid) => {
if (valid) { if (valid) {
this.$emit('submit', this.form); this.saving = true; // 开始加载
this.$emit('submit', {
form: this.form,
done: () => {
this.saving = false; // 加载完成
}
});
setTimeout(() => {
this.saving = false;
}, 3000);
} }
}); });
}, },
cancel() { cancel() {
this.saving = false; // 取消时重置状态
this.$emit('cancel'); this.$emit('cancel');
} }
}, },
+37 -5
View File
@@ -44,9 +44,19 @@
<!-- 右侧内容 --> <!-- 右侧内容 -->
<div class="content-area"> <div class="content-area">
<el-card class="model-card" shadow="never"> <el-card class="model-card" shadow="never">
<el-table ref="modelTable" style="width: 100%" :header-cell-style="{ background: 'transparent' }" <el-table
:data="modelList" class="data-table" header-row-class-name="table-header" ref="modelTable"
:header-cell-class-name="headerCellClassName" @selection-change="handleSelectionChange"> style="width: 100%"
v-loading="loading"
element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.7)"
:header-cell-style="{ background: 'transparent' }"
:data="modelList"
class="data-table"
header-row-class-name="table-header"
:header-cell-class-name="headerCellClassName"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"></el-table-column> <el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column label="模型名称" prop="modelName" align="center"></el-table-column> <el-table-column label="模型名称" prop="modelName" align="center"></el-table-column>
<el-table-column label="模型编码" prop="modelCode" align="center"></el-table-column> <el-table-column label="模型编码" prop="modelCode" align="center"></el-table-column>
@@ -157,7 +167,8 @@ export default {
pageSize: 10, pageSize: 10,
total: 0, total: 0,
selectedModels: [], selectedModels: [],
isAllSelected: false isAllSelected: false,
loading: false
}; };
}, },
@@ -301,9 +312,10 @@ export default {
this.currentPage = page; this.currentPage = page;
this.$refs.modelTable.clearSelection(); this.$refs.modelTable.clearSelection();
}, },
handleModelSave({ provideCode, formData }) { handleModelSave({ provideCode, formData, done }) {
const modelType = this.activeTab; const modelType = this.activeTab;
const id = formData.id; const id = formData.id;
Api.model.updateModel( Api.model.updateModel(
{ modelType, provideCode, id, formData }, { modelType, provideCode, id, formData },
({ data }) => { ({ data }) => {
@@ -314,6 +326,7 @@ export default {
} else { } else {
this.$message.error(data.msg || '保存失败'); this.$message.error(data.msg || '保存失败');
} }
done && done(); // 调用done回调关闭加载状态
} }
); );
}, },
@@ -385,6 +398,7 @@ export default {
// 获取模型配置列表 // 获取模型配置列表
loadData() { loadData() {
this.loading = true; // 开始加载
const params = { const params = {
modelType: this.activeTab, modelType: this.activeTab,
modelName: this.search, modelName: this.search,
@@ -393,6 +407,7 @@ export default {
}; };
Api.model.getModelList(params, ({ data }) => { Api.model.getModelList(params, ({ data }) => {
this.loading = false; // 结束加载
if (data.code === 0) { if (data.code === 0) {
this.modelList = data.data.list; this.modelList = data.data.list;
this.total = data.data.total; this.total = data.data.total;
@@ -912,4 +927,21 @@ export default {
overflow-y: auto; overflow-y: auto;
} }
::v-deep .el-loading-mask {
background-color: rgba(255, 255, 255, 0.6) !important;
backdrop-filter: blur(2px);
}
::v-deep .el-loading-spinner .circular {
width: 28px;
height: 28px;
}
::v-deep .el-loading-spinner .path {
stroke: #6b8cff;
}
::v-deep .el-loading-text {
color: #6b8cff !important;
font-size: 14px;
margin-top: 8px;
}
</style> </style>
+81 -47
View File
@@ -15,8 +15,15 @@
<div class="content-panel"> <div class="content-panel">
<div class="content-area"> <div class="content-area">
<el-card class="params-card" shadow="never"> <el-card class="params-card" shadow="never">
<el-table ref="paramsTable" :data="paramsList" class="transparent-table" <el-table
:header-cell-class-name="headerCellClassName"> ref="paramsTable"
:data="paramsList"
class="transparent-table"
v-loading="loading"
element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.7)"
:header-cell-class-name="headerCellClassName">
<el-table-column label="选择" align="center" width="120"> <el-table-column label="选择" align="center" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox v-model="scope.row.selected"></el-checkbox> <el-checkbox v-model="scope.row.selected"></el-checkbox>
@@ -92,6 +99,7 @@ export default {
searchCode: "", searchCode: "",
paramsList: [], paramsList: [],
currentPage: 1, currentPage: 1,
loading: false,
pageSize: 10, pageSize: 10,
pageSizeOptions: [10, 20, 50, 100], pageSizeOptions: [10, 20, 50, 100],
total: 0, total: 0,
@@ -138,27 +146,29 @@ export default {
this.fetchParams(); this.fetchParams();
}, },
fetchParams() { fetchParams() {
Api.admin.getParamsList( this.loading = true;
{ Api.admin.getParamsList(
page: this.currentPage, {
limit: this.pageSize, page: this.currentPage,
paramCode: this.searchCode, limit: this.pageSize,
}, paramCode: this.searchCode,
({ data }) => { },
if (data.code === 0) { ({ data }) => {
this.paramsList = data.data.list.map(item => ({ this.loading = false;
...item, if (data.code === 0) {
selected: false this.paramsList = data.data.list.map(item => ({
})); ...item,
this.total = data.data.total; selected: false
} else { }));
this.$message.error({ this.total = data.data.total;
message: data.msg || '获取参数列表失败', } else {
showClose: true this.$message.error({
}); message: data.msg || '获取参数列表失败',
} showClose: true
} });
); }
}
);
}, },
handleSearch() { handleSearch() {
this.currentPage = 1; this.currentPage = 1;
@@ -185,32 +195,35 @@ export default {
this.paramForm = { ...row }; this.paramForm = { ...row };
this.dialogVisible = true; this.dialogVisible = true;
}, },
handleSubmit(form) {
if (form.id) { handleSubmit({ form, done }) {
// 编辑 if (form.id) {
Api.admin.updateParam(form, ({ data }) => { // 编辑
if (data.code === 0) { Api.admin.updateParam(form, ({ data }) => {
this.$message.success({ if (data.code === 0) {
message:"修改成功", this.$message.success({
showClose:true message:"修改成功",
}); showClose:true
this.dialogVisible = false;
this.fetchParams();
}
}); });
} else { this.dialogVisible = false;
// 新增 this.fetchParams();
Api.admin.addParam(form, ({ data }) => { }
if (data.code === 0) { done && done();
this.$message.success({ });
message:"新增成功", } else {
showClose:true // 新增
}); Api.admin.addParam(form, ({ data }) => {
this.dialogVisible = false; if (data.code === 0) {
this.fetchParams(); this.$message.success({
} message:"新增成功",
showClose:true
}); });
} this.dialogVisible = false;
this.fetchParams();
}
done && done();
});
}
}, },
deleteSelectedParams() { deleteSelectedParams() {
@@ -656,4 +669,25 @@ export default {
max-height: calc(var(--table-max-height) - 40px); max-height: calc(var(--table-max-height) - 40px);
} }
} }
:deep(.el-loading-mask) {
background-color: rgba(255, 255, 255, 0.6) !important;
backdrop-filter: blur(2px);
}
:deep(.el-loading-spinner .circular) {
width: 28px;
height: 28px;
}
:deep(.el-loading-spinner .path) {
stroke: #6b8cff;
}
:deep(.el-loading-text) {
color: #6b8cff !important;
font-size: 14px;
margin-top: 8px;
}
</style> </style>
+44 -18
View File
@@ -15,7 +15,14 @@
<div class="content-panel"> <div class="content-panel">
<div class="content-area"> <div class="content-area">
<el-card class="user-card" shadow="never"> <el-card class="user-card" shadow="never">
<el-table ref="userTable" :data="userList" class="transparent-table"> <el-table
ref="userTable"
:data="userList"
class="transparent-table"
v-loading="loading"
element-loading-text="拼命加载中"
element-loading-spinner="el-icon-loading"
element-loading-background="rgba(255, 255, 255, 0.7)">
<el-table-column label="选择" align="center" width="120"> <el-table-column label="选择" align="center" width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-checkbox v-model="scope.row.selected"></el-checkbox> <el-checkbox v-model="scope.row.selected"></el-checkbox>
@@ -103,7 +110,8 @@ export default {
currentPage: 1, currentPage: 1,
pageSize: 10, pageSize: 10,
total: 0, total: 0,
isAllSelected: false isAllSelected: false,
loading: false,
}; };
}, },
created() { created() {
@@ -137,22 +145,24 @@ export default {
}, },
fetchUsers() { fetchUsers() {
Api.admin.getUserList( this.loading = true;
{ Api.admin.getUserList(
page: this.currentPage, {
limit: this.pageSize, page: this.currentPage,
mobile: this.searchPhone, limit: this.pageSize,
}, mobile: this.searchPhone,
({ data }) => { },
if (data.code === 0) { ({ data }) => {
this.userList = data.data.list.map(item => ({ this.loading = false; // 结束加载
...item, if (data.code === 0) {
selected: false this.userList = data.data.list.map(item => ({
})); ...item,
this.total = data.data.total; selected: false
} }));
} this.total = data.data.total;
); }
}
);
}, },
handleSearch() { handleSearch() {
this.currentPage = 1; this.currentPage = 1;
@@ -682,5 +692,21 @@ export default {
} }
} }
:deep(.el-loading-mask) {
background-color: rgba(255, 255, 255, 0.6) !important;
backdrop-filter: blur(2px);
}
:deep(.el-loading-spinner .circular) {
width: 28px;
height: 28px;
}
:deep(.el-loading-spinner .path) {
stroke: #6b8cff;
}
:deep(.el-loading-text) {
color: #6b8cff !important;
font-size: 14px;
margin-top: 8px;
}
</style> </style>