|
|
@ -4,17 +4,23 @@ |
|
|
|
<div class="head-container"> |
|
|
|
<div class="head-search"> |
|
|
|
<!-- 搜索 --> |
|
|
|
<el-input v-model="blurry" clearable size="small" placeholder="输入字典名称或字典代码搜索" prefix-icon="el-icon-search" style="width: 240px;" class="filter-item" @keyup.enter.native="getDictsList" /> |
|
|
|
<el-button class="filter-item filter-search" size="mini" type="success" icon="el-icon-search" @click="getDictsList">搜索</el-button> |
|
|
|
<el-input v-model="query.blurry" clearable size="small" placeholder="输入字典名称或字典代码搜索" prefix-icon="el-icon-search" style="width: 240px;" class="filter-item" @keyup.enter.native="crud.toQuery" /> |
|
|
|
<el-button class="filter-item filter-search" size="mini" type="success" icon="el-icon-search" @click="crud.toQuery">搜索</el-button> |
|
|
|
<el-button v-if="crud.optShow.reset" class="filter-item filter-refresh" size="mini" type="warning" icon="el-icon-refresh-left" @click="resetQuery()">重置</el-button> |
|
|
|
</div> |
|
|
|
<crudOperation :permission="permission"> |
|
|
|
<!-- <template v-slot:left> |
|
|
|
<el-button v-permission="permission.add" size="mini" type="primary" icon="el-icon-plus" :disabled="!activeAddBtn" @click="crud.toAdd">新增</el-button> |
|
|
|
<template v-slot:middle> |
|
|
|
<el-button slot="reference" size="mini" :loading="crud.delAllLoading" :disabled="crud.selections.length === 0" @click="toDelete(crud.selections)"> |
|
|
|
<i class="iconfont icon-shanchu" /> |
|
|
|
删除 |
|
|
|
</el-button> |
|
|
|
</template> |
|
|
|
<template v-slot:right> |
|
|
|
<el-button v-permission="permission.del" icon="el-icon-delete" size="mini" :loading="crud.delAllLoading" :disabled="crud.selections.length === 0" @click="toDelete(crud.selections)">删除</el-button> |
|
|
|
</template> --> |
|
|
|
<el-button :loading="crud.downloadLoading" size="mini" :disabled="crud.selections.length === 0" @click="doExport(crud.selections)"> |
|
|
|
<i class="iconfont icon-daochu" /> |
|
|
|
导出 |
|
|
|
</el-button> |
|
|
|
</template> |
|
|
|
</crudOperation> |
|
|
|
</div> |
|
|
|
<!--表单组件--> |
|
|
@ -28,7 +34,7 @@ |
|
|
|
<el-input v-model="form.dictionaryCode" /> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="顶级节点" prop="isTop"> |
|
|
|
<el-radio-group v-model="form.isTop"> |
|
|
|
<el-radio-group v-model="form.isTop" @input="changeIsTop"> |
|
|
|
<el-radio label="1">是</el-radio> |
|
|
|
<el-radio label="0">否</el-radio> |
|
|
|
</el-radio-group> |
|
|
@ -50,7 +56,9 @@ |
|
|
|
:options="dicts" |
|
|
|
:normalizer="normalizer" |
|
|
|
placeholder="选择上级节点" |
|
|
|
/> |
|
|
|
> |
|
|
|
<div slot="value-label" slot-scope="{ node }">{{ getAutoNameUnknown(node.label) }}</div> |
|
|
|
</treeselect> |
|
|
|
</el-form-item> |
|
|
|
</el-row> |
|
|
|
<el-form-item label="内容说明" prop="dictionaryRemarks"> |
|
|
@ -88,19 +96,19 @@ |
|
|
|
lazy |
|
|
|
:load="getDictsDatas" |
|
|
|
:data="tableData" |
|
|
|
:tree-props="{children: 'childMenus', hasChildren: 'hasChildren'}" |
|
|
|
highlight-current-row |
|
|
|
row-key="id" |
|
|
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}" |
|
|
|
:row-key="getRowKey" |
|
|
|
style="width: 100%;" |
|
|
|
@select="crud.selectChange" |
|
|
|
@select-all="crud.selectAllChange" |
|
|
|
@select-all="selectAll" |
|
|
|
@select="selectTr" |
|
|
|
@selection-change="crud.selectionChangeHandler" |
|
|
|
@row-click="clickRowHandler" |
|
|
|
> |
|
|
|
<el-table-column type="selection" width="55" /> |
|
|
|
<el-table-column type="selection" align="center" width="55" /> |
|
|
|
<el-table-column prop="dictionaryName" label="字典名称" /> |
|
|
|
<el-table-column prop="dictionaryCode" label="字典代码" /> |
|
|
|
<el-table-column prop="dictionaryRemarks" label="内容说明" /> |
|
|
|
<el-table-column prop="dicdictionaryOrder" label="排序" /> |
|
|
|
<el-table-column prop="dictionaryOrder" label="排序" /> |
|
|
|
<el-table-column prop="createTime" label="创建日期" width="200px"> |
|
|
|
<template slot-scope="scope"> |
|
|
|
<div>{{ scope.row.createTime | parseTime }}</div> |
|
|
@ -108,16 +116,7 @@ |
|
|
|
</el-table-column> |
|
|
|
</el-table> |
|
|
|
<!--分页组件--> |
|
|
|
<el-pagination |
|
|
|
v-if="page.total" |
|
|
|
:page-size.sync="page.size" |
|
|
|
:total="page.total" |
|
|
|
:current-page.sync="page.page" |
|
|
|
style="margin-top: 8px;" |
|
|
|
layout="total, prev, pager, next, sizes" |
|
|
|
@size-change="sizeChangeHandler($event)" |
|
|
|
@current-change="pageChangeHandler" |
|
|
|
/> |
|
|
|
<pagination v-if="crud.data.length!==0" /> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</template> |
|
|
@ -127,24 +126,33 @@ import crudDict from '@/api/system/dict' |
|
|
|
// import crudDictDetail from '@/api/archivesConfig/dictDetail' |
|
|
|
import CRUD, { presenter, header, form } from '@crud/crud' |
|
|
|
import crudOperation from '@crud/CRUD.operation' |
|
|
|
// import pagination from '@crud/Pagination' |
|
|
|
import pagination from '@crud/Pagination' |
|
|
|
import Treeselect from '@riophae/vue-treeselect' |
|
|
|
import '@riophae/vue-treeselect/dist/vue-treeselect.css' |
|
|
|
import { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect' |
|
|
|
import { mapGetters } from 'vuex' |
|
|
|
import { exportFile } from '@/utils/index' |
|
|
|
import qs from 'qs' |
|
|
|
|
|
|
|
const defaultForm = { id: null, dictionaryName: null, isTop: '1', dictionaryCode: null, dictionaryOrder: 999, dictionaryRemarks: null, dictionaryParents: null } |
|
|
|
|
|
|
|
export default { |
|
|
|
name: 'Dicts', |
|
|
|
components: { crudOperation, Treeselect }, |
|
|
|
components: { crudOperation, Treeselect, pagination }, |
|
|
|
cruds() { |
|
|
|
return [ |
|
|
|
CRUD({ |
|
|
|
title: '字典', url: '', |
|
|
|
title: '字典', idField: 'dictionaryId', url: 'api/dictionary/initDictionaryList', |
|
|
|
crudMethod: { ...crudDict }, |
|
|
|
queryOnPresenterCreated: false, |
|
|
|
sort: [] |
|
|
|
}) |
|
|
|
sort: [], |
|
|
|
optShow: { |
|
|
|
add: true, |
|
|
|
edit: true, |
|
|
|
del: false, |
|
|
|
reset: true, |
|
|
|
download: false, |
|
|
|
group: false |
|
|
|
}}) |
|
|
|
] |
|
|
|
}, |
|
|
|
mixins: [ |
|
|
@ -161,16 +169,8 @@ export default { |
|
|
|
}, |
|
|
|
data() { |
|
|
|
return { |
|
|
|
tableData: [], |
|
|
|
blurry: null, |
|
|
|
page: { |
|
|
|
total: 0, |
|
|
|
size: 10, |
|
|
|
page: 1 |
|
|
|
}, |
|
|
|
dicts: [], |
|
|
|
dictionaryParents: null, |
|
|
|
needRefreshTree: false, |
|
|
|
rules: { |
|
|
|
dictionaryName: [ |
|
|
|
{ required: true, message: '请输入字典名称', trigger: 'blur' } |
|
|
@ -191,63 +191,154 @@ export default { |
|
|
|
del: ['admin', 'dict:del'] |
|
|
|
}, |
|
|
|
deleteVisible: false, |
|
|
|
deleteData: {} |
|
|
|
deleteData: {}, |
|
|
|
isAllSelect: false |
|
|
|
} |
|
|
|
}, |
|
|
|
computed: { |
|
|
|
...mapGetters([ |
|
|
|
'baseApi' |
|
|
|
]) |
|
|
|
}, |
|
|
|
mounted() { |
|
|
|
this.getDictsList() |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
resetQuery() { |
|
|
|
this.blurry = null |
|
|
|
this.getDictsList() |
|
|
|
// 处理vue-treeSelect回显出现unknown问题 |
|
|
|
getAutoNameUnknown(name) { |
|
|
|
if (name.lastIndexOf('unknown') > -1) { |
|
|
|
return name.split('(')[0] |
|
|
|
} else { |
|
|
|
return name |
|
|
|
} |
|
|
|
}, |
|
|
|
[CRUD.HOOK.afterSubmit]() { |
|
|
|
this.needRefreshTree = true |
|
|
|
getRowKey(row) { |
|
|
|
return row.dictionaryId |
|
|
|
}, |
|
|
|
[CRUD.HOOK.afterDelete]() { |
|
|
|
this.needRefreshTree = true |
|
|
|
resetQuery() { |
|
|
|
this.crud.query.blurry = '' |
|
|
|
this.crud.toQuery() |
|
|
|
}, |
|
|
|
// 新增与编辑前做的操作 |
|
|
|
[CRUD.HOOK.afterToCU](crud, form) { |
|
|
|
if (form.dictionaryParents !== null) { |
|
|
|
form.isTop = '0' |
|
|
|
} else if (form.id !== null) { |
|
|
|
} else if (form.dictionaryId !== null) { |
|
|
|
form.isTop = '1' |
|
|
|
} |
|
|
|
this.getDictsList() |
|
|
|
this.getDictsTreeList() |
|
|
|
}, |
|
|
|
// 获取数据前设置默认参数 |
|
|
|
[CRUD.HOOK.beforeRefresh]() { |
|
|
|
this.crud.query.id = this.dictionaryParents |
|
|
|
this.tableData = [] |
|
|
|
}, |
|
|
|
[CRUD.HOOK.afterRefresh](crud) { |
|
|
|
if (this.needRefreshTree) { |
|
|
|
this.needRefreshTree = false |
|
|
|
this.$emit('treeRefresh', crud.data) |
|
|
|
crud.data.forEach(function(item, index) { |
|
|
|
if (item.sonNum !== 0) { |
|
|
|
item.hasChildren = true |
|
|
|
} else { |
|
|
|
item.hasChildren = false |
|
|
|
} |
|
|
|
if (!item.hasChildren) { |
|
|
|
item.children = null |
|
|
|
} |
|
|
|
}) |
|
|
|
this.tableData = this.crud.data |
|
|
|
}, |
|
|
|
// 编辑前 |
|
|
|
[CRUD.HOOK.beforeToEdit](crud, form) { |
|
|
|
crud.form.id = form.dictionaryId |
|
|
|
}, |
|
|
|
// 提交前的验证 |
|
|
|
[CRUD.HOOK.afterValidateCU](crud) { |
|
|
|
if (crud.form.isTop === '1') { |
|
|
|
crud.form.dictionaryParents = null |
|
|
|
} |
|
|
|
delete crud.form.isTop |
|
|
|
console.log(crud.form) |
|
|
|
return true |
|
|
|
}, |
|
|
|
changeIsTop(val) { |
|
|
|
if (val === '0') { |
|
|
|
this.getDictsTreeList() |
|
|
|
} |
|
|
|
}, |
|
|
|
selectAll() { |
|
|
|
this.isAllSelect = !this.isAllSelect |
|
|
|
const data = this.tableData |
|
|
|
this.toggleSelect(data, this.isAllSelect, 'all') |
|
|
|
console.log(data) |
|
|
|
}, |
|
|
|
// 选择某行 |
|
|
|
selectTr(selection, row) { |
|
|
|
this.$set(row, 'isChecked', !row.isChecked) |
|
|
|
this.$nextTick(() => { |
|
|
|
this.isAllSelect = row.isChecked |
|
|
|
this.toggleSelect(row, row.isChecked, 'tr') |
|
|
|
}) |
|
|
|
}, |
|
|
|
// 递归子级 |
|
|
|
toggleSelect(data, flag, type) { |
|
|
|
if (type === 'all') { |
|
|
|
if (data.length > 0) { |
|
|
|
data.forEach((item) => { |
|
|
|
this.toggleSelection(item, flag) |
|
|
|
if (item.children && item.children.length > 0) { |
|
|
|
this.toggleSelect(item.children, flag, type) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} else { |
|
|
|
if (data.children && data.children.length > 0) { |
|
|
|
data.children.forEach((item) => { |
|
|
|
item.isChecked = flag |
|
|
|
this.$refs.table.toggleRowSelection(item, flag) |
|
|
|
this.toggleSelect(item, flag, type) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
// 改变选中 |
|
|
|
toggleSelection(row, flag) { |
|
|
|
this.$set(row, 'isChecked', flag) |
|
|
|
this.$nextTick(() => { |
|
|
|
if (flag) { |
|
|
|
this.$refs.table.toggleRowSelection(row, flag) |
|
|
|
} else { |
|
|
|
this.$refs.table.clearSelection() |
|
|
|
} |
|
|
|
}) |
|
|
|
}, |
|
|
|
clickRowHandler(row) { |
|
|
|
this.$refs.table.clearSelection() |
|
|
|
this.$refs.table.toggleRowSelection(row) |
|
|
|
}, |
|
|
|
getDictsDatas(tree, treeNode, resolve) { |
|
|
|
const params = { pid: tree.id } |
|
|
|
setTimeout(() => { |
|
|
|
crudDict.getDictsList(params).then(res => { |
|
|
|
resolve(res.content) |
|
|
|
console.log(treeNode) |
|
|
|
crudDict.FetchSonDictionaryList({ pid: tree.dictionaryId }).then(res => { |
|
|
|
const data = res.map(function(obj) { |
|
|
|
if (obj.sonNum !== 0) { |
|
|
|
obj.hasChildren = true |
|
|
|
obj.children = null |
|
|
|
} else { |
|
|
|
obj.hasChildren = false |
|
|
|
} |
|
|
|
return obj |
|
|
|
}) |
|
|
|
resolve(data) |
|
|
|
}) |
|
|
|
}, 100) |
|
|
|
}, |
|
|
|
getDictsList() { |
|
|
|
this.crud.loading = true |
|
|
|
const params = { |
|
|
|
blurry: this.blurry, |
|
|
|
page: this.page.page - 1, |
|
|
|
size: this.page.size |
|
|
|
} |
|
|
|
crudDict.getDictsList(params).then(res => { |
|
|
|
this.tableData = res.content |
|
|
|
this.total = res.totalPages |
|
|
|
this.dicts = res.content.map(function(obj) { |
|
|
|
if (!obj.childMenus) { |
|
|
|
obj.childMenus = null |
|
|
|
getDictsTreeList() { |
|
|
|
crudDict.FetchDictionaryTree().then(res => { |
|
|
|
this.dicts = res.map(function(obj) { |
|
|
|
if (obj.sonNum !== 0) { |
|
|
|
obj.hasChildren = true |
|
|
|
} else { |
|
|
|
obj.hasChildren = false |
|
|
|
} |
|
|
|
if (obj.hasChildren) { |
|
|
|
obj.children = null |
|
|
|
} |
|
|
|
return obj |
|
|
|
}) |
|
|
@ -257,7 +348,7 @@ export default { |
|
|
|
// 获取弹窗内字典数据 |
|
|
|
loadDicts({ action, parentNode, callback }) { |
|
|
|
if (action === LOAD_CHILDREN_OPTIONS) { |
|
|
|
crudDict.getDictsList().then(res => { |
|
|
|
crudDict.FetchDictionaryTree().then(res => { |
|
|
|
parentNode.children = res.map(function(obj) { |
|
|
|
if (obj.children) { |
|
|
|
obj.childMenus = null |
|
|
@ -270,60 +361,60 @@ export default { |
|
|
|
}) |
|
|
|
} |
|
|
|
}, |
|
|
|
// clickRowHandler(row) { |
|
|
|
// this.$refs.table.clearSelection() |
|
|
|
// this.$refs.table.toggleRowSelection(row) |
|
|
|
// }, |
|
|
|
// selectionChangeHandler(val) { |
|
|
|
// if (val.length > 1) { |
|
|
|
// // 取出最后val的最后一个返回出来 |
|
|
|
// const finalVal = val.pop() |
|
|
|
// // 清除所有选中 |
|
|
|
// this.$refs.table.clearSelection() |
|
|
|
// // 给最后一个加上选中 |
|
|
|
// this.$refs.table.toggleRowSelection(finalVal) |
|
|
|
// this.crud.selectionChangeHandler([finalVal]) |
|
|
|
// } else { |
|
|
|
// this.crud.selectionChangeHandler(val) |
|
|
|
// } |
|
|
|
// }, |
|
|
|
// toDelete(data) { |
|
|
|
// this.deleteData = data |
|
|
|
// this.deleteVisible = true |
|
|
|
// }, |
|
|
|
// handleConfirm() { |
|
|
|
// this.deleteVisible = false |
|
|
|
// this.crud.delAllLoading = true |
|
|
|
// this.crud.doDelete(this.deleteData) |
|
|
|
// }, |
|
|
|
// handleClose(done) { |
|
|
|
// this.deleteData = {} |
|
|
|
// done() |
|
|
|
// }, |
|
|
|
toDelete(datas) { |
|
|
|
this.deleteData = datas |
|
|
|
this.$confirm('此操作将删除当前所选' + this.crud.title + '<span>你是否还要继续?</span>', '提示', { |
|
|
|
confirmButtonText: '继续', |
|
|
|
cancelButtonText: '取消', |
|
|
|
type: 'warning', |
|
|
|
dangerouslyUseHTMLString: true |
|
|
|
}).then(() => { |
|
|
|
this.crud.delAllLoading = true |
|
|
|
const dictionaryIds = [] |
|
|
|
this.deleteData.forEach(val => { |
|
|
|
dictionaryIds.push(val.dictionaryId) |
|
|
|
}) |
|
|
|
crudDict.del(dictionaryIds).then(() => { |
|
|
|
this.crud.notify('删除成功', CRUD.NOTIFICATION_TYPE.SUCCESS) |
|
|
|
this.crud.delAllLoading = false |
|
|
|
this.crud.refresh() |
|
|
|
}).catch(err => { |
|
|
|
this.crud.delAllLoading = false |
|
|
|
console.log(err) |
|
|
|
}) |
|
|
|
}).catch(() => { |
|
|
|
}) |
|
|
|
}, |
|
|
|
doExport(data) { |
|
|
|
console.log(data) |
|
|
|
this.crud.downloadLoading = true |
|
|
|
this.$confirm('此操作将导出所选数据' + '<span>你是否还要继续?</span>', '提示', { |
|
|
|
confirmButtonText: '继续', |
|
|
|
cancelButtonText: '取消', |
|
|
|
type: 'warning', |
|
|
|
dangerouslyUseHTMLString: true |
|
|
|
}).then(() => { |
|
|
|
const ids = [] |
|
|
|
data.forEach(val => { |
|
|
|
ids.push(val.dictionaryId) |
|
|
|
}) |
|
|
|
const params = { |
|
|
|
'dictionaryIds': ids |
|
|
|
} |
|
|
|
exportFile(this.baseApi + '/api/dictionary/download?' + qs.stringify(params, { indices: false })) |
|
|
|
this.crud.downloadLoading = false |
|
|
|
}).catch(() => { |
|
|
|
}) |
|
|
|
}, |
|
|
|
normalizer(node) { |
|
|
|
if (node.childMenus == null || node.childMenus === 'null') { |
|
|
|
delete node.childMenus |
|
|
|
if (node.childDictionarys == null || node.childDictionarys === 'null') { |
|
|
|
delete node.childDictionarys |
|
|
|
} |
|
|
|
return { |
|
|
|
id: node.id, |
|
|
|
label: node.dictionaryName, |
|
|
|
children: node.childMenus |
|
|
|
children: node.childDictionarys |
|
|
|
} |
|
|
|
}, |
|
|
|
// 每页条数改变 |
|
|
|
sizeChangeHandler(e) { |
|
|
|
this.crud.loading = true |
|
|
|
this.page.size = e |
|
|
|
this.page.page = 1 |
|
|
|
this.getDictsList() |
|
|
|
this.crud.loading = false |
|
|
|
}, |
|
|
|
// 当前页改变 |
|
|
|
pageChangeHandler(e) { |
|
|
|
this.crud.loading = true |
|
|
|
this.page.page = e |
|
|
|
this.getDictsList() |
|
|
|
this.crud.loading = false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|