@vtj/renderer
Version:
VTJ 是一款基于 Vue3 + Typescript 的低代码页面可视化设计器。内置低代码引擎、渲染器和代码生成器,面向前端开发者,开箱即用。 无缝嵌入本地开发工程,不改变前端开发流程和编码习惯。
1,824 lines • 61 kB
JavaScript
import { Base as ze, BUILT_IN_COMPONENTS as Ge, ProjectModel as L, HistoryModel as Ee } from "@vtj/core";
import { isUrl as se, url as F, dedupArray as Ve, isString as C, isFunction as q, logger as k, storage as X, cookie as Y, toArray as ye, unRSA as _e, delay as J, createRequest as be, jsonp as Re, merge as Qe, pathToRegexp as We, pathToRegexpMatch as Xe, formDataToJson as Ye, Queue as Ze, cloneDeep as we, camelCase as P, isObject as et, upperFirst as tt, pick as st, request as ne, loadScript as Se, Storage as nt, mapToObject as ue } from "@vtj/utils";
import * as z from "vue";
import { inject as Pe, defineComponent as Ce, h as re, ref as oe, watchEffect as rt, defineAsyncComponent as $e } from "vue";
import { useRoute as Ae } from "vue-router";
/**!
* Copyright (c) 2025, VTJ.PRO All rights reserved.
* @name @vtj/renderer
* @author CHC chenhuachun1549@dingtalk.com
* @version 0.13.13
* @license <a href="https://vtj.pro/license.html">MIT License</a>
*/
const O = "0.13.13";
var _ = /* @__PURE__ */ ((n) => (n.Runtime = "Runtime", n.Design = "Design", n.Raw = "Raw", n.VNode = "VNode", n))(_ || {});
const je = [
"$el",
"$emit",
"$nextTick",
"$parent",
"$root",
"$attrs",
"$slots",
"$watch",
"$props",
"$options",
"$forceUpdate"
], gs = [
"beforeCreate",
"created",
"beforeMount",
"mounted",
"beforeUpdate",
"updated",
"beforeUnmount",
"unmounted",
"errorCaptured",
"renderTracked",
"renderTriggered",
"activated",
"deactivated"
], ot = [
"vIf",
"vElseIf",
"vElse",
"vShow",
"vModel",
"vFor",
"vBind",
"vHtml"
], it = {
String,
Number,
Boolean,
Array,
Object,
Function,
Date
}, D = "VtjPage", N = "VtjHomepage", at = "html,body,base,head,link,meta,style,title,address,article,aside,footer,header,hgroup,h1,h2,h3,h4,h5,h6,nav,section,div,dd,dl,dt,figcaption,figure,picture,hr,img,li,main,ol,p,pre,ul,a,b,abbr,bdi,bdo,br,cite,code,data,dfn,em,i,kbd,mark,q,rp,rt,ruby,s,samp,small,span,strong,sub,sup,time,u,var,wbr,area,audio,map,track,video,embed,object,param,source,canvas,script,noscript,del,ins,caption,col,colgroup,table,thead,tbody,td,th,tr,button,datalist,fieldset,form,input,label,legend,meter,optgroup,option,output,progress,select,textarea,details,dialog,menu,summary,template,blockquote,iframe,tfoot,svg".split(
","
), ct = "component,slot".split(","), vs = [
"h",
"t",
"t",
"p",
"s",
":",
"/",
"/",
"l",
"c",
"d",
"p",
".",
"v",
"t",
"j",
".",
"p",
"r",
"o"
].join(""), ys = {
auth: [
"h",
"t",
"t",
"p",
"s",
":",
"/",
"/",
"l",
"c",
"d",
"p",
".",
"v",
"t",
"j",
".",
"p",
"r",
"o",
"/",
"a",
"u",
"t",
"h",
".",
"h",
"t",
"m",
"l"
].join(""),
storageKey: [
"R",
"R",
"O",
"_",
"I",
"D",
"E",
"_",
"A",
"C",
"C",
"E",
"S",
"S",
"_",
"S",
"T",
"O",
"R",
"A",
"G",
"E",
"_",
"_"
].join(""),
privateKey: "MIIBOgIBAAJBAKoIzmn1FYQ1YOhOBw9EhABxZ+PySAIaydI+zdhoKflrdgJ4A5E4/5gbQmRpk09hPWG8nvX7h+l/QLU8kXxAIBECAwEAAQJAAlgpxQY6sByLsXqzJcthC8LSGsLf2JEJkHwlnpwFqlEV8UCkoINpuZ2Wzl+aftURu5rIfAzRCQBvHmeOTW9/zQIhAO5ufWDmnSLyfAAsNo5JRNpVuLFCFodR8Xm+ulDlosR/AiEAtpAltyP9wmCABKG/v/hrtTr3mcvFNGCjoGa9bUAok28CIHbrVs9w1ijrBlvTsXYwJw46uP539uKRRT4ymZzlm9QjAiB+1KH/G9f9pEEL9rtaSOG7JF5D0JcOjlze4MGVFs+ZrQIhALKOUFBNr2zEsyJIjw2PlvEucdlG77UniszjXTROHSPd"
};
function B(n, e) {
return n.map((t) => se(t) || t.startsWith("/") ? t : `${e}${t}`);
}
function G(n) {
return /\.css$/.test(n);
}
function V(n) {
return /\.js$/.test(n);
}
function lt(n) {
return /\.json$/.test(n);
}
function _s(n) {
return n.map(
(e) => `<script src="${F.append(e, { v: O })}"><\/script>`
).join("");
}
function ws(n = []) {
return n.map(
(e) => `<link rel="stylesheet" href="${F.append(e, { v: O })}" />`
).join("");
}
function ut(n, e = !1) {
return e && n.endsWith(".prod.js") ? n.replace(".prod.js", ".js") : n;
}
function ft(n, e, t = !1) {
const s = n.filter((h) => !!h.enabled), r = [], o = [], i = [], a = [], l = {}, c = {}, u = [], f = {};
return s.forEach(
({ urls: h, assetsUrl: p, library: d, assetsLibrary: g, localeLibrary: v }) => {
h?.forEach((m) => {
V(m) && r.push(ut(m, t)), G(m) && o.push(m);
}), d && (a.push(d), l[d] = B(h || [], e), v && (c[d] = v)), p && i.push(p), g && u.push(g), d && g && (f[g] = d);
}
), {
scripts: B(r, e),
css: B(o, e),
materials: B(i, e),
libraryExports: a,
materialExports: Ve(u),
materialMapLibrary: f,
libraryMap: l,
libraryLocaleMap: c
};
}
function pt(n, e) {
const { name: t, parent: s, alias: r } = n;
return s ? e[s]?.[r || t] : e[r || t];
}
function dt(n = []) {
const e = n.filter((s) => G(s)), t = n.filter((s) => V(s));
return {
css: e,
js: t
};
}
function ht(n, e) {
const t = (c) => {
const u = [];
let f = 0;
for (; f < c.length; ) {
if (/\s/.test(c[f])) {
f++;
continue;
}
if (c.substring(f, f + 2) === "/*") {
const m = c.indexOf("*/", f + 2);
if (m !== -1) {
f = m + 2;
continue;
}
}
if (c[f] === "@") {
const m = f;
for (; f < c.length && c[f] !== "{" && c[f] !== ";"; )
f++;
const b = c.substring(m, f).trim(), y = b.includes("@keyframes");
if (c[f] === ";")
u.push({
type: "simple-at-rule",
content: c.substring(m, f + 1)
}), f++;
else if (c[f] === "{") {
const x = f + 1;
let A = 1;
for (f++; f < c.length && A > 0; )
c[f] === "{" ? A++ : c[f] === "}" && A--, f++;
const Q = c.substring(m, f), R = c.substring(x, f - 1);
u.push({
type: y ? "keyframes" : "at-rule",
rule: b,
content: Q,
inner: R
});
}
continue;
}
const h = f;
for (; f < c.length && c[f] !== "{"; )
f++;
if (f >= c.length) break;
const p = c.substring(h, f).trim();
if (!p) {
f++;
continue;
}
const d = f + 1;
let g = 1;
for (f++; f < c.length && g > 0; )
c[f] === "{" ? g++ : c[f] === "}" && g--, f++;
const v = c.substring(d, f - 1);
u.push({
type: "rule",
selector: p,
content: v.trim()
});
}
return u;
}, s = (c) => {
const u = c.trim();
return /^(from|to|\d+(\.\d+)?%)$/.test(u);
}, r = (c) => c.replace(/::v-deep\(/g, ":deep(").replace(/::v-deep\s+/g, ":deep(").replace(/\/deep\//g, " ").replace(/>>>/g, " ").replace(/(.*?):deep\(([^)]+)\)/g, (u, f, h) => {
const p = f.trim(), d = h.trim();
return p ? `${p}[${e}] ${d}` : d;
}), o = (c) => {
const u = c.trim();
if (!u || u.includes(`[${e}]`) || /^(:root|:host|html|body)(\s|$|:|\.|\#|\[)/.test(u) || s(u))
return u;
const f = u.match(/^(.+?)((?:::?[\w-]+(?:\([^)]*\))?)*)\s*$/);
if (f) {
const [, h, p = ""] = f, d = h.trim();
return d ? `${d}[${e}]${p}` : u;
}
return `${u}[${e}]`;
}, i = (c) => r(c).split(",").map((f) => o(f)).filter((f) => f.trim()).join(", "), a = (c) => c.map((u) => {
switch (u.type) {
case "simple-at-rule":
return u.content;
case "keyframes":
return u.content;
case "at-rule":
try {
const h = t(u.inner), p = a(h);
return `${u.rule} { ${p} }`;
} catch {
return u.content;
}
case "rule":
if (!u.selector || !u.content)
return "";
const f = i(u.selector);
return f.trim() ? `${f} { ${u.content} }` : "";
default:
return "";
}
}).filter((u) => u.trim()).join(" "), l = (c) => c.replace(/\s*{\s*/g, " { ").replace(/\s*}\s*/g, " } ").replace(/\s*;\s*/g, "; ").replace(/\s*,\s*/g, ", ").replace(/\s+/g, " ").replace(/^\s+|\s+$/g, "").replace(/\s*}\s*}/g, " } }").trim();
try {
const c = n.replace(/\/\*(?!\s*!)[\s\S]*?\*\//g, "").replace(/^\s+|\s+$/gm, "").replace(/\n\s*\n/g, `
`), u = t(c), f = a(u);
return l(f);
} catch (c) {
return console.error("CSS scoping failed:", c), console.error("Input CSS:", n), n.replace(/\/\*[\s\S]*?\*\//g, "").replace(
/(@keyframes\s+[^{]+\s*{[^{}]*(?:{[^}]*}[^{}]*)*})/g,
(u) => u
).replace(/([^{}@]+)(?=\s*{)/g, (u) => {
const f = u.trim();
return !f || f.startsWith("@") || f.includes(`[${e}]`) || s(f) ? u : `${f}[${e}]`;
});
}
}
function Ie(n) {
return C(n) ? n : JSON.stringify(n);
}
function fe(n, e, t, s = !1) {
const r = n.CSSStyleSheet, o = s ? `data-v-${e}` : e, i = s ? ht(t, o) : t;
if (r.prototype.replaceSync) {
const a = new r();
a.id = e, a.replaceSync(i);
const l = n.document, c = l.adoptedStyleSheets, u = Array.from(c).filter(
(f) => f.id !== e
);
l.adoptedStyleSheets = [...u, a];
} else {
const a = n.document;
let l = a.getElementById(e);
l ? l.innerHTML = i : (l = a.createElement("style"), l.id = e, l.innerHTML = i, a.head.appendChild(l));
}
}
async function mt(n, e) {
const t = await window.fetch(e).then((s) => s.text()).catch(() => "");
t && fe(window, n, t);
}
function Fe(n, e = window) {
const t = e.document, s = e.document.head;
for (const r of n)
if (!t.getElementById(r)) {
const i = t.createElement("link");
i.rel = "stylesheet", i.id = r, i.href = r, s.appendChild(i);
}
}
async function ke(n, e, t = window) {
const s = t.document, r = t.document.head;
let o = t[e];
return o ? o.default || o : new Promise((i, a) => {
for (const l of n) {
const c = s.createElement("script");
c.src = l, c.onload = () => {
o = t[e], o ? i(o.default || o) : a(null);
}, c.onerror = (u) => {
a(u);
}, r.appendChild(c);
}
});
}
function gt(n) {
return q(n) || q(n?.install);
}
function vt(n) {
return ct.includes(n);
}
function yt(n) {
return at.includes(n);
}
function T(n = window) {
const e = window?.Mock;
if (e) return e;
const t = n?.Mock;
if (t && window)
return window.Mock = t, t;
}
function Ss(n, e, t) {
Object.assign(e.meta, t.meta);
const s = n?._container;
t?.type === "page" && s.classList.add("is-page"), t?.pure && s.classList.add("is-pure");
}
function H(n, e, t = !1, s = !1, r = !1) {
try {
const o = ['"use strict";', "var __self = arguments[0];"];
o.push("return ");
let i = (n.value || "").trim();
r || (i = i.replace(/this(\W|$)/g, (l, c) => `__self${c}`)), i = o.join(`
`) + i;
const a = r ? `
${i}
` : `with(${t ? "{}" : "$scope || {}"}) { ${i} }`;
return new Function("$scope", a)(e);
} catch (o) {
if (k.error("parseExpression.error", o, n, e?.__self ?? e), s)
throw o;
}
}
function E(n, e, t = !1, s = !1, r = !1) {
const o = H(n, e, t, s, r);
if (typeof o != "function" && (k.error(
"parseFunction.error",
"not a function",
n,
e?.__self ?? e
), s))
throw new Error(`"${n.value}" not a function`);
return o;
}
function j(n) {
return n && n.type === "JSExpression";
}
function S(n) {
return typeof n == "object" && n && n.type === "JSFunction";
}
function _t(n) {
return j(n) || S(n);
}
function $s(n) {
return _t(n) ? n.value : JSON.stringify(n);
}
const wt = {
session: !1,
authKey: "Authorization",
storageKey: "ACCESS_STORAGE",
storagePrefix: "__VTJ_",
unauthorized: void 0,
auth: "/#/login",
redirectParam: "r",
unauthorizedCode: 401,
unauthorizedMessage: "登录已经失效,请重新登录!",
noPermissionMessage: "无权限访问该页面",
appName: "",
statusKey: "code"
}, Me = Symbol("access");
class pe {
options;
data = null;
mode = _.Raw;
interceptResponse = !0;
constructor(e) {
this.options = Object.assign({}, wt, e), this.loadData();
}
enableIntercept() {
this.interceptResponse = !0;
}
disableIntercept() {
this.interceptResponse = !1;
}
connect(e) {
const { mode: t, router: s, request: r } = e;
this.mode = t, s && this.mode !== _.Design && this.setGuard(s), r && this.setRequest(r);
}
login(e) {
const { storageKey: t, storagePrefix: s, session: r, authKey: o } = this.options;
this.setData(e), this.data && (X.save(t, e, {
type: "local",
prefix: s
}), r && Y.set(o, this.data.token));
}
clear() {
const { storageKey: e, storagePrefix: t, session: s, authKey: r } = this.options;
this.data = null, X.remove(e, {
type: "local",
prefix: t
}), s && Y.remove(r);
}
logout() {
this.clear(), this.toLogin();
}
getData() {
return this.data ? this.data : (this.loadData(), this.data);
}
getToken() {
return this.data || this.loadData(), this.data?.token;
}
can(e) {
const { appName: t } = this.options, { permissions: s = {} } = this.data || {};
return typeof e == "function" ? e(s) : ye(e).every((o) => s[o] || s[t + "." + o]);
}
some(e) {
const { appName: t } = this.options, { permissions: s = {} } = this.data || {};
return ye(e).some((o) => s[o] || s[t + "." + o]);
}
install(e) {
e.config.globalProperties.$access = this, e.provide(Me, this);
}
isAuthPath(e) {
const { auth: t, isAuth: s } = this.options;
if (s)
return s(e);
if (e.path && typeof t == "string") {
const r = t.split("#")[1] || t;
return e.path === r;
}
return !1;
}
toLogin() {
const { auth: e, redirectParam: t } = this.options;
if (!e) return;
const s = t ? `?${t}=${encodeURIComponent(location.href)}` : "";
typeof e == "function" ? e(s) : location.href = t ? `${e}${s}` : e;
}
setData(e) {
const { privateKey: t } = this.options;
if (Array.isArray(e) && t) {
const s = e.map((r) => _e(r, t));
try {
this.data = JSON.parse(s.join(""));
} catch (r) {
console.warn(r);
}
return;
}
if (typeof e == "string")
try {
const s = t ? _e(e, t) : e;
s ? this.data = JSON.parse(s) : console.warn("RSA解密失败或登录信息缺失");
} catch (s) {
console.warn(s);
}
else
this.data = e;
}
loadData() {
const { storageKey: e, storagePrefix: t } = this.options, s = X.get(e, {
type: "local",
prefix: t
});
this.setData(s || null);
}
isLogined() {
const { session: e, authKey: t } = this.options;
return e && t ? !!Y.get(t) : !!this.getToken();
}
hasRoutePermission(e) {
if (e.name === D) {
const t = e.params.id;
return t && this.can(t);
}
return e.meta.__vtj__ ? this.can(e.meta.__vtj__) : !0;
}
setGuard(e) {
e.beforeEach((t, s, r) => this.guard(t, r));
}
async guard(e, t) {
if (this.isWhiteList(e) || this.isAuthPath(e))
return t();
if (this.isLogined()) {
if (this.hasRoutePermission(e))
return t();
{
const { noPermissionMessage: s = "无权限访问", unauthorized: r = !1 } = this.options;
return await this.showTip(s), q(r) ? (r(), t(!1)) : C(r) ? t(r) : t(!1);
}
}
t(!1), await J(0), this.toLogin();
}
isWhiteList(e) {
const { whiteList: t } = this.options;
return t ? Array.isArray(t) ? t.some((s) => e.fullPath.startsWith(s)) : t(e) : !1;
}
isUnauthorized(e) {
const { unauthorizedCode: t = 401, statusKey: s = "code" } = this.options;
return e.status === t || e.data?.[s] === t;
}
async showUnauthorizedAlert(e) {
const { unauthorizedMessage: t = "登录已失效" } = this.options;
this.isUnauthorized(e) && (await this.showTip(t), this.toLogin());
}
async showTip(e) {
const { alert: t } = this.options;
return t ? (await J(150), await t(e, {
title: "提示",
type: "warning"
})?.catch(() => !1)) : (window.alert(e), !1);
}
setRequest(e) {
e.useRequest((t) => (this.data?.token && (t.headers[this.options.authKey] = this.data?.token), t)), e.useResponse(
async (t) => (this.interceptResponse && await this.showUnauthorizedAlert(t), t),
async (t) => {
if (!this.interceptResponse) return Promise.reject(t);
const s = t.response || t || {};
return await this.showUnauthorizedAlert(s), Promise.reject(t);
}
);
}
}
function St() {
return Pe(Me, null);
}
function js(n = {}) {
const {
notify: e,
loading: t,
settings: s = {},
Startup: r,
access: o,
useTitle: i,
alert: a
} = n;
let l = null;
return {
request: be({
settings: {
type: "form",
validSuccess: !0,
originResponse: !1,
loading: !0,
validate: (u) => u.data?.code === 0 || !!u.data?.success,
failMessage: !0,
showError: (u) => {
e && e(u || "未知错误");
},
showLoading: () => {
l && l.close(), t && (l = t());
},
hideLoading: () => {
l && (l.close(), l = null);
},
...s
}
}),
jsonp: Re,
notify: e,
loading: t,
useTitle: i,
alert: a,
startupComponent: r,
access: o ? new pe({ alert: a, ...o }) : void 0
};
}
function Es(n = {}) {
return new pe(n);
}
function $t(n, e) {
const { jsonp: t, request: s } = e;
if (n.method === "jsonp")
return (r = {}) => t(n.url, {
...n.jsonpOptions,
query: r
});
{
const r = n.headers ? H(n.headers, {}, !0) : void 0, o = {
url: n.url,
method: n.method,
settings: {
...n.settings,
headers: r
}
};
return (i, a) => (delete o.data, s.send(Qe(o, a || {}, { data: i })));
}
}
function jt(n, e) {
const { metaQuery: t } = e;
if (!t) return;
const { code: s, queryCode: r } = n;
return (o, i) => {
if (!t) {
console.warn("adapter.metaQuery is not defined!");
return;
}
return t(s, r, o, i);
};
}
function Et(n = [], e = [], t) {
const s = {};
for (const r of n)
s[r.id] = $t(r, t);
for (const r of e)
s[r.id] = jt(r, t);
return s;
}
async function bt(n = [], e = window) {
const t = T(e);
t && (Oe(e), n.forEach((s) => Pt(t, s)));
}
function Rt(n, e = window) {
const t = S(n.mockTemplate) && n.mockTemplate.value ? E(n.mockTemplate, {}, !0) : void 0, s = T(e);
return async (...r) => {
let o = {};
if (t)
try {
o = await t.apply(t, r);
} catch (i) {
k.warn("模拟数据模版异常", i);
}
return s?.mock(o);
};
}
function Pt(n, e) {
if (!e.mock) return;
const { url: t, mockTemplate: s } = e;
if (t && s)
try {
const r = se(t) ? new URL(t).pathname : t, o = We(`(.*)${r}(.*)`), i = Xe(r, { decode: decodeURIComponent }), a = H(s, {}, !0);
n.mock(o, (l) => {
const c = F.parse(l.url) || {}, u = l.body instanceof FormData ? Ye(l.body) : l.body, f = se(l.url) ? new URL(l.url).pathname : l.url.split("?")[0], h = i(f)?.params;
Object.assign(l, { data: u, params: h, query: c });
try {
return n.mock(a(l));
} catch (p) {
return console.warn("[mockApi]", o, l, p), null;
}
});
} catch (r) {
console.warn("mockApi", r);
}
}
function Oe(n = window) {
const e = T(n);
e && (e._mocked = {});
}
class Ct {
__id = null;
__mode;
__instance = null;
__contextRefs = {};
__refs = {};
context = {};
state = {};
props = {};
$props = {};
$refs = {};
$el = null;
$emit = null;
$nextTick = null;
$parent = null;
$root = null;
$attrs = null;
$slots = null;
$watch = null;
$options = null;
$forceUpdate = null;
$components = {};
$libs = {};
$apis = {};
__transform = {};
constructor(e) {
const { mode: t, dsl: s, attrs: r } = e;
this.__mode = t, s && (this.__id = s.id || null, this.__transform = s.transform || {}), r && Object.assign(this, r);
}
setup(e, t = z) {
const s = t.getCurrentInstance();
if (!s) return;
this.__refs = {}, this.$refs = {}, this.context = {}, this.__contextRefs = {}, this.__instance = s.proxy;
const r = s.appContext.config.globalProperties;
Object.assign(this, r), Object.assign(this, e || {}), this.__proxy(), t.onMounted(() => {
this.__proxy();
}), t.onUnmounted(() => {
this.__cleanup();
}), t.onBeforeUpdate(() => {
this.__reset();
});
}
__proxy() {
this.__instance && je.forEach((e) => {
this[e] = this.__instance?.[e];
});
}
__cleanup() {
je.forEach((e) => {
this[e] = null;
}), this.__reset();
}
__reset() {
this.__refs = {}, this.$refs = {}, this.__contextRefs = {}, this.context = {};
}
__parseFunction(e) {
if (e)
if (this.__mode === _.Runtime) {
const { id: t, type: s } = e, r = t ? this.__transform[t] ?? e.value : e.value;
return E({ type: s, value: r }, this);
} else
return E(e, this);
}
__parseExpression(e) {
if (e)
if (this.__mode === _.Runtime) {
const { id: t, type: s } = e, r = t ? this.__transform[t] ?? e.value : e.value;
return H({ type: s, value: r }, this);
} else
return H(e, this);
}
__ref(e = null, t) {
if (this.__mode !== _.VNode)
return e && e !== this.__id && (this.__contextRefs[e] = this), async (s) => {
await J(0);
let r = s?.$vtjEl || s?.$el || s?._?.vnode?.el || s;
if (!r) {
typeof t == "string" && (delete this.$refs[t], e && delete this.__refs[e]);
return;
}
return r.nodeType === 3 && r.nextSibling && (r = r.nextSibling), r.__vtj__ = e, _.Design === this.__mode && (r.__context__ = this, r.draggable = !0), e && (this.__refs[e] = this.__getRefEl(this.__refs, e, s)), typeof t == "function" ? t(s) : t && (this.$refs[t] = this.__getRefEl(this.$refs, t, s)), s;
};
}
__getRefEl(e, t, s) {
const r = e[t];
if (r && s !== r) {
const o = new Set([].concat(r, s));
return Array.from(o);
} else
return s;
}
__clone(e = {}) {
const t = { ...this.context, ...e }, s = {
...t,
context: t
};
return s.context.__proto__ = this.context, s.__proto__ = this, s;
}
}
function ie(n) {
const {
Vue: e = z,
mode: t = _.Runtime,
components: s = {},
libs: r = {},
apis: o = {},
loader: i
} = n, a = e.computed(() => n.dsl), l = {
$components: s,
$libs: r,
$apis: o
}, c = new Ct({
mode: t,
dsl: a.value,
attrs: l
}), u = e.defineComponent({
name: a.value.name,
__scopeId: a.value.id ? `data-v-${a.value.id}` : void 0,
props: {
...It(a.value.props ?? [], c)
},
setup(f) {
c.$props = f, c.props = f, a.value.id && fe(
n.window || window,
a.value.id,
a.value.css || "",
!0
), c.state = Ft(e, a.value.state ?? {}, c);
const h = kt(e, a.value.computed ?? {}, c), p = Mt(a.value.methods ?? {}, c), d = Ot(e, a.value.inject, c);
for (const [m, b] of Object.entries(d || {}))
d[m] = e.inject(m, b);
const g = Dt(
a.value.dataSources || {},
c
), v = {
...d,
...h,
...p,
...g
};
return c.setup(v, e), Tt(e, a.value.watch ?? [], c), {
vtj: c
};
},
emits: At(a.value.emits),
expose: ["vtj"],
render() {
if (!a.value.nodes) return null;
const f = a.value.nodes || [];
return f.length === 1 ? M(f[0], c, e, i, f) : f.map(
(h) => M(h, c, e, i, f)
);
},
...Ht(a.value.lifeCycles ?? {}, c)
});
return {
renderer: e.markRaw(u),
context: c
};
}
function At(n = []) {
return n.map((e) => C(e) ? e : e.name);
}
function It(n = [], e) {
const t = (s) => s ? (Array.isArray(s) ? s : [s]).map((o) => it[o]) : void 0;
return n.map((s) => C(s) ? {
name: s
} : {
name: s.name,
type: s.type,
required: s.required,
default: j(s.default) ? e.__parseExpression(s.default) : s.default
}).reduce(
(s, r) => (s[r.name] = {
type: t(r.type),
required: r.required,
default: r.default
}, s),
{}
);
}
function Ft(n, e, t) {
return n.reactive(
Object.keys(e || {}).reduce(
(s, r) => {
let o = e[r];
return j(o) ? o = t.__parseExpression(o) : S(o) && (o = t.__parseFunction(o)), s[r] = o, s;
},
{}
)
);
}
function kt(n, e, t) {
return Object.entries(e ?? {}).reduce(
(s, [r, o]) => (s[r] = n.computed(t.__parseFunction(o)), s),
{}
);
}
function Mt(n, e) {
return Object.entries(n ?? {}).reduce(
(t, [s, r]) => (t[s] = e.__parseFunction(r), t),
{}
);
}
function Ot(n, e = [], t) {
return e.reduce(
(s, r) => {
const { name: o, from: i } = r || {};
r.default;
const a = j(i) ? t.__parseExpression(i) || o : i ?? o, l = j(r.default) ? t.__parseExpression(r.default) : r.default ?? null;
return s[o] = n.inject(a, l), s;
},
{}
);
}
function Dt(n, e) {
return Object.keys(n).reduce(
(t, s) => {
const r = n[s];
if (r.type === "mock")
t[s] = Rt(r);
else if (r.ref) {
const o = e.$apis[r.ref], i = S(r.transform) ? r.transform.value ? e.__parseFunction(r.transform) : void 0 : r.transform;
t[s] = async (...a) => {
const l = await o.apply(e, a);
return i ? i(l) : l;
};
}
return t;
},
{}
);
}
function Tt(n, e = [], t) {
e.forEach((s) => {
n.watch(
t.__parseExpression(s.source),
t.__parseFunction(s.handler),
{
deep: s.deep,
immediate: s.immediate
}
);
});
}
function Ht(n, e) {
return Object.entries(n ?? {}).reduce(
(t, [s, r]) => {
const o = e.__parseFunction(r);
return t[s] = async () => {
await J(0), q(o) && o();
}, t;
},
{}
);
}
const De = new Ze();
let Z = [], I = {};
const xt = (n) => n;
async function Te(n, e = window) {
const { urls: t = [], library: s } = n, r = t.filter((a) => V(a));
if (r.length === 0 || !s) return null;
const o = t.filter((a) => G(a));
return o.length && Fe(o, e), await ke(r, s, e).catch(
(a) => (console.warn("loadScriptUrl error", r, s, a), null)
);
}
function ae(n) {
const { getDsl: e, getDslByUrl: t, options: s } = n;
return s.window && (Z.forEach((r) => {
delete s.window[r];
}), Z = []), (r, o, i = z) => {
if (!o || typeof o == "string") return r;
if (o.type === "Schema" && o.id)
return i.defineAsyncComponent(async () => {
const a = I[o.id] || await De.add(
o.id,
() => e(o.id)
);
return a && (a.name = r, I[o.id] = a), a ? ie({
...s,
Vue: i,
dsl: we(a),
mode: _.Runtime,
loader: ae(n)
}).renderer : null;
});
if (o.type === "UrlSchema" && o.url)
return i.defineAsyncComponent(async () => {
const a = I[o.url] || await t(o.url);
return a && (a.name = r, I[o.url] = a), a ? ie({
...s,
Vue: i,
dsl: we(a),
mode: _.Runtime,
loader: ae(n)
}).renderer : null;
});
if (o.type === "Plugin") {
let a = o.library ? I[o.library] : null;
return a || (o.library && Z.push(o.library), a = I[o.library || Symbol()] = i.defineAsyncComponent(
async () => {
const l = await Te(o, s.window);
return l || (console.warn("getPlugin result is null", o), null);
}
), a);
}
return r;
};
}
function bs() {
I = {}, De.clearAllCache();
}
function M(n, e, t = z, s = xt, r = [], o = !1) {
if (!n || !n.name || n.invisible) return null;
const i = t.getCurrentInstance()?.appContext, { id: a = null, directives: l = [] } = n, { vIf: c, vElseIf: u, vElse: f, vFor: h, vShow: p, vModels: d, vBind: g, vHtml: v, others: m } = He(l);
if (!o && (u || f))
return null;
if (c && !Ut(c, e))
return Jt(n, e, t, s, r);
const b = (y, x = 0) => {
const A = y.$components, Q = (() => {
if (n.name === "component")
return Nt(y, n.props?.is);
if (n.name === "slot") return n.name;
const $ = s(n.name, n.from, t);
if (C($))
return vt($) || yt($) ? $ : A[$] ?? i?.app?.component($) ?? $;
if (et($) && n.id) {
const ge = `Loader${n.id}_${x}`, ve = A[ge];
return ve || (A[ge] = $);
}
return $;
})(), R = Lt(a, n.props ?? {}, y), qe = qt(t, n.events ?? {}, y);
if (n.name === "slot")
return Kt(t, n, R, y, s);
g && Object.assign(R, y.__parseExpression(g.value)), p && (R.style = Object.assign(
R.style ?? {},
Gt(p, y)
)), v && Object.assign(R, Vt(v, y)), d.forEach(($) => {
Object.assign(R, Qt(t, $, y));
});
const Je = Wt(
t,
n.children ?? [],
y,
s,
n
), he = y?.__id ? `data-v-${y.__id}` : void 0, Ke = he ? { [he]: "" } : {};
let W = t.createVNode(
Q,
{ key: `${a}_${x}`, ...Ke, ...R, ...qe },
Je
);
const me = i ? Bt(i, m, y) : [];
return me.length && (W = t.withDirectives(W, me)), W;
};
return h ? Zt(h, b, e) : b(e);
}
function Bt(n, e, t) {
const s = n.app;
return e.map((r) => {
const o = typeof r.name == "string" ? s.directive(r.name) : t.__parseExpression(r.name);
if (!o) return null;
const i = [o];
return r.value && i.push(t.__parseExpression(r.value)), r.arg && i.push(r.arg), r.modifiers && i.push(r.modifiers), i;
}).filter((r) => !!r);
}
function He(n = []) {
const e = n.find((u) => P(u.name) === "vIf"), t = n.find(
(u) => P(u.name) === "vElseIf"
), s = n.find((u) => P(u.name) === "vElse"), r = n.find((u) => P(u.name) === "vFor"), o = n.find((u) => P(u.name) === "vShow"), i = n.find((u) => P(u.name) === "vBind"), a = n.find((u) => P(u.name) === "vHtml"), l = n.filter(
(u) => P(u.name) === "vModel"
), c = n.filter(
(u) => !ot.includes(P(u.name))
);
return {
vIf: e,
vElseIf: t,
vElse: s,
vFor: r,
vShow: o,
vModels: l,
vBind: i,
others: c,
vHtml: a
};
}
function Ut(n, e) {
return !!e.__parseExpression(n.value);
}
function Nt(n, e) {
return e ? j(e) ? n.__parseExpression(e) : e : "div";
}
function Lt(n, e, t) {
const s = ce(e, t);
return s.ref = t.__ref(n, s.ref), s;
}
function ce(n, e) {
return j(n) ? e.__parseExpression(n) : S(n) ? e.__parseFunction(n) : Array.isArray(n) ? n.map((t) => ce(t, e)) : typeof n == "object" ? Object.keys(n || {}).reduce(
(t, s) => {
let r = n[s];
return t[s] = ce(r, e), t;
},
{}
) : n;
}
function qt(n, e, t) {
const s = ["passive", "capture", "once"], r = {
capture: "Capture",
once: "Once",
passive: "OnceCapture"
};
return Object.keys(e || {}).reduce(
(o, i) => {
const a = e[i], l = xe(a.modifiers), c = l.find((h) => s.includes(h)), u = "on" + tt(i) + (c && r[c] || ""), f = t.__parseFunction(a.handler);
return f && (o[u] = n.withModifiers(f, l)), o;
},
{}
);
}
function Jt(n, e, t, s, r = []) {
let o = r.findIndex((i) => i.id === n.id);
for (let i = ++o; i < r.length; i++) {
const { directives: a = [] } = r[i], { vElseIf: l, vElse: c } = He(a);
if (l) {
if (e.__parseExpression(l.value))
return M(r[i], e, t, s, r, !0);
continue;
}
if (c)
return M(r[i], e, t, s, r, !0);
}
return null;
}
function xe(n = {}, e = !1) {
const t = Object.keys(n);
return e ? t.map((s) => "." + s) : t;
}
function Kt(n, e, t, s, r) {
const { children: o } = e, i = zt(e, s), a = s.$slots?.[i.name];
return a ? a(t) : o ? C(o) ? n.createTextVNode(o) : j(o) ? n.createTextVNode(
Ie(s.__parseExpression(o))
) : Array.isArray(o) ? o.map(
(l) => M(l, s, n, r, o)
) : null : null;
}
function zt(n, e) {
const { props: t } = n, s = t?.name || "default";
return {
name: j(s) ? e.__parseExpression(s) : s,
params: []
};
}
function Gt(n, e) {
return e.__parseExpression(n.value) ? {} : {
display: "none"
};
}
function Vt(n, e) {
return {
innerHTML: e.__parseExpression(n.value) || ""
};
}
function Qt(n, e, t) {
const s = {
type: "JSFunction",
value: e.value?.value ? `(v) => {
${e.value.value} = v;
}` : "(v) => {}"
}, r = t.__parseFunction(s), o = xe(
j(e.modifiers) ? t.__parseExpression(e.modifiers) : e.modifiers
), i = j(e.arg) ? t.__parseExpression(e.arg) : e.arg || "modelValue";
return {
[i]: t.__parseExpression(e.value),
[`onUpdate:${i}`]: o.length && r ? n.withModifiers(r, o) : r
};
}
function Wt(n, e, t, s, r) {
if (!e) return null;
if (C(e))
return { default: () => e };
if (j(e))
return {
default: () => Ie(t.__parseExpression(e))
};
if (Array.isArray(e) && e.length > 0) {
const o = Xt(e), i = (a, l) => !a || !r ? {} : r?.id && Object.keys(a).length ? l ? {
[l]: a
} : {
[`scope_${r.id}`]: a
} : l ? { [l]: /* @__PURE__ */ Object.create(null) } : {};
return Object.entries(o).reduce(
(a, [l, { nodes: c, params: u, scope: f }]) => (a[l] = (h) => {
const p = u.length ? st(h ?? {}, u) : i(h, f);
return c.map(
(d) => M(d, t.__clone(p), n, s, c)
);
}, a),
{}
);
}
return null;
}
function Xt(n) {
const e = {};
for (const t of n) {
const s = Yt(t.slot), r = s.name;
e[r] ? (e[r].nodes.push(t), e[r].params = e[r].params.concat(s.params), e[r].scope = s.scope || "") : e[r] = {
nodes: [t],
params: s.params,
scope: s.scope || ""
};
}
return e;
}
function Yt(n = "default") {
return C(n) ? { name: n, params: [], scope: "" } : { params: [], scope: "", ...n };
}
function Zt(n, e, t) {
const { value: s, iterator: r } = n, { item: o = "item", index: i = "index" } = r || {};
let a = t.__parseExpression(s) || [];
return Number.isInteger(a) && (a = new Array(a).fill(!0).map((l, c) => c + 1)), Array.isArray(a) ? a.map((l, c) => e(t.__clone({ [o]: l, [i]: c }), c)) : (console.warn("[vForRender]:", `${s?.value} is not a Arrary`), []);
}
const ee = Ce({
name: "VtjPageContainer",
async setup() {
const n = Ne(), e = Ae(), t = e.meta.__vtj__ || e.params.id, s = t ? n.getPage(t) : n.getHomepage(), r = s ? await n.getRenderComponent(s.id) : null, o = oe(Symbol());
if (s) {
Object.assign(e.meta, s.meta || {}, { cache: s.cache });
const { useTitle: i } = n?.adapter;
i && i(s.title || "VTJ");
}
return {
provider: n,
component: r,
file: s,
query: e.query,
meta: e.meta,
sid: o,
route: e
};
},
render() {
const { component: n, query: e, sid: t } = this;
return n ? re(n, { ...e, key: t }) : re("div", "页面不存在");
},
activated() {
this.meta.cache === !1 && (this.sid = Symbol());
}
}), es = Ce({
name: "VtjStartupContainer",
render() {
return re("div", "page not found!");
}
});
function K(n, e, t = []) {
const s = [];
for (const r of t) {
const { id: o, title: i, icon: a, children: l, hidden: c, layout: u } = r;
if (u) {
const f = K(n, e, l || []);
s.push(...f);
} else {
const f = {
id: o,
title: i,
icon: a,
hidden: c,
url: `${n}/${e}/${o}`,
children: l && l.length ? K(n, e, l) : void 0
};
s.push(f);
}
}
return s;
}
function Be(n, e) {
if (!e) return n;
let t = [];
for (const s of n)
if (s.children && s.children.length) {
const r = Be(s.children, e);
r.length && (s.children = r, t.push(s));
} else
e.can(s.id.toString()) && t.push(s);
return t;
}
function Rs(n) {
const {
menuPathPrefix: e = "",
pageRouteName: t = "page",
disableMenusFilter: s = !1
} = n || {}, r = Ne(), o = Ae(), i = St(), a = oe(!1), l = oe(!1), c = r.project, u = (p, d) => {
a.value = !p?.mask, l.value = d?.pure ?? !!p?.pure;
};
rt(() => {
const { name: p, params: d, meta: g } = o;
if (p === D) {
const v = r.getPage(d.id);
u(v, g);
} else if (p === N) {
const v = r.getHomepage();
u(v, g);
} else {
const v = g.__vtj__;
if (v) {
const m = r.getPage(v);
u(m, g);
} else
a.value = !g.mask, l.value = !!g.pure;
}
});
const f = K(
e,
t,
c?.pages
), h = c?.config;
return {
disabled: a,
logo: h?.logo,
themeSwitchable: h?.themeSwitchable,
title: h?.title || c?.description || c?.name || "VTJ App",
menus: s ? f : Be(f, i),
pure: l
};
}
function te(n, e) {
const { id: t, title: s, meta: r } = n, { name: o = "page", prefix: i = "", component: a, routeMeta: l } = e;
return {
name: t,
path: `${i}${o}/${t}`,
component: a,
meta: {
title: s,
...l,
...r,
__vtj__: t
}
};
}
function le(n) {
const {
name: e = "page",
prefix: t = "",
pages: s = [],
component: r,
loader: o,
routeMeta: i,
homepage: a
} = n, l = [];
for (const c of s) {
const { id: u, title: f, dir: h, layout: p, children: d, meta: g } = c;
if (h) {
const v = le({
name: e,
prefix: t,
component: r,
routeMeta: i,
homepage: a,
loader: o,
pages: d || []
});
l.push(...v);
} else if (p) {
const v = le({
name: e,
prefix: t,
component: r,
routeMeta: i,
homepage: a,
loader: o,
pages: d || []
}), m = {
name: `layout_${u}`,
path: t,
component: () => o(u),
meta: {
title: f,
...i,
...g,
__vtj__: u
},
children: v
};
l.push(m), l.push(te(c, n));
} else if (l.push(te(c, n)), a === u) {
const v = te(c, n);
v.path = "", v.name = `home_${u}`, l.push(v);
}
}
return l;
}
function ts(n = {}, e) {
const { css: t, store: s, enhance: r } = n, { window: o, app: i, library: a = {}, adapter: l, mode: c } = e, { Pinia: u } = a;
fe(o, "global-css", t || ""), u && s && ss(s, i, u), rs(i, l, n), !l.access && n.access && ns(n.access, i, c, l), os(i, n), r && is(r, i);
}
function ss(n, e, t) {
const s = t.createPinia();
if (e.use(s), S(n) && n.value) {
const r = E(n, {}, !1, !1, !0), o = t.defineStore("$store", r(e) || {});
e.config.globalProperties.$store = o();
}
}
function ns(n, e, t, s) {
if (S(n) && n.value) {
const r = E(n, {}, !1, !1, !0), { alert: o, request: i } = s, a = new pe({
alert: o,
storagePrefix: "__VTJ_APP_",
...r(e)
}), l = e.config.globalProperties.$router;
a.connect({ mode: t, router: l, request: i }), e.use(a);
}
}
function rs(n, e, t) {
if (!e.request) return;
const { axios: s, request: r, response: o } = t;
if (s && S(s) && s.value) {
const i = E(s, {}, !1, !1, !0);
e.request.setConfig(i(n));
}
if (r && S(r) && r.value) {
const i = E(r, {}, !1, !1, !0);
e.request.useRequest((a) => i(a, n));
}
if (o && S(o) && o.value) {
const i = E(o, {}, !1, !1, !0);
e.request.useResponse((a) => i(a, n));
}
}
function os(n, e) {
const { beforeEach: t, afterEach: s } = e, r = n.config.globalProperties.$router;
if (t && S(t) && t.value) {
const o = E(t, {}, !1, !1, !0);
r && r.beforeEach((i, a, l) => o(i, a, l, n));
}
if (s && S(s) && s.value) {
const o = E(s, {}, !1, !1, !0);
r && r.afterEach((i, a, l) => o(i, a, l, n));
}
}
function is(n, e) {
S(n) && n.value && E(n, {}, !1, !1, !0)(e);
}
const Ue = Symbol("Provider");
var as = /* @__PURE__ */ ((n) => (n.Production = "production", n.Development = "development", n))(as || {});
class cs extends ze {
// DSL缓存
/**
* 创建Provider实例
* @param options 配置选项
*/
constructor(e) {
super(), this.options = e;
const {
service: t,
mode: s = _.Raw,
dependencies: r,
materials: o,
project: i = {},
adapter: a = {},
globals: l = {},
modules: c = {},
router: u = null,
materialPath: f = "./",
nodeEnv: h = "development"
/* Development */
} = e;
this.mode = s, this.modules = c, this.service = t, this.router = u, this.materialPath = f, this.nodeEnv = h, r && (this.dependencies = r), o && (this.materials = o), Object.assign(this.globals, l), Object.assign(this.adapter, a);
const { access: p, request: d } = this.adapter;
p && p.connect({ mode: s, router: u, request: d }), i && s !== _.Design ? this.load(i) : this.project = i;
}
mode;
// 当前运行模式(设计/源码/预览等)
globals = {};
// 全局变量
modules = {};
// 异步模块加载器
adapter = { request: ne, jsonp: Re };
// 适配器接口
apis = {};
// API集合
dependencies = {};
// 依赖项
materials = {};
// 物料资源
library = {};
// 第三方库
service;
// 核心服务
project = null;
// 当前项目配置
components = {};
// 组件集合
nodeEnv = "development";
// 运行环境
router = null;
// 路由实例
materialPath = "./";
// 物料路径
urlDslCaches = {};
createMock(e) {
return async (...t) => {
let s = {};
if (e)
try {
s = await e.apply(e, t);
} catch (o) {
k.warn("模拟数据模版异常", o);
}
return T()?.mock(s);
};
}
/**
* 加载项目配置并初始化
* 1. 从模块或服务加载项目配置
* 2. 根据运行模式加载依赖或资源
* 3. 初始化Mock数据
* 4. 创建API接口
* 5. 初始化路由(非uniapp平台)
* @param project 项目配置
*/
async load(e) {
const { vtjDir: t = ".vtj" } = this.options, s = this.modules[`${t}/projects/${e.id}.json`] || this.modules[`/src/${t}/projects/${e.id}.json`];
if (this.project = s ? await s() : await this.service.init(e), !this.project)
throw new Error("project is null");
const { apis: r = [], meta: o = [] } = this.project, i = window;
i && (i.CKEDITOR_VERSION = void 0), this.mode === _.Raw ? await this.loadDependencies(i) : await this.loadAssets(i), this.initMock(i), this.apis = Et(r, o, this.adapter), Oe(i), bt(r, i), e.platform !== "uniapp" && this.initRouter(), this.triggerReady();
}
initMock(e) {
const t = T(e);
t && t.setup({
timeout: "50-500"
});
}
async loadDependencies(e) {
const t = Object.entries(this.dependencies);
for (const [s, r] of t)
e[s] || (e[s] = this.library[s] = await r());
}
async loadAssets(e) {
const { dependencies: t = [] } = this.project, { dependencies: s, library: r, components: o, materialPath: i, nodeEnv: a } = this, {
libraryExports: l,
libraryMap: c,
materials: u,
materialExports: f,
materialMapLibrary: h
} = ft(
t,
i,
a === "development"
/* Development */
);
for (const p of l) {
const d = s[p], g = e[p];
if (g)
r[p] = g;
else if (d)
e[p] = r[p] = await d();
else {
const v = c[p] || [];
for (const m of v)
G(m) && await mt(m, F.append(m, { v: O })), V(m) && await Se(F.append(m, { v: O }));
r[p] = e[p];
}
}
if (a === "development") {
for (const d of u)
await Se(F.append(d, { v: O }));
const p = this.materials || {};
for (const d of f) {
const g = e[h[d]], v = Ge[d];
if (v)
g && v.forEach((m) => {
o[m] = g[m];
});
else {
const m = p[d] ? (await p[d]()).default : e[d];
m && g && (m.components || []).forEach((b) => {
o[b.name] = pt(b, g);
});
}
}
}
}
initRouter() {
const { router: e, project: t, options: s, adapter: r } = this;
if (!e) return;
const o = t?.platform === "uniapp" ? "pages" : "page", {
routeAppendTo: i,
pageRouteName: a = o,
routeMeta: l
} = s, c = i ? "" : "/", u = {
path: `${c}${a}/:id`,
name: D,
component: ee
}, f = {
path: c,
name: N,
component: t?.homepage ? ee : r.startupComponent || es,
meta: l
};
if (e.hasRoute(D) && e.removeRoute(D), e.hasRoute(N) && e.removeRoute(N), s.enableStaticRoute) {
const h = t?.pages || [];
le({
name: a,
prefix: c,
pages: h,
component: ee,
loader: this.getRenderComponent.bind(this),
homepage: t?.homepage
}).forEach((d) => {
i ? e.addRoute(i, d) : e.addRoute(d);
}), t?.homepage || (i ? e.addRoute(i, f) : e.addRoute(f));
} else
i ? (e.addRoute(i, u), e.addRoute(i, f)) : (e.addRoute(u), e.addRoute(f));
}
/**
* Vue 插件安装方法
* 1. 安装所有第三方库插件
* 2. 执行自定义安装函数(如果提供)
* 3. 安装访问适配器
* 4. 提供全局 Provider 实例
* 5. 设计模式下设置错误处理器
* 6. 执行增强函数(如果提供)
* @param app Vue 应用实例
*/
install(e) {
const t = e.config.globalProperties.installed || {};
for (const [s, r] of Object.entries(this.library))
!t[s] && gt(r) && (e.use(r), t[s] = !0);
this.options.install && e.use(this.options.install), this.adapter.access && e.use(this.adapter.access), e.provide(Ue, this), e.config.globalProperties.$provider = this, this.project?.platform !== "uniapp" && this.initGlobals(this.project?.globals || {}, {
app: e,
window,
adapter: this.adapter,
library: this.library,
mode: this.mode
}), this.options.enhance && e.use(this.options.enhance, this), this.mode === _.Design && (e.config.errorHandler = (s, r, o) => {
const i = r?.$options.name, a = typeof s == "string" ? s : s?.message || s?.msg || "未知错误", l = `[ ${i} ] ${a} ${o}`;
console.error(
"[VTJ Error]:",
{
err: s,
instance: r,
info: o
},
s?.stack
), this.adapter.notify && this.adapter.notify(l, "组件渲染错误", "error");
}), e.config.globalProperties.installed = t;
}
getFile(e) {
const { blocks: t = [] } = this.project || {};
return this.getPage(e) || t.find((s) => s.id === e) || null;
}
getPage(e) {
const { pages: t = [] } = this.project || {}, s = (r, o = []) => {
for (const i of o) {
if (i.id === r)
return i;
if (i.children && i.children.length) {
const a = s(r, i.children);
if (a)
return a;
}
}
};
return s(e, t) || null;
}
getMenus(e = "page", t = "") {
return K(t, e, this.project?.pages || []);
}
getHomepage() {
const { homepage: e } = this.project || {};
return e ? this.getPage(e) : null;
}
async getDsl(e) {
const { vtjDir: t = ".vtj" } = this.options, s = this.modules[`${t}/files/${e}.json`] || this.modules[`/src/${t}/files/${e}.json`];
return s ? await s() : this.service.getFile(e, this.project || void 0).catch(() => null);
}
async getDslByUrl(e) {
const t = this.urlDslCaches[e];
return t || (this.adapter.request ? this.urlDslCaches[e] = this.adapter.request.send({
url: e,
method: "get",
settings: {
validSuccess: !1,
originResponse: !0
}
}).then((s) => s.data).catch(() => null) : null);
}
/**
* 创建 DSL 渲染器
* 1. 合并默认选项和自定义选项
* 2. 创建 DSL 加载器
* 3. 返回渲染器实例
* @param dsl 区块 DSL 配置
* @param opts 渲染选项
* @returns 渲染器实例
*/
createDslRenderer(e, t = {}) {
const { library: s, components: r, mode: o, apis: i } = this, a = {
mode: o,
Vue: s.Vue,
components: r,
libs: s,
apis: i,
window,
...t
}, l = ae({
getDsl: async (c) => await this.getDsl(c) || null,
getDslByUrl: async (c) => await this.getDslByUrl(c) || null,
options: a
});
return ie({
...a,
dsl: e,
loader: l
});
}
/**
* 获取渲染组件
* 1. 根据ID查找文件(页面或区块)
* 2. 如果找到文件且提供了output回调,则调用它
* 3. 尝试从模块缓存加载原始Vue组件
* 4. 如果找不到原始组件,则获取DSL并创建渲染器
* @param id 文件ID
* @param output 找到文件时的回调函数
* @returns Promise<Vue组件>
*/
async getRenderComponent(e, t) {
const s = this.getFile(e);
if (!s)
return k.warn(`Can not find file: ${e}`), null;
if (t && t(s), this.mode === _.Raw) {
const { vtjRawDir: o = ".vtj/vue" } = this.options, i = `${o}/${e}.vue`, a = this.modules[i] || this.modules[`/src/pages/${e}.vue`];
return a ? (await a())?.default : this.nodeEnv === "development" && this.adapter.startupComponent || null;
}
const r = await this.getDsl(s.id);
return r ? this.createDslRenderer(r).renderer : (k.warn(`Can not find dsl: ${e}`), null);
}
/**
* 定义基于URL的异步组件
* 1. 根据URL获取DSL配置
* 2. 如果获取成功,设置组件名称
* 3. 创建并返回DSL渲染器
* @param url DSL配置URL
* @param name 可选的自定义组件名称
* @returns Vue异步组件
*/
defineUrlSchemaComponent(e, t) {
return $e(async () => {
const s = await this.getDslByUrl(e);
return s ? (s.name = t || s.name, this.createDslRenderer(s).renderer) : null;
});
}
/**
* 定义基于插件的异步组件
* 1. 根据插件来源获取插件实例
* 2. 返回插件组件
* @param from 插件来源配置
* @returns Vue异步组件
*/
definePluginComponent(e) {
return $e(async () => await Te(e, window));
}
/**
* 设置应用全局
* @param css
* @param win
*/
initGlobals(e, t) {
const s = Object.assign(
{
adapter: this.adapter,
window
},
t
);
ts(e, s);
}
}
function Ps(n) {
const e = new cs(n);
return {
provider: e,
onReady: (s) => e.ready(s)
};
}
function Ne(n = {}) {
const e = Pe(Ue, null);
if (!e)
throw new Error("Can not find provider");
if (e.nodeEnv === "development") {
const { id: t, version: s } = n;
t && s && (async () => {
const r = await e.getDsl(t);
r?.__VERSION__ !== s && e.adapter.notify && e.adapter.notify(
`[ ${r?.name} ] 组件源码版本与运行时版本不一致,请重新发布组件`,
"版本不一致",
"warning"
);
})();
}
return e;
}
async function Cs(n, e = "") {
const { name: t, urls: s = [] } = n || {}, r = s.map((a) => e + a), { css: o, js: i } = dt(r);
if (o.length && Fe(o), i.length)
return await ke(i, t).catch(
() => {
}
);
}
const Le = {
type: "json",
validSuccess: !0,
originRespo