diff --git a/.gitignore b/.gitignore index 8ee54e8..921ac05 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ coverage # Editor directories and files .vscode/* !.vscode/extensions.json +!.vscode/settings.json .idea *.suo *.ntvs* diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..38822d2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,35 @@ +{ + // 一、格式化相关 + "editor.formatOnType": false, + "editor.formatOnSave": true, + "editor.formatOnPaste": false, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + + // 二、编辑器显示与行为 + "editor.tabSize": 2, + "editor.snippetSuggestions": "top", + "editor.guides.bracketPairs": "active", + "editor.suggestSelection": "first", + "editor.acceptSuggestionOnCommitCharacter": false, + "editor.quickSuggestions": { + "other": true, + "comments": true, + "strings": true + }, + + // 三、换行和列宽限制 + "editor.wordWrap": "on", + "editor.wordWrapColumn": 180, + "editor.rulers": [180], + + // 四、文件与保存 + "files.autoSave": "off", + + // 五、Git 设置 + "git.confirmSync": false, + + // 六、工作台与启动项 + "workbench.startupEditor": "newUntitledFile" +} diff --git a/package-lock.json b/package-lock.json index 44bc733..55b0f5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "name": "smdoceditor", "version": "0.0.0", "dependencies": { + "@iconify/vue": "^4.3.0", "axios": "^1.8.4", "element-plus": "^2.9.7", "pinia": "^3.0.1", @@ -1337,6 +1338,25 @@ "url": "https://github.com/sponsors/nzakas" } }, + "node_modules/@iconify/types": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@iconify/types/-/types-2.0.0.tgz", + "integrity": "sha512-+wluvCrRhXrhyOmRDJ3q8mux9JkKy5SJ/v8ol2tu4FVjyYvtEzkc/3pK15ET6RKg4b4w4BmTk1+gsCUhf21Ykg==" + }, + "node_modules/@iconify/vue": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/@iconify/vue/-/vue-4.3.0.tgz", + "integrity": "sha512-Xq0h6zMrHBbrW8jXJ9fISi+x8oDQllg5hTDkDuxnWiskJ63rpJu9CvJshj8VniHVTbsxCg9fVoPAaNp3RQI5OQ==", + "dependencies": { + "@iconify/types": "^2.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/cyberalien" + }, + "peerDependencies": { + "vue": ">=3" + } + }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", diff --git a/package.json b/package.json index 1b9ba1b..db835d6 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "format": "prettier --write src/" }, "dependencies": { + "@iconify/vue": "^4.3.0", "axios": "^1.8.4", "element-plus": "^2.9.7", "pinia": "^3.0.1", diff --git a/src/components/RendererDom.vue b/src/components/RendererDom.vue index 049090f..02bd409 100644 --- a/src/components/RendererDom.vue +++ b/src/components/RendererDom.vue @@ -1,6 +1,7 @@ + + \ No newline at end of file diff --git a/src/main.ts b/src/main.ts index d1d3c3c..dcf73bc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,7 @@ +/* eslint-disable vue/multi-word-component-names */ import { createApp } from 'vue' import { createPinia } from 'pinia' +import { Icon } from '@iconify/vue' import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' import './assets/css/main.css' @@ -8,6 +10,7 @@ import router from './router' const app = createApp(App) app.use(ElementPlus) +app.component('Icon', Icon) app.use(createPinia()) app.use(router) diff --git a/src/types/widgetsConfigInterface.ts b/src/types/widgetsConfigInterface.ts index a054bd9..2bf724c 100644 --- a/src/types/widgetsConfigInterface.ts +++ b/src/types/widgetsConfigInterface.ts @@ -2,7 +2,7 @@ export interface IOption { // 元素唯一标识符 name: string // 隐藏状态 - hidden: boolean + hidden?: boolean // 自定义类名 customClass?: string // 标签名称 @@ -23,7 +23,7 @@ export type ICategory = 'container' | 'formItem' export interface IWidget { // 元素唯一标识符 - key?: number + key?: string // 元素id id?: string // 类别 @@ -34,16 +34,23 @@ export interface IWidget { displayName: string // 图标 icon: string - // 子类 - rows?: [{ cols: [IWidget] }] // 属性 options: IOption // 子结构 - widgetList?: [] + subDomList?: [IWidget] | [[IWidget]] // 单元格是否被合并 merged?: boolean + // X轴坐标 + axisX?: number + // Y轴坐标 + axisY?: number } export interface IWidgetJson { - widgetList: IWidget[] + // 页面结构 + subDomList: IWidget[] + // 当前选中元素ID + activeId: string + // 当前选中元素名称 + activeDomName: string } diff --git a/src/utils/index.ts b/src/utils/index.ts index 168aa9f..15fd3ca 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,16 +1,76 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import melonJson from "./melon.json"; +// import melonjson from "./melon.json"; /** * 初始化和重置文书结构 * @param widgetJson */ export const initJson = (widgetJson: any) => { - widgetJson['widgetList'] = [] + widgetJson['subDomList'] = [] + widgetJson['activeId'] = "" + widgetJson['activeDomName'] = "" // widgetJson['formConfig'] = {} } -export const addItem = (fatherId = "", widgetJson: any) => { +/** + * 添加新的子元素 + * @param addItemDataOrigin 新元素 + * @param fatherId 父容器id + * @param widgetJson w文书结构JSON + */ +export const addItem = (addItemDataOrigin: any, fatherId = "", widgetJson: any) => { + const { addItemData, activeId, activeDomName } = formatAddItem(addItemDataOrigin) if (fatherId) { } else { - widgetJson['widgetList'] = [melonJson] + widgetJson['subDomList'] = [addItemData] } -} \ No newline at end of file + widgetJson['activeId'] = activeId + widgetJson['activeDomName'] = activeDomName +} + +/** + * 根据表单元素 格式化对应的属性 + * @param addItemDataOrigin + */ +const formatAddItem = (addItemDataOrigin: any) => { + const addItemData = JSON.parse(JSON.stringify(addItemDataOrigin)); + let activeId = ''; + let activeDomName = ''; + addItemData['key'] = Date.now().toString().slice(-6); + addItemData['id'] = `${addItemData['type']}-${addItemData['key']}`; + activeId = addItemData['id'] + activeDomName = addItemData['displayName'] + addItemData['options'] = { + name: `table-${addItemData['key']}`, + hidden: false, + customClass: '' + }; + // 针对表格 需要初始化子单元格 + if (addItemData['type'] == 'table') { + const key = addItemData['key'].slice(-1) + addItemData['key'].slice(0, -1); + // 子单元格 + const colItem = { + key: key, + id: `table-cell-${key}`, + category: "container", + type: "table-cell", + displayName: "子单元格", + icon: "Monitor", + merged: false, + subDomList: [], + options: { + name: `table-cell-${key}`, + hidden: false, + colspan: 1, + rowspan: 1, + customClass: '' + } + }; + addItemData['subDomList'] = [[colItem]] + // activeId = colItem['id'] + // activeDomName = colItem['displayName'] + } + return { + addItemData, + activeId, + activeDomName + } +} diff --git a/src/utils/melon.json b/src/utils/melon.json index 01d064e..1b16141 100644 --- a/src/utils/melon.json +++ b/src/utils/melon.json @@ -5,166 +5,155 @@ "type": "table", "displayName": "表格", "icon": "Monitor", - "rows": [ - { - "cols": [ - { - "key": 47005, - "id": "table-cell-12332", - "category": "container", - "type": "table-cell", - "displayName": "子单元格", - "icon": "Monitor", - "merged": false, - "widgetList": [ - { - "key": 47016, - "id": "input-12355", - "category": "formItem", - "type": "el-input", - "displayName": "输入框", - "icon": "Folder", - "options": { - "name": "input-12355", - "keyNameEnabled": false, - "keyName": "", - "label": "名称", - "labelAlign": "", - "type": "text", - "defaultValue": "", - "hidden": false, - "customClass": "", - "placeholder": "请输入名称" - } + "subDomList": [ + [ + { + "key": 47005, + "id": "table-cell-12332", + "category": "container", + "type": "table-cell", + "displayName": "子单元格", + "icon": "Monitor", + "merged": false, + "subDomList": [ + { + "key": 47016, + "id": "input-12355", + "category": "formItem", + "type": "el-input", + "displayName": "输入框", + "icon": "Folder", + "options": { + "name": "input-12355", + "keyNameEnabled": false, + "keyName": "", + "label": "名称", + "labelAlign": "", + "defaultValue": "", + "hidden": false, + "customClass": "", + "placeholder": "请输入名称" } - ], - "rows": [], - "options": { - "name": "table-cell-12332", - "cellWidth": "", - "cellHeight": "", - "colspan": 1, - "rowspan": 1, - "wordBreak": false, - "customClass": "" } - }, - { - "key": 47015, - "id": "table-cell-12344", - "category": "container", - "type": "table-cell", - "displayName": "子单元格", - "icon": "Monitor", - "merged": false, - "widgetList": [ - { - "key": 47016, - "id": "input-12366", - "category": "formItem", - "type": "el-input-number", - "displayName": "输入框", - "icon": "Folder", - "options": { - "name": "input-12366", - "keyNameEnabled": false, - "keyName": "", - "label": "年龄", - "labelAlign": "", - "type": "number", - "defaultValue": "", - "hidden": false, - "customClass": "" - } + ], + "options": { + "name": "table-cell-12332", + "cellWidth": "", + "cellHeight": "", + "colspan": 1, + "rowspan": 1, + "wordBreak": false, + "customClass": "" + } + }, + { + "key": 47015, + "id": "table-cell-12344", + "category": "container", + "type": "table-cell", + "displayName": "子单元格", + "icon": "Monitor", + "merged": false, + "subDomList": [ + { + "key": 47016, + "id": "input-12366", + "category": "formItem", + "type": "el-input-number", + "displayName": "输入框", + "icon": "Folder", + "options": { + "name": "input-12366", + "keyNameEnabled": false, + "keyName": "", + "label": "年龄", + "labelAlign": "", + "defaultValue": "", + "hidden": false, + "customClass": "" } - ], - "rows": [], - "options": { - "name": "table-cell-12344", - "cellWidth": "", - "cellHeight": "", - "colspan": 1, - "rowspan": 1, - "wordBreak": false, - "customClass": "" } + ], + "options": { + "name": "table-cell-12344", + "cellWidth": "", + "cellHeight": "", + "colspan": 1, + "rowspan": 1, + "wordBreak": false, + "customClass": "" } - ] - }, - { - "cols": [ - { - "key": 47015, - "id": "table-cell-12344", - "category": "container", - "type": "table-cell", - "displayName": "子单元格", - "icon": "Monitor", - "merged": false, - "widgetList": [ - { - "key": 47016, - "id": "radio-12377", - "category": "formItem", - "type": "el-radio", - "displayName": "单选框", - "icon": "Folder", - "options": { - "name": "input-12377", - "keyNameEnabled": false, - "keyName": "", - "label": "性别", - "labelAlign": "", - "type": "text", - "defaultValue": "1", - "hidden": false, - "customClass": "", - "optionItems": [ - { - "label": "男", - "value": "1" - }, - { - "label": "女", - "value": 2 - } - ] - } + } + ], + [ + { + "key": 47015, + "id": "table-cell-12344", + "category": "container", + "type": "table-cell", + "displayName": "子单元格", + "icon": "Monitor", + "merged": false, + "subDomList": [ + { + "key": 47016, + "id": "radio-12377", + "category": "formItem", + "type": "el-radio", + "displayName": "单选框", + "icon": "Folder", + "options": { + "name": "input-12377", + "keyNameEnabled": false, + "keyName": "", + "label": "性别", + "labelAlign": "", + "defaultValue": "1", + "hidden": false, + "customClass": "", + "optionItems": [ + { + "label": "男", + "value": "1" + }, + { + "label": "女", + "value": 2 + } + ] } - ], - "rows": [], - "options": { - "name": "table-cell-12344", - "cellWidth": "", - "cellHeight": "", - "colspan": 2, - "rowspan": 1, - "wordBreak": false, - "customClass": "" - } - }, - { - "key": 47018, - "id": "table-cell-12399", - "category": "container", - "type": "table-cell", - "displayName": "子单元格", - "icon": "Monitor", - "merged": true, - "widgetList": [], - "rows": [], - "options": { - "name": "table-cell-12399", - "cellWidth": "", - "cellHeight": "", - "colspan": 2, - "rowspan": 1, - "wordBreak": false, - "customClass": "" } + ], + "options": { + "name": "table-cell-12344", + "cellWidth": "", + "cellHeight": "", + "colspan": 2, + "rowspan": 1, + "wordBreak": false, + "customClass": "" + } + }, + { + "key": 47018, + "id": "table-cell-12399", + "category": "container", + "type": "table-cell", + "displayName": "子单元格", + "icon": "Monitor", + "merged": true, + "widgetList": [], + "options": { + "name": "table-cell-12399", + "cellWidth": "", + "cellHeight": "", + "colspan": 2, + "rowspan": 1, + "wordBreak": false, + "customClass": "" } - ] - } + } + ] ], "options": { "name": "", diff --git a/src/utils/widgetsConfig.ts b/src/utils/widgetsConfig.ts index 4155ece..ea9f704 100644 --- a/src/utils/widgetsConfig.ts +++ b/src/utils/widgetsConfig.ts @@ -3,23 +3,17 @@ import type { IWidget } from "@/types/widgetsConfigInterface" export const containers: IWidget[] = [ { category: 'container', - type: 'el-table', + type: 'table', displayName: '表格', icon: 'Monitor', - options: { - name: '', - hidden: false, - } + options: { name: '' } }, { category: 'container', - type: 'el-table-column', + type: 'table-cell', displayName: '子单元格', icon: 'Monitor', - options: { - name: '', - hidden: false, - } + options: { name: '' } } ] @@ -30,29 +24,20 @@ export const basicFields: IWidget[] = [ type: 'el-input', displayName: '输入框', icon: 'Folder', - options: { - name: '', - hidden: false, - }, + options: { name: '' } }, { category: 'formItem', type: 'el-input-number', displayName: '数值输入框', icon: 'Folder', - options: { - name: '', - hidden: false, - }, + options: { name: '' } }, { category: 'formItem', type: 'el-redio', displayName: ' 单选项', icon: 'Folder', - options: { - name: '', - hidden: false, - }, + options: { name: '' } }, ] diff --git a/src/views/Home/HomeView.vue b/src/views/Home/HomeView.vue index eef690a..8013afa 100644 --- a/src/views/Home/HomeView.vue +++ b/src/views/Home/HomeView.vue @@ -1,13 +1,13 @@ diff --git a/src/views/Home/subCom/LeftSide.vue b/src/views/Home/subCom/LeftSide.vue index a445d28..757d8a1 100644 --- a/src/views/Home/subCom/LeftSide.vue +++ b/src/views/Home/subCom/LeftSide.vue @@ -35,9 +35,7 @@ const widgetJson = inject('widgetJson')