优化字典页面新增功能

This commit is contained in:
BianLzhaoMin 2024-07-15 15:18:21 +08:00
parent cbaec067a0
commit 1afea4da70
1 changed files with 409 additions and 323 deletions

View File

@ -1,6 +1,13 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form
:model="queryParams"
ref="queryForm"
size="small"
:inline="true"
v-show="showSearch"
label-width="68px"
>
<el-form-item label="字典名称" prop="name">
<el-input
v-model="queryParams.name"
@ -23,7 +30,8 @@
<el-select
v-model="queryParams.status"
placeholder="字典状态"
clearable filterable
clearable
filterable
style="width: 240px"
>
<el-option
@ -46,8 +54,19 @@
></el-date-picker>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
<el-button
type="primary"
icon="el-icon-search"
size="mini"
@click="handleQuery"
>搜索</el-button
>
<el-button
icon="el-icon-refresh"
size="mini"
@click="resetQuery"
>重置</el-button
>
</el-form-item>
</el-form>
@ -60,7 +79,8 @@
size="mini"
@click="handleAdd"
v-hasPermi="['system:dict:add']"
>新增</el-button>
>新增</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
@ -71,7 +91,8 @@
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:dict:edit']"
>修改</el-button>
>修改</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
@ -82,7 +103,8 @@
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:dict:remove']"
>删除</el-button>
>删除</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
@ -92,7 +114,8 @@
size="mini"
@click="handleExport"
v-hasPermi="['system:dict:export']"
>导出</el-button>
>导出</el-button
>
</el-col>
<el-col :span="1.5">
<el-button
@ -102,34 +125,61 @@
size="mini"
@click="handleRefreshCache"
v-hasPermi="['system:dict:remove']"
>刷新缓存</el-button>
>刷新缓存</el-button
>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
<el-table
v-loading="loading"
:data="typeList"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="字典编号" align="center" prop="id" />
<!-- <el-table-column label="字典名称" align="center" prop="name" :show-overflow-tooltip="true" /> -->
<el-table-column label="字典名称" align="center" :show-overflow-tooltip="true">
<el-table-column
label="字典名称"
align="center"
:show-overflow-tooltip="true"
>
<template slot-scope="scope">
<router-link :to="'/system/dict-data/index/' + scope.row.id" class="link-type">
<router-link
:to="'/system/dict-data/index/' + scope.row.id"
class="link-type"
>
<span>{{ scope.row.name }}</span>
</router-link>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status">
<template slot-scope="scope">
<dict-tag :options="dict.type.sys_normal_disable" :value="scope.row.status"/>
<dict-tag
:options="dict.type.sys_normal_disable"
:value="scope.row.status"
/>
</template>
</el-table-column>
<!-- <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> -->
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<el-table-column
label="创建时间"
align="center"
prop="createTime"
width="180"
>
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<el-table-column
label="操作"
align="center"
class-name="small-padding fixed-width"
>
<template slot-scope="scope">
<el-button
size="mini"
@ -137,14 +187,16 @@
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['system:dict:edit']"
>修改</el-button>
>修改</el-button
>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['system:dict:remove']"
>删除</el-button>
>删除</el-button
>
</template>
</el-table-column>
</el-table>
@ -158,10 +210,18 @@
/>
<!-- 添加或修改参数配置对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-dialog
:title="title"
:visible.sync="open"
width="500px"
append-to-body
>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="字典名称" prop="name">
<el-input v-model="form.name" placeholder="请输入字典名称" />
<el-input
v-model="form.name"
placeholder="请输入字典名称"
/>
</el-form-item>
<!-- <el-form-item label="字典类型" prop="dictType">
<el-input v-model="form.dictType" placeholder="请输入字典类型" />
@ -172,11 +232,16 @@
v-for="dict in dict.type.sys_normal_disable"
:key="dict.value"
:label="dict.value"
>{{dict.label}}</el-radio>
>{{ dict.label }}</el-radio
>
</el-radio-group>
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
<el-input
v-model="form.remark"
type="textarea"
placeholder="请输入内容"
></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
@ -188,10 +253,14 @@
</template>
<script>
import { listType, refreshCache } from "@/api/system/dict/type";
import { addDictData,updateDictData,delDictData} from "@/api/system/dict/data";
import { listType, refreshCache } from '@/api/system/dict/type'
import {
addDictData,
updateDictData,
delDictData,
} from '@/api/system/dict/data'
export default {
name: "Dict",
name: 'Dict',
dicts: ['sys_normal_disable'],
data() {
return {
@ -210,7 +279,7 @@ export default {
//
typeList: [],
//
title: "",
title: '',
//
open: false,
//
@ -222,39 +291,48 @@ export default {
id: '0',
name: undefined,
dictType: undefined,
status: undefined
status: undefined,
},
//
form: {},
//
rules: {
name: [
{ required: true, message: "字典名称不能为空", trigger: "blur" }
{
required: true,
message: '字典名称不能为空',
trigger: 'blur',
},
],
dictType: [
{ required: true, message: "字典类型不能为空", trigger: "blur" }
]
{
required: true,
message: '字典类型不能为空',
trigger: 'blur',
},
],
},
}
};
},
created() {
this.getList();
this.getList()
},
methods: {
/** 查询字典类型列表 */
getList() {
this.loading = true;
listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.typeList = response.rows;
this.total = response.total;
this.loading = false;
}
);
this.loading = true
listType(this.addDateRange(this.queryParams, this.dateRange)).then(
(response) => {
this.typeList = response.rows
this.total = response.total
this.loading = false
},
)
},
//
cancel() {
this.open = false;
this.reset();
this.open = false
this.reset()
},
//
reset() {
@ -262,85 +340,93 @@ export default {
pId: '0',
name: undefined,
dictType: undefined,
status: "0",
remark: undefined
};
this.resetForm("form");
status: '0',
remark: undefined,
}
this.resetForm('form')
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
this.queryParams.pageNum = 1
this.getList()
},
/** 重置按钮操作 */
resetQuery() {
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
this.dateRange = []
this.resetForm('queryForm')
this.handleQuery()
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加字典类型";
this.reset()
this.open = true
this.title = '添加字典类型'
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.pId)
this.ids = selection.map((item) => item.pId)
this.single = selection.length != 1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
this.reset()
let formData = row
this.form = formData;
this.open = true;
this.title = "修改字典类型";
this.form = formData
this.open = true
this.title = '修改字典类型'
},
/** 提交按钮 */
submitForm: function () {
this.$refs["form"].validate(valid => {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.form.pId != undefined) {
updateDictData(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
if (this.title === '修改字典类型') {
updateDictData(this.form).then((response) => {
this.$modal.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addDictData(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
addDictData(this.form).then((response) => {
this.$modal.msgSuccess('新增成功')
this.open = false
this.getList()
})
}
}
});
})
},
/** 删除按钮操作 */
handleDelete(row) {
const dictIds = row.pId || this.ids;
this.$modal.confirm('是否确认删除所选择的数据项?').then(function() {
return delDictData(dictIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
const dictIds = row.pId || this.ids
this.$modal
.confirm('是否确认删除所选择的数据项?')
.then(function () {
return delDictData(dictIds)
})
.then(() => {
this.getList()
this.$modal.msgSuccess('删除成功')
})
.catch(() => {})
},
/** 导出按钮操作 */
handleExport() {
this.download('system/dict/type/export', {
...this.queryParams
}, `type_${new Date().getTime()}.xlsx`)
this.download(
'system/dict/type/export',
{
...this.queryParams,
},
`type_${new Date().getTime()}.xlsx`,
)
},
/** 刷新缓存按钮操作 */
handleRefreshCache() {
refreshCache().then(() => {
this.$modal.msgSuccess("刷新成功");
this.$store.dispatch('dict/cleanDict');
});
this.$modal.msgSuccess('刷新成功')
this.$store.dispatch('dict/cleanDict')
})
},
},
}
}
};
</script>