|
@@ -10,7 +10,8 @@ function getVisible(this: EditorModule, comp: DesignComp) {
|
|
type ItemParams = Pick<ToolbarItem, "getValue" | "component" | "onClick"> & {
|
|
type ItemParams = Pick<ToolbarItem, "getValue" | "component" | "onClick"> & {
|
|
getVisible?: typeof getVisible;
|
|
getVisible?: typeof getVisible;
|
|
};
|
|
};
|
|
-class ToolbarItem {
|
|
|
|
|
|
+
|
|
|
|
+export class ToolbarItem {
|
|
component: any;
|
|
component: any;
|
|
getValue?: (c: DesignComp) => number;
|
|
getValue?: (c: DesignComp) => number;
|
|
onClick: (this: EditorModule, c: DesignComp) => void;
|
|
onClick: (this: EditorModule, c: DesignComp) => void;
|
|
@@ -36,7 +37,7 @@ export type ICompToolbars = { [name in ICompKeys]?: ToolbarItem[] } & {
|
|
MultiSelector: ToolbarItem[];
|
|
MultiSelector: ToolbarItem[];
|
|
};
|
|
};
|
|
|
|
|
|
-function createToolbars<T extends Record<string, ItemParams>>(obj: T) {
|
|
|
|
|
|
+export function createToolbars<T extends Record<string, ItemParams>>(obj: T) {
|
|
const data: any = {};
|
|
const data: any = {};
|
|
Object.entries(obj).forEach(([key, value]) => {
|
|
Object.entries(obj).forEach(([key, value]) => {
|
|
data[key] = new ToolbarItem(value);
|
|
data[key] = new ToolbarItem(value);
|
|
@@ -140,7 +141,7 @@ export const toolbars = createToolbars({
|
|
// 全屏尺寸
|
|
// 全屏尺寸
|
|
fullWidth: {
|
|
fullWidth: {
|
|
component: TipIcons.FullWidth,
|
|
component: TipIcons.FullWidth,
|
|
- getVisible: (comp) => !comp.isTransformed && !comp.isFullWidth,
|
|
|
|
|
|
+ getVisible: (comp) => !!comp && !comp.isTransformed && !comp.isFullWidth,
|
|
onClick(comp) {
|
|
onClick(comp) {
|
|
this.actions.fullCompWidth(comp);
|
|
this.actions.fullCompWidth(comp);
|
|
},
|
|
},
|
|
@@ -148,7 +149,7 @@ export const toolbars = createToolbars({
|
|
// 清除变换
|
|
// 清除变换
|
|
clearTransform: {
|
|
clearTransform: {
|
|
component: TipIcons.ClearTransform,
|
|
component: TipIcons.ClearTransform,
|
|
- getVisible: (comp) => comp.isTransformed(),
|
|
|
|
|
|
+ getVisible: (comp) => !!comp && comp.isTransformed(),
|
|
onClick(comp) {
|
|
onClick(comp) {
|
|
this.actions.clearCompTransform(comp);
|
|
this.actions.clearCompTransform(comp);
|
|
},
|
|
},
|
|
@@ -156,7 +157,7 @@ export const toolbars = createToolbars({
|
|
// 定位图层上移
|
|
// 定位图层上移
|
|
layerUp: {
|
|
layerUp: {
|
|
component: TipIcons.LayerUp,
|
|
component: TipIcons.LayerUp,
|
|
- getVisible: (comp) => comp.isPostioned(),
|
|
|
|
|
|
+ getVisible: (comp) =>true,
|
|
onClick(comp) {
|
|
onClick(comp) {
|
|
this.actions.setCompLayer(comp, 1);
|
|
this.actions.setCompLayer(comp, 1);
|
|
},
|
|
},
|
|
@@ -164,7 +165,7 @@ export const toolbars = createToolbars({
|
|
// 定位图层下移
|
|
// 定位图层下移
|
|
layerDown: {
|
|
layerDown: {
|
|
component: TipIcons.LayerDown,
|
|
component: TipIcons.LayerDown,
|
|
- getVisible: (comp) => comp.isPostioned(),
|
|
|
|
|
|
+ getVisible: (comp) => true,
|
|
onClick(comp) {
|
|
onClick(comp) {
|
|
this.actions.setCompLayer(comp, -1);
|
|
this.actions.setCompLayer(comp, -1);
|
|
},
|
|
},
|
|
@@ -173,7 +174,7 @@ export const toolbars = createToolbars({
|
|
parentComp: {
|
|
parentComp: {
|
|
component: TipIcons.ParentComp,
|
|
component: TipIcons.ParentComp,
|
|
getVisible(comp) {
|
|
getVisible(comp) {
|
|
- return !this.helper.isCustomChildComp(comp);
|
|
|
|
|
|
+ return !!comp && !this.helper.isCustomChildComp(comp);
|
|
},
|
|
},
|
|
onClick(comp) {
|
|
onClick(comp) {
|
|
this.actions.pickParentComp(comp.id);
|
|
this.actions.pickParentComp(comp.id);
|
|
@@ -183,9 +184,10 @@ export const toolbars = createToolbars({
|
|
saveAsComp: {
|
|
saveAsComp: {
|
|
component: TipIcons.SaveAsComp,
|
|
component: TipIcons.SaveAsComp,
|
|
getVisible(comp) {
|
|
getVisible(comp) {
|
|
- return this.helper.isShowSaveComp(comp);
|
|
|
|
|
|
+ return !!comp && this.helper.isShowSaveComp(comp);
|
|
},
|
|
},
|
|
async onClick(comp) {
|
|
async onClick(comp) {
|
|
|
|
+ if (!comp) return;
|
|
await this.actions.saveAsComp(comp);
|
|
await this.actions.saveAsComp(comp);
|
|
this.controls.compUICtrl.init();
|
|
this.controls.compUICtrl.init();
|
|
},
|
|
},
|
|
@@ -194,10 +196,10 @@ export const toolbars = createToolbars({
|
|
cancelGroup: {
|
|
cancelGroup: {
|
|
component: TipIcons.CancelGroup,
|
|
component: TipIcons.CancelGroup,
|
|
getVisible(comp) {
|
|
getVisible(comp) {
|
|
- return comp && comp.compKey == "Group" && this.store.selected.length == 1 && this.helper.isStreamCardChild(comp.id);
|
|
|
|
|
|
+ return !!comp && comp.compKey == "Group" && this.store.selected.length == 1 && this.helper.isStreamCardChild(comp.id);
|
|
},
|
|
},
|
|
-
|
|
|
|
onClick(comp) {
|
|
onClick(comp) {
|
|
|
|
+ if (!comp) return;
|
|
this.actions.cancelGroupComps(comp);
|
|
this.actions.cancelGroupComps(comp);
|
|
},
|
|
},
|
|
},
|
|
},
|