代码改造完成,加入多字典查询方式
This commit is contained in:
@@ -3,7 +3,7 @@ import { initData } from '@/api/data'
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
loading: true, data: [], page: 0, size: 10, total: 0, url: '', params: {}, query: {}, time: 170
|
||||
loading: true, data: [], page: 0, size: 10, total: 0, url: '', params: {}, query: {}, time: 170, isAdd: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -46,6 +46,10 @@ export default {
|
||||
if (this.data.length === size && this.page !== 0) {
|
||||
this.page = this.page - 1
|
||||
}
|
||||
},
|
||||
toQuery() {
|
||||
this.page = 0
|
||||
this.init()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { get } from '@/api/dictDetail'
|
||||
import { get, getDictMap } from '@/api/dictDetail'
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
dicts: []
|
||||
dicts: [], dictMap: {}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -16,6 +16,26 @@ export default {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
},
|
||||
// 多个字典查询时使用逗号拼接, 如:
|
||||
// 加载多个数据字典,如何调用如下:
|
||||
// this.getDict('user_status,job_status')
|
||||
// 在vue中使用加载出来的字典:
|
||||
// dictMap.[字典名称] 如:dictMap.user_status、 dictMap.job_status
|
||||
async getDictMap(names) {
|
||||
// 优先放入到dictMap中,避免页面加载时 undefined
|
||||
const arr = names.split(',')
|
||||
for (let i = 0; i < arr.length; i++) {
|
||||
this.dictMap[arr[i]] = []
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
getDictMap(names).then(res => {
|
||||
this.dictMap = res
|
||||
resolve(res)
|
||||
}).catch(err => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user