diff --git a/packages/ui-react/src/useApp.ts b/packages/ui-react/src/useApp.ts
index 420b35cd..6a92e43a 100644
--- a/packages/ui-react/src/useApp.ts
+++ b/packages/ui-react/src/useApp.ts
@@ -35,18 +35,18 @@ export default ({ config, methods }: UseAppOptions) => {
const node = app?.page?.getNode(config.id);
const [created, setCreated] = useState(false);
+ const emitData = {
+ config,
+ ...methods,
+ };
+
if (!created) {
// 只需要触发一次 created
setCreated(true);
- node?.emit('created', { methods });
+ node?.emit('created', emitData);
}
useEffect(() => {
- const emitData = {
- config,
- ...methods,
- };
-
node?.emit('mounted', emitData);
return () => {
diff --git a/packages/ui/src/Component.vue b/packages/ui/src/Component.vue
index b1d1804f..5d138e58 100644
--- a/packages/ui/src/Component.vue
+++ b/packages/ui/src/Component.vue
@@ -1,6 +1,7 @@
-
diff --git a/packages/ui/src/button/src/index.vue b/packages/ui/src/button/src/index.vue
index 053c2c6b..b609b2be 100644
--- a/packages/ui/src/button/src/index.vue
+++ b/packages/ui/src/button/src/index.vue
@@ -1,63 +1,34 @@
-
-
diff --git a/packages/ui/src/container/src/Container.vue b/packages/ui/src/container/src/Container.vue
index c6f8b093..16c60ab7 100644
--- a/packages/ui/src/container/src/Container.vue
+++ b/packages/ui/src/container/src/Container.vue
@@ -6,47 +6,47 @@
:style="style"
>
-
+
-
diff --git a/packages/ui/src/img/src/index.vue b/packages/ui/src/img/src/index.vue
index 92a3c5d9..202586ff 100644
--- a/packages/ui/src/img/src/index.vue
+++ b/packages/ui/src/img/src/index.vue
@@ -1,32 +1,27 @@
-
diff --git a/packages/ui/src/overlay/src/index.vue b/packages/ui/src/overlay/src/index.vue
index c88f32c6..41f81ee9 100644
--- a/packages/ui/src/overlay/src/index.vue
+++ b/packages/ui/src/overlay/src/index.vue
@@ -3,60 +3,55 @@
-
diff --git a/packages/ui/src/page/src/index.vue b/packages/ui/src/page/src/index.vue
index 05ddd13d..ba90e017 100644
--- a/packages/ui/src/page/src/index.vue
+++ b/packages/ui/src/page/src/index.vue
@@ -7,40 +7,39 @@
:style="style"
>
-
+
-
diff --git a/packages/ui/src/qrcode/src/index.vue b/packages/ui/src/qrcode/src/index.vue
index b2f4bed2..1e2ecf0d 100644
--- a/packages/ui/src/qrcode/src/index.vue
+++ b/packages/ui/src/qrcode/src/index.vue
@@ -2,46 +2,41 @@
-
diff --git a/packages/ui/src/text/src/index.vue b/packages/ui/src/text/src/index.vue
index c320bb10..56ad5642 100644
--- a/packages/ui/src/text/src/index.vue
+++ b/packages/ui/src/text/src/index.vue
@@ -1,63 +1,24 @@
-
diff --git a/packages/ui/src/types.ts b/packages/ui/src/types.ts
index fbb318c8..2bc7db51 100644
--- a/packages/ui/src/types.ts
+++ b/packages/ui/src/types.ts
@@ -16,8 +16,6 @@
* limitations under the License.
*/
-import { ComponentPublicInstance } from 'vue';
-
/* style */
export type PartCSSStyle = {
[key in keyof CSSStyleDeclaration]?: string | number;
@@ -45,203 +43,3 @@ export interface MEventBus {
$once: (...args: any) => void;
$emit: (...args: any) => void;
}
-
-/* component */
-export interface MComponent {
- type: string;
- id?: number | string;
- name?: string;
- style?: StyleCfg;
- disabledStyle?: StyleCfg;
- className?: string | ((p1: any, p2: any) => string);
- display?: boolean | ((p1: any, p2: any) => boolean);
- html?: string;
- created?: (p1: any, p2: any) => Promise;
- mounted?: (p1: any, p2: any) => Promise;
- renderType?: number;
- events?: MEvent[];
-}
-export interface MComponentProps {
- config: MComponent;
- model: Object;
-}
-export type MComponentInstance =
- | ComponentPublicInstance<
- MComponentProps,
- {},
- {
- [propName: string]: any;
- disabled: boolean;
- }
- >
- | null
- | undefined;
-
-/* container */
-export interface MContainer extends MComponent {
- items?: MComponent[] | MContainer[];
-}
-export interface MContainerProps {
- config: MContainer;
- model: Object;
-}
-export type MContainerInstance =
- | ComponentPublicInstance<
- MContainerProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-
-/* page */
-export interface MPage extends MContainer {
- title?: string;
- cssFile?: string;
-}
-export interface MPageProps {
- config: MPage;
-}
-export type MPageInstance =
- | ComponentPublicInstance<
- MPageProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-
-/* pop */
-export interface MPop extends MContainer {
- activate: () => void;
- maskClose: boolean;
-}
-export interface MPopProps {
- config: MPop;
- model: Object;
- fillWithSlot: boolean;
- beforeOpen: (p1: MPopInstance, p2: any) => boolean;
- beforeClose: (p1: MPopInstance) => boolean;
-}
-export interface MPopObj {
- name: string;
- options: object;
-}
-export type MPopInstance =
- | ComponentPublicInstance<
- MPopProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-
-/* app */
-export interface MApp extends MComponent {
- items: MPage[];
-}
-export interface MAppProps {
- config: [MApp];
- pageConfig: MPage;
-}
-export enum MAppElementType {
- pages = 'pages',
- containers = 'containers',
- components = 'components',
- pops = 'pops',
-}
-export type MAppInstance =
- | ComponentPublicInstance<
- MAppProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-export type MCommonInstance = MContainerInstance | MPageInstance | MComponentInstance | MPopInstance;
-
-/* tabs */
-export type MTabs = MContainer;
-export interface MTabsProps {
- config: MTabs;
- model: Object;
-}
-export type MTabsInstance =
- | ComponentPublicInstance<
- MTabsProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-
-/* text */
-export interface MText extends MComponent {
- text?: string | ((p1: any, p2: any) => string);
- disabledText?: string | ((p1: any, p2: any) => string);
- multiple?: boolean;
-}
-export interface MTextProps {
- config: MText;
- model: Object;
- vars: Object;
-}
-export type MTextInstance =
- | ComponentPublicInstance<
- MTextProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-
-/* button */
-export interface MButton extends MComponent {
- preAction?: (p1: any, p2: any) => string;
- postAction?: (p1: any, p2: any) => string;
- text?: string | ((p1: any, p2: any) => string);
- disabledText?: string | ((p1: any, p2: any) => string);
-}
-export interface MButtonProps {
- config: MButton;
- model: Object;
-}
-export type MButtonInstance =
- | ComponentPublicInstance<
- MButtonProps,
- {},
- {
- [propName: string]: any;
- }
- >
- | null
- | undefined;
-
-export type ArrayOneOrMore = { 0: string } & string[];
-
-export interface MImg {
- src: string;
- url: string;
-}
-
-export interface MQrcode {
- url: string;
-}
-
-export interface MPop extends MComponent {
- items?: MComponent[] | MContainer[];
- closeButtonStyle?: any;
- closeButton?: boolean;
-}
diff --git a/packages/ui/src/useApp.ts b/packages/ui/src/useApp.ts
index 8b47eda5..4c916e02 100644
--- a/packages/ui/src/useApp.ts
+++ b/packages/ui/src/useApp.ts
@@ -16,24 +16,35 @@
* limitations under the License.
*/
-import { getCurrentInstance, inject, onMounted, onUnmounted } from 'vue';
+import { inject, onMounted, onUnmounted } from 'vue';
import Core from '@tmagic/core';
+import type { MComponent } from '@tmagic/schema';
-export default (props: any) => {
+interface UseAppOptions {
+ config: MComponent;
+ methods?: {
+ [key: string]: Function;
+ };
+}
+
+export default ({ config, methods }: UseAppOptions) => {
const app: Core | undefined = inject('app');
- const node = app?.page?.getNode(props.config.id);
+ const node = app?.page?.getNode(config.id);
- const vm = getCurrentInstance()?.proxy;
+ const emitData = {
+ config,
+ ...methods,
+ };
- node?.emit('created', vm);
+ node?.emit('created', emitData);
onMounted(() => {
- node?.emit('mounted', vm);
+ node?.emit('mounted', emitData);
});
onUnmounted(() => {
- node?.emit('destroy', vm);
+ node?.emit('destroy', emitData);
});
return app;