From 6d227245b5702fc4656f018957daa0a7a92d0b2e Mon Sep 17 00:00:00 2001 From: yy-wow Date: Tue, 14 Jan 2025 18:06:07 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BDnpm?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../render/src/application-function/utils.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/canvas/render/src/application-function/utils.ts b/packages/canvas/render/src/application-function/utils.ts index 55ef60971..96195106e 100644 --- a/packages/canvas/render/src/application-function/utils.ts +++ b/packages/canvas/render/src/application-function/utils.ts @@ -2,6 +2,7 @@ import { ref } from 'vue' import TinyVue from '@opentiny/vue' import * as TinyVueIcon from '@opentiny/vue-icon' import { generateFunction } from '../data-utils' +import { globalNotify } from '../canvas-function' export interface IUtil { name: string @@ -18,7 +19,7 @@ export function useUtils(context: Record) { const utils: Record = {} const getUtils = () => utils - const setUtils = (data: Array) => { + const setUtils = async (data: Array) => { if (!Array.isArray(data)) { return } @@ -52,6 +53,29 @@ export function useUtils(context: Record) { utilsCollection[item.name] = generateFunction(item.content.value, context) || defaultFn } }) + + const npmUtilsImports = data + .filter((item) => item.type === 'npm' && item.content.cdnLink) + .map((item) => import(/* @vite-ignore */ item.content.cdnLink)) + const npmUtils = await Promise.allSettled(npmUtilsImports) + + npmUtils.forEach((res, index) => { + const { name, content } = data[index] + const { exportName, destructuring, cdnLink } = content + + if (res.status !== 'fulfilled') { + globalNotify({ + type: 'error', + message: `加载工具类“${name}”失败,请检查cdn链接是否正确,${cdnLink}` + }) + + return + } + + const module = res.value + utilsCollection[name] = destructuring ? module[exportName] : module.default + }) + Object.assign(utils, utilsCollection) refreshKey.value++