神仙都没用 1 жил өмнө
parent
commit
f0e31aceb8

+ 1 - 1
package.json

@@ -37,7 +37,7 @@
 		"xlsx": "^0.18.5"
 	},
 	"devDependencies": {
-		"@cool-vue/vite-plugin": "^7.1.1",
+		"@cool-vue/vite-plugin": "^7.1.2",
 		"@types/file-saver": "^2.0.7",
 		"@types/lodash-es": "^4.17.8",
 		"@types/mockjs": "^1.0.7",

+ 4 - 2
packages/crud/src/utils/parse.tsx

@@ -62,9 +62,11 @@ export function parseTableDict(value: any, item: ClTable.Column) {
 				label: v,
 				value: v
 			};
-			delete d.children;
 
-			return d;
+			return {
+				...d,
+				children: []
+			};
 		});
 
 	// 格式化返回

+ 21 - 5
packages/vite-plugin/dist/index.js

@@ -724,17 +724,31 @@
 
     async function virtual() {
         const virtualModuleIds = ["virtual:eps", "virtual:ctx"];
-        const eps = await createEps();
-        const ctx = await createCtx();
         return {
             name: "vite-cool-virtual",
             enforce: "pre",
+            configureServer(server) {
+                server.middlewares.use(async (req, res, next) => {
+                    // 页面刷新时触发
+                    if (req.url == "/@vite/client") {
+                        // 重新加载虚拟模块
+                        virtualModuleIds.forEach((vm) => {
+                            const mod = server.moduleGraph.getModuleById(`\0${vm}`);
+                            if (mod) {
+                                server.moduleGraph.invalidateModule(mod);
+                            }
+                        });
+                    }
+                    next();
+                });
+            },
             handleHotUpdate({ file, server }) {
-                if (!["pages.json", "dist", "build/cool"].some((e) => file.includes(e))) {
+                // 文件修改时触发
+                if (!["pages.json", "dist", "build/cool", "eps.json", "eps.d.ts"].some((e) => file.includes(e))) {
                     createCtx();
                     createEps().then((data) => {
                         // 通知客户端刷新
-                        server.ws.send({
+                        (server.hot || server.ws).send({
                             type: "custom",
                             event: "eps-update",
                             data,
@@ -747,13 +761,15 @@
                     return "\0" + id;
                 }
             },
-            load(id) {
+            async load(id) {
                 if (id === "\0virtual:eps") {
+                    const eps = await createEps();
                     return `
 					export const eps = ${JSON.stringify(eps)}
 				`;
                 }
                 if (id === "\0virtual:ctx") {
+                    const ctx = await createCtx();
                     return `
 					export const ctx = ${JSON.stringify(ctx)}
 				`;

+ 1 - 1
packages/vite-plugin/package.json

@@ -1,6 +1,6 @@
 {
 	"name": "@cool-vue/vite-plugin",
-	"version": "7.1.1",
+	"version": "7.1.2",
 	"description": "cool-admin/cool-uni builder",
 	"main": "/dist/index.js",
 	"scripts": {

+ 29 - 6
packages/vite-plugin/src/virtual.ts

@@ -5,19 +5,38 @@ import { createCtx } from "./ctx";
 export async function virtual(): Promise<Plugin> {
 	const virtualModuleIds: string[] = ["virtual:eps", "virtual:ctx"];
 
-	const eps = await createEps();
-	const ctx = await createCtx();
-
 	return {
 		name: "vite-cool-virtual",
 		enforce: "pre",
+		configureServer(server) {
+			server.middlewares.use(async (req, res, next) => {
+				// 页面刷新时触发
+				if (req.url == "/@vite/client") {
+					// 重新加载虚拟模块
+					virtualModuleIds.forEach((vm) => {
+						const mod = server.moduleGraph.getModuleById(`\0${vm}`);
+
+						if (mod) {
+							server.moduleGraph.invalidateModule(mod);
+						}
+					});
+				}
+
+				next();
+			});
+		},
 		handleHotUpdate({ file, server }) {
-			if (!["pages.json", "dist", "build/cool"].some((e) => file.includes(e))) {
+			// 文件修改时触发
+			if (
+				!["pages.json", "dist", "build/cool", "eps.json", "eps.d.ts"].some((e) =>
+					file.includes(e),
+				)
+			) {
 				createCtx();
 
 				createEps().then((data) => {
 					// 通知客户端刷新
-					server.ws.send({
+					(server.hot || server.ws).send({
 						type: "custom",
 						event: "eps-update",
 						data,
@@ -30,13 +49,17 @@ export async function virtual(): Promise<Plugin> {
 				return "\0" + id;
 			}
 		},
-		load(id) {
+		async load(id) {
 			if (id === "\0virtual:eps") {
+				const eps = await createEps();
+
 				return `
 					export const eps = ${JSON.stringify(eps)}
 				`;
 			}
 			if (id === "\0virtual:ctx") {
+				const ctx = await createCtx();
+
 				return `
 					export const ctx = ${JSON.stringify(ctx)}
 				`;

+ 4 - 4
pnpm-lock.yaml

@@ -86,8 +86,8 @@ dependencies:
 
 devDependencies:
   '@cool-vue/vite-plugin':
-    specifier: ^7.1.1
-    version: 7.1.1
+    specifier: ^7.1.2
+    version: 7.1.2
   '@types/file-saver':
     specifier: ^2.0.7
     version: 2.0.7
@@ -482,8 +482,8 @@ packages:
       - typescript
     dev: false
 
-  /@cool-vue/vite-plugin@7.1.1:
-    resolution: {integrity: sha512-bCf0+ICwjYWYdS3DOrgr74YulvQLVjzNKPiTeL32pTyTecmFSOqbiQ+PbVYxIPHtZjnNjupWOz5vYm1kmBscWQ==}
+  /@cool-vue/vite-plugin@7.1.2:
+    resolution: {integrity: sha512-VRkJWIJP3eMJod7gCqrSdpKUOHrJJYwW2jyuEo1LroFjgPqhf1qH2IvPFRreKDdiFfDlwwE4g67nP/VBI/CpOw==}
     dependencies:
       '@vue/compiler-sfc': 3.4.25
       axios: 1.6.8