-
-
-
- {{ element.name }}
-
-
+
+
@@ -210,12 +172,12 @@ export default {
.panel-main {
@apply flex-1;
- .phone-wrapper {
+ .edit-wrapper {
flex-basis: 375px;
min-height: 812px;
@apply flex-col flex m-auto;
- .phone {
+ .edit {
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.2);
@apply h-full w-full flex-1;
}
diff --git a/tsconfig.json b/tsconfig.json
index 8d23599..2c04905 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -7,7 +7,6 @@
"@/*": ["./src/*"]
}
},
-
"references": [
{
"path": "./tsconfig.config.json"
From 620a412ed54ec88cc80ec6715bff685d36fdea59 Mon Sep 17 00:00:00 2001
From: JamesCurtis <49338067+james-curtis@users.noreply.github.com>
Date: Wed, 3 Aug 2022 14:22:51 +0800
Subject: [PATCH 007/235] =?UTF-8?q?feat:=20=E6=8A=BD=E7=A6=BB=E4=BB=A3?=
=?UTF-8?q?=E7=A0=81=E7=BC=96=E8=BE=91=E5=99=A8=E7=BB=84=E4=BB=B6=20feat:?=
=?UTF-8?q?=20=E5=AE=8C=E5=96=84=E4=BB=A3=E7=A0=81=E7=BC=96=E8=BE=91?=
=?UTF-8?q?=E5=99=A8=E5=AF=B9=E9=A1=B5=E9=9D=A2=E6=95=B0=E6=8D=AE=E7=9A=84?=
=?UTF-8?q?=E5=93=8D=E5=BA=94=E5=BC=8F=20feat:=20=E6=8B=96=E5=8A=A8drop?=
=?UTF-8?q?=E4=B9=8B=E5=90=8E=E6=95=B0=E6=8D=AE=E6=B7=BB=E5=8A=A0=E5=88=B0?=
=?UTF-8?q?pinia=E5=85=A8=E5=B1=80=20fix:=20=E7=89=A9=E6=96=99=E7=BB=84?=
=?UTF-8?q?=E4=BB=B6=E5=88=9B=E5=BB=BA=E5=AE=9E=E4=BE=8B=E5=8F=82=E6=95=B0?=
=?UTF-8?q?=E4=B8=8D=E6=AD=A3=E7=A1=AE=20feat:=20=E9=A1=B5=E9=9D=A2?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=8C=81=E4=B9=85=E5=8C=96=E5=88=B0localStor?=
=?UTF-8?q?age?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.eslintrc.cjs | 4 +-
index.html | 2 +-
package-lock.json | 57 ++++++++++++++
package.json | 1 +
src/components/attributePanel/config.ts | 19 +++++
src/components/attributePanel/index.vue | 18 +++++
src/components/attributePanel/types.ts | 31 ++++++++
src/components/codePanel/index.vue | 76 +++++++++++++++++++
src/components/editPanel/index.vue | 55 ++++++++------
src/components/editPanel/types.ts | 70 +++++++++++++++++
.../libraryPanel/genericsLib/index.vue | 17 ++---
src/library/button/index.vue | 22 +++++-
src/library/image/index.vue | 20 ++++-
src/library/types.ts | 21 ++++-
src/main.ts | 23 ++----
src/stores/code.ts | 24 ++++++
src/stores/libraryComponentData.ts | 14 ++++
src/stores/storage.ts | 10 ---
src/utils/library.ts | 64 +++++++++++++++-
src/views/HomeView.vue | 61 ++-------------
tsconfig.config.json | 2 +-
21 files changed, 485 insertions(+), 126 deletions(-)
create mode 100644 src/components/attributePanel/config.ts
create mode 100644 src/components/attributePanel/index.vue
create mode 100644 src/components/attributePanel/types.ts
create mode 100644 src/components/codePanel/index.vue
create mode 100644 src/stores/code.ts
create mode 100644 src/stores/libraryComponentData.ts
delete mode 100644 src/stores/storage.ts
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
index 2637a0c..c96faa4 100644
--- a/.eslintrc.cjs
+++ b/.eslintrc.cjs
@@ -16,6 +16,8 @@ module.exports = {
"@vue/eslint-config-prettier",
],
rules: {
- 'vue/multi-word-component-names': 0
+ 'vue/multi-word-component-names': 'off',
+ '@typescript-eslint/no-explicit-any': 'off',
+ '@typescript-eslint/no-non-null-assertion': 'off',
}
};
diff --git a/index.html b/index.html
index 11603f8..c40b9f1 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,5 @@
-
+
diff --git a/package-lock.json b/package-lock.json
index f34befd..1210bb9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -15,6 +15,7 @@
"lodash": "^4.17.21",
"monaco-editor": "^0.33.0",
"pinia": "^2.0.16",
+ "pinia-plugin-persist": "^1.0.0",
"uuid": "^8.3.2",
"vant": "^3.5.3",
"vue": "^3.2.37",
@@ -5538,6 +5539,46 @@
}
}
},
+ "node_modules/pinia-plugin-persist": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmmirror.com/pinia-plugin-persist/-/pinia-plugin-persist-1.0.0.tgz",
+ "integrity": "sha512-M4hBBd8fz/GgNmUPaaUsC29y1M09lqbXrMAHcusVoU8xlQi1TqgkWnnhvMikZwr7Le/hVyMx8KUcumGGrR6GVw==",
+ "dependencies": {
+ "vue-demi": "^0.12.1"
+ },
+ "peerDependencies": {
+ "@vue/composition-api": "^1.0.0",
+ "pinia": "^2.0.0",
+ "vue": "^2.0.0 || >=3.0.0"
+ },
+ "peerDependenciesMeta": {
+ "@vue/composition-api": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/pinia-plugin-persist/node_modules/vue-demi": {
+ "version": "0.12.5",
+ "resolved": "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.12.5.tgz",
+ "integrity": "sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==",
+ "hasInstallScript": true,
+ "bin": {
+ "vue-demi-fix": "bin/vue-demi-fix.js",
+ "vue-demi-switch": "bin/vue-demi-switch.js"
+ },
+ "engines": {
+ "node": ">=12"
+ },
+ "peerDependencies": {
+ "@vue/composition-api": "^1.0.0-rc.1",
+ "vue": "^3.0.0-0 || ^2.6.0"
+ },
+ "peerDependenciesMeta": {
+ "@vue/composition-api": {
+ "optional": true
+ }
+ }
+ },
"node_modules/pinia/node_modules/vue-demi": {
"version": "0.13.6",
"resolved": "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.13.6.tgz",
@@ -11183,6 +11224,22 @@
}
}
},
+ "pinia-plugin-persist": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmmirror.com/pinia-plugin-persist/-/pinia-plugin-persist-1.0.0.tgz",
+ "integrity": "sha512-M4hBBd8fz/GgNmUPaaUsC29y1M09lqbXrMAHcusVoU8xlQi1TqgkWnnhvMikZwr7Le/hVyMx8KUcumGGrR6GVw==",
+ "requires": {
+ "vue-demi": "^0.12.1"
+ },
+ "dependencies": {
+ "vue-demi": {
+ "version": "0.12.5",
+ "resolved": "https://registry.npmmirror.com/vue-demi/-/vue-demi-0.12.5.tgz",
+ "integrity": "sha512-BREuTgTYlUr0zw0EZn3hnhC3I6gPWv+Kwh4MCih6QcAeaTlaIX0DwOVN0wHej7hSvDPecz4jygy/idsgKfW58Q==",
+ "requires": {}
+ }
+ }
+ },
"postcss": {
"version": "8.4.14",
"resolved": "https://registry.npmmirror.com/postcss/-/postcss-8.4.14.tgz",
diff --git a/package.json b/package.json
index 68ab524..575b61a 100644
--- a/package.json
+++ b/package.json
@@ -19,6 +19,7 @@
"lodash": "^4.17.21",
"monaco-editor": "^0.33.0",
"pinia": "^2.0.16",
+ "pinia-plugin-persist": "^1.0.0",
"uuid": "^8.3.2",
"vant": "^3.5.3",
"vue": "^3.2.37",
diff --git a/src/components/attributePanel/config.ts b/src/components/attributePanel/config.ts
new file mode 100644
index 0000000..2c45497
--- /dev/null
+++ b/src/components/attributePanel/config.ts
@@ -0,0 +1,19 @@
+import {
+ EAttributePanels,
+ type IAttributePanelTabConfig,
+} from "@/components/attributePanel/types";
+
+export const panelList: IAttributePanelTabConfig[] = [
+ {
+ title: "属性",
+ name: EAttributePanels.appearance,
+ },
+ {
+ title: "外观",
+ name: EAttributePanels.attribute,
+ },
+ {
+ title: "事件",
+ name: EAttributePanels.event,
+ },
+];
diff --git a/src/components/attributePanel/index.vue b/src/components/attributePanel/index.vue
new file mode 100644
index 0000000..dc1de8d
--- /dev/null
+++ b/src/components/attributePanel/index.vue
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/attributePanel/types.ts b/src/components/attributePanel/types.ts
new file mode 100644
index 0000000..d2a70f6
--- /dev/null
+++ b/src/components/attributePanel/types.ts
@@ -0,0 +1,31 @@
+/**
+ * 右侧编辑面板的子tab枚举
+ */
+export enum EAttributePanels {
+ /**
+ * 属性 编辑面板
+ */
+ attribute = "attribute",
+ /**
+ * 外观 编辑面板
+ */
+ appearance = "appearance",
+ /**
+ * 事件 编辑面板
+ */
+ event = "event",
+}
+
+/**
+ * 单个子tab配置
+ */
+export interface IAttributePanelTabConfig {
+ /**
+ * 显示的文字
+ */
+ title: string;
+ /**
+ * 唯一标识符
+ */
+ name: EAttributePanels;
+}
diff --git a/src/components/codePanel/index.vue b/src/components/codePanel/index.vue
new file mode 100644
index 0000000..b4438e2
--- /dev/null
+++ b/src/components/codePanel/index.vue
@@ -0,0 +1,76 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/components/editPanel/index.vue b/src/components/editPanel/index.vue
index 27ed652..d51b403 100644
--- a/src/components/editPanel/index.vue
+++ b/src/components/editPanel/index.vue
@@ -7,43 +7,46 @@
>
-
+
diff --git a/src/components/editPanel/types.ts b/src/components/editPanel/types.ts
index 10f51b6..9007fcb 100644
--- a/src/components/editPanel/types.ts
+++ b/src/components/editPanel/types.ts
@@ -1,7 +1,77 @@
import type { ELibraryName } from "@/components/libraryPanel/types";
+import type { EAttributePanels } from "@/components/attributePanel/types";
+/**
+ * 此类型是作用于物料组件实例的
+ */
+export type IEditableConfigValue = Partial<{
+ [key in EAttributePanels]: Record
;
+}>;
+
+/**
+ * 物料组件实例的参数
+ */
export interface IEditableInstancedLibraryComponentData {
+ /**
+ * 全局唯一ID
+ * TODO:暂时不知道干啥用
+ */
uuid: string;
+ /**
+ * 是否选中当前物料组件实例
+ */
+ focus: boolean;
+ /**
+ * 物料库标识符
+ */
libraryName: ELibraryName;
+ /**
+ * 在vue中组件名
+ */
componentName: string;
+ /**
+ *右侧属性面板可编辑参数
+ */
+ editableConfig?: IEditableConfigValue;
+}
+
+/**
+ * 编辑面板每个config的表单类型
+ * TODO:这里需要拓展其他类型
+ */
+export enum EEditableConfigItemInputType {
+ /**
+ * 输入框
+ */
+ input = "input",
+ /**
+ * 开关
+ */
+ switch = "switch",
+}
+
+/**
+ * 编辑面板每个config的结构
+ */
+export interface IEditableConfigPanelItemSchema {
+ /**
+ * 表单name,唯一标识符
+ */
+ name: string;
+ /**
+ * 表单类型
+ */
+ type: EEditableConfigItemInputType;
+ /**
+ * 描述标题
+ */
+ title: string;
+ /**
+ * 提示信息
+ */
+ tips?: string;
+ /**
+ * 默认值
+ */
+ default?: any;
}
diff --git a/src/components/libraryPanel/genericsLib/index.vue b/src/components/libraryPanel/genericsLib/index.vue
index 8872c77..a9cbc8c 100644
--- a/src/components/libraryPanel/genericsLib/index.vue
+++ b/src/components/libraryPanel/genericsLib/index.vue
@@ -58,7 +58,6 @@
diff --git a/src/library/button/index.vue b/src/library/button/index.vue
index 738b14e..57a45f3 100644
--- a/src/library/button/index.vue
+++ b/src/library/button/index.vue
@@ -1,4 +1,5 @@
+
主要按钮
@@ -7,9 +8,14 @@ import { Button } from "vant";
import { ElIcon } from "element-plus";
import { Aim } from "@element-plus/icons-vue";
import { ELibraryName } from "@/components/libraryPanel/types";
-import type { ILibraryComponent } from "@/library/types";
+import { EAttributePanels } from "@/components/attributePanel/types";
+import {
+ createEditableConfigPanelItem,
+ defineLibraryComponent,
+} from "@/utils/library";
+import { EEditableConfigItemInputType } from "@/components/editPanel/types";
-export default {
+export default defineLibraryComponent({
name: "LibButton",
libraryName: ELibraryName.generics,
tabName: "show",
@@ -37,10 +43,20 @@ export default {
>
),
},
+ editableConfig: {
+ [EAttributePanels.attribute]: [
+ createEditableConfigPanelItem({
+ name: "title",
+ title: "按钮名称",
+ default: "按钮",
+ type: EEditableConfigItemInputType.input,
+ }),
+ ],
+ },
setup() {
return {};
},
-} as ILibraryComponent;
+});
diff --git a/src/library/image/index.vue b/src/library/image/index.vue
index 637f52d..03a7727 100644
--- a/src/library/image/index.vue
+++ b/src/library/image/index.vue
@@ -11,9 +11,14 @@ import { Image as VanImage } from "vant";
import { ElIcon } from "element-plus";
import { Aim } from "@element-plus/icons-vue";
import { ELibraryName } from "@/components/libraryPanel/types";
-import type { ILibraryComponent } from "@/library/types";
+import {
+ createEditableConfigPanelItem,
+ defineLibraryComponent,
+} from "@/utils/library";
+import { EAttributePanels } from "@/components/attributePanel/types";
+import { EEditableConfigItemInputType } from "@/components/editPanel/types";
-export default {
+export default defineLibraryComponent({
name: "LibImage",
libraryName: ELibraryName.generics,
tabName: "show",
@@ -37,7 +42,16 @@ export default {
>
),
},
-} as ILibraryComponent;
+ editableConfig: {
+ [EAttributePanels.attribute]: [
+ createEditableConfigPanelItem({
+ name: "url",
+ title: "url链接",
+ type: EEditableConfigItemInputType.input,
+ }),
+ ],
+ },
+});
diff --git a/src/library/types.ts b/src/library/types.ts
index b1d3d35..b383e01 100644
--- a/src/library/types.ts
+++ b/src/library/types.ts
@@ -1,9 +1,22 @@
import type { ComponentOptions } from "vue";
import type { ELibraryName } from "@/components/libraryPanel/types";
+import type { EAttributePanels } from "@/components/attributePanel/types";
+import type { IEditableConfigPanelItemSchema } from "@/components/editPanel/types";
-export interface ILibraryComponent extends ComponentOptions {
+/**
+ * 物料组件可编辑的参数
+ * 存在的意义是为了在组件types.ts中定义时候约束[键名]
+ * 此类型是作用于物料组件的,而不是物料组件实例
+ * TODO:这里的泛型可以删除了
+ */
+export type IEditableConfig = Partial<{
+ [key in EAttributePanels]: IEditableConfigPanelItemSchema[];
+}>;
+
+export interface ILibraryComponent
+ extends ComponentOptions {
/**
- * 组件标识符
+ * 物料组件标识符
*/
name: string;
/**
@@ -48,4 +61,8 @@ export interface ILibraryComponent extends ComponentOptions {
*/
preview?: JSX.Element;
};
+ /**
+ *右侧属性面板可编辑参数
+ */
+ editableConfig?: T;
}
diff --git a/src/main.ts b/src/main.ts
index 899542a..854caa6 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -1,33 +1,26 @@
import { createApp } from "vue";
import App from "./App.vue";
-
-const app = createApp(App);
import router from "./router";
-
-app.use(router);
-
import { createPinia } from "pinia";
-
-app.use(createPinia());
-
+import piniaPersist from "pinia-plugin-persist";
import "@/assets/tailwind.css";
-
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
+import Vant from "vant";
+import "vant/lib/index.css";
+const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
app.component(key, component);
}
-
app.use(ElementPlus, {
locale: zhCn,
});
-
-import Vant from "vant";
-import "vant/lib/index.css";
-
app.use(Vant);
-
+app.use(router);
+const pinia = createPinia();
+pinia.use(piniaPersist);
+app.use(pinia);
app.mount("#app");
diff --git a/src/stores/code.ts b/src/stores/code.ts
new file mode 100644
index 0000000..30a05d0
--- /dev/null
+++ b/src/stores/code.ts
@@ -0,0 +1,24 @@
+import { defineStore } from "pinia";
+import { ref, shallowRef } from "vue";
+import type { IEditableInstancedLibraryComponentData } from "@/components/editPanel/types";
+
+export const useCode = defineStore(
+ "Code",
+ () => {
+ const jsonCode = ref([]);
+
+ return {
+ jsonCode,
+ };
+ },
+ {
+ persist: {
+ enabled: true,
+ strategies: [
+ {
+ storage: localStorage,
+ },
+ ],
+ },
+ }
+);
diff --git a/src/stores/libraryComponentData.ts b/src/stores/libraryComponentData.ts
new file mode 100644
index 0000000..d690cb2
--- /dev/null
+++ b/src/stores/libraryComponentData.ts
@@ -0,0 +1,14 @@
+import { defineStore } from "pinia";
+import { ref } from "vue";
+import type { IEditableInstancedLibraryComponentData } from "@/components/editPanel/types";
+
+export const useLibraryComponentData = defineStore(
+ "LibraryComponentData",
+ () => {
+ const focusData = ref();
+
+ return {
+ focusData,
+ };
+ }
+);
diff --git a/src/stores/storage.ts b/src/stores/storage.ts
deleted file mode 100644
index 2c35253..0000000
--- a/src/stores/storage.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { defineStore } from "pinia";
-import { ref } from "vue";
-
-export const useStorage = defineStore("Storage", () => {
- const code = ref>({});
-
- return {
- code,
- };
-});
diff --git a/src/utils/library.ts b/src/utils/library.ts
index 20d5724..469bff7 100644
--- a/src/utils/library.ts
+++ b/src/utils/library.ts
@@ -1,15 +1,73 @@
import { v4 as uuidv4 } from "uuid";
-import type { ILibraryComponent } from "@/library/types";
-import type { IEditableInstancedLibraryComponentData } from "@/components/editPanel/types";
+import type { IEditableConfig, ILibraryComponent } from "@/library/types";
+import type {
+ IEditableConfigPanelItemSchema,
+ IEditableConfigValue,
+ IEditableInstancedLibraryComponentData,
+} from "@/components/editPanel/types";
+import { EAttributePanels } from "@/components/attributePanel/types";
+import { cloneDeep } from "lodash";
export const uuid = uuidv4;
+/**
+ * 从物料组件克隆一个组件实例
+ * @param com
+ */
export function createEditableInstancedLibraryComponentData(
com: ILibraryComponent
): IEditableInstancedLibraryComponentData {
- return {
+ const data = {
uuid: uuidv4(),
componentName: com.name,
libraryName: com.libraryName,
+ focus: false,
};
+ if (com.editableConfig) {
+ Object.assign(data, {
+ editableConfig: createEditableValueByConfig(com.editableConfig),
+ });
+ }
+ return data;
+}
+
+/**
+ * 生成组件实例属性
+ * @param config
+ */
+export function createEditableValueByConfig(
+ config: IEditableConfig
+): IEditableConfigValue {
+ const _config = cloneDeep(config);
+ const result = {} as IEditableConfigValue;
+ Object.entries(_config).forEach(([panelIdentifier, configSchema]) => {
+ const enumPanelIdentifier =
+ panelIdentifier as keyof typeof EAttributePanels;
+ result[EAttributePanels[enumPanelIdentifier]] = configSchema.reduce(
+ (pre, cursor) => {
+ pre[cursor.name] = cursor.default ?? undefined;
+ return pre;
+ },
+ {} as Record
+ );
+ });
+ return result;
+}
+
+/**
+ * 快速定义物料组件
+ * @param com
+ */
+export function defineLibraryComponent(com: ILibraryComponent) {
+ return com;
+}
+
+/**
+ * 快速创建物料组件可编辑的一个属性
+ * @param data
+ */
+export function createEditableConfigPanelItem(
+ data: IEditableConfigPanelItemSchema
+) {
+ return data;
}
diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue
index 01cf539..fef62ea 100644
--- a/src/views/HomeView.vue
+++ b/src/views/HomeView.vue
@@ -25,56 +25,14 @@ const stylePanelWidth = computed(() => {
//----------左侧组件栏
import libraryPanels from "@/components/libraryPanel";
-import * as monaco from "monaco-editor";
-// eslint-disable-next-line @typescript-eslint/ban-ts-comment
-// @ts-ignore
-import editorWorker from "monaco-editor/esm/vs/editor/editor.worker?worker";
-// eslint-disable-next-line @typescript-eslint/ban-ts-comment
-// @ts-ignore
-import jsonWorker from "monaco-editor/esm/vs/language/json/json.worker?worker";
-
-// eslint-disable-next-line @typescript-eslint/ban-ts-comment
-// @ts-ignore
-window.MonacoEnvironment = {
- getWorker(_: string, label: string) {
- if (label === "json") {
- return new jsonWorker();
- }
- return new editorWorker();
- },
-};
-import { useStorage } from "@/stores/storage";
-import { storeToRefs } from "pinia";
-
-const Storage = useStorage();
-const { code } = storeToRefs(Storage);
-const codeContainer = ref>();
-onMounted(() => {
- monaco.editor.create(codeContainer.value!, {
- value: JSON.stringify(code.value),
- language: "json",
- automaticLayout: true, //开启自适应大小
- minimap: {
- enabled: false, // 不需要小的缩略图
- },
- lineNumbers: "off", //关闭显示行号
- folding: false, //关闭折叠
- });
-});
+import CodePanel from "@/components/codePanel/index.vue";
//-------------拖拽、数据核心
// TODO:禁止自己拖入自己,从组件区域拖出去再拖入自己区域时候图标应该是禁止,不应该是默认的
-
-
-
@@ -110,10 +68,7 @@ export default {
-
+
@@ -127,11 +82,7 @@ export default {