diff --git a/examples/src/pages/UIView.vue b/examples/src/pages/UIView.vue index bafb233c..27541c9a 100644 --- a/examples/src/pages/UIView.vue +++ b/examples/src/pages/UIView.vue @@ -96,6 +96,7 @@ + diff --git a/packages/base/src/components/RenderSlot.ts b/packages/base/src/components/RenderSlot.ts index a89af280..df299ab3 100644 --- a/packages/base/src/components/RenderSlot.ts +++ b/packages/base/src/components/RenderSlot.ts @@ -6,6 +6,6 @@ export default defineComponent({ }, // @ts-ignore setup(props) { - return () => [h('template', {}, props.slots)] + return () => [h('div', {}, props.slots)] } }) diff --git a/packages/designer/src/components/xicon/index.ts b/packages/designer/src/components/xicon/index.ts index 83307fe4..59380eed 100644 --- a/packages/designer/src/components/xicon/index.ts +++ b/packages/designer/src/components/xicon/index.ts @@ -1,5 +1,6 @@ import type { App } from 'vue' +import useIcon from './useIcon' import XIcon from './XIcon.vue' export { XIcon } @@ -10,3 +11,5 @@ export default { app.component('XIcon', XIcon) } } + +export { useIcon } diff --git a/packages/designer/src/components/xicon/useIcon.ts b/packages/designer/src/components/xicon/useIcon.ts new file mode 100644 index 00000000..5361a2dd --- /dev/null +++ b/packages/designer/src/components/xicon/useIcon.ts @@ -0,0 +1,49 @@ +import { Icon } from '@vicons/utils' +import type { Component, ComputedRef, PropType } from 'vue' +import { computed, defineComponent, h, inject } from 'vue' + +import stanadarIcon from './icon-map' + +export default function useIcon(icons?: Record) { + stanadarIcon as Record + const iconMap = { ...stanadarIcon, ...(icons || {}) } + return defineComponent({ + props: { + name: { + type: String as PropType, + default: 'help' + }, + color: { + type: String as PropType + }, + size: { + type: Number as PropType, + default: 25 + } + }, + setup(props, _context) { + const darkTheme = inject>( + 'DarkTheme', + computed(() => true) + ) + const getIconColor = () => { + return darkTheme.value ? '#eeee' : '#333' + } + const iconColor = computed(() => (props.color ? props.color : getIconColor())) + return { iconColor } + }, + render: ({ name, size, iconColor }: { name: string; size: number; iconColor: string }) => { + const obIcon = iconMap[name] + return h( + Icon, + { + class: 'h-full inline-flex justify-center items-center', + tag: 'span', + size: size, + color: iconColor + }, + () => h(obIcon, {}) + ) + } + }) +} diff --git a/packages/designer/src/loadPlugin.ts b/packages/designer/src/loadPlugin.ts index 56c00e80..91c69196 100644 --- a/packages/designer/src/loadPlugin.ts +++ b/packages/designer/src/loadPlugin.ts @@ -1,14 +1,18 @@ -import type { App } from 'vue' +import type { App, Component } from 'vue' import { defineAsyncComponent } from 'vue' import Group from './components/Group' +import { useIcon } from './components/xicon' import useCanvasState from './state/canvas' const canvasState = useCanvasState() - -const useComponentPlugin = ({ codeEditorComponent }: { codeEditorComponent?: any }) => { - const OXIcon = defineAsyncComponent(() => import('./components/xicon/XIcon.vue')) - +const useComponentPlugin = ({ + codeEditorComponent, + icons +}: { + codeEditorComponent?: Component + icons?: Record +}) => { const OCodeEditor = codeEditorComponent ? codeEditorComponent : defineAsyncComponent(() => import('./components/CodeEditor.vue')) @@ -19,11 +23,13 @@ const useComponentPlugin = ({ codeEditorComponent }: { codeEditorComponent?: any timeout: 3000 }) canvasState.loadComponent(Group.componentName, Group.config) + + const OIcon = useIcon(icons) return { install(app: App) { // 插入元素 app.component('OCodeEditor', OCodeEditor) - app.component('XIcon', OXIcon) + app.component('XIcon', OIcon) app.component(Group.componentName, groupComp) } }