提交 | 用户 | 时间
|
e57a89
|
1 |
import { mergeRecursive } from "@/utils/ruoyi"; |
懒 |
2 |
import dictConverter from './DictConverter' |
|
3 |
|
|
4 |
export const options = { |
|
5 |
metas: { |
|
6 |
'*': { |
|
7 |
/** |
|
8 |
* 字典请求,方法签名为function(dictMeta: DictMeta): Promise |
|
9 |
*/ |
|
10 |
request: (dictMeta) => { |
|
11 |
console.log(`load dict ${dictMeta.type}`) |
|
12 |
return Promise.resolve([]) |
|
13 |
}, |
|
14 |
/** |
|
15 |
* 字典响应数据转换器,方法签名为function(response: Object, dictMeta: DictMeta): DictData |
|
16 |
*/ |
|
17 |
responseConverter, |
|
18 |
labelField: 'label', |
|
19 |
valueField: 'value', |
|
20 |
}, |
|
21 |
}, |
|
22 |
/** |
|
23 |
* 默认标签字段 |
|
24 |
*/ |
|
25 |
DEFAULT_LABEL_FIELDS: ['label', 'name', 'title'], |
|
26 |
/** |
|
27 |
* 默认值字段 |
|
28 |
*/ |
|
29 |
DEFAULT_VALUE_FIELDS: ['value', 'id', 'uid', 'key'], |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* 映射字典 |
|
34 |
* @param {Object} response 字典数据 |
|
35 |
* @param {DictMeta} dictMeta 字典元数据 |
|
36 |
* @returns {DictData} |
|
37 |
*/ |
|
38 |
function responseConverter(response, dictMeta) { |
|
39 |
const dicts = response.content instanceof Array ? response.content : response |
|
40 |
if (dicts === undefined) { |
|
41 |
console.warn(`no dict data of "${dictMeta.type}" found in the response`) |
|
42 |
return [] |
|
43 |
} |
|
44 |
return dicts.map(d => dictConverter(d, dictMeta)) |
|
45 |
} |
|
46 |
|
|
47 |
export function mergeOptions(src) { |
|
48 |
mergeRecursive(options, src) |
|
49 |
} |
|
50 |
|
|
51 |
export default options |