update 迁移table和modal-form组件,迁移app管理
This commit is contained in:
42
web-react/src/util/dic/index.js
Normal file
42
web-react/src/util/dic/index.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { api } from 'common/api'
|
||||
import { mapKeys } from 'lodash'
|
||||
import store from 'store'
|
||||
import { toCamelCase } from 'util/format'
|
||||
|
||||
const { getState, dispatch } = store
|
||||
|
||||
const getDicData = async (...args) => {
|
||||
const dicData = getState('dicData')
|
||||
let result = {}
|
||||
const code = []
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const codeName = toCamelCase(args[i])
|
||||
if (!dicData.hasOwnProperty(codeName)) {
|
||||
code.push(args[i])
|
||||
} else {
|
||||
result[codeName] = dicData[codeName]
|
||||
}
|
||||
}
|
||||
|
||||
if (code.length) {
|
||||
try {
|
||||
const value = mapKeys((await api.sysDictTypeDropDowns({ code })).data, (value, key) => {
|
||||
return toCamelCase(key)
|
||||
})
|
||||
|
||||
dispatch({
|
||||
type: 'ADD_DIC_DATA',
|
||||
value
|
||||
})
|
||||
|
||||
result = { ...result, ...value }
|
||||
|
||||
return result
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
return dicData
|
||||
}
|
||||
|
||||
export default getDicData
|
||||
@@ -16,4 +16,29 @@ export const numberToChinese = (val) => {
|
||||
|
||||
const chinanum = overWan ? getWan(overWan) + '万' + getWan(noWan) : getWan(num)
|
||||
return chinanum
|
||||
}
|
||||
|
||||
/**
|
||||
* 下划线转驼峰
|
||||
* @param {String} str
|
||||
*/
|
||||
export const toCamelCase = (str) => {
|
||||
if (typeof str === 'string') {
|
||||
return str.toLowerCase().split('_').map((p, i) => {
|
||||
if (i > 0) {
|
||||
return p[0].toUpperCase() + p.slice(1)
|
||||
} else {
|
||||
return p
|
||||
}
|
||||
}).join('')
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰转下划线
|
||||
* @param {String} str
|
||||
*/
|
||||
export const toUnderScoreCase = (str) => {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user