字典管理完成
pull/1/head
李强 2021-02-26 00:16:08 +08:00
parent 7d0b762122
commit e7805b6211
4 changed files with 87 additions and 68 deletions

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询字典数据列表
export function listData(query) {
return request({
url: '/system/dict/data/list',
url: '/system/dict/data/',
method: 'get',
params: query
})
@ -12,7 +12,7 @@ export function listData(query) {
// 查询字典数据详细
export function getData(dictCode) {
return request({
url: '/system/dict/data/' + dictCode,
url: '/system/dict/data/' + dictCode + '/',
method: 'get'
})
}
@ -20,7 +20,7 @@ export function getData(dictCode) {
// 根据字典类型查询字典数据信息
export function getDicts(dictType) {
return request({
url: '/system/dict/data/type/' + dictType,
url: '/system/dict/get/type/' + dictType + '/',
method: 'get'
})
}
@ -28,7 +28,7 @@ export function getDicts(dictType) {
// 新增字典数据
export function addData(data) {
return request({
url: '/system/dict/data',
url: '/system/dict/data' + '/',
method: 'post',
data: data
})
@ -37,7 +37,7 @@ export function addData(data) {
// 修改字典数据
export function updateData(data) {
return request({
url: '/system/dict/data',
url: '/system/dict/data/' + data.id + '/',
method: 'put',
data: data
})
@ -46,7 +46,7 @@ export function updateData(data) {
// 删除字典数据
export function delData(dictCode) {
return request({
url: '/system/dict/data/' + dictCode,
url: '/system/dict/data/' + dictCode + '/',
method: 'delete'
})
}
@ -54,8 +54,8 @@ export function delData(dictCode) {
// 导出字典数据
export function exportData(query) {
return request({
url: '/system/dict/data/export',
url: '/system/dict/data/export/',
method: 'get',
params: query
})
}
}

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询字典类型列表
export function listType(query) {
return request({
url: '/system/dict/type/list',
url: '/system/dict/type/',
method: 'get',
params: query
})
@ -12,7 +12,7 @@ export function listType(query) {
// 查询字典类型详细
export function getType(dictId) {
return request({
url: '/system/dict/type/' + dictId,
url: '/system/dict/type/' + dictId + '/',
method: 'get'
})
}
@ -20,7 +20,7 @@ export function getType(dictId) {
// 新增字典类型
export function addType(data) {
return request({
url: '/system/dict/type',
url: '/system/dict/type/',
method: 'post',
data: data
})
@ -29,7 +29,7 @@ export function addType(data) {
// 修改字典类型
export function updateType(data) {
return request({
url: '/system/dict/type',
url: '/system/dict/type/' + data.id + '/',
method: 'put',
data: data
})
@ -38,7 +38,7 @@ export function updateType(data) {
// 删除字典类型
export function delType(dictId) {
return request({
url: '/system/dict/type/' + dictId,
url: '/system/dict/type/' + dictId + '/',
method: 'delete'
})
}
@ -66,4 +66,4 @@ export function optionselect() {
url: '/system/dict/type/optionselect',
method: 'get'
})
}
}

View File

@ -6,14 +6,14 @@
<el-option
v-for="item in typeOptions"
:key="item.dictId"
:label="item.dictName"
:label="item.name"
:value="item.dictType"
/>
</el-select>
</el-form-item>
<el-form-item label="字典标签" prop="dictLabel">
<el-form-item label="字典标签" prop="name">
<el-input
v-model="queryParams.dictLabel"
v-model="queryParams.name"
placeholder="请输入字典标签"
clearable
size="small"
@ -84,10 +84,18 @@
<el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="字典编码" align="center" prop="dictCode" />
<el-table-column label="字典标签" align="center" prop="dictLabel" />
<el-table-column label="字典编码" align="center" prop="id" />
<el-table-column label="字典标签" align="center" prop="name" />
<el-table-column label="字典键值" align="center" prop="dictValue" />
<el-table-column label="字典排序" align="center" prop="dictSort" />
<el-table-column label="字典排序" align="center" prop="sort" />
<el-table-column label="是否默认" align="center" prop="is_default" >
<template slot-scope="scope">
<el-switch
disabled
:value="scope.row.is_default">
</el-switch>
</template>
</el-table-column>
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" />
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@ -129,14 +137,21 @@
<el-form-item label="字典类型">
<el-input v-model="form.dictType" :disabled="true" />
</el-form-item>
<el-form-item label="数据标签" prop="dictLabel">
<el-input v-model="form.dictLabel" placeholder="请输入数据标签" />
<el-form-item label="数据标签" prop="name">
<el-input v-model="form.name" placeholder="请输入数据标签" />
</el-form-item>
<el-form-item label="数据键值" prop="dictValue">
<el-input v-model="form.dictValue" placeholder="请输入数据键值" />
</el-form-item>
<el-form-item label="显示排序" prop="dictSort">
<el-input-number v-model="form.dictSort" controls-position="right" :min="0" />
<el-form-item label="显示排序" prop="sort">
<el-input-number v-model="form.sort" controls-position="right" :min="0" />
</el-form-item>
<el-form-item label="是否默认" prop="is_default">
<el-switch
v-model="form.is_default"
active-text="是"
inactive-text="否">
</el-switch>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="form.status">
@ -188,13 +203,13 @@ export default {
//
open: false,
//
statusOptions: [],
statusOptions: [{dictLabel: '正常', dictValue: '1',}, {dictLabel: '停用', dictValue: '0',}],
//
typeOptions: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
pageSize: 1000,
dictName: undefined,
dictType: undefined,
status: undefined
@ -203,13 +218,13 @@ export default {
form: {},
//
rules: {
dictLabel: [
name: [
{ required: true, message: "数据标签不能为空", trigger: "blur" }
],
dictValue: [
{ required: true, message: "数据键值不能为空", trigger: "blur" }
],
dictSort: [
sort: [
{ required: true, message: "数据顺序不能为空", trigger: "blur" }
]
}
@ -217,11 +232,12 @@ export default {
},
created() {
const dictId = this.$route.params && this.$route.params.dictId;
console.log(11111,this.$route.params)
this.getType(dictId);
this.getTypeList();
this.getDicts("sys_normal_disable").then(response => {
this.statusOptions = response.data;
});
// this.getDicts("sys_normal_disable").then(response => {
// this.statusOptions = response.data;
// });
},
methods: {
/** 查询字典类型详细 */
@ -235,15 +251,16 @@ export default {
/** 查询字典类型列表 */
getTypeList() {
listType().then(response => {
this.typeOptions = response.rows;
this.typeOptions = response.data.results;
});
},
/** 查询字典数据列表 */
getList() {
this.loading = true;
listData(this.queryParams).then(response => {
this.dataList = response.rows;
this.total = response.total;
console.log(1212,response.data.count)
this.dataList = response.data.results;
this.total = response.data.count;
this.loading = false;
});
},
@ -259,10 +276,10 @@ export default {
//
reset() {
this.form = {
dictCode: undefined,
dictLabel: undefined,
id: undefined,
name: undefined,
dictValue: undefined,
dictSort: 0,
sort: 0,
status: "0",
remark: undefined
};
@ -288,15 +305,15 @@ export default {
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.dictCode)
this.ids = selection.map(item => item.id)
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const dictCode = row.dictCode || this.ids
getData(dictCode).then(response => {
const id = row.id || this.ids
getData(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改字典数据";
@ -306,13 +323,15 @@ export default {
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.dictCode != undefined) {
if (this.form.id != undefined) {
updateData(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
const dictId = this.$route.params && this.$route.params.dictId;
this.form.dict_data = dictId
addData(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
@ -324,7 +343,7 @@ export default {
},
/** 删除按钮操作 */
handleDelete(row) {
const dictCodes = row.dictCode || this.ids;
const dictCodes = row.id || this.ids;
this.$confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
@ -351,4 +370,4 @@ export default {
}
}
};
</script>
</script>

View File

@ -1,9 +1,9 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="字典名称" prop="dictName">
<el-form-item label="字典名称" prop="name">
<el-input
v-model="queryParams.dictName"
v-model="queryParams.name"
placeholder="请输入字典名称"
clearable
size="small"
@ -113,11 +113,11 @@
<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="dictId" />
<el-table-column label="字典名称" align="center" prop="dictName" :show-overflow-tooltip="true" />
<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">
<template slot-scope="scope">
<router-link :to="'/dict/type/data/' + scope.row.dictId" class="link-type">
<router-link :to="'/dict/type/data/' + scope.row.id" class="link-type">
<span>{{ scope.row.dictType }}</span>
</router-link>
</template>
@ -160,8 +160,8 @@
<!-- 添加或修改参数配置对话框 -->
<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="dictName">
<el-input v-model="form.dictName" placeholder="请输入字典名称" />
<el-form-item label="字典名称" prop="name">
<el-input v-model="form.name" placeholder="请输入字典名称" />
</el-form-item>
<el-form-item label="字典类型" prop="dictType">
<el-input v-model="form.dictType" placeholder="请输入字典类型" />
@ -213,14 +213,14 @@ export default {
//
open: false,
//
statusOptions: [],
statusOptions: [{dictLabel: '正常', dictValue: '1',}, {dictLabel: '停用', dictValue: '0',}],
//
dateRange: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
dictName: undefined,
name: undefined,
dictType: undefined,
status: undefined
},
@ -228,7 +228,7 @@ export default {
form: {},
//
rules: {
dictName: [
name: [
{ required: true, message: "字典名称不能为空", trigger: "blur" }
],
dictType: [
@ -239,17 +239,17 @@ export default {
},
created() {
this.getList();
this.getDicts("sys_normal_disable").then(response => {
this.statusOptions = response.data;
});
// this.getDicts("sys_normal_disable").then(response => {
// this.statusOptions = response.data;
// });
},
methods: {
/** 查询字典类型列表 */
getList() {
this.loading = true;
listType(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
this.typeList = response.rows;
this.total = response.total;
this.typeList = response.data.results;
this.total = response.data.count;
this.loading = false;
}
);
@ -266,8 +266,8 @@ export default {
//
reset() {
this.form = {
dictId: undefined,
dictName: undefined,
id: undefined,
name: undefined,
dictType: undefined,
status: "0",
remark: undefined
@ -293,15 +293,15 @@ export default {
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.dictId)
this.ids = selection.map(item => item.id)
this.single = selection.length!=1
this.multiple = !selection.length
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const dictId = row.dictId || this.ids
getType(dictId).then(response => {
const id = row.id || this.ids
getType(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改字典类型";
@ -311,7 +311,7 @@ export default {
submitForm: function() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.dictId != undefined) {
if (this.form.id != undefined) {
updateType(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
@ -329,13 +329,13 @@ export default {
},
/** 删除按钮操作 */
handleDelete(row) {
const dictIds = row.dictId || this.ids;
this.$confirm('是否确认删除字典编号为"' + dictIds + '"的数据项?', "警告", {
const ids = row.id || this.ids;
this.$confirm('是否确认删除字典编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delType(dictIds);
return delType(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
@ -362,4 +362,4 @@ export default {
}
}
};
</script>
</script>