修复“删除”和“批量删除”功能,优化“新增/编辑”页面

This commit is contained in:
CGD
2025-04-11 09:29:34 +08:00
parent 3d8afac9e1
commit a36887d885
4 changed files with 174 additions and 126 deletions
+8 -23
View File
@@ -113,37 +113,22 @@ export default {
}).send()
},
// 删除
deleteParam(id, callback) {
deleteParam(ids, callback) {
console.log(4444,ids )
RequestService.sendRequest()
.url(`${getServiceUrl()}/admin/params`)
.method('DELETE')
.data({ ids: [id] })
.url(`${getServiceUrl()}/admin/params/delete`)
.method('POST')
.data(ids)
.success((res) => {
RequestService.clearRequestTime()
callback(res)
callback(res);
})
.fail((err) => {
console.error('删除参数失败:', err)
RequestService.reAjaxFun(() => {
this.deleteParam(id, callback)
this.deleteParam(ids, callback)
})
}).send()
},
// 批量删除
batchDeleteParams(ids, callback) {
RequestService.sendRequest()
.url(`${getServiceUrl()}/admin/params`)
.method('DELETE')
.data({ ids })
.success((res) => {
RequestService.clearRequestTime()
callback(res)
})
.fail((err) => {
console.error('批量删除参数失败:', err)
RequestService.reAjaxFun(() => {
this.batchDeleteParams(ids, callback)
})
}).send()
}
}
+2 -1
View File
@@ -106,7 +106,8 @@ export default {
},
// 修改用户状态
changeUserStatus(status, userIds, successCallback) {
return RequestService.sendRequest()
console.log(555,userIds)
RequestService.sendRequest()
.url(`${getServiceUrl()}/admin/users/changeStatus/${status}`)
.method('put')
.data(userIds)
+117 -69
View File
@@ -1,7 +1,7 @@
<template>
<el-dialog :title="title"
:visible.sync="visible"
width="500px"
width="520px"
class="param-dialog-wrapper"
:append-to-body="true"
:close-on-click-modal="false"
@@ -12,10 +12,14 @@
<div class="dialog-container">
<div class="dialog-header">
<h2 class="dialog-title">{{ title }}</h2>
<button class="custom-close-btn" @click="cancel">×</button>
<button class="custom-close-btn" @click="cancel">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13 1L1 13M1 1L13 13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
</button>
</div>
<el-form :model="form" :rules="rules" ref="form" label-width="100px" label-position="left" class="param-form">
<el-form :model="form" :rules="rules" ref="form" label-width="110px" label-position="left" class="param-form">
<el-form-item label="参数编码" prop="paramCode" class="form-item">
<el-input v-model="form.paramCode" placeholder="请输入参数编码" class="custom-input"></el-input>
</el-form-item>
@@ -115,8 +119,10 @@ export default {
<style>
.custom-param-dialog {
border-radius: 20px !important;
border-radius: 16px !important;
overflow: hidden;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
border: none !important;
.el-dialog__header {
display: none;
@@ -124,7 +130,7 @@ export default {
.el-dialog__body {
padding: 0 !important;
border-radius: 20px;
border-radius: 16px;
}
}
</style>
@@ -132,45 +138,53 @@ export default {
<style scoped lang="scss">
.param-dialog-wrapper {
.dialog-container {
padding: 20px 30px;
padding: 24px 32px;
background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}
.dialog-header {
position: relative;
margin-bottom: 20px;
margin-bottom: 24px;
text-align: center;
}
.dialog-title {
font-size: 24px;
color: #3d4566;
font-size: 20px;
color: #1e293b;
margin: 0;
padding: 0;
font-weight: normal;
font-weight: 600;
letter-spacing: 0.5px;
}
.custom-close-btn {
position: absolute;
top: 0;
right: 0;
width: 35px;
height: 35px;
top: -8px;
right: -8px;
width: 32px;
height: 32px;
border-radius: 50%;
border: 2px solid #cfcfcf;
background: none;
font-size: 24px;
color: #cfcfcf;
border: none;
background: #f1f5f9;
color: #64748b;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
padding: 0;
outline: none;
transition: all 0.2s ease;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
&:hover {
color: #409EFF;
border-color: #409EFF;
color: #ffffff;
background: #ef4444;
transform: rotate(90deg);
box-shadow: 0 4px 6px rgba(239, 68, 68, 0.2);
}
svg {
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
}
@@ -179,30 +193,36 @@ export default {
margin-bottom: 20px;
:deep(.el-form-item__label) {
color: #3d4566;
font-weight: normal;
padding-right: 20px;
color: #475569;
font-weight: 500;
padding-right: 12px;
text-align: right;
font-size: 14px;
letter-spacing: 0.2px;
}
}
.custom-input {
:deep(.el-input__inner) {
background-color: #f6f8fc;
background-color: #ffffff;
border-radius: 8px;
border: 1px solid #e0e3e9;
height: 40px;
padding: 0 12px;
transition: all 0.3s;
border: 1px solid #e2e8f0;
height: 42px;
padding: 0 14px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
font-size: 14px;
color: #334155;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
&:focus {
border-color: #5b8cff;
box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.2);
background-color: #fff;
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
background-color: #ffffff;
}
&::placeholder {
color: #9c9f9e;
color: #94a3b8;
font-weight: 400;
}
}
}
@@ -211,40 +231,49 @@ export default {
width: 100%;
:deep(.el-input__inner) {
background-color: #f6f8fc;
background-color: #ffffff;
border-radius: 8px;
border: 1px solid #e0e3e9;
height: 40px;
transition: all 0.3s;
border: 1px solid #e2e8f0;
height: 42px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
font-size: 14px;
color: #334155;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
&:focus {
border-color: #5b8cff;
box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.2);
background-color: #fff;
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
background-color: #ffffff;
}
&::placeholder {
color: #9c9f9e;
color: #94a3b8;
font-weight: 400;
}
}
}
.custom-textarea {
:deep(.el-textarea__inner) {
background-color: #f6f8fc;
background-color: #ffffff;
border-radius: 8px;
border: 1px solid #e0e3e9;
padding: 12px;
transition: all 0.3s;
border: 1px solid #e2e8f0;
padding: 12px 14px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
font-size: 14px;
color: #334155;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
line-height: 1.5;
&:focus {
border-color: #5b8cff;
box-shadow: 0 0 0 2px rgba(91, 140, 255, 0.2);
background-color: #fff;
border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
background-color: #ffffff;
}
&::placeholder {
color: #9c9f9e;
color: #94a3b8;
font-weight: 400;
}
}
}
@@ -257,40 +286,59 @@ export default {
.dialog-footer {
display: flex;
justify-content: center;
padding: 15px 0 0;
margin-top: 10px;
padding: 16px 0 0;
margin-top: 16px;
.save-btn {
width: 120px;
height: 40px;
font-size: 16px;
height: 42px;
font-size: 14px;
font-weight: 500;
border-radius: 8px;
transition: all 0.3s ease;
background: #e6f0fd;
color: #237ff4;
border: 1px solid #b3d1ff;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
background: #3b82f6;
color: white;
border: none;
letter-spacing: 0.5px;
box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2);
&:hover {
background: #237ff4;
color: white;
border: none;
background: #2563eb;
transform: translateY(-1px);
box-shadow: 0 4px 6px rgba(59, 130, 246, 0.3);
}
&:active {
transform: translateY(0);
box-shadow: 0 2px 3px rgba(59, 130, 246, 0.2);
}
}
.cancel-btn {
width: 120px;
height: 40px;
font-size: 16px;
height: 42px;
font-size: 14px;
font-weight: 500;
border-radius: 8px;
transition: all 0.3s ease;
background: #f6f8fc;
color: #3d4566;
border: 1px solid #e0e3e9;
margin-left: 20px;
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
background: #ffffff;
color: #64748b;
border: 1px solid #e2e8f0;
margin-left: 16px;
letter-spacing: 0.5px;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
&:hover {
background: #e9e9e9;
border-color: #d9d9d9;
background: #f8fafc;
color: #475569;
border-color: #cbd5e1;
transform: translateY(-1px);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
&:active {
transform: translateY(0);
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
}
}
+47 -33
View File
@@ -35,7 +35,7 @@
@click="handleSelectAll">全选</el-button>
<el-button size="mini" type="success" @click="showAddDialog">新增</el-button>
<el-button size="mini" type="danger" icon="el-icon-delete"
@click="batchDelete">删除</el-button>
@click="deleteParam($refs.paramsTable.selection)">删除</el-button>
</div>
<div class="custom-pagination">
<button class="pagination-btn" :disabled="currentPage === 1" @click="goFirst">
@@ -173,43 +173,57 @@ export default {
}
},
deleteParam(row) {
this.$confirm("确定要删除该参数吗?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
Api.admin.deleteParam(row.id, ({ data }) => {
if (data.code === 0) {
this.$message.success("删除成功");
this.fetchParams();
}
});
})
.catch(() => { });
},
batchDelete() {
const selectedParams = this.$refs.paramsTable.selection;
if (selectedParams.length === 0) {
// 处理单个参数或参数数组
const params = Array.isArray(row) ? row : [row];
if (Array.isArray(row) && row.length === 0) {
this.$message.warning("请先选择需要删除的参数");
return;
}
this.$confirm(`确定要删除选中的${selectedParams.length}个参数吗?`, "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {
const ids = selectedParams.map(item => item.id);
Api.admin.batchDeleteParams(ids, ({ data }) => {
if (data.code === 0) {
this.$message.success("删除成功");
this.fetchParams();
}
const paramCount = params.length;
this.$confirm(`确定要删除选中的${paramCount}个参数吗?`, '警告', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
distinguishCancelAndClose: true
}).then(() => {
const ids = params.map(param => param.id);
if (ids.some(id => isNaN(id))) {
this.$message.error('存在无效的参数ID');
return;
}
Api.admin.deleteParam(ids, ({ data }) => {
if (data.code === 0) {
this.$message.success({
message: `成功删除${paramCount}个参数`,
showClose: true
});
this.fetchParams(); // 刷新参数列表
} else {
this.$message.error({
message: data.msg || '删除失败,请重试',
showClose: true
});
}
});
}).catch(action => {
if (action === 'cancel') {
this.$message({
type: 'info',
message: '已取消删除操作',
duration: 1000
});
})
.catch(() => { });
} else {
this.$message({
type: 'info',
message: '操作已关闭',
duration: 1000
});
}
});
},
headerCellClassName({ columnIndex }) {
if (columnIndex === 0) {