Skip to content

Commit

Permalink
调整逻辑另外删除无用代码
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Mar 5, 2024
1 parent ad2f95f commit 4209954
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 254 deletions.
2 changes: 0 additions & 2 deletions packages/amis-editor-core/src/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import {
guid,
appTranslate,
JSONGetByPath,
getDialogListBySchema,
getFixDialogType,
addModal
} from '../../src/util';
import {
Expand Down
110 changes: 0 additions & 110 deletions packages/amis-editor-core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1414,113 +1414,3 @@ export function addModal(schema: any, modal: any) {

return [schema, `modal-ref-${idx}`];
}

/**
* 获取弹窗事件
* @param schema 遍历的schema
* @param listType 列表形式,弹窗list或label value形式的数据源
* @param filterId 要过滤弹窗的id
*/
export const getDialogListBySchema = (
schema: Schema,
listType: 'list' | 'source',
filterId?: string
) => {
let items: any[] = [];
const dialogMap: any = {
dialog: {
title: '弹窗',
body: 'dialog'
},
drawer: {
title: '抽屉式弹窗',
body: 'drawer'
},
confirmDialog: {
title: '确认对话框',
// 兼容历史args参数
body: ['dialog', 'args']
}
};

JSONTraverse(
schema,
(value: any, key: string, object: any) => {
// definitions中的弹窗
if (key === 'type' && value === 'page') {
const definitions = object.definitions;
if (definitions) {
Object.keys(definitions).forEach(key => {
if (key.includes('ref-')) {
if (listType === 'list') {
items.push(definitions[key]);
} else {
const dialog = definitions[key];
const dialogTypeName = dialogMap[dialog.type].title;
items.push({
label: `${dialog.title || '-'}${dialogTypeName})`,
value: dialog.$$id
});
}
}
});
}
} else if (
(key === 'actionType' && value === 'dialog') ||
(key === 'actionType' && value === 'drawer') ||
(key === 'actionType' && value === 'confirmDialog')
) {
let dialogBody = dialogMap[value].body!;
let dialogBodyContent = Array.isArray(dialogBody)
? object[dialogBody[0]] || object[dialogBody[1]]
: object[dialogBody];

// 有 $ref 的弹窗在definitions中
if (dialogMap[value] && dialogBodyContent && !dialogBodyContent.$ref) {
if (listType == 'list') {
// 没有 type: dialog的历史数据兼容一下
items.push({
...dialogBodyContent,
type: Array.isArray(dialogBody) ? 'dialog' : dialogBody
});
} else {
// 新建弹窗切换到现有弹窗把自身过滤掉
if (!filterId || (filterId && filterId !== dialogBodyContent.id)) {
items.push({
label: `${dialogBodyContent?.title || '-'}${
dialogMap[value].title
})`,
value: dialogBodyContent.$$id
});
}
}
}
}
},
(value, key) => key.toString().startsWith('__')
);
return items;
};

/**
* 获取弹窗的类型,来源于事件或definitions,由于历史数据可能没有type: dialog,在这里兼容一下
* @param json
* @param previewDialogId
*/
export const getFixDialogType = (json: Schema, dialogId: string) => {
const dialogBodyMap = {
dialog: 'dialog',
drawer: 'drawer',
confirmDialog: 'dialog'
};
let parentSchema = JSONGetParentById(json, dialogId);
// 事件中的弹窗
if (parentSchema.actionType) {
return dialogBodyMap[parentSchema.actionType as keyof typeof dialogBodyMap];
}
// definitions中的弹窗
else {
let dialogRefSchema = JSONGetById(parentSchema, dialogId);
return dialogRefSchema.type;
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,14 @@ function DialogActionPanel({
})
};

// schema中存在__actionModals 直接更新Id会更新到冗余数据__actionModals 先去除再更新
JSONValueMap(schema, (value, key, host: any) => {
if (key === '__actionModals') {
host[key] = undefined;
}
});
// 这个要先执行,否则下面的那个 update 有可能更新的是 __actionModals 里面的对象
schema = JSONUpdate(
schema,
actionSchema.$$id,
JSONPipeIn(newActionSchema),
true
);

// 原来的动作也要更新
schema = JSONUpdate(
schema,
Expand All @@ -164,6 +166,7 @@ function DialogActionPanel({
}),
true
);
return schema;
}

schema = JSONUpdate(
Expand Down
133 changes: 0 additions & 133 deletions packages/amis-editor/src/renderer/event-control/helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
BaseEventContext,
defaultValue,
EditorManager,
getFixDialogType,
getSchemaTpl,
JsonGenerateID,
JSONGetById,
Expand Down Expand Up @@ -3176,138 +3175,6 @@ export const getEventControlConfig = (
action[key] = action[key] ?? actionData?.[key];
});

// if (config.actionType === 'openDialog') {
// // 初始化弹窗schema
// const dialogInitSchema = {
// type: 'dialog',
// title: action.__dialogTitle,
// body: [
// {
// type: 'tpl',
// tpl: '对,你刚刚点击了',
// wrapperComponent: '',
// inline: false
// }
// ],
// showCloseButton: true,
// showErrorMsg: true,
// showLoading: true,
// className: 'app-popover :AMISCSSWrapper',
// actions: [
// {
// type: 'button',
// actionType: 'cancel',
// label: '取消'
// },
// {
// type: 'button',
// actionType: 'confirm',
// label: '确认',
// primary: true
// }
// ]
// };

// const drawerInitSchema = {
// type: 'drawer',
// title: action.__dialogTitle,
// body: [
// {
// type: 'tpl',
// tpl: '对,你刚刚点击了',
// wrapperComponent: '',
// inline: false
// }
// ],
// className: 'app-popover :AMISCSSWrapper',
// actions: [
// {
// type: 'button',
// actionType: 'cancel',
// label: '取消'
// },
// {
// type: 'button',
// actionType: 'confirm',
// label: '确认',
// primary: true
// }
// ]
// };

// const confirmDialogInitSchema = {
// type: 'dialog',
// title: action.__dialogTitle,
// body: [
// {
// type: 'tpl',
// tpl: '对,你刚刚点击了',
// wrapperComponent: '',
// inline: false
// }
// ],
// dialogType: 'confirm',
// confirmText: '确认',
// cancelText: '取消',
// confirmBtnLevel: 'primary'
// };

// const setInitSchema = (groupType: string, action: ActionConfig) => {
// if (groupType === 'dialog') {
// JsonGenerateID(dialogInitSchema);
// action.dialog = dialogInitSchema;
// } else if (groupType === 'drawer') {
// JsonGenerateID(drawerInitSchema);
// action.drawer = drawerInitSchema;
// } else if (groupType === 'confirmDialog') {
// JsonGenerateID(confirmDialogInitSchema);
// action.dialog = confirmDialogInitSchema;
// }
// };

// const chooseCurrentDialog = (action: ActionConfig, schema: Schema) => {
// const selectDialog = action.__selectDialog;
// let dialogType = getFixDialogType(schema, selectDialog);
// // 选择现有弹窗后为了使之前的弹窗和现有弹窗$$id唯一,这里重新生成一下
// let newDialogId = guid();
// action.actionType = dialogType;
// action[dialogType] = {
// $$id: newDialogId,
// type: dialogType
// };
// // 在这里记录一下新生成的弹窗id
// action.__relatedDialogId = newDialogId;
// };

// if (type === 'add') {
// if (config.__dialogSource === 'new') {
// setInitSchema(config.groupType, action);
// } else if (config.__dialogSource === 'current') {
// chooseCurrentDialog(action, shcema!);
// }
// }
// // 编辑
// else if (type === 'update') {
// if (config.__dialogSource === 'new') {
// // 如果切换了弹窗类型或切换了弹窗来源,则初始化schema
// if (
// config.groupType !== actionData?.groupType ||
// (config.__dialogSource === 'new' &&
// actionData?.__dialogSource === 'current')
// ) {
// setInitSchema(config.groupType, action);
// } else {
// action[config.groupType] = {
// ...actionData![config.groupType],
// title: config.__dialogTitle
// };
// }
// } else if (config.__dialogSource === 'current') {
// chooseCurrentDialog(action, shcema!);
// }
// }
// }

// 刷新组件时,处理是否追加事件变量
if (config.actionType === 'reload') {
action.data = undefined;
Expand Down
4 changes: 1 addition & 3 deletions packages/amis-editor/src/renderer/event-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ import {
PluginEvents,
RendererPluginAction,
RendererPluginEvent,
SubRendererPluginAction,
getDialogListBySchema,
getFixDialogType
SubRendererPluginAction
} from 'amis-editor-core';
export * from './helper';
import {i18n as _i18n} from 'i18n-runtime';
Expand Down

0 comments on commit 4209954

Please sign in to comment.