diff --git a/docs/package.json b/docs/package.json index 19dd8edc..4ca26efa 100644 --- a/docs/package.json +++ b/docs/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.0.9", + "@tmagic/design": "1.2.0-beta.2", "@tmagic/element-plus-adapter": "1.2.0-beta.2", "@tmagic/form": "1.2.0-beta.2", "@tmagic/schema": "1.2.0-beta.2", diff --git a/docs/src/.vuepress/client.ts b/docs/src/.vuepress/client.ts index c0480c48..ba3ec2e5 100644 --- a/docs/src/.vuepress/client.ts +++ b/docs/src/.vuepress/client.ts @@ -4,6 +4,7 @@ import 'highlight.js/styles/github.css'; import './polyfills'; import { defineClientConfig } from '@vuepress/client'; import ElementPlus from 'element-plus'; +import TMagicDesign from '@tmagic/design'; import MagicElementPlusAdapter from '@tmagic/element-plus-adapter'; import MagicForm from '@tmagic/form'; import DemoBlock from './demo-block.vue'; @@ -11,8 +12,8 @@ import DemoBlock from './demo-block.vue'; export default defineClientConfig({ enhance({ app, router, siteData }) { app.use(ElementPlus); + app.use(TMagicDesign, MagicElementPlusAdapter) app.use(MagicForm, { - uiAdapter: MagicElementPlusAdapter, request: (options: any) => new Promise((resolve) => { if (options.url === 'select/remote') { setTimeout(() => { diff --git a/docs/src/.vuepress/config.ts b/docs/src/.vuepress/config.ts index 63f28948..c0a2d57c 100644 --- a/docs/src/.vuepress/config.ts +++ b/docs/src/.vuepress/config.ts @@ -228,6 +228,7 @@ export default defineUserConfig({ { find: /^@tmagic\/form/, replacement: path.join(__dirname, '../../../packages/form/src/index.ts') }, { find: /^@tmagic\/utils/, replacement: path.join(__dirname, '../../../packages/utils/src/index.ts') }, { find: /^@tmagic\/schema/, replacement: path.join(__dirname, '../../../packages/schema/src/index.ts') }, + { find: /^@tmagic\/design/, replacement: path.join(__dirname, '../../../packages/design/src/index.ts') }, { find: /^@tmagic\/element-plus-adapter/, replacement: path.join(__dirname, '../../../packages/element-plus-adapter/src/index.ts') }, ] }, diff --git a/packages/design/src/OptionGroup.vue b/packages/design/src/OptionGroup.vue index 618b7aad..e49506bc 100644 --- a/packages/design/src/OptionGroup.vue +++ b/packages/design/src/OptionGroup.vue @@ -1,11 +1,11 @@ diff --git a/packages/design/src/Popover.vue b/packages/design/src/Popover.vue new file mode 100644 index 00000000..60cb79d4 --- /dev/null +++ b/packages/design/src/Popover.vue @@ -0,0 +1,25 @@ + + + diff --git a/packages/design/src/Table.vue b/packages/design/src/Table.vue index 62c5617d..edf0bdd1 100644 --- a/packages/design/src/Table.vue +++ b/packages/design/src/Table.vue @@ -53,5 +53,9 @@ defineExpose({ toggleRowSelection(...args: any[]) { table.value?.toggleRowSelection(...args); }, + + toggleRowExpansion(...args: any[]) { + table.value?.toggleRowExpansion(...args); + }, }); diff --git a/packages/design/src/Tag.vue b/packages/design/src/Tag.vue new file mode 100644 index 00000000..ade207be --- /dev/null +++ b/packages/design/src/Tag.vue @@ -0,0 +1,20 @@ + + + diff --git a/packages/design/src/index.ts b/packages/design/src/index.ts index 5df23135..6a14d84e 100644 --- a/packages/design/src/index.ts +++ b/packages/design/src/index.ts @@ -1,9 +1,10 @@ import { App } from 'vue'; import { getConfig, setConfig } from './config'; -import { PluginOptions, TMagicMessage } from './type'; +import { PluginOptions, TMagicMessage, TMagicMessageBox } from './type'; export * from './type'; +export * from './config'; /* eslint-disable @typescript-eslint/no-unused-vars */ export { default as TMagicButton } from './Button.vue'; @@ -23,6 +24,7 @@ export { default as TMagicInputNumber } from './InputNumber.vue'; export { default as TMagicOption } from './Option.vue'; export { default as TMagicOptionGroup } from './OptionGroup.vue'; export { default as TMagicPagination } from './Pagination.vue'; +export { default as TMagicPopover } from './Popover.vue'; export { default as TMagicRadio } from './Radio.vue'; export { default as TMagicRadioGroup } from './RadioGroup.vue'; export { default as TMagicRow } from './Row.vue'; @@ -34,11 +36,13 @@ export { default as TMagicTable } from './Table.vue'; export { default as TMagicTableColumn } from './TableColumn.vue'; export { default as TMagicTabPane } from './TabPane.vue'; export { default as TMagicTabs } from './Tabs.vue'; +export { default as TMagicTag } from './Tag.vue'; export { default as TMagicTimePicker } from './TimePicker.vue'; export { default as TMagicTooltip } from './Tooltip.vue'; export { default as TMagicUpload } from './Upload.vue'; export const tMagicMessage: TMagicMessage = getConfig('message') as TMagicMessage; +export const tMagicMessageBox: TMagicMessageBox = getConfig('messageBox') as TMagicMessageBox; export default { install(app: App, options: PluginOptions) { diff --git a/packages/design/src/type.ts b/packages/design/src/type.ts index 9e7df53a..7ebc310a 100644 --- a/packages/design/src/type.ts +++ b/packages/design/src/type.ts @@ -14,7 +14,26 @@ export interface TMagicMessage { error: (msg: string) => void; } +export type ElMessageBoxShortcutMethod = (( + message: string, + title: string, + options?: any, + appContext?: any | null, +) => Promise) & + ((message: string, options?: any, appContext?: any | null) => Promise); + +export interface TMagicMessageBox { + alert: ElMessageBoxShortcutMethod; + + confirm: ElMessageBoxShortcutMethod; + + prompt: ElMessageBoxShortcutMethod; + + close(): void; +} + export interface PluginOptions { message?: TMagicMessage; + messageBox?: TMagicMessageBox; components?: Record; } diff --git a/packages/element-plus-adapter/src/index.ts b/packages/element-plus-adapter/src/index.ts index b6b9fcbf..16aa38a4 100644 --- a/packages/element-plus-adapter/src/index.ts +++ b/packages/element-plus-adapter/src/index.ts @@ -14,6 +14,7 @@ import { ElInput, ElInputNumber, ElMessage, + ElMessageBox, ElOption, ElOptionGroup, ElPagination, @@ -35,6 +36,7 @@ import { const adapter: any = { message: ElMessage, + messageBox: ElMessageBox, components: { button: { component: ElButton, @@ -176,6 +178,11 @@ const adapter: any = { props: (props: any) => props, }, + tag: { + component: ElTabs, + props: (props: any) => props, + }, + timePicker: { component: ElTimePicker, props: (props: any) => props, diff --git a/packages/form/src/fields/SelectOptionGroups.vue b/packages/form/src/fields/SelectOptionGroups.vue index 81a8a404..527ea573 100644 --- a/packages/form/src/fields/SelectOptionGroups.vue +++ b/packages/form/src/fields/SelectOptionGroups.vue @@ -1,22 +1,25 @@ diff --git a/packages/form/src/index.ts b/packages/form/src/index.ts index 27dc3c97..f436bc37 100644 --- a/packages/form/src/index.ts +++ b/packages/form/src/index.ts @@ -18,8 +18,6 @@ import { App } from 'vue'; -import TMagicDesign from '@tmagic/design'; - import Container from './containers/Container.vue'; import Fieldset from './containers/Fieldset.vue'; import GroupList from './containers/GroupList.vue'; @@ -87,8 +85,6 @@ export { default as MDynamicField } from './fields/DynamicField.vue'; const defaultInstallOpt = {}; const install = (app: App, opt: any) => { - app.use(TMagicDesign, opt.uiAdapter); - const option = Object.assign(defaultInstallOpt, opt); // eslint-disable-next-line no-param-reassign diff --git a/packages/form/src/schema.ts b/packages/form/src/schema.ts index f1ca4531..3b86b4f7 100644 --- a/packages/form/src/schema.ts +++ b/packages/form/src/schema.ts @@ -215,7 +215,8 @@ export interface SelectGroupOption { disabled: boolean; options: { /** 选项的标签 */ - label: string; + label?: string; + text?: string; /** 选项的值 */ value: any; /** 是否禁用该选项 */ diff --git a/packages/table/package.json b/packages/table/package.json index 8d52b583..4f9723f7 100644 --- a/packages/table/package.json +++ b/packages/table/package.json @@ -32,6 +32,7 @@ "url": "https://github.com/Tencent/tmagic-editor.git" }, "dependencies": { + "@tmagic/design": "1.2.0-beta.2", "@tmagic/form": "1.2.0-beta.2", "@tmagic/utils": "1.2.0-beta.2", "element-plus": "^2.2.17", diff --git a/packages/table/src/ActionsColumn.vue b/packages/table/src/ActionsColumn.vue index 536b132a..ac7dbe3d 100644 --- a/packages/table/src/ActionsColumn.vue +++ b/packages/table/src/ActionsColumn.vue @@ -1,7 +1,7 @@ - - diff --git a/packages/table/src/PopoverColumn.vue b/packages/table/src/PopoverColumn.vue index cbb29ed8..063dc84d 100644 --- a/packages/table/src/PopoverColumn.vue +++ b/packages/table/src/PopoverColumn.vue @@ -1,40 +1,39 @@ - diff --git a/packages/table/src/Table.vue b/packages/table/src/Table.vue index dd7dbd34..1d8eaade 100644 --- a/packages/table/src/Table.vue +++ b/packages/table/src/Table.vue @@ -1,8 +1,8 @@ - diff --git a/packages/table/src/TextColumn.vue b/packages/table/src/TextColumn.vue index 2d70b3df..91b64aaf 100644 --- a/packages/table/src/TextColumn.vue +++ b/packages/table/src/TextColumn.vue @@ -1,5 +1,5 @@ - diff --git a/packages/table/src/index.ts b/packages/table/src/index.ts index c654a441..cc3bbe1f 100644 --- a/packages/table/src/index.ts +++ b/packages/table/src/index.ts @@ -22,12 +22,8 @@ import Table from './Table.vue'; export { default as MagicTable } from './Table.vue'; -const components = [Table]; - export default { install(app: App) { - components.forEach((component) => { - app.component(component.name, component); - }); + app.component('m-table', Table); }, }; diff --git a/packages/table/src/schema.ts b/packages/table/src/schema.ts index 7bc4895f..3f58a16e 100644 --- a/packages/table/src/schema.ts +++ b/packages/table/src/schema.ts @@ -35,23 +35,23 @@ export type ColumnConfig = { values?: FormValue; selection?: boolean | 'single'; selectable?: (row: any, index: number) => boolean; - label: string; + label?: string; fixed?: 'left' | 'right' | boolean; width?: number | string; actions?: ColumnActionConfig[]; - type: 'popover' | 'expand' | string | ((value: any, row: any) => string); - text: string; - prop: string; - showHeader: boolean; + type?: 'popover' | 'expand' | string | ((value: any, row: any) => string); + text?: string; + prop?: string; + showHeader?: boolean; table?: ColumnConfig[]; formatter?: 'datetime' | ((item: any, row: Record) => any); - popover: { - placement: ''; - width: ''; - trigger: ''; - tableEmbed: ''; + popover?: { + placement: string; + width: string; + trigger: string; + tableEmbed: string; }; sortable?: boolean | 'custom'; action?: 'tip' | 'actionLink' | 'img' | 'link' | 'tag'; - handler: (row: any) => void; + handler?: (row: any) => void; }; diff --git a/packages/table/src/utils.ts b/packages/table/src/utils.ts index e812ff70..c3b05105 100644 --- a/packages/table/src/utils.ts +++ b/packages/table/src/utils.ts @@ -21,6 +21,8 @@ import { datetimeFormatter } from '@tmagic/utils'; import { ColumnConfig } from './schema'; export const formatter = (item: ColumnConfig, row: any) => { + if (!item.prop) return ''; + if (item.formatter) { if (item.formatter === 'datetime') { // eslint-disable-next-line no-param-reassign diff --git a/packages/table/vite.config.ts b/packages/table/vite.config.ts index 47f82035..9d4c7bef 100644 --- a/packages/table/vite.config.ts +++ b/packages/table/vite.config.ts @@ -30,7 +30,10 @@ export default defineConfig({ alias: process.env.NODE_ENV === 'production' ? [] - : [{ find: /^@tmagic\/form/, replacement: path.join(__dirname, '../form/src/index.ts') }], + : [ + { find: /^@tmagic\/form/, replacement: path.join(__dirname, '../form/src/index.ts') }, + { find: /^@tmagic\/design/, replacement: path.join(__dirname, '../form/design/index.ts') }, + ], }, build: { diff --git a/playground/package.json b/playground/package.json index 79bb3f1b..83823f39 100644 --- a/playground/package.json +++ b/playground/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.0.9", + "@tmagic/design": "1.2.0-beta.2", "@tmagic/editor": "1.2.0-beta.2", "@tmagic/element-plus-adapter": "1.2.0-beta.2", "@tmagic/form": "1.2.0-beta.2", diff --git a/playground/src/main.ts b/playground/src/main.ts index 48113d91..105a7b96 100644 --- a/playground/src/main.ts +++ b/playground/src/main.ts @@ -26,6 +26,7 @@ import HtmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker'; import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'; import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'; +import TMagicDesign from '@tmagic/design'; import MagicEditor from '@tmagic/editor'; import MagicElementPlusAdapter from '@tmagic/element-plus-adapter'; import MagicForm from '@tmagic/form'; @@ -63,9 +64,8 @@ app.use(router); app.use(ElementPlus, { locale: zhCn, }); +app.use(TMagicDesign, MagicElementPlusAdapter); app.use(MagicEditor); -app.use(MagicForm, { - uiAdapter: MagicElementPlusAdapter, -}); +app.use(MagicForm); app.use(MagicTable); app.mount('#app'); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d91e9d1f..b46c82ea 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -77,6 +77,7 @@ importers: docs: specifiers: '@element-plus/icons-vue': ^2.0.9 + '@tmagic/design': 1.2.0-beta.2 '@tmagic/element-plus-adapter': 1.2.0-beta.2 '@tmagic/form': 1.2.0-beta.2 '@tmagic/schema': 1.2.0-beta.2 @@ -96,6 +97,7 @@ importers: vuepress: ^2.0.0-beta.51 dependencies: '@element-plus/icons-vue': 2.0.9_vue@3.2.37 + '@tmagic/design': link:../packages/design '@tmagic/element-plus-adapter': link:../packages/element-plus-adapter '@tmagic/form': link:../packages/form '@tmagic/schema': link:../packages/schema @@ -354,6 +356,7 @@ importers: packages/table: specifiers: + '@tmagic/design': 1.2.0-beta.2 '@tmagic/form': 1.2.0-beta.2 '@tmagic/utils': 1.2.0-beta.2 '@types/color': ^3.0.1 @@ -371,6 +374,7 @@ importers: vue: ^3.2.37 vue-tsc: ^0.39.4 dependencies: + '@tmagic/design': link:../design '@tmagic/form': link:../form '@tmagic/utils': link:../utils element-plus: 2.2.17_vue@3.2.37 @@ -476,6 +480,7 @@ importers: playground: specifiers: '@element-plus/icons-vue': ^2.0.9 + '@tmagic/design': 1.2.0-beta.2 '@tmagic/editor': 1.2.0-beta.2 '@tmagic/element-plus-adapter': 1.2.0-beta.2 '@tmagic/form': 1.2.0-beta.2 @@ -500,6 +505,7 @@ importers: vue-tsc: ^0.39.4 dependencies: '@element-plus/icons-vue': 2.0.9_vue@3.2.37 + '@tmagic/design': link:../packages/design '@tmagic/editor': link:../packages/editor '@tmagic/element-plus-adapter': link:../packages/element-plus-adapter '@tmagic/form': link:../packages/form