Commit 374d875b authored by wends's avatar wends

add 获取字典表

parent f10e31c3
......@@ -18,4 +18,11 @@ export function verifyCaptcha(data) {
data
})
}
// 获取字典表
export function getDictionaryTable(data) {
return request({
url: `${baseURL}/base/dict/get`,
method: 'post',
data
})
}
......@@ -49,7 +49,7 @@ export default {
.svg-icon {
width: 1em;
height: 1em;
vertical-align: -0.15em;
vertical-align: -0.2em;
fill: currentColor;
overflow: hidden;
}
......
......@@ -68,6 +68,9 @@ router.beforeEach(async(to, from, next) => {
// get user info
await store.dispatch('user/getInfo')
// 获取字典表数据
await store.dispatch('app/getDictionary')
// 获取可访问的 菜单页面列表 和 按键列表
const { data: menuList } = await store.dispatch('user/getMenuList')
const { data: permissionList } = await store.dispatch('user/getPermissionList')
......
......@@ -12,6 +12,7 @@ const getters = {
permissions: state => state.permission.permissions,
tokenValid: state => state.user.tokenValid,
userInfo: state => state.user.userInfo,
currentMenuId: state => state.permission.currentMenuId
currentMenuId: state => state.permission.currentMenuId,
dictionary: state => state.app.dictionary
}
export default getters
import Cookies from 'js-cookie'
import { getDictionaryTable } from '@/api/components/basic-services'
const state = {
sidebar: {
......@@ -6,7 +7,8 @@ const state = {
withoutAnimation: false
},
device: 'desktop',
size: Cookies.get('size') || 'medium'
size: Cookies.get('size') || 'medium',
dictionary: {}
}
const mutations = {
......@@ -30,6 +32,9 @@ const mutations = {
SET_SIZE: (state, size) => {
state.size = size
Cookies.set('size', size)
},
SET_DIST: (state, dictionary) => {
state.dictionary = dictionary
}
}
......@@ -45,6 +50,20 @@ const actions = {
},
setSize({ commit }, size) {
commit('SET_SIZE', size)
},
getDictionary({ commit }) {
return new Promise((resolve, reject) => {
getDictionaryTable({ type: null })
.then(res => {
const data = {}
res.data.forEach(v => {
data[v.type.replace(v.type[0], v.type[0].toLowerCase())] = v.dictList
})
commit('SET_DIST', data)
resolve()
})
.catch(err => reject(err))
})
}
}
......
import { mapGetters } from 'vuex'
const dictionary = {
data() {
return {
goodsTypeProps: {
value: 'code',
label: 'name'
}
}
},
computed: {
...mapGetters([
'dictionary'
])
},
methods: {
$_dictionaryFormat(row, column, cellValue, index, prop) {
// 3种情况
// 用在 table-column 中,使用默认入参,4个入参
// 用在 table-column 中,使用指定入参,5个入参
// 当作 filter 使用,使用指定入参,2个入参
// 处理cellValue为0时 (cellValue && true)为false的情况,
const val = ((cellValue === 0 ? true : cellValue) && true) ? cellValue : row
const property = prop || column.property || column
const data = this.dictionary[property].find(v => v.code === parseInt(val))
return data ? data.name : null
}
}
}
export default dictionary
......@@ -6,7 +6,7 @@ import { getToken } from '@/utils/auth'
// create an axios instance
const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
withCredentials: true, // send cookies when cross-domain requests
withCredentials: false, // send cookies when cross-domain requests
timeout: 20000 // request timeout
})
......
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