Commit 88a97c3b authored by wangxl's avatar wangxl

888

parent acdcbe9d
...@@ -913,10 +913,6 @@ export default { ...@@ -913,10 +913,6 @@ export default {
getArrayListByType (params) { getArrayListByType (params) {
return fetch(`/v1/science-admin/system-parameter/getArrayListByType`, params) return fetch(`/v1/science-admin/system-parameter/getArrayListByType`, params)
}, },
// 根据字典类型查询字典数据信息
getDicts (dictType) {
return fetch(`/v1/science-admin/system-parameter/getArrayListByType`, { typeId: dictType })
},
getTreeListByType (params) { getTreeListByType (params) {
return fetch(`/v1/science-admin/system-parameter/getTreeListByType`, params) return fetch(`/v1/science-admin/system-parameter/getTreeListByType`, params)
}, },
......
...@@ -67,14 +67,14 @@ export default { ...@@ -67,14 +67,14 @@ export default {
components: { components: {
talentView, audit, batchAudit, paraSelect talentView, audit, batchAudit, paraSelect
}, },
// dicts: ['PROJECT_STATUS', 'PARAMETER_TYPE', 'STATUS_TYPE'], dicts: ['title'],
// mounted () { mounted () {
// // 监听字典数据加载完成事件 // 监听字典数据加载完成事件
// this.$on('dictReady', () => { this.$on('dictReady', () => {
// console.log('字典数据加载完成') console.log('字典数据加载完成')
// console.log('项目状态字典:', this.dict.projectStatus) console.log('项目状态字典:', this.dict.title, this.dict.dictLabel.title)
// }) })
// }, },
data () { data () {
return { return {
selectedRowKeys: [], selectedRowKeys: [],
......
<template>
<div style=" width:auto; display:inline-block !important; display:inline;z-index:100">
<a-select :style="{width: width + 'px'}" v-model="parSelected" @change="parentChange($event)" :key="0">
<a-select-option v-for="item in parArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
<a-select :style="{width: width + 'px'}" v-model="selected" @change="childChange($event)" :key="1">
<a-select-option v-for="item in chArray" :key="item.key" :value="item.key" select>{{ item.title }}</a-select-option>
</a-select>
</div>
</template>
<script>
export default {
//用法 <para-multi-select v-model="formData.projClass" :typeId="52" />
name: "paraMultiSelect",
data () {
return {
parArray: [],
chArray: [],
parSelected: '',
selected: '',
defaultAll: {
title: "--请选择" + this.title + "--",
key: "",
children: [{
title: "--请先选择上级-",
key: "",
}]
},
loading: false
};
},
props: {
value: {
type: String,
default () {
return null
}
},
typeId: {
type: Number,
default () {
return 0
}
},
width: {
type: Number,
default () {
return 180
}
},
title: {
type: String,
default () {
return ''
}
},
},
created () {
this.load(this.value)
},
methods: {
async load (value) {
if (!!!this.parArray || this.parArray.length == 0) {
this.parArray = await this.$store.dispatch('cache/getDictByType', 6)
this.parArray.unshift(this.defaultAll)
this.chArray = this.parArray[0].children
this.parSelected = ''
this.selected = ''
}
if (!!value) {
var show = this.getParIndex(this.parArray, value)
this.chArray = this.parArray[show].children
this.parSelected = this.parArray[show].key
this.selected = value
}
},
parentChange (value) {
this.childArray = [];
this.childArray.unshift(this.defaultChild)
this.childValue = ''
if (value != '') {
let pars2 = { typeId: this.typeId, parentId: value };
this.$api.parameter.getParameterList(pars2).then(({ data = {} }) => {
if (data) {
this.childArray = data.data
this.childArray.unshift(this.defaultChild)
}
}).catch(() => { });
}
else {
this.childArray = [this.defaultChild]
this.childValue = ''
this.$emit("input", null);
this.$emit("change");
}
this.$emit('parentChange', value)
this.$emit("change");
},
childChange (value) {
this.$emit("input", value);
var newArr = this.childArray.filter(x => x.key == value);
if (!!newArr && newArr.length > 0) {
var text = !!value ? newArr[0].title : ''
this.$emit('changeTitle', text)
}
this.$emit("change");
},
getParIndex (list, value) {
var show = 0
if (!!list && list.length > 0) {
for (var i = 0; i < list.length; i++) {
for (var j = 0; j < list[i].children.length; j++) {
if (list[i].children[j].key == value) {
show = i
break
}
}
}
}
return show
}
},
watch: {
value: {
handler (value) {
if (!!value && !this.loading) {
this.loading = true
this.load(value)
}
},
},
}
}
</script>
import Vue from 'vue' import Vue from 'vue'
import api from '@/api'
import DictTypes from './DictTypes' import DictTypes from './DictTypes'
export default class Dict { export default class Dict {
constructor(dict) { constructor(dict) {
this.dict = dict this.dict = dict
} }
/** /**
* 初始化字典数据 * 初始化字典数据
* @param {Array} names 字典类型名称数组 * @param {Array} names 字典类型名称数组
...@@ -17,15 +15,15 @@ export default class Dict { ...@@ -17,15 +15,15 @@ export default class Dict {
throw new Error('need Dict names') throw new Error('need Dict names')
} }
const promises = names.map(n => { const promises = names.map(n => {
let param = DictTypes[n] let obj = DictTypes[n]
if (param === undefined || param === null) { if (obj === undefined || obj === null) {
throw new Error('need Dict names') throw new Error('need Dict names')
} }
// 初始化字典数据结构 // 初始化字典数据结构
Vue.set(this.dict.dictLabel, n, {}) Vue.set(this.dict.dictLabel, n, {})
Vue.set(this.dict, n, []) Vue.set(this.dict, n, [])
// 获取字典数据 // 获取字典数据
return api.parameter.getDicts(n).then(res => { return obj.api.then(res => {
if (res && res.data) { if (res && res.data) {
// 更新字典数据 // 更新字典数据
this.dict[n].splice(0, 0, ...res.data) this.dict[n].splice(0, 0, ...res.data)
...@@ -76,13 +74,15 @@ export default class Dict { ...@@ -76,13 +74,15 @@ export default class Dict {
*/ */
async refreshDict (name) { async refreshDict (name) {
try { try {
let obj = DictTypes[n]
if (obj === undefined || obj === null) {
throw new Error('need Dict names')
}
Vue.set(this.dict.dictLabel, name, {}) Vue.set(this.dict.dictLabel, name, {})
Vue.set(this.dict, name, []) Vue.set(this.dict, name, [])
const res = await obj.api
const res = await api.parameter.getDicts(name)
if (res && res.data) { if (res && res.data) {
this.dict[name].splice(0, 0, ...res.data) this.dict[name].splice(0, 0, ...res.data)
res.data.forEach(d => { res.data.forEach(d => {
Vue.set(this.dict.dictLabel[name], d.key, d.title) Vue.set(this.dict.dictLabel[name], d.key, d.title)
}) })
......
import api from '@/api'
/** /**
* 字典类型常量定义 * 字典类型常量定义
* 用于统一管理系统中所有字典类型的ID * 用于统一管理系统中所有字典类型的ID
*/ */
export default { export default {
// 基础字典类型 title: { type:7,api:api.parameter.getArrayListByType({typeId:7})},
UNIT_TYPE: 1, // 单位类型 education: { type:8,api:api.parameter.getParameterList({typeId:8})},
PERSON_TYPE: 2, // 人员类型 nation: { type:11,api:api.parameter.getParameterList({typeId:11})},
PROJECT_TYPE: 3, // 项目类型 degree: { type:9,api:api.parameter.getParameterList({typeId:9})},
TALENT_TYPE: 4, // 人才类型 knowledge: { type:56,api:api.parameter.getParameterList({typeId:56})},
EXPERT_TYPE: 5, // 专家类型 proj_class: { type:52,api:api.parameter.getParameterList({typeId:52})},
PARAMETER_TYPE: 6, // 参数类型 unit_role: { type:65,api:api.parameter.getParameterList({typeId:65})},
EVALUATION_TYPE: 7, // 评估类型 talent_category: { type:21,api:api.parameter.getParameterList({typeId:21})},
AUDIT_TYPE: 8, // 审核类型 unit_nature: { type:58,api:api.parameter.getParameterList({typeId:58})},
STATUS_TYPE: 9, // 状态类型 }
\ No newline at end of file
// 项目相关
PROJECT_STATUS: 10, // 项目状态
PROJECT_CATEGORY: 11, // 项目分类
PROJECT_LEVEL: 12, // 项目级别
}
/**
* 字典类型描述映射
*/
export const DictTypeLabels = {
1: '单位类型',
2: '人员类型',
3: '项目类型',
4: '人才类型',
5: '专家类型',
6: '参数类型',
7: '评估类型',
8: '审核类型',
9: '状态类型',
10: '项目状态',
}
\ No newline at end of file
<template> <template>
<div class="dict-example"> <div class="dict-example">
<h2>字典系统使用示例</h2> <h2>字典系统使用示例</h2>
<!-- 基本使用示例 --> <!-- 基本使用示例 -->
<div class="section"> <div class="section">
<h3>1. 基本使用</h3> <h3>1. 基本使用</h3>
<div class="demo-item"> <div class="demo-item">
<label>项目状态选择:</label> <label>项目状态选择:</label>
<a-select v-model="projectStatus" placeholder="请选择项目状态" style="width: 200px"> <a-select v-model="projectStatus" placeholder="请选择项目状态" style="width: 200px">
<a-select-option <a-select-option v-for="item in dict.projectStatus" :key="item.key" :value="item.key">
v-for="item in dict.projectStatus"
:key="item.key"
:value="item.key"
>
{{ item.title }} {{ item.title }}
</a-select-option> </a-select-option>
</a-select> </a-select>
<span class="result">选中值:{{ projectStatus }}</span> <span class="result">选中值:{{ projectStatus }}</span>
</div> </div>
<div class="demo-item"> <div class="demo-item">
<label>项目状态标签:</label> <label>项目状态标签:</label>
<span>{{ getDictLabel('projectStatus', projectStatus) || '未知状态' }}</span> <span>{{ getDictLabel('projectStatus', projectStatus) || '未知状态' }}</span>
...@@ -31,11 +27,7 @@ ...@@ -31,11 +27,7 @@
<div class="demo-item"> <div class="demo-item">
<label>多选项目状态:</label> <label>多选项目状态:</label>
<a-select v-model="multipleStatus" mode="multiple" placeholder="请选择多个状态" style="width: 300px"> <a-select v-model="multipleStatus" mode="multiple" placeholder="请选择多个状态" style="width: 300px">
<a-select-option <a-select-option v-for="item in dict.projectStatus" :key="item.key" :value="item.key">
v-for="item in dict.projectStatus"
:key="item.key"
:value="item.key"
>
{{ item.title }} {{ item.title }}
</a-select-option> </a-select-option>
</a-select> </a-select>
...@@ -49,25 +41,17 @@ ...@@ -49,25 +41,17 @@
<div class="demo-item"> <div class="demo-item">
<label>单选按钮:</label> <label>单选按钮:</label>
<a-radio-group v-model="radioValue"> <a-radio-group v-model="radioValue">
<a-radio <a-radio v-for="item in dict.projectStatus" :key="item.key" :value="item.key">
v-for="item in dict.projectStatus"
:key="item.key"
:value="item.key"
>
{{ item.title }} {{ item.title }}
</a-radio> </a-radio>
</a-radio-group> </a-radio-group>
<span class="result">选中值:{{ radioValue }}</span> <span class="result">选中值:{{ radioValue }}</span>
</div> </div>
<div class="demo-item"> <div class="demo-item">
<label>多选按钮:</label> <label>多选按钮:</label>
<a-checkbox-group v-model="checkboxValues"> <a-checkbox-group v-model="checkboxValues">
<a-checkbox <a-checkbox v-for="item in dict.projectStatus" :key="item.key" :value="item.key">
v-for="item in dict.projectStatus"
:key="item.key"
:value="item.key"
>
{{ item.title }} {{ item.title }}
</a-checkbox> </a-checkbox>
</a-checkbox-group> </a-checkbox-group>
...@@ -92,7 +76,7 @@ ...@@ -92,7 +76,7 @@
<h4>项目状态字典数据:</h4> <h4>项目状态字典数据:</h4>
<pre>{{ JSON.stringify(dict.projectStatus, null, 2) }}</pre> <pre>{{ JSON.stringify(dict.projectStatus, null, 2) }}</pre>
</div> </div>
<div class="demo-item"> <div class="demo-item">
<h4>字典标签映射:</h4> <h4>字典标签映射:</h4>
<pre>{{ JSON.stringify(dict.dictLabel.projectStatus, null, 2) }}</pre> <pre>{{ JSON.stringify(dict.dictLabel.projectStatus, null, 2) }}</pre>
...@@ -108,7 +92,7 @@ export default { ...@@ -108,7 +92,7 @@ export default {
name: 'DictExample', name: 'DictExample',
// 配置需要使用的字典类型 // 配置需要使用的字典类型
dicts: ['projectStatus', 'taskStatus', 'auditStatus'], dicts: ['projectStatus', 'taskStatus', 'auditStatus'],
data() { data () {
return { return {
DictTypes, DictTypes,
projectStatus: '', projectStatus: '',
...@@ -117,7 +101,7 @@ export default { ...@@ -117,7 +101,7 @@ export default {
checkboxValues: [] checkboxValues: []
} }
}, },
mounted() { mounted () {
// 监听字典数据加载完成事件 // 监听字典数据加载完成事件
this.$on('dictReady', () => { this.$on('dictReady', () => {
console.log('字典数据加载完成') console.log('字典数据加载完成')
...@@ -126,12 +110,12 @@ export default { ...@@ -126,12 +110,12 @@ export default {
}, },
methods: { methods: {
// 获取字典标签 // 获取字典标签
getDictLabel(name, value) { getDictLabel (name, value) {
return this.getDictLabel(name, value) return this.getDictLabel(name, value)
}, },
// 刷新项目状态字典 // 刷新项目状态字典
async refreshProjectStatus() { async refreshProjectStatus () {
try { try {
await this.refreshDict('projectStatus') await this.refreshDict('projectStatus')
this.$message.success('项目状态字典刷新成功') this.$message.success('项目状态字典刷新成功')
...@@ -141,13 +125,13 @@ export default { ...@@ -141,13 +125,13 @@ export default {
}, },
// 清除项目状态缓存 // 清除项目状态缓存
clearProjectStatus() { clearProjectStatus () {
this.clearDict('projectStatus') this.clearDict('projectStatus')
this.$message.success('项目状态缓存清除成功') this.$message.success('项目状态缓存清除成功')
}, },
// 清除所有缓存 // 清除所有缓存
clearAllDicts() { clearAllDicts () {
this.clearAllDicts() this.clearAllDicts()
this.$message.success('所有字典缓存清除成功') this.$message.success('所有字典缓存清除成功')
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment