refactor: simplified code

main
renqian805 2 years ago
parent 74df8be4f2
commit 035663eb3b
  1. 1
      components.d.ts
  2. 32
      package.json
  3. 511
      pnpm-lock.yaml
  4. 8
      src/packages/base-widgets/index.ts
  5. 2
      src/packages/base-widgets/text/fontArr.ts
  6. 2
      src/packages/base-widgets/text/index.tsx
  7. 4
      src/packages/container-component/index.ts
  8. 4
      src/packages/container-component/layout/index.tsx
  9. 4
      src/visual-editor/components/header/index.vue
  10. 31
      src/visual-editor/components/header/preview.vue
  11. 9
      src/visual-editor/components/left-aside/components/data-source/data-fetch.vue
  12. 14
      src/visual-editor/components/left-aside/components/data-source/utils.tsx
  13. 4
      src/visual-editor/components/left-aside/components/index.ts
  14. 8
      src/visual-editor/components/left-aside/index.vue
  15. 4
      src/visual-editor/components/right-attribute-panel/components/animate/Animate.tsx
  16. 20
      src/visual-editor/components/right-attribute-panel/components/animate/animateConfig.ts
  17. 2
      src/visual-editor/components/right-attribute-panel/components/attr-editor/components/table-prop-editor/table-prop-edit.service.tsx
  18. 28
      src/visual-editor/components/simulator-editor/draggable-transition-group.vue
  19. 34
      src/visual-editor/components/simulator-editor/simulator-editor.vue
  20. 27
      src/visual-editor/components/simulator-editor/slot-item.vue
  21. 2
      src/visual-editor/hooks/useModal.tsx
  22. 2
      src/visual-editor/utils/dialog-service.tsx
  23. 68
      src/visual-editor/visual-editor.utils.ts
  24. 8
      src/visual.config.tsx

1
components.d.ts vendored

@ -32,7 +32,6 @@ declare module '@vue/runtime-core' {
RouterLink: typeof import('vue-router')['RouterLink']; RouterLink: typeof import('vue-router')['RouterLink'];
RouterView: typeof import('vue-router')['RouterView']; RouterView: typeof import('vue-router')['RouterView'];
} }
export interface ComponentCustomProperties { export interface ComponentCustomProperties {
vInfiniteScroll: typeof import('element-plus/es')['ElInfiniteScroll']; vInfiniteScroll: typeof import('element-plus/es')['ElInfiniteScroll'];
} }

@ -33,13 +33,13 @@
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "^2.0.6", "@element-plus/icons-vue": "^2.0.6",
"@vant/touch-emulator": "^1.3.2", "@vant/touch-emulator": "^1.3.2",
"@vueuse/core": "^8.7.5", "@vueuse/core": "^8.9.1",
"@vueuse/integrations": "^8.7.5", "@vueuse/integrations": "^8.9.1",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"axios": "^0.27.2", "axios": "^0.27.2",
"dayjs": "^1.11.3", "dayjs": "^1.11.3",
"dexie": "^3.2.2", "dexie": "^3.2.2",
"element-plus": "2.2.8", "element-plus": "2.2.9",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"monaco-editor": "^0.33.0", "monaco-editor": "^0.33.0",
"nanoid": "^4.0.0", "nanoid": "^4.0.0",
@ -57,9 +57,9 @@
"@commitlint/cli": "^17.0.3", "@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3", "@commitlint/config-conventional": "^17.0.3",
"@types/lodash-es": "^4.17.6", "@types/lodash-es": "^4.17.6",
"@types/node": "^18.0.0", "@types/node": "^18.0.3",
"@typescript-eslint/eslint-plugin": "^5.30.3", "@typescript-eslint/eslint-plugin": "^5.30.5",
"@typescript-eslint/parser": "^5.30.3", "@typescript-eslint/parser": "^5.30.5",
"@vitejs/plugin-legacy": "^1.8.2", "@vitejs/plugin-legacy": "^1.8.2",
"@vitejs/plugin-vue": "^2.3.3", "@vitejs/plugin-vue": "^2.3.3",
"@vitejs/plugin-vue-jsx": "^1.3.10", "@vitejs/plugin-vue-jsx": "^1.3.10",
@ -71,32 +71,32 @@
"eslint-define-config": "^1.5.1", "eslint-define-config": "^1.5.1",
"eslint-plugin-import": "^2.26.0", "eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1", "eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-vue": "^9.1.1", "eslint-plugin-vue": "^9.2.0",
"husky": "^8.0.1", "husky": "^8.0.1",
"lint-staged": "^13.0.3", "lint-staged": "^12.5.0",
"postcss": "^8.4.14", "postcss": "^8.4.14",
"postcss-html": "^1.4.1", "postcss-html": "^1.5.0",
"postcss-scss": "^4.0.4", "postcss-scss": "^4.0.4",
"prettier": "^2.7.1", "prettier": "^2.7.1",
"pretty-quick": "^3.1.3", "pretty-quick": "^3.1.3",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"sass": "1.53.0", "sass": "1.53.0",
"stylelint": "^14.9.1", "stylelint": "^14.9.1",
"stylelint-config-html": "^1.0.0", "stylelint-config-html": "^1.1.0",
"stylelint-config-prettier": "^9.0.3", "stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^8.0.0", "stylelint-config-recommended": "^8.0.0",
"stylelint-config-standard": "^26.0.0", "stylelint-config-standard": "^26.0.0",
"stylelint-order": "^5.0.0", "stylelint-order": "^5.0.0",
"stylelint-scss": "^4.2.0", "stylelint-scss": "^4.3.0",
"typescript": "^4.7.4", "typescript": "^4.7.4",
"unplugin-auto-import": "^0.9.2", "unplugin-auto-import": "^0.9.2",
"unplugin-vue-components": "^0.21.0", "unplugin-vue-components": "^0.21.1",
"unplugin-vue-define-options": "^0.6.1", "unplugin-vue-define-options": "^0.6.2",
"vite": "2.9.13", "vite": "2.9.14",
"vite-plugin-checker": "^0.4.7", "vite-plugin-checker": "^0.4.8",
"vite-plugin-windicss": "^1.8.6", "vite-plugin-windicss": "^1.8.6",
"vue-eslint-parser": "^9.0.3", "vue-eslint-parser": "^9.0.3",
"vue-tsc": "^0.38.2", "vue-tsc": "^0.38.3",
"windicss": "^3.5.6" "windicss": "^3.5.6"
}, },
"repository": { "repository": {

File diff suppressed because it is too large Load Diff

@ -1,10 +1,12 @@
import { VisualEditorComponent } from '@/visual-editor/visual-editor.utils';
const modules = import.meta.globEager('./*/index.tsx'); const modules = import.meta.globEager('./*/index.tsx');
const components = {}; const components: Record<string, VisualEditorComponent> = {};
Object.keys(modules).forEach((key: string) => { Object.entries(modules).forEach(([key, module]) => {
const name = key.replace(/\.\/(.*)\/index\.(tsx|vue)/, '$1'); const name = key.replace(/\.\/(.*)\/index\.(tsx|vue)/, '$1');
components[name] = modules[key]?.default || modules[key]; components[name] = module?.default || module;
}); });
console.log(components, 'base-widgets'); console.log(components, 'base-widgets');

@ -51,4 +51,4 @@ export const fontArr = [
{ label: '思源黑体', value: 'Source Han Sans CN' }, { label: '思源黑体', value: 'Source Han Sans CN' },
{ label: '思源宋体', value: 'Source Han Serif SC' }, { label: '思源宋体', value: 'Source Han Serif SC' },
{ label: '文泉驿微米黑', value: 'WenQuanYi Micro Hei' }, { label: '文泉驿微米黑', value: 'WenQuanYi Micro Hei' },
]; ] as const;

@ -40,7 +40,7 @@ export default {
}, },
props: { props: {
text: createEditorInputProp({ label: '显示文本' }), text: createEditorInputProp({ label: '显示文本' }),
font: createEditorSelectProp({ label: '字体设置', options: fontArr }), font: createEditorSelectProp({ label: '字体设置', options: [...fontArr] }),
color: createEditorColorProp({ label: '字体颜色' }), color: createEditorColorProp({ label: '字体颜色' }),
size: createEditorInputNumberProp({ size: createEditorInputNumberProp({
label: '字体大小', label: '字体大小',

@ -1,6 +1,8 @@
import { VisualEditorComponent } from '@/visual-editor/visual-editor.utils';
const modules = import.meta.globEager('./*/index.tsx'); const modules = import.meta.globEager('./*/index.tsx');
const components = {}; const components: Record<string, VisualEditorComponent> = {};
Object.keys(modules).forEach((key: string) => { Object.keys(modules).forEach((key: string) => {
const name = key.replace(/\.\/(.*)\/index\.(tsx|vue)/, '$1'); const name = key.replace(/\.\/(.*)\/index\.(tsx|vue)/, '$1');

@ -44,9 +44,9 @@ export default {
watchEffect(() => { watchEffect(() => {
if (Object.keys(props.slots || {}).length) { if (Object.keys(props.slots || {}).length) {
Object.keys(props.slots).forEach((key) => { Object.entries<SlotItem>(props.slots).forEach(([key, slot]) => {
if (slotsTemp[block._vid][key]?.children) { if (slotsTemp[block._vid][key]?.children) {
props.slots[key].children = slotsTemp[block._vid][key].children; slot.children = slotsTemp[block._vid][key].children;
} }
}); });
} }

@ -74,6 +74,10 @@
import { useVisualData, localKey } from '@/visual-editor/hooks/useVisualData'; import { useVisualData, localKey } from '@/visual-editor/hooks/useVisualData';
import { BASE_URL } from '@/visual-editor/utils'; import { BASE_URL } from '@/visual-editor/utils';
defineOptions({
name: 'PageHeader',
});
const isShowH5Preview = ref(false); const isShowH5Preview = ref(false);
const tools = useTools(); const tools = useTools();

@ -10,37 +10,24 @@
</el-dialog> </el-dialog>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineComponent, reactive, toRefs } from 'vue';
import { useVModel } from '@vueuse/core'; import { useVModel } from '@vueuse/core';
import { BASE_URL } from '@/visual-editor/utils'; import { BASE_URL } from '@/visual-editor/utils';
/**
* @name: preview defineOptions({
* @author: 卜启缘
* @date: 2021/4/29 23:09
* @descriptionpreview
* @update: 2021/4/29 23:09
*/
export default defineComponent({
name: 'Preview', name: 'Preview',
props: { });
const props = defineProps({
visible: { visible: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
},
emits: ['update:visible'],
setup(props, { emit }) {
const state = reactive({
dialogVisible: useVModel(props, 'visible', emit),
previewUrl: `${BASE_URL}preview/${location.hash}`,
}); });
const emits = defineEmits(['update:visible']);
return { const dialogVisible = useVModel(props, 'visible', emits);
...toRefs(state), const previewUrl = `${BASE_URL}preview/${location.hash}`;
};
},
});
</script> </script>
<style lang="scss"> <style lang="scss">

@ -60,6 +60,7 @@
ElMessage, ElMessage,
ElCascader, ElCascader,
ElIcon, ElIcon,
ExpandTrigger,
} from 'element-plus'; } from 'element-plus';
import { cloneDeep } from 'lodash-es'; import { cloneDeep } from 'lodash-es';
import { Delete, Edit } from '@element-plus/icons-vue'; import { Delete, Edit } from '@element-plus/icons-vue';
@ -163,14 +164,14 @@
<ElFormItem label="请求数据" prop={'data.bind'}> <ElFormItem label="请求数据" prop={'data.bind'}>
<ElCascader <ElCascader
v-model={state.ruleForm.data.bind} v-model={state.ruleForm.data.bind}
options={models.value} options={[...models.value]}
clearable={true} clearable={true}
props={{ props={{
checkStrictly: true, checkStrictly: true,
children: 'entitys', children: 'entitys',
label: 'name', label: 'name',
value: 'key', value: 'key',
expandTrigger: 'hover', expandTrigger: ExpandTrigger.HOVER,
}} }}
placeholder="请选择绑定的请求数据" placeholder="请选择绑定的请求数据"
onChange={handleBindChange} onChange={handleBindChange}
@ -184,12 +185,12 @@
children: 'entitys', children: 'entitys',
label: 'name', label: 'name',
value: 'key', value: 'key',
expandTrigger: 'hover', expandTrigger: ExpandTrigger.HOVER,
}} }}
placeholder="请选择绑定的响应数据" placeholder="请选择绑定的响应数据"
onChange={handleBindChange} onChange={handleBindChange}
v-model={state.ruleForm.data.recv} v-model={state.ruleForm.data.recv}
options={models.value} options={[...models.value]}
></ElCascader> ></ElCascader>
</ElFormItem> </ElFormItem>
</ElForm> </ElForm>

@ -22,25 +22,25 @@ import { useModal } from '@/visual-editor/hooks/useModal';
export const importSwaggerJson = (swagger: any) => { export const importSwaggerJson = (swagger: any) => {
swagger = typeof swagger == 'string' ? JSON.parse(swagger) : swagger; swagger = typeof swagger == 'string' ? JSON.parse(swagger) : swagger;
const models: VisualEditorModel[] = []; const models: VisualEditorModel[] = [];
Object.keys(swagger.definitions).forEach((model) => { Object.entries<any>(swagger.definitions).forEach(([name, model]) => {
const properties = swagger.definitions[model].properties; const properties = model.properties;
const modelItem: VisualEditorModel = { const modelItem: VisualEditorModel = {
name: model, name,
key: generateNanoid(), key: generateNanoid(),
entitys: [], entitys: [],
}; };
Object.keys(properties).forEach((field) => { Object.entries<any>(properties).forEach(([field, property]) => {
modelItem.entitys.push({ modelItem.entitys.push({
key: field, key: field,
name: properties[field].description || field, name: property.description || field,
type: properties[field].type, type: property.type,
value: '', value: '',
}); });
}); });
models.push(modelItem); models.push(modelItem);
}); });
const apis: FetchApiItem[] = []; const apis: FetchApiItem[] = [];
Object.keys(swagger.paths).forEach((url) => { Object.entries(swagger.paths).forEach(([url]) => {
Object.keys(swagger.paths[url]).forEach((method) => { Object.keys(swagger.paths[url]).forEach((method) => {
const apiUrlObj = swagger.paths[url][method]; const apiUrlObj = swagger.paths[url][method];
const model = apiUrlObj.parameters?.[0]?.schema?.$ref?.split('/').pop(); const model = apiUrlObj.parameters?.[0]?.schema?.$ref?.split('/').pop();

@ -1,6 +1,8 @@
import { DefineComponent } from 'vue';
const modules = import.meta.globEager('./*/index.(tsx|vue)'); const modules = import.meta.globEager('./*/index.(tsx|vue)');
const components = {}; const components: Record<string, DefineComponent> = {};
console.log(modules, '起航'); console.log(modules, '起航');

@ -33,10 +33,10 @@
name: 'LeftAside', name: 'LeftAside',
}); });
const tabs = Object.keys(components) const tabs = Object.entries(components)
.map((name) => { .map(([name, component]) => {
const { label, icon, order } = components[name]; const { label, icon, order } = component;
return { label, icon, name, order, comp: components[name] }; return { label, icon, name, order, comp: component };
}) })
.sort((a, b) => a.order - b.order); .sort((a, b) => a.order - b.order);

@ -142,10 +142,10 @@ export const Animate = defineComponent({
// 可添加的动画列表组件 // 可添加的动画列表组件
const AnimateList = () => ( const AnimateList = () => (
<ElTabs v-model={state.activeName} stretch> <ElTabs v-model={state.activeName} stretch>
{Object.keys(animationTabs).map((tabKey) => ( {Object.entries(animationTabs).map(([tabKey, animationBox]) => (
<ElTabPane label={animationTabs[tabKey].label} name={tabKey} key={tabKey}> <ElTabPane label={animationTabs[tabKey].label} name={tabKey} key={tabKey}>
<ElRow gutter={10}> <ElRow gutter={10}>
{animationTabs[tabKey].value.map((animateItem: Animation) => ( {animationBox.value.map((animateItem: Animation) => (
<ElCol span={8} key={animateItem.value}> <ElCol span={8} key={animateItem.value}>
<div <div
class={'animate-item'} class={'animate-item'}

@ -1,17 +1,17 @@
import type { Animation } from '@/visual-editor/visual-editor.utils'; import type { Animation } from '@/visual-editor/visual-editor.utils';
export interface animationBoxTs { export type AnimationBox = {
label: string; label: string;
value: Animation[]; value: Animation[];
} };
// 动画类型 // 动画类型
export interface animationTabsTs { export type AnimationTabs = {
in: animationBoxTs; in: AnimationBox;
out: animationBoxTs; out: AnimationBox;
other: animationBoxTs; other: AnimationBox;
} };
export const animationTabs: animationTabsTs = { export const animationTabs: AnimationTabs = {
in: { in: {
label: '进入', label: '进入',
value: [], value: [],
@ -431,7 +431,7 @@ const opt = [
}, },
], ],
}, },
]; ] as const;
/** /**
* @return {Object} { animationValue: animatonLabel } * @return {Object} { animationValue: animatonLabel }
@ -446,7 +446,7 @@ const defaultOption = {
}; };
for (let index = 0; index < opt.length; index++) { for (let index = 0; index < opt.length; index++) {
const items = opt[index].children; const items = opt[index].children;
items.forEach((item) => { items.forEach((item: LabelValue) => {
if (inReg.test(item.label)) { if (inReg.test(item.label)) {
animationTabs.in.value.push({ animationTabs.in.value.push({
...item, ...item,

@ -66,7 +66,7 @@ const ServiceComponent = defineComponent({
return () => ( return () => (
<> <>
<ElDialog modelValue={state.showFlag}> <ElDialog v-model={state.showFlag}>
{{ {{
default: () => ( default: () => (
<div> <div>

@ -22,7 +22,7 @@
</draggable> </draggable>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
/** /**
* @name: draggable-transition-group * @name: draggable-transition-group
* @author:卜启缘 * @author:卜启缘
@ -30,14 +30,15 @@
* @descriptiondraggable-transition-group * @descriptiondraggable-transition-group
* @update: 2021/5/1 23:15 * @update: 2021/5/1 23:15
*/ */
import { computed, defineComponent, reactive, toRefs, SetupContext } from 'vue'; import { computed } from 'vue';
import draggable from 'vuedraggable'; import draggable from 'vuedraggable';
import { useVModel } from '@vueuse/core'; import { useVModel } from '@vueuse/core';
export default defineComponent({ defineOptions({
name: 'DraggableTransitionGroup', name: 'DraggableTransitionGroup',
components: { draggable }, });
props: {
const props = defineProps({
moduleValue: { moduleValue: {
type: Array, type: Array,
default: () => [], default: () => [],
@ -55,13 +56,11 @@
default: () => ({ name: 'components' }), default: () => ({ name: 'components' }),
}, },
fallbackClass: String, fallbackClass: String,
},
emits: ['update:moduleValue', 'update:drag'],
setup(props, { emit }: SetupContext) {
const state = reactive({
list: useVModel(props, 'moduleValue', emit),
isDrag: useVModel(props, 'drag', emit),
}); });
const emit = defineEmits(['update:moduleValue', 'update:drag']);
const list = useVModel(props, 'moduleValue', emit);
const isDrag = useVModel(props, 'drag', emit);
const dragOptions = computed(() => ({ const dragOptions = computed(() => ({
animation: 200, animation: 200,
@ -69,13 +68,6 @@
scroll: true, scroll: true,
ghostClass: 'ghost', ghostClass: 'ghost',
})); }));
return {
...toRefs(state),
dragOptions,
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

@ -53,8 +53,8 @@
</div> </div>
</template> </template>
<script lang="tsx"> <script lang="tsx" setup>
import { defineComponent, reactive, watchEffect, toRefs } from 'vue'; import { ref, watchEffect } from 'vue';
import { cloneDeep } from 'lodash-es'; import { cloneDeep } from 'lodash-es';
import DraggableTransitionGroup from './draggable-transition-group.vue'; import DraggableTransitionGroup from './draggable-transition-group.vue';
import CompRender from './comp-render'; import CompRender from './comp-render';
@ -67,22 +67,15 @@
import { useModal } from '@/visual-editor/hooks/useModal'; import { useModal } from '@/visual-editor/hooks/useModal';
import { generateNanoid } from '@/visual-editor/utils'; import { generateNanoid } from '@/visual-editor/utils';
export default defineComponent({ defineOptions({
name: 'SimulatorEditor', name: 'SimulatorEditor',
components: { });
DraggableTransitionGroup,
CompRender,
SlotItem,
},
emits: ['on-selected'],
setup() {
const { currentPage, setCurrentBlock } = useVisualData(); const { currentPage, setCurrentBlock } = useVisualData();
const { globalProperties } = useGlobalProperties(); const { globalProperties } = useGlobalProperties();
const state = reactive({ const drag = ref(false);
drag: false,
});
/** /**
* @description 操作当前页面样式表 * @description 操作当前页面样式表
@ -166,10 +159,7 @@
/** /**
* 删除组件 * 删除组件
*/ */
const deleteComp = ( const deleteComp = (block: VisualEditorBlockData, parentBlocks = currentPage.value.blocks) => {
block: VisualEditorBlockData,
parentBlocks = currentPage.value.blocks,
) => {
console.log(block, 'block'); console.log(block, 'block');
const index = parentBlocks.findIndex((item) => item._vid == block._vid); const index = parentBlocks.findIndex((item) => item._vid == block._vid);
if (index != -1) { if (index != -1) {
@ -247,16 +237,6 @@
), ),
}); });
}; };
return {
...toRefs(state),
currentPage,
deleteComp,
selectComp,
onContextmenuBlock,
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import './func.scss'; @import './func.scss';

@ -39,7 +39,7 @@
</draggable-transition-group> </draggable-transition-group>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
/** /**
* @name: slot-item * @name: slot-item
* @author:卜启缘 * @author:卜启缘
@ -48,16 +48,17 @@
* @update: 2021/5/2 22:36 * @update: 2021/5/2 22:36
*/ */
import { defineComponent, PropType } from 'vue'; import { PropType } from 'vue';
import { useVModel } from '@vueuse/core'; import { useVModel } from '@vueuse/core';
import DraggableTransitionGroup from './draggable-transition-group.vue'; import DraggableTransitionGroup from './draggable-transition-group.vue';
import CompRender from './comp-render'; import CompRender from './comp-render';
import type { VisualEditorBlockData } from '@/visual-editor/visual-editor.utils'; import type { VisualEditorBlockData } from '@/visual-editor/visual-editor.utils';
export default defineComponent({ defineOptions({
name: 'SlotItem', name: 'SlotItem',
components: { CompRender, DraggableTransitionGroup }, });
props: {
const props = defineProps({
slotKey: { slotKey: {
type: String as PropType<string | number>, type: String as PropType<string | number>,
default: '', default: '',
@ -84,18 +85,14 @@
>, >,
required: true, required: true,
}, },
}, });
emits: ['update:children', 'on-selected', 'update:drag'], const emit = defineEmits(['update:children', 'on-selected', 'update:drag']);
setup(props, { emit }) {
const isDrag = useVModel(props, 'drag', emit);
const slotChildren = useVModel(props, 'children', emit);
// //
props.children.some((item) => item.focus && props.selectComp(item)); props.children.some((item) => item.focus && props.selectComp(item));
return {
isDrag: useVModel(props, 'drag', emit),
slotChildren: useVModel(props, 'children', emit),
};
},
});
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

@ -67,7 +67,7 @@ const Modal = defineComponent({
return () => ( return () => (
<ElDialog <ElDialog
modelValue={state.visible} v-model={state.visible}
title={state.options.title} title={state.options.title}
destroyOnClose={true} destroyOnClose={true}
{...state.options.props} {...state.options.props}

@ -64,7 +64,7 @@ const ServiceComponent = defineComponent({
return () => ( return () => (
<> <>
<ElDialog modelValue={state.showFlag} title={state.option.title} key={state.key}> <ElDialog v-model={state.showFlag} title={state.option.title} key={state.key}>
{{ {{
default: () => ( default: () => (
<div> <div>

@ -8,7 +8,7 @@ import { generateNanoid } from '@/visual-editor/utils';
/** /**
* @description * @description
*/ */
export interface VisualEditorBlockData { export type VisualEditorBlockData = {
/** 组件id 时间戳, 组件唯一标识 */ /** 组件id 时间戳, 组件唯一标识 */
_vid: string; _vid: string;
/** 组件所属的模块(基础组件、容器组件) */ /** 组件所属的模块(基础组件、容器组件) */
@ -42,11 +42,11 @@ export interface VisualEditorBlockData {
/** 组件事件集合 */ /** 组件事件集合 */
events: { label: string; value: string }[]; events: { label: string; value: string }[];
[prop: string]: any; [prop: string]: any;
} };
/** /**
* @description * @description
*/ */
export interface ActionHandle { export type ActionHandle = {
key: string; key: string;
name: string; name: string;
link: string[]; link: string[];
@ -54,32 +54,32 @@ export interface ActionHandle {
bind?: string; bind?: string;
recv?: string; recv?: string;
}; };
} };
/** /**
* @description * @description
*/ */
export interface Action { export type Action = {
key: string; key: string;
name: string; name: string;
event: string; event: string;
handle: ActionHandle[]; handle: ActionHandle[];
} };
/** /**
* @description * @description
*/ */
export interface PageConfig { export type PageConfig = {
/** 背景图片 */ /** 背景图片 */
bgImage: string; bgImage: string;
/** 背景颜色 */ /** 背景颜色 */
bgColor: string; bgColor: string;
/** 是否缓存当前页面 */ /** 是否缓存当前页面 */
keepAlive: boolean; keepAlive: boolean;
} };
/** /**
* @description * @description
*/ */
export interface VisualEditorPage { export type VisualEditorPage = {
/** 页面标题 */ /** 页面标题 */
title: string; title: string;
/** 页面路径 */ /** 页面路径 */
@ -90,13 +90,13 @@ export interface VisualEditorPage {
config: PageConfig; config: PageConfig;
/** 当前页面的所有组件 */ /** 当前页面的所有组件 */
blocks: VisualEditorBlockData[]; blocks: VisualEditorBlockData[];
} };
/** /**
* @description => * @description =>
*/ */
export interface VisualEditorPages { export type VisualEditorPages = {
[path: string]: VisualEditorPage; [path: string]: VisualEditorPage;
} };
/** /**
* @description * @description
*/ */
@ -114,18 +114,18 @@ export type EntityType = {
/** /**
* @description * @description
*/ */
export interface VisualEditorModel { export type VisualEditorModel = {
/** 数据源名称 */ /** 数据源名称 */
name: string; name: string;
/** 绑定的字段 该字段创建的时候生成 */ /** 绑定的字段 该字段创建的时候生成 */
key: string; key: string;
/** 实体集合 */ /** 实体集合 */
entitys: EntityType[]; entitys: EntityType[];
} };
/** /**
* @description * @description
*/ */
export interface FetchApiItem { export type FetchApiItem = {
/** 随机生成的key */ /** 随机生成的key */
key: string; key: string;
/** 随机生成的key */ /** 随机生成的key */
@ -144,12 +144,12 @@ export interface FetchApiItem {
/** 响应的结果绑定到某个实体上 */ /** 响应的结果绑定到某个实体上 */
recv: string; recv: string;
}; };
} };
/** /**
* @description * @description
*/ */
export interface VisualEditorActions { export type VisualEditorActions = {
fetch: { fetch: {
name: '接口请求'; name: '接口请求';
apis: FetchApiItem[]; apis: FetchApiItem[];
@ -158,22 +158,22 @@ export interface VisualEditorActions {
name: '对话框'; name: '对话框';
handlers: []; handlers: [];
}; };
} };
/** /**
* @description * @description
*/ */
export interface VisualEditorModelValue { export type VisualEditorModelValue = {
/** 页面 */ /** 页面 */
pages: VisualEditorPages; pages: VisualEditorPages;
/** 实体 */ /** 实体 */
models: VisualEditorModel[]; models: VisualEditorModel[];
/** 动作 */ /** 动作 */
actions: VisualEditorActions; actions: VisualEditorActions;
} };
/** /**
* @description * @description
*/ */
export interface Animation { export type Animation = {
/** 动画名称 */ /** 动画名称 */
label: string; label: string;
/** 动画类名 */ /** 动画类名 */
@ -186,11 +186,11 @@ export interface Animation {
count: number; count: number;
/** 是否无限循环动画 */ /** 是否无限循环动画 */
infinite: boolean; infinite: boolean;
} };
/** /**
* @description * @description
*/ */
export interface VisualEditorComponent { export type VisualEditorComponent = {
/** 组件name */ /** 组件name */
key: string; key: string;
/** 组件所属模块名称 */ /** 组件所属模块名称 */
@ -221,12 +221,12 @@ export interface VisualEditorComponent {
events?: { label: string; value: string }[]; events?: { label: string; value: string }[];
/** 组件样式 */ /** 组件样式 */
styles?: CSSProperties; styles?: CSSProperties;
} };
export interface VisualEditorMarkLines { export type VisualEditorMarkLines = {
x: { left: number; showLeft: number }[]; x: { left: number; showLeft: number }[];
y: { top: number; showTop: number }[]; y: { top: number; showTop: number }[];
} };
export function createNewBlock(component: VisualEditorComponent): VisualEditorBlockData { export function createNewBlock(component: VisualEditorComponent): VisualEditorBlockData {
return { return {
@ -246,10 +246,10 @@ export function createNewBlock(component: VisualEditorComponent): VisualEditorBl
tempPadding: '0', tempPadding: '0',
}, },
hasResize: false, hasResize: false,
props: Object.keys(component.props || {}).reduce((prev, curr) => { props: Object.entries(component.props || {}).reduce((prev, [propName, propSchema]) => {
const { propObj, prop } = useDotProp(prev, curr); const { propObj, prop } = useDotProp(prev, propName);
if (component.props![curr]?.defaultValue) { if (propSchema?.defaultValue) {
propObj[prop] = prev[curr] = component.props![curr]?.defaultValue; propObj[prop] = prev[propName] = propSchema?.defaultValue;
} }
return prev; return prev;
}, {}), }, {}),
@ -262,7 +262,7 @@ export function createNewBlock(component: VisualEditorComponent): VisualEditorBl
}; };
} }
export interface VisualDragEvent { export type VisualDragEvent = {
dragstart: { dragstart: {
on: (cb: () => void) => void; on: (cb: () => void) => void;
off: (cb: () => void) => void; off: (cb: () => void) => void;
@ -273,7 +273,7 @@ export interface VisualDragEvent {
off: (cb: () => void) => void; off: (cb: () => void) => void;
emit: () => void; emit: () => void;
}; };
} };
export const VisualDragProvider = (() => { export const VisualDragProvider = (() => {
const VISUAL_DRAG_PROVIDER = '@@VISUAL_DRAG_PROVIDER'; const VISUAL_DRAG_PROVIDER = '@@VISUAL_DRAG_PROVIDER';
@ -288,10 +288,10 @@ export const VisualDragProvider = (() => {
})(); })();
// 组件模块 // 组件模块
export interface ComponentModules { export type ComponentModules = {
baseWidgets: VisualEditorComponent[]; // 基础组件 baseWidgets: VisualEditorComponent[]; // 基础组件
containerComponents: VisualEditorComponent[]; // 容器组件 containerComponents: VisualEditorComponent[]; // 容器组件
} };
/** /**
* @description * @description
* @returns {} * @returns {}

@ -4,12 +4,12 @@ import containerComponent from '@/packages/container-component';
export const visualConfig = createVisualEditorConfig(); export const visualConfig = createVisualEditorConfig();
// 注册基础控件 // 注册基础控件
Object.keys(baseWidgets).forEach((name: string) => Object.entries(baseWidgets).forEach(([name, widget]) =>
visualConfig.registry('baseWidgets', name, baseWidgets[name]), visualConfig.registry('baseWidgets', name, widget),
); );
// 注册容器组件 // 注册容器组件
Object.keys(containerComponent).forEach((name: string) => Object.entries(containerComponent).forEach(([name, widget]) =>
visualConfig.registry('containerComponents', name, containerComponent[name]), visualConfig.registry('containerComponents', name, widget),
); );
console.log( console.log(

Loading…
Cancel
Save