|
@@ -19,24 +19,48 @@ export class CompController{
|
|
|
this.state._id = designData._id;
|
|
|
this.state.title = designData.title;
|
|
|
this.state.pageStyle = designData.pageStyle;
|
|
|
- this.state.content = designData.content;
|
|
|
- const arr = this.state.content || [];
|
|
|
+ this.state.content = designData.content || [];
|
|
|
+ const arr = this.state.content;
|
|
|
this.designCompMap.clear();
|
|
|
while (arr.length) {
|
|
|
const item = arr[0];
|
|
|
this.designCompMap.set(item.id, item);
|
|
|
}
|
|
|
}
|
|
|
- insertPageCompData(data: any) {
|
|
|
- this.state.content.push( data );
|
|
|
- this.designCompMap.set(data.id, data);
|
|
|
+
|
|
|
+ insertDesignContent(compKey: string, index?: number) {
|
|
|
+ index === undefined && (index = this.state.content.length);
|
|
|
+ const comp = this.createCompData(compKey);
|
|
|
+ if (!comp) return;
|
|
|
+
|
|
|
+ this.state.content.push( comp );
|
|
|
+ this.designCompMap.set(comp.id, comp);
|
|
|
+
|
|
|
+ return comp;
|
|
|
+ }
|
|
|
+
|
|
|
+ insertCompContainer(compKey: string, container: DesignComp) {
|
|
|
+ const compData = this.createCompData(compKey)
|
|
|
+ if (!compData) {
|
|
|
+ console.error("没有找到对应的组件")
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ container.value.children || (container.value.children = []);
|
|
|
+ container.value.children.push( compData );
|
|
|
+
|
|
|
+ return compData;
|
|
|
}
|
|
|
|
|
|
createCompData(compKey: string) {
|
|
|
const CompType = this.CompTypes.find(item=>item.type == compKey);
|
|
|
if (!CompType) return;
|
|
|
|
|
|
- return CompType.createCompData({});
|
|
|
+
|
|
|
+ return CompType.createCompData(this.isText(compKey) ? "": {});
|
|
|
+ }
|
|
|
+
|
|
|
+ isText(compKey:string) {
|
|
|
+ return compKey == "Text";
|
|
|
}
|
|
|
|
|
|
getCompType(compKey:string) {
|
|
@@ -60,12 +84,21 @@ export function RegCompType<T>(info: {type:string , name:string, thumbnail:strin
|
|
|
const createCompData = function(values: Partial<T>, comm?: Partial<CommPropType>) {
|
|
|
const defvalues = typeof getDef == "function" ? getDef(): cloneDeep(getDef);
|
|
|
defvalues.compKey = info.type as any
|
|
|
- const c = Object.assign({}, defvalues, comm, {value: values}) as CommPropType &{value: T}
|
|
|
+
|
|
|
+ const isStrValue = (typeof values == "string" || typeof defvalues.value == "string");
|
|
|
+ if (isStrValue && values) {
|
|
|
+ //@ts-ignore
|
|
|
+ defvalues.value = values;
|
|
|
+ }
|
|
|
+ const c = Object.assign({}, defvalues, comm) as CommPropType &{value: T}
|
|
|
+ if (!isStrValue && values != null ) {
|
|
|
+ c.value = {...c.value, ...values}
|
|
|
+ }
|
|
|
const ret = new DesignComp(c) as typeof c;
|
|
|
+ const out = reactive(ret)
|
|
|
+ CompCtrl.setCompState(ret.id, out);
|
|
|
|
|
|
- CompCtrl.setCompState(ret.id, reactive(ret));
|
|
|
-
|
|
|
- return ret;
|
|
|
+ return out;
|
|
|
}
|
|
|
|
|
|
type ValueType = ReturnType<typeof createCompData>
|