优化字典页面新增功能

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