解决 crud 模块下实例组件无法渲染问题

This commit is contained in:
icssoa 2021-04-08 15:17:39 +08:00
parent 9fcd212900
commit 529c1cc08d
15 changed files with 75 additions and 46 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "front-next", "name": "front-next",
"version": "0.2.4", "version": "0.2.5",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",
"build": "vue-tsc --noEmit --skipLibCheck && vite build", "build": "vue-tsc --noEmit --skipLibCheck && vite build",

View File

@ -1,17 +1,17 @@
export interface Token { export declare interface Token {
expire: number; expire: number;
refreshExpire: number; refreshExpire: number;
refreshToken: string; refreshToken: string;
token: string; token: string;
} }
export enum MenuType { export declare enum MenuType {
"目录" = 0, "目录" = 0,
"菜单" = 1, "菜单" = 1,
"权限" = 2 "权限" = 2
} }
export interface MenuItem { export declare interface MenuItem {
id: number; id: number;
parentId: number; parentId: number;
path: string; path: string;

View File

@ -1,3 +1,3 @@
import { FormItem } from "./form"; import { FormItem } from "./form";
export type AdvSearchItem = FormItem; export declare type AdvSearchItem = FormItem;

View File

@ -1,4 +1,4 @@
export type Browser = { export declare type Browser = {
screen: string; screen: string;
isMini: boolean; isMini: boolean;
}; };

View File

@ -1,4 +1,4 @@
export interface ContextMenuItem { export declare interface ContextMenuItem {
label: string; label: string;
"prefix-icon"?: string; "prefix-icon"?: string;
"suffix-icon"?: string; "suffix-icon"?: string;
@ -10,6 +10,6 @@ export interface ContextMenuItem {
callback?(item: ContextMenuItem, done: Function): void; callback?(item: ContextMenuItem, done: Function): void;
} }
export interface ContextMenuOptions { export declare interface ContextMenuOptions {
list?: ContextMenuItem[]; list?: ContextMenuItem[];
} }

View File

@ -1,8 +1,8 @@
import { TableOptions } from "./table"; import { TableOptions } from "./table";
export type ServiceName = "page" | "list" | "add" | "delete" | "update" | "info" | string; export declare type ServiceName = "page" | "list" | "add" | "delete" | "update" | "info" | string;
export interface Service { export declare interface Service {
page?( page?(
params?: any params?: any
): Promise<{ ): Promise<{
@ -20,7 +20,7 @@ export interface Service {
info?(params: any): Promise<any>; info?(params: any): Promise<any>;
} }
export interface Dict { export declare interface Dict {
api: { api: {
list: string; list: string;
add: string; add: string;
@ -53,7 +53,7 @@ export interface Dict {
}; };
} }
export interface Permission { export declare interface Permission {
page?: boolean; page?: boolean;
list?: boolean; list?: boolean;
add?: boolean; add?: boolean;
@ -62,23 +62,23 @@ export interface Permission {
info?: boolean; info?: boolean;
} }
interface LoadCtx { declare interface LoadCtx {
service(s: Service): LoadCtx; service(s: Service): LoadCtx;
permission(p: Function | any): LoadCtx; permission(p: Function | any): LoadCtx;
set(key: "dict" | "style", value: any): LoadCtx; set(key: "dict" | "style", value: any): LoadCtx;
done(): void; done(): void;
} }
interface LoadApp { declare interface LoadApp {
refresh(params?: any): Promise<any>; refresh(params?: any): Promise<any>;
} }
export interface CrudLoad { export declare interface CrudLoad {
app: LoadApp; app: LoadApp;
ctx: LoadCtx; ctx: LoadCtx;
} }
export interface CrudRef { export declare interface CrudRef {
getPermission(key?: string): boolean; getPermission(key?: string): boolean;
rowAdd(): any; rowAdd(): any;
rowEdit(data: any): any; rowEdit(data: any): any;
@ -90,7 +90,7 @@ export interface CrudRef {
refresh(params?: any): void; refresh(params?: any): void;
} }
export interface Crud extends CrudRef { export declare interface Crud extends CrudRef {
crudRef: any; crudRef: any;
permission: Permission; permission: Permission;
service: any; service: any;
@ -101,7 +101,7 @@ export interface Crud extends CrudRef {
loading: boolean; loading: boolean;
} }
export interface Mitt { export declare interface Mitt {
on(name: string, ...args: any[]): void; on(name: string, ...args: any[]): void;
emit(name: string, ...args: any[]): void; emit(name: string, ...args: any[]): void;
off(name: string, ...args: any[]): void; off(name: string, ...args: any[]): void;

View File

@ -1,6 +1,6 @@
import { RenderOptions } from "./render"; import { RenderOptions } from "./render";
export interface FormItem { export declare interface FormItem {
type?: "tabs" | string; type?: "tabs" | string;
prop?: string; prop?: string;
props?: { props?: {
@ -23,16 +23,28 @@ export interface FormItem {
append?: RenderOptions; append?: RenderOptions;
rules?: any; rules?: any;
} }
export interface Form {
declare interface FormOpenEvent {
close(): void;
submit(): void;
done(): void;
}
declare interface FormSubmitEvent {
done(): void;
close(): void;
}
export declare interface Form {
title?: string; title?: string;
width?: string; width?: string;
props?: any; props?: any;
items: Array<FormItem>; items: Array<FormItem>;
form?: any; form?: any;
on?: { on?: {
open?(form: any, { close, submit, done }: any): void; open?(form: any, event: FormOpenEvent): void;
close?(done: Function): void; close?(done: Function): void;
submit?(data: any, { done, close }: any): void; submit?(data: any, event: FormSubmitEvent): void;
}; };
op?: { op?: {
hidden?: boolean; hidden?: boolean;
@ -48,7 +60,7 @@ export interface Form {
_data?: any; _data?: any;
} }
export interface FormRef { export declare interface FormRef {
create(options: Form): FormRef; create(options: Form): FormRef;
open(options: Form): FormRef; open(options: Form): FormRef;
close(): void; close(): void;

View File

@ -1,4 +1,4 @@
export interface RefreshOp { export declare interface RefreshOp {
/** /**
* *
* @param list * @param list
@ -18,11 +18,11 @@ export interface RefreshOp {
done(): void; done(): void;
} }
export interface DeleteOp { export declare interface DeleteOp {
next(params?: any): Promise<any>; next(params?: any): Promise<any>;
} }
export interface UpsertOpenOp { export declare interface UpsertOpenOp {
/** /**
* *
* @param form * @param form
@ -40,14 +40,14 @@ export interface UpsertOpenOp {
close(): void; close(): void;
} }
export interface UpsertCloseOp { export declare interface UpsertCloseOp {
/** /**
* *
*/ */
done(): void; done(): void;
} }
export interface UpsertInfoOp { export declare interface UpsertInfoOp {
/** /**
* *
* @param params * @param params
@ -65,7 +65,7 @@ export interface UpsertInfoOp {
close(): void; close(): void;
} }
export interface UpsertSubmitOp { export declare interface UpsertSubmitOp {
/** /**
* *
* @param params * @param params
@ -83,7 +83,7 @@ export interface UpsertSubmitOp {
close(): void; close(): void;
} }
export interface AdvOpenOp { export declare interface AdvOpenOp {
/** /**
* *
* @param data * @param data
@ -91,14 +91,14 @@ export interface AdvOpenOp {
next(data: any): Promise<any>; next(data: any): Promise<any>;
} }
export interface AdvCloseOp { export declare interface AdvCloseOp {
/** /**
* *
*/ */
done(): void; done(): void;
} }
export interface AdvSearchOp { export declare interface AdvSearchOp {
/** /**
* *
* @param params * @param params

View File

@ -1,4 +1,4 @@
export interface QueryList { export declare interface QueryList {
label: string; label: string;
value: any; value: any;
} }

View File

@ -1,6 +1,6 @@
import { ComponentOptions } from "vue"; import { ComponentOptions } from "vue";
export interface Options extends ComponentOptions { export declare interface Options extends ComponentOptions {
name: string; name: string;
options?: Array<{ options?: Array<{
@ -9,4 +9,4 @@ export interface Options extends ComponentOptions {
}>; }>;
} }
export type RenderOptions = Options | Function; export declare type RenderOptions = Options | Function;

View File

@ -1,7 +1,7 @@
import { ContextMenuItem } from "./context-menu"; import { ContextMenuItem } from "./context-menu";
import { RenderOptions } from "./render"; import { RenderOptions } from "./render";
export interface TableOptions { export declare interface TableOptions {
"context-menu"?: "context-menu"?:
| boolean | boolean
| Array< | Array<
@ -16,7 +16,7 @@ export interface TableOptions {
>; >;
} }
export interface TableColumn { export declare interface TableColumn {
value?: any; value?: any;
type?: "index" | "selection" | "expand" | "op"; type?: "index" | "selection" | "expand" | "op";
hidden?: boolean | (({ scope }: any) => boolean); hidden?: boolean | (({ scope }: any) => boolean);
@ -60,7 +60,7 @@ export interface TableColumn {
sortOrders?: unknown[]; sortOrders?: unknown[];
} }
export interface Table extends TableOptions { export declare interface Table extends TableOptions {
props?: {}; props?: {};
columns: TableColumn[]; columns: TableColumn[];
} }

View File

@ -1,7 +1,7 @@
import { Form, FormItem, FormRef } from "./form"; import { Form, FormItem, FormRef } from "./form";
export type UpsertItem = FormItem; export declare type UpsertItem = FormItem;
export type UpsertRef = FormRef; export declare type UpsertRef = FormRef;
export type Upsert = Form; export declare type Upsert = Form;

View File

@ -1,6 +1,9 @@
import { h, resolveComponent } from "vue"; // @ts-nocheck
import { h, resolveComponent, toRaw } from "vue";
import { isFunction, isString, isObject } from "./index"; import { isFunction, isString, isObject } from "./index";
const Regs: string[] = [];
/** /**
* *
* @param {*} vnode * @param {*} vnode
@ -20,11 +23,21 @@ function parseNode(vnode: any, options: any) {
} }
} }
// 是否全局注册
let isReg: boolean = Regs.includes(vnode.name);
// 实例模式下,先注册到全局,再分解组件渲染
if (vnode.__file && !isReg) {
window.__app__.component(vnode.name, vnode);
isReg = true;
Regs.push(vnode.name);
}
// 组件参数 // 组件参数
const props = { const props = {
...vnode.props,
...vnode, ...vnode,
...vnode.attrs, ...vnode.attrs,
...vnode.props,
scope scope
}; };
@ -40,12 +53,11 @@ function parseNode(vnode: any, options: any) {
} }
// 组件实例渲染 // 组件实例渲染
if (props.render) { if (props.render && !isReg) {
return h(props, props); return h(props, props);
} }
// @ts-ignore return h(toRaw(resolveComponent(vnode.name)), props, {
return h(resolveComponent(vnode.name), props, {
default: () => { default: () => {
return vnode._children; return vnode._children;
} }

View File

@ -84,6 +84,8 @@ export default defineComponent({
}, },
{ {
label: ".vue 组件", label: ".vue 组件",
value: 10,
prop: "vue",
component: Test component: Test
}, },
{ {

View File

@ -40,3 +40,6 @@ bootstrap(app)
}); });
store.dispatch("appLoad"); store.dispatch("appLoad");
// @ts-ignore
window.__app__ = app;