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