pull/27/MERGE
fenda 2021-05-02 21:12:33 +08:00
parent 3cefa07d53
commit fdbd517276
1 changed files with 115 additions and 77 deletions

View File

@ -1,6 +1,12 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> <el-form
:model="queryParams"
ref="queryForm"
:inline="true"
v-show="showSearch"
label-width="68px"
>
<el-form-item label="字典名称" prop="dictType"> <el-form-item label="字典名称" prop="dictType">
<el-select v-model="queryParams.dictType" size="small"> <el-select v-model="queryParams.dictType" size="small">
<el-option <el-option
@ -21,7 +27,12 @@
/> />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-select v-model="queryParams.status" placeholder="数据状态" clearable size="small"> <el-select
v-model="queryParams.status"
placeholder="数据状态"
clearable
size="small"
>
<el-option <el-option
v-for="dict in statusOptions" v-for="dict in statusOptions"
:key="dict.dictValue" :key="dict.dictValue"
@ -31,7 +42,9 @@
</el-select> </el-select>
</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 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 icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -45,7 +58,8 @@
size="mini" size="mini"
@click="handleAdd" @click="handleAdd"
v-hasPermi="['system:dict:type:post']" v-hasPermi="['system:dict:type:post']"
>新增</el-button> >新增</el-button
>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
@ -56,7 +70,8 @@
:disabled="single" :disabled="single"
@click="handleUpdate" @click="handleUpdate"
v-hasPermi="['system:dict:type:{id}:put']" v-hasPermi="['system:dict:type:{id}:put']"
>修改</el-button> >修改</el-button
>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
@ -67,7 +82,8 @@
:disabled="multiple" :disabled="multiple"
@click="handleDelete" @click="handleDelete"
v-hasPermi="['system:dict:type:{id}:delete']" v-hasPermi="['system:dict:type:{id}:delete']"
>删除</el-button> >删除</el-button
>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
@ -77,7 +93,8 @@
size="mini" size="mini"
@click="handleExport" @click="handleExport"
v-hasPermi="['system:dict:type:export:get']" v-hasPermi="['system:dict:type:export:get']"
>导出</el-button> >导出</el-button
>
</el-col> </el-col>
<el-col :span="1.5"> <el-col :span="1.5">
<el-button <el-button
@ -87,27 +104,39 @@
size="mini" size="mini"
@click="handleClearCache" @click="handleClearCache"
v-hasPermi="['system:dict:type:clearcache:delete']" v-hasPermi="['system:dict:type:clearcache:delete']"
>清理缓存</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="dataList" @selection-change="handleSelectionChange"> <el-table
v-loading="loading"
:data="dataList"
@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="dictLabel" /> <el-table-column label="字典标签" align="center" prop="dictLabel" />
<el-table-column label="字典键值" align="center" prop="dictValue" /> <el-table-column label="字典键值" align="center" prop="dictValue" />
<el-table-column label="字典排序" align="center" prop="sort" /> <el-table-column label="字典排序" align="center" prop="sort" />
<el-table-column label="是否默认" align="center" prop="is_default" > <el-table-column label="是否默认" align="center" prop="is_default">
<template slot-scope="scope"> <template slot-scope="scope">
<el-switch <el-switch disabled :value="scope.row.is_default"> </el-switch>
disabled
:value="scope.row.is_default">
</el-switch>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" /> <el-table-column
<el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> 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="create_datetime" width="180"> <el-table-column label="创建时间" align="center" prop="create_datetime" width="180">
<template slot-scope="scope"> <template slot-scope="scope">
<span>{{ parseTime(scope.row.create_datetime) }}</span> <span>{{ parseTime(scope.row.create_datetime) }}</span>
@ -117,7 +146,7 @@
label="操作" label="操作"
align="center" align="center"
class-name="small-padding fixed-width" class-name="small-padding fixed-width"
v-if="hasPermi(['system:dict:type:{id}:put','system:dict:type:{id}:delete'])" v-if="hasPermi(['system:dict:type:{id}:put', 'system:dict:type:{id}:delete'])"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button
@ -126,20 +155,22 @@
icon="el-icon-edit" icon="el-icon-edit"
@click="handleUpdate(scope.row)" @click="handleUpdate(scope.row)"
v-hasPermi="['system:dict:type:{id}:put']" v-hasPermi="['system:dict:type:{id}:put']"
>修改</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:type:{id}:delete']" v-hasPermi="['system:dict:type:{id}:delete']"
>删除</el-button> >删除</el-button
>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination <pagination
v-show="total>0" v-show="total > 0"
:total="total" :total="total"
:page.sync="queryParams.pageNum" :page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize" :limit.sync="queryParams.pageSize"
@ -162,10 +193,7 @@
<el-input-number v-model="form.sort" controls-position="right" :min="0" /> <el-input-number v-model="form.sort" controls-position="right" :min="0" />
</el-form-item> </el-form-item>
<el-form-item label="是否默认" prop="is_default"> <el-form-item label="是否默认" prop="is_default">
<el-switch <el-switch v-model="form.is_default" active-text="是" inactive-text="否">
v-model="form.is_default"
active-text="是"
inactive-text="否">
</el-switch> </el-switch>
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
@ -174,11 +202,16 @@
v-for="dict in statusOptions" v-for="dict in statusOptions"
:key="dict.dictValue" :key="dict.dictValue"
:label="dict.dictValue" :label="dict.dictValue"
>{{dict.dictLabel}}</el-radio> >{{ dict.dictLabel }}</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">
@ -190,10 +223,17 @@
</template> </template>
<script> <script>
import {addData, delData, exportData, getData, listData, updateData} from "@/api/vadmin/system/dict/data"; import {
import {getType, listType, clearCache} from "@/api/vadmin/system/dict/type"; addData,
delData,
exportData,
getData,
listData,
updateData,
} from "@/api/vadmin/system/dict/data";
import { getType, listType, clearCache } from "@/api/vadmin/system/dict/type";
export default { export default {
name: "Data", name: "Data",
data() { data() {
return { return {
@ -224,39 +264,33 @@
// //
queryParams: { queryParams: {
pageNum: 1, pageNum: 1,
pageSize: 1000, pageSize: 10,
dictName: undefined, dictName: 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" } dictValue: [{ required: true, message: "数据键值不能为空", trigger: "blur" }],
], sort: [{ required: true, message: "数据顺序不能为空", trigger: "blur" }],
dictValue: [ },
{ required: true, message: "数据键值不能为空", trigger: "blur" }
],
sort: [
{ required: true, message: "数据顺序不能为空", trigger: "blur" }
]
}
}; };
}, },
created() { created() {
const dictId = this.$route.params && this.$route.params.dictId; const dictId = this.$route.params && this.$route.params.dictId;
this.getType(dictId); this.getType(dictId);
this.getTypeList(); this.getTypeList();
this.getDicts("sys_normal_disable").then(response => { this.getDicts("sys_normal_disable").then((response) => {
this.statusOptions = response.data; this.statusOptions = response.data;
}); });
}, },
methods: { methods: {
/** 查询字典类型详细 */ /** 查询字典类型详细 */
getType(dictId) { getType(dictId) {
getType(dictId).then(response => { getType(dictId).then((response) => {
this.queryParams.dictType = response.data.dictType; this.queryParams.dictType = response.data.dictType;
this.defaultDictType = response.data.dictType; this.defaultDictType = response.data.dictType;
this.getList(); this.getList();
@ -264,14 +298,14 @@
}, },
/** 查询字典类型列表 */ /** 查询字典类型列表 */
getTypeList() { getTypeList() {
listType({pageNum: 'all'}).then(response => { listType({ pageNum: "all" }).then((response) => {
this.typeOptions = response.data; this.typeOptions = response.data;
}); });
}, },
/** 查询字典数据列表 */ /** 查询字典数据列表 */
getList() { getList() {
this.loading = true; this.loading = true;
listData(this.queryParams).then(response => { listData(this.queryParams).then((response) => {
this.dataList = response.data.results; this.dataList = response.data.results;
this.total = response.data.count; this.total = response.data.count;
this.loading = false; this.loading = false;
@ -294,19 +328,19 @@
dictValue: undefined, dictValue: undefined,
sort: 0, sort: 0,
status: this.selectDictDefault(this.typeOptions), status: this.selectDictDefault(this.typeOptions),
remark: undefined remark: undefined,
}; };
this.resetForm("form"); this.resetForm("form");
}, },
/** 搜索按钮操作 */ /** 搜索按钮操作 */
handleQuery() { handleQuery() {
let dictId = '' let dictId = "";
this.typeOptions.map(val => { this.typeOptions.map((val) => {
if (val.dictType === this.queryParams.dictType) { if (val.dictType === this.queryParams.dictType) {
dictId = val.id dictId = val.id;
} }
}) });
this.$route.params.dictId = dictId this.$route.params.dictId = dictId;
this.queryParams.pageNum = 1; this.queryParams.pageNum = 1;
this.getList(); this.getList();
}, },
@ -325,34 +359,34 @@
}, },
// //
handleSelectionChange(selection) { handleSelectionChange(selection) {
this.ids = selection.map(item => item.id) this.ids = selection.map((item) => item.id);
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();
const id = row.id || this.ids const id = row.id || this.ids;
getData(id).then(response => { getData(id).then((response) => {
this.form = response.data; this.form = response.data;
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.id != undefined) { if (this.form.id != undefined) {
updateData(this.form).then(response => { updateData(this.form).then((response) => {
this.msgSuccess("修改成功"); this.msgSuccess("修改成功");
this.open = false; this.open = false;
this.getList(); this.getList();
}); });
} else { } else {
const dictId = this.$route.params && this.$route.params.dictId; const dictId = this.$route.params && this.$route.params.dictId;
this.form.dict_data = dictId this.form.dict_data = dictId;
addData(this.form).then(response => { addData(this.form).then((response) => {
this.msgSuccess("新增成功"); this.msgSuccess("新增成功");
this.open = false; this.open = false;
this.getList(); this.getList();
@ -367,33 +401,37 @@
this.$confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?', "警告", { this.$confirm('是否确认删除字典编码为"' + dictCodes + '"的数据项?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning",
}).then(function() { })
.then(function () {
return delData(dictCodes); return delData(dictCodes);
}).then(() => { })
.then(() => {
this.getList(); this.getList();
this.msgSuccess("删除成功"); this.msgSuccess("删除成功");
}) });
}, },
/** 导出按钮操作 */ /** 导出按钮操作 */
handleExport() { handleExport() {
const queryParams = this.queryParams; const queryParams = this.queryParams;
this.$confirm('是否确认导出所有数据项?', "警告", { this.$confirm("是否确认导出所有数据项?", "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning",
}).then(function() {
return exportData(queryParams);
}).then(response => {
this.download(response.data.file_url,response.data.name);
}) })
.then(function () {
return exportData(queryParams);
})
.then((response) => {
this.download(response.data.file_url, response.data.name);
});
}, },
/** 清理缓存按钮操作 */ /** 清理缓存按钮操作 */
handleClearCache() { handleClearCache() {
clearCache().then(response => { clearCache().then((response) => {
this.msgSuccess("清理成功"); this.msgSuccess("清理成功");
}); });
} },
} },
}; };
</script> </script>