<template>
|
<div class="main">
|
<div class="main_header">
|
<div class="header_item">
|
<span class="header_label">类型:</span>
|
<el-select v-model="search.dictType" placeholder="请选择类型" clearable filterable>
|
<el-option
|
v-for="item in optionsType"
|
:key="item.dictType"
|
:label="item.dictTypeName"
|
:value="item.dictType">
|
</el-option>
|
</el-select>
|
</div>
|
<div class="header_item">
|
<el-button icon="el-icon-search" v-if="showButton('search')" @click="searchButtonInfo(true)">查询</el-button>
|
<el-button class="search_btn" icon="el-icon-plus" v-if="showButton('insert')" @click="insertProp">新增</el-button>
|
</div>
|
</div>
|
<div class="main_content">
|
<el-table
|
v-loading="loading"
|
:data="dataList"
|
height="100%">
|
<el-table-column prop="dictTypeName" label="类型" align="center"></el-table-column>
|
<el-table-column prop="dictName" label="内容" align="center"></el-table-column>
|
<!-- <el-table-column prop="dictTypeName" label="字典类型名称" align="center">
|
<template #default="{row}">
|
{{row.dictTypeName === 'null'?' ':row.dictTypeName}}
|
</template>
|
</el-table-column> -->
|
<el-table-column prop="dictValue" label="排序" align="center"></el-table-column>
|
<el-table-column label="操作" align="center">
|
<template #default="{ row }">
|
<el-button class="table_btn" size="mini" v-if="showButton('update')" @click="updateProp(row)">修改</el-button>
|
<el-button class="delete_btn" size="mini" v-if="showButton('delete')" @click="deleteInfo(row)">删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
<div class="main_footer">
|
<el-pagination
|
background
|
@current-change="changePageNum"
|
@size-change="changePageSize"
|
:current-page="pageNum"
|
:page-sizes="[10, 20, 50, 100]"
|
:page-size="pageSize"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="total">
|
</el-pagination>
|
</div>
|
<el-dialog
|
class="prop_dialog"
|
:title="asyncTitle ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="asyncVisible"
|
width="35%">
|
<el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="auto" class="rule_form">
|
<el-form-item label="类型:" prop="dictType">
|
<el-select v-model="ruleForm.dictType" placeholder="请选择类型" @change='showColors'>
|
<el-option
|
v-for="item in optionsType"
|
:key="item.dictType"
|
:label="item.dictTypeName"
|
:value="item.dictType">
|
</el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item label="颜色:" prop="colors" v-show="showClor">
|
<el-input v-model="ruleForm.colors" :size="size" clearable placeholder="请输入颜色名称(例:#fff或#ffffff)" disabled="true"></el-input>
|
<el-color-picker v-model="colorsList" @change="changeClor" style="margin-left:5px"></el-color-picker>
|
</el-form-item>
|
<el-form-item label="内容:" prop="dictName">
|
<el-input v-model="ruleForm.dictName" :size="size" clearable placeholder="请输入内容"></el-input>
|
</el-form-item>
|
<!-- <el-form-item label="字典类型名称:" prop="dictTypeName">
|
<el-input v-model="ruleForm.dictTypeName" :size="size" clearable placeholder="请输入字典类型名称"></el-input>
|
</el-form-item> -->
|
<el-form-item label="排序:" prop="dictValue">
|
<el-input v-model="ruleForm.dictValue" type="number" :size="size" clearable placeholder="请输入排序"></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer">
|
<el-button @click="asyncVisible = false">取 消</el-button>
|
<el-button class="submit_btn" @click="asyncTitle ? submitInsert() : submitUpdate()">提 交</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import { buttonPinia } from '../../pinia/index';
|
import { throttle, changeSize } from '../../plugins/public'; // 导入节流、动态切换组件尺寸方法
|
export default {
|
data() {
|
return {
|
size: changeSize(), // 组件尺寸
|
pageNum: 1,
|
pageSize: 10,
|
search:{},//查询条件
|
total: 0,
|
loading: false,
|
showClor:false,//是否展示颜色字段
|
colorsList:null,//颜色
|
dataList: [], //字典信息列表
|
asyncTitle: true, // 对话框title 新增:true 修改:false
|
asyncVisible: false, // 添加 修改对话框
|
ruleForm: {}, // 按钮表单
|
rules: {
|
dictName: [{
|
required: true,
|
message: '请输入内容',
|
trigger: 'blur'
|
}],
|
dictValue: [{
|
required: true,
|
message: '请输入排序',
|
trigger: 'blur'
|
}],
|
dictType: [{
|
required: true,
|
message: '请选择类型',
|
trigger: 'change'
|
}],
|
dictTypeName: [{
|
required: true,
|
message: '请输入字典类型名称',
|
trigger: 'blur'
|
}],
|
},
|
optionsType:[//类别下拉框
|
],
|
}
|
},
|
watch: {
|
asyncVisible(bol) {
|
if(!bol) {
|
this.ruleForm = {};
|
this.$refs.ruleForm.resetFields();
|
}
|
}
|
},
|
mounted() {
|
const that = this;
|
// 根据窗口大小动态修改组件尺寸
|
window.onresize = () => {
|
that.size = changeSize();
|
}
|
that.searchButtonInfo(true);
|
that.getalltypeList()
|
},
|
methods: {
|
//选择颜色
|
changeClor(){
|
this.$set(this.ruleForm,'colors',this.colorsList)
|
},
|
//获取字典类型下拉框
|
getalltypeList(){
|
this.$api.Dictionary.getAllTypeLists({}).then(res=>{
|
if(res.statusMsg === 'ok'){
|
this.optionsType = res.data
|
}else{
|
this.$message.warning(res.statusMsg)
|
}
|
})
|
},
|
//展示添加颜色字段
|
showColors(e){
|
if(e === '2'){
|
this.showClor = true
|
}else{
|
this.showClor = false
|
}
|
},
|
// 查询按钮列表信息
|
searchButtonInfo(bol) {
|
if(bol) {
|
this.pageNum = 1;
|
}
|
let params = Object.assign({},this.search,{
|
pageNum: this.pageNum,
|
pageSize: this.pageSize
|
})
|
this.loading = true;
|
this.$api.Dictionary.searchDictionary(params).then((res) => {
|
if(res.statusMsg === 'ok') {
|
this.total = res.data.total;
|
this.dataList = res.data.list;
|
}
|
this.loading = false;
|
})
|
},
|
// 新增按钮信息
|
insertProp() {
|
this.asyncTitle = true;
|
this.asyncVisible = true;
|
},
|
// 修改按钮信息
|
updateProp(row) {
|
this.asyncTitle = false;
|
this.asyncVisible = true;
|
this.$api.Dictionary.detailsDictionary({dictId: row.dictId}).then(res=>{
|
if(res.statusMsg === 'ok'){
|
this.ruleForm = res.data
|
if(res.data.dictType === '2'){
|
this.showClor = true
|
}else{
|
this.showClor = false
|
}
|
}else{
|
this.$message.warning(res.statusMsg)
|
}
|
})
|
},
|
// 删除按钮信息
|
deleteInfo(row) {
|
this.$confirm("该操作将删除该信息,是否继续删除?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning"
|
})
|
.then(() => {
|
this.$api.Dictionary.deleteDictionary({dictId: row.dictId})
|
.then(res => {
|
if(res.statusMsg === 'ok') {
|
this.searchButtonInfo(true);
|
this.$message.success("删除成功!");
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
})
|
.catch(() => {
|
this.$message.warning("您已取消");
|
})
|
},
|
// 提交添加按钮信息
|
submitInsert: throttle(function() {
|
this.$refs.ruleForm.validate((valid) => {
|
if(valid) {
|
const params = Object.assign({}, this.ruleForm);
|
this.$api.Dictionary.insertDictionary(params).then((res) => {
|
if(res.statusMsg === 'ok') {
|
this.asyncVisible = false;
|
this.searchButtonInfo(true);
|
this.$message.success('添加成功!');
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
}
|
})
|
}, 3000),
|
// 提交修改按钮信息
|
submitUpdate: throttle(function() {
|
this.$refs.ruleForm.validate((valid) => {
|
if(valid) {
|
const params = Object.assign({}, this.ruleForm);
|
this.$api.Dictionary.updateDictionary(params).then((res) => {
|
if(res.statusMsg === 'ok') {
|
this.asyncVisible = false;
|
this.searchButtonInfo(true);
|
this.$message.success('修改成功!');
|
} else {
|
this.$message.warning(res.statusMsg);
|
}
|
})
|
}
|
})
|
}, 3000),
|
// 判断按钮权限信息
|
showButton(str) {
|
const pinia = buttonPinia();
|
return pinia.$state.buttonInfo.includes(str);
|
},
|
// 切换页数
|
changePageNum(page) {
|
this.pageNum = page;
|
this.searchButtonInfo();
|
},
|
// 切换每页条数
|
changePageSize(size) {
|
this.pageSize = size;
|
this.searchButtonInfo();
|
}
|
}
|
}
|
</script>
|
|
<style lang="scss" scoped>
|
@import '../../style/layout-main.scss';
|
/deep/.el-color-picker__trigger{
|
border-color:#1C4390;
|
}
|
/deep/.el-color-picker__color{
|
border-color:#1C4390;
|
}
|
</style>
|