12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import _ from 'lodash';
- // import { BillboardType, HeaderConfig, ListConfig, TableConfig, TitleConfig } from './billboard.data';
- /**
- * 功能类似 lodash.get 但是当取值为 null 时也直接返回默认值
- */
- export function get(object?: Object, path?: Array<string> | string, defaultValue: any = '/') {
- if (!object || path === undefined) return defaultValue;
- const d = _.get(object, path, defaultValue);
- return d === null ? defaultValue : d;
- }
- // /** 依据配置获取适用于 CommonTitle 的数据 */
- // export function parseTitleConfig(data: BillboardType, config: TitleConfig) {
- // const val = get(data, config.prop);
- // return {
- // label: config.label,
- // value: config.translation ? get(config.translation, val) : val,
- // };
- // }
- // /** 依据配置获取适用于 LargeBoard 的数据 */
- // export function parseHeaderConfigs(data: BillboardType, configs: HeaderConfig[]) {
- // const types = ['to-top-right', 'to-bottom-right'];
- // return configs.map((cfg, i) => {
- // const val = get(data, cfg.prop);
- // return {
- // label: cfg.label,
- // value: cfg.translation ? get(cfg.translation, val) : val,
- // type: types[i % configs.length],
- // };
- // });
- // }
- // /** 依据配置获取适用于 CommonTable、CollapseTable 的数据 */
- // export function parseTableConfig(data: BillboardType, config: TableConfig) {
- // const arr = get(data, config.prop, []);
- // if (config.translation) {
- // const finalRes = arr.reduce((res: any[], ele) => {
- // // 对于表格里的每条数据,如果需要翻译则翻译之
- // config.columns.forEach((col) => {
- // if (col._t) {
- // const v = get(ele, col.prop);
- // _.set(ele, col.prop, get(config.translation, v));
- // }
- // });
- // config.collapses.forEach((col) => {
- // if (col._t) {
- // const v = get(ele, col.prop);
- // _.set(ele, col.prop, get(config.translation, v));
- // }
- // });
- // res.push(ele);
- // return res;
- // }, []);
- // return {
- // data: finalRes,
- // collapses: config.collapses,
- // columns: config.columns,
- // };
- // } else {
- // return {
- // data,
- // collapses: config.collapses,
- // columns: config.columns,
- // };
- // }
- // }
- // /** 依据配置获取适用于 ListItem 的数据 */
- // export function parseListConfigs(data: BillboardType, configs: ListConfig[]) {
- // const types = ['blue', 'green'];
- // return configs.map((cfg, i) => {
- // const val = get(data, cfg.prop);
- // return {
- // icon: cfg.icon,
- // label: cfg.label,
- // value: cfg.translation ? get(cfg.translation, val) : val,
- // type: types[i % configs.length],
- // collapses: cfg.collapses.map((col) => {
- // return {
- // label: col.label,
- // };
- // }),
- // };
- // });
- // }
|