<template>
|
<div class="clients-wrapper" style="position: initial;">
|
<div class="clients-content clients-scroll container-p-x container-p-y overflow-y">
|
<!-- Header -->
|
<h4 class="d-flex flex-wrap justify-content-between align-items-center font-weight-bold pt-2 mb-2">
|
<div class="mb-2">数据字典管理</div>
|
<div class="mb-2" style="max-width: 200px;">
|
<fButton type="warning" @click.native="handleAdd" authority="sys:dict:add">
|
<span class="fas fa-plus pr10"></span>
|
新增字典
|
</fButton>
|
</div>
|
</h4>
|
<!-- / Header -->
|
|
<!-- 设备列表 -->
|
<b-card no-body>
|
<!-- 检索 start -->
|
<b-card-header header-tag="h4" class="media flex-wrap align-items-center py-4">
|
<span style="font-size: 16px;">字典类型:</span>
|
<b-form-select style="max-width: 10rem;" v-model="currentType" @change="(e)=>{currentType = e;fetchData()}" text-field="lable" :options="sys_type" class="mr10" />
|
<b-input placeholder="字典名称..." autocomplete="off" style="max-width: 20rem;" class="mr10" v-model="name" @keyup.enter.native="handleSearch" />
|
<b-btn variant="primary" class="mr10" @click="handleSearch">
|
<span class="fs fas-search"></span>
|
搜索
|
</b-btn>
|
</b-card-header>
|
<!-- 检索 end -->
|
<div class="pl20 pr20 pt10 pb30">
|
<Table :data="dicList" highlight-current-row ref="leftTable">
|
<TableColumn type="index" prop="index" label="序号" :index="snMethod" width="100" />
|
<TableColumn label="字典类型" prop="type" :formatter="formatType" />
|
<TableColumn label="字典名称" prop="lable" />
|
<TableColumn label="字典值" prop="value" />
|
<TableColumn label="字典附加字段" prop="revJson" />
|
<TableColumn label="操作" width="280">
|
<template slot-scope="scope">
|
<div @click.stop>
|
<fButton type="link" style="padding:2px;" authority="sys:dict:edit" @click.native.self="$router.push({path:'/dic/add',query:{id:scope.row.id, type:'edit'}})">
|
编辑字典
|
</fButton>
|
<fButton type="link" style="padding:2px;" @click.native="handleDel(scope.row.id)" authority="sys:dict:delete">
|
删除
|
</fButton>
|
</div>
|
</template>
|
</TableColumn>
|
</Table>
|
<div class="pt20 pb20">
|
<b-pagination class="justify-content-center justify-content-sm-end m-0" v-if="total" v-model="currentPage" :total-rows="total" :per-page="length" />
|
</div>
|
</div>
|
</b-card>
|
<!-- / 设备列表 -->
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import { Table, TableColumn } from 'element-ui'
|
import { getSysDicts, getGloDicts, sysDictsDel } from '../../server/dic.js'
|
export default {
|
metaInfo: {
|
title: '数字字典管理'
|
},
|
data: () => ({
|
dicList: [],
|
sys_type: [],
|
length: 10,
|
currentPage: 1,
|
name: '',
|
total: 0,
|
currentType: ''
|
}),
|
computed: {
|
userInfo() {
|
return this.$store.getters.basicUserInfo
|
}
|
},
|
async mounted() {
|
await this._initGloDicts()
|
await this.fetchData()
|
},
|
methods: {
|
// * 数据获取
|
async fetchData() {
|
const res = await getSysDicts({
|
orgId: this.userInfo.orgId,
|
type: this.currentType,
|
module: this.$store.state.menuName,
|
start: this.length * (this.currentPage - 1),
|
length: this.length,
|
name: this.name
|
})
|
if (res) {
|
this.dicList = res.data
|
this.total = res.total - 0
|
}
|
},
|
// * 序号计算
|
snMethod(index) {
|
return this.currentPage > 1
|
? this.length * (this.currentPage - 1) + index + 1
|
: index + 1
|
},
|
// * 字典类型
|
async fetchtGloDicts(type) {
|
const res = await getGloDicts({ type })
|
if (res && res.code - 0 === 0) {
|
return res.data
|
}
|
},
|
// * 初始化字典
|
async _initGloDicts() {
|
this.sys_type = await this.fetchtGloDicts('SYSTEM_DICT')
|
this.sys_type = [{ lable: '全部', value: '' }, ...this.sys_type]
|
},
|
// * 格式化 type
|
formatType({ type }) {
|
const result = this.sys_type.find(item => item.value === type)
|
if (result && result.lable) {
|
return result.lable
|
} else {
|
return ''
|
}
|
},
|
// * 搜索
|
handleSearch() {
|
this.fetchData()
|
},
|
// * 添加页面跳转
|
handleAdd() {
|
this.$router.push('dic/add')
|
},
|
// * 删除
|
handleDel(id) {
|
this.$swal(
|
{
|
title: '确定删除吗?',
|
type: 'warning',
|
showCancelButton: true,
|
allowOutsideClick: true,
|
confirmButtonText: '确定删除!',
|
cancelButtonText: '取消删除!',
|
closeOnConfirm: true
|
},
|
async () => {
|
let res = await sysDictsDel({ id })
|
if (res && res.code - 0 === 0) {
|
this.$toast({
|
type: 'success',
|
message: '删除成功'
|
})
|
this.fetchData()
|
} else {
|
this.$toast({
|
type: 'success',
|
message: res.message
|
})
|
}
|
}
|
)
|
}
|
},
|
watch: {
|
currentPage(val, oldVal) {
|
if (val !== oldVal) {
|
this.currentPage = val
|
this.fetchData()
|
}
|
}
|
},
|
components: {
|
Table,
|
TableColumn
|
}
|
}
|
</script>
|