| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import _ from 'lodash-es';
- import { ModuleData, ShowStyle } from './types';
- /** 将原本的 formData 格式化为 api.saveOrUpdate 需要的格式 */
- export function parseFormDataToParams(formData: Record<string, number | string | undefined>) {
- const params = {};
- _.forEach(formData, (v: string | undefined, k) => {
- if (!v) return;
- // 如果是以 moduleData/showStyle 打头的数据要特殊处理,因为这是配置的主要项目,表单配置见 ./configuration.data
- if (k.startsWith('moduleData')) {
- return _.set(params, k, JSON.parse(v));
- }
- return _.set(params, k, v);
- });
- return params;
- }
- /** 将 api.list 返回的 moduleData 格式化,格式化之后可以支持对应的表单以用,该方法会修改源数据 */
- export function parseModuleData(listData: { moduleData: ModuleData; showStyle: ShowStyle }) {
- _.forEach(listData.moduleData, (v, k) => {
- listData[`moduleData.${k}`] = JSON.stringify(v);
- });
- return listData;
- }
- // export function parseModuleDataToConfig(moduleData: ModuleData): {
- // chart: { label: string; prop: string }[];
- // list: { label: string; prop: string }[];
- // };
- // export function parseModuleDataToConfig(
- // moduleData: ModuleData,
- // data: any
- // ): {
- // chart: { label: string; value: string }[];
- // list: { label: string; value: string }[];
- // };
- /** 将 api.list 返回的 moduleData 格式化为配置对象,如果传入了 data,那么会返回带数据的配置,否则返回默认配置,这些配置通常可用于页面展示 */
- // export function parseModuleDataToConfig(moduleData: ModuleData): {
- // chart: { label: string; prop: string }[];
- // list: { label: string; prop: string }[];
- // } {
- // // if (data) {
- // // return {
- // // chart: _.map(_.get(moduleData, 'chart', []), (label, prop) => {
- // // return { label, value: _.get(data, prop, '/') };
- // // }),
- // // list: _.map(_.get(moduleData, 'list', []), (label, prop) => {
- // // return { label, value: _.get(data, prop, '/') };
- // // }),
- // // };
- // // }
- // return {
- // chart: _.map(_.get(moduleData, 'chart', []), (label, prop) => {
- // return { label, prop };
- // }),
- // list: _.map(_.get(moduleData, 'list', []), (label, prop) => {
- // return { label, prop };
- // }),
- // };
- // }
|