@vtj/renderer
Version:
VTJ 是一款基于 Vue3 + Typescript 的低代码页面可视化设计器。内置低代码引擎、渲染器和代码生成器,面向前端开发者,开箱即用。 无缝嵌入本地开发工程,不改变前端开发流程和编码习惯。
1,787 lines • 64.3 kB
JavaScript
import { Base as Ge, BUILT_IN_COMPONENTS as ze, ProjectModel as U, HistoryModel as Ee } from "@vtj/core";
import { isUrl as se, url as F, dedupArray as Ve, isString as I, isFunction as q, logger as O, storage as X, cookie as Y, toArray as ve, unRSA as _e, delay as J, createRequest as je, jsonp as Re, merge as We, pathToRegexp as Qe, pathToRegexpMatch as Xe, formDataToJson as Ye, Queue as Ze, cloneDeep as we, camelCase as A, 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 G from "vue";
import { inject as Pe, defineComponent as Ce, h as re, ref as ie, watchEffect as rt, defineAsyncComponent as $e } from "vue";
import { useRoute as Ae } from "vue-router";
/**!
* Copyright (c) 2026, VTJ.PRO All rights reserved.
* @name @vtj/renderer
* @author CHC chenhuachun1549@dingtalk.com
* @version 0.14.0
* @license <a href="https://vtj.pro/license.html">MIT License</a>
*/
const T = "0.14.0";
var w = /* @__PURE__ */ ((n) => (n.Runtime = "Runtime", n.Design = "Design", n.Raw = "Raw", n.VNode = "VNode", n))(w || {});
const be = [
"$el",
"$emit",
"$nextTick",
"$parent",
"$root",
"$attrs",
"$slots",
"$watch",
"$props",
"$options",
"$forceUpdate"
], ws = [
"beforeCreate",
"created",
"beforeMount",
"mounted",
"beforeUpdate",
"updated",
"beforeUnmount",
"unmounted",
"errorCaptured",
"renderTracked",
"renderTriggered",
"activated",
"deactivated"
], it = [
"vIf",
"vElseIf",
"vElse",
"vShow",
"vModel",
"vFor",
"vBind",
"vHtml"
], ot = {
String,
Number,
Boolean,
Array,
Object,
Function,
Date
}, x = "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(","), Ss = [
"h",
"t",
"t",
"p",
"s",
":",
"/",
"/",
"a",
"p",
"p",
".",
"v",
"t",
"j",
".",
"p",
"r",
"o"
].join(""), $s = {
auth: [
"h",
"t",
"t",
"p",
"s",
":",
"/",
"/",
"a",
"p",
"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 z(n) {
return /\.css$/.test(n);
}
function V(n) {
return /\.js$/.test(n);
}
function lt(n) {
return /\.json$/.test(n);
}
function bs(n) {
return n.map(
(e) => `<script src="${F.append(e, { v: T })}"><\/script>`
).join("");
}
function Es(n = []) {
return n.map(
(e) => `<link rel="stylesheet" href="${F.append(e, { v: T })}" />`
).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((p) => !!p.enabled), r = [], i = [], a = [], o = [], l = {}, c = {}, f = [], u = {};
return s.forEach(
({ urls: p, assetsUrl: h, library: d, assetsLibrary: m, localeLibrary: g }) => {
p?.forEach((y) => {
V(y) && r.push(ut(y, t)), z(y) && i.push(y);
}), d && (o.push(d), l[d] = B(p || [], e), g && (c[d] = g)), h && a.push(h), m && f.push(m), d && m && (u[m] = d);
}
), {
scripts: B(r, e),
css: B(i, e),
materials: B(a, e),
libraryExports: o,
materialExports: Ve(f),
materialMapLibrary: u,
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) => z(s)), t = n.filter((s) => V(s));
return {
css: e,
js: t
};
}
function ht(n, e) {
const t = (c) => {
const f = [];
let u = 0;
for (; u < c.length; ) {
if (/\s/.test(c[u])) {
u++;
continue;
}
if (c.substring(u, u + 2) === "/*") {
const y = c.indexOf("*/", u + 2);
if (y !== -1) {
u = y + 2;
continue;
}
}
if (c[u] === "@") {
const y = u;
for (; u < c.length && c[u] !== "{" && c[u] !== ";"; )
u++;
const _ = c.substring(y, u).trim(), v = _.includes("@keyframes");
if (c[u] === ";")
f.push({
type: "simple-at-rule",
content: c.substring(y, u + 1)
}), u++;
else if (c[u] === "{") {
const S = u + 1;
let P = 1;
for (u++; u < c.length && P > 0; )
c[u] === "{" ? P++ : c[u] === "}" && P--, u++;
const W = c.substring(y, u), C = c.substring(S, u - 1);
f.push({
type: v ? "keyframes" : "at-rule",
rule: _,
content: W,
inner: C
});
}
continue;
}
const p = u;
for (; u < c.length && c[u] !== "{"; )
u++;
if (u >= c.length) break;
const h = c.substring(p, u).trim();
if (!h) {
u++;
continue;
}
const d = u + 1;
let m = 1;
for (u++; u < c.length && m > 0; )
c[u] === "{" ? m++ : c[u] === "}" && m--, u++;
const g = c.substring(d, u - 1);
f.push({
type: "rule",
selector: h,
content: g.trim()
});
}
return f;
}, s = (c) => {
const f = c.trim();
return /^(from|to|\d+(\.\d+)?%)$/.test(f);
}, r = (c) => c.replace(/::v-deep\(/g, ":deep(").replace(/::v-deep\s+/g, ":deep(").replace(/\/deep\//g, " ").replace(/>>>/g, " ").replace(/(.*?):deep\(([^)]+)\)/g, (f, u, p) => {
const h = u.trim(), d = p.trim();
return h ? `${h}[${e}] ${d}` : d;
}), i = (c) => {
const f = c.trim();
if (!f || f.includes(`[${e}]`) || /^(:root|:host|html|body)(\s|$|:|\.|\#|\[)/.test(f) || s(f))
return f;
const u = f.match(/^(.+?)((?:::?[\w-]+(?:\([^)]*\))?)*)\s*$/);
if (u) {
const [, p, h = ""] = u, d = p.trim();
return d ? `${d}[${e}]${h}` : f;
}
return `${f}[${e}]`;
}, a = (c) => r(c).split(",").map((u) => i(u)).filter((u) => u.trim()).join(", "), o = (c) => c.map((f) => {
switch (f.type) {
case "simple-at-rule":
return f.content;
case "keyframes":
return f.content;
case "at-rule":
try {
const p = t(f.inner), h = o(p);
return `${f.rule} { ${h} }`;
} catch {
return f.content;
}
case "rule":
if (!f.selector || !f.content)
return "";
const u = a(f.selector);
return u.trim() ? `${u} { ${f.content} }` : "";
default:
return "";
}
}).filter((f) => f.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, `
`), f = t(c), u = o(f);
return l(u);
} catch (c) {
return console.error("CSS scoping failed:", c), console.error("Input CSS:", n), n.replace(/\/\*[\s\S]*?\*\//g, "").replace(
/(@keyframes\s+[^{]+\s*{[^{}]*(?:{[^}]*}[^{}]*)*})/g,
(f) => f
).replace(/([^{}@]+)(?=\s*{)/g, (f) => {
const u = f.trim();
return !u || u.startsWith("@") || u.includes(`[${e}]`) || s(u) ? f : `${u}[${e}]`;
});
}
}
const mt = 750;
function gt(n, e, t) {
let s;
typeof n < "u" ? s = n.innerWidth || n.document.documentElement.clientWidth : (console.warn("无法获取屏幕宽度,使用默认值375"), s = 375);
const r = t || mt;
return e * s / r;
}
function yt(n, e) {
let t = !1, s = !1, r = !1, i = "";
for (let a = 0; a < e.length; a++) {
const o = e[a];
if (o === "'" && !s && !r ? t = !t : o === '"' && !t && !r ? s = !s : e.substr(a, 4).toLowerCase() === "url(" && !t && !s ? r = !0 : o === ")" && r && (r = !1), !t && !s && !r) {
const l = e.substr(a).match(/^(-?\d+(?:\.\d+)?)\s*rpx/);
if (l) {
const c = l[1], f = parseFloat(c), p = `${gt(n, f).toFixed(6).replace(/\.?0+$/, "")}px`;
i += p, a += l[0].length - 1;
continue;
}
}
i += o;
}
return i;
}
function Ie(n) {
return I(n) ? n : JSON.stringify(n);
}
function fe(n, e, t, s = !1) {
const r = n.CSSStyleSheet, i = s ? `data-v-${e}` : e, a = n.__uniConfig ? yt(n, t) : t, o = s ? ht(a, i) : a;
if (r.prototype.replaceSync) {
const l = new r();
l.id = e, l.replaceSync(o);
const c = n.document, f = c.adoptedStyleSheets, u = Array.from(f).filter(
(p) => p.id !== e
);
c.adoptedStyleSheets = [...u, l];
} else {
const l = n.document;
let c = l.getElementById(e);
c ? c.innerHTML = o : (c = l.createElement("style"), c.id = e, c.innerHTML = o, l.head.appendChild(c));
}
}
function js(n) {
const e = n.adoptedStyleSheets || [];
let t = "";
if (e.forEach((s) => {
try {
for (const r of s.cssRules)
t += r.cssText + `
`;
} catch (r) {
console.error("Failed to read cssRules from adopted stylesheet:", r);
}
}), t) {
const s = n.createElement("style");
s.textContent = t, n.head.appendChild(s);
}
}
async function vt(n, e) {
const t = await window.fetch(e).then((s) => s.text()).catch(() => "");
t && fe(window, n, t);
}
function ke(n, e = window) {
const t = e.document, s = e.document.head;
for (const r of n)
if (!t.getElementById(r)) {
const a = t.createElement("link");
a.rel = "stylesheet", a.id = r, a.href = r, s.appendChild(a);
}
}
async function Fe(n, e, t = window) {
const s = t.document, r = t.document.head;
let i = t[e];
return i ? i.default || i : new Promise((a, o) => {
for (const l of n) {
const c = s.createElement("script");
c.src = l, c.onload = () => {
i = t[e], i ? a(i.default || i) : o(null);
}, c.onerror = (f) => {
o(f);
}, r.appendChild(c);
}
});
}
function _t(n) {
return q(n) && Object.getOwnPropertyNames(n.prototype || {}).length === 0 || q(n?.install);
}
function wt(n) {
return ct.includes(n);
}
function St(n) {
return at.includes(n);
}
function D(n = window) {
const e = window?.Mock;
if (e) return e;
const t = n?.Mock;
if (t && window)
return window.Mock = t, t;
}
function Rs(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 i = ['"use strict";', "var __self = arguments[0];"];
i.push("return ");
let a = (n.value || "").trim();
r || (a = a.replace(/this(\W|$)/g, (l, c) => `__self${c}`)), a = i.join(`
`) + a;
const o = r ? `
${a}
` : `with(${t ? "{}" : "$scope || {}"}) { ${a} }`;
return new Function("$scope", o)(e);
} catch (i) {
if (O.error("parseExpression.error", i, n, e?.__self ?? e), s)
throw i;
}
}
function R(n, e, t = !1, s = !1, r = !1) {
const i = H(n, e, t, s, r);
if (typeof i != "function" && (O.error(
"parseFunction.error",
"not a function",
n,
e?.__self ?? e
), s))
throw new Error(`"${n.value}" not a function`);
return i;
}
function j(n) {
return n && n.type === "JSExpression";
}
function b(n) {
return typeof n == "object" && n && n.type === "JSFunction";
}
function $t(n) {
return j(n) || b(n);
}
function Ps(n) {
return $t(n) ? n.value : JSON.stringify(n);
}
const bt = {
session: !1,
authKey: "Authorization",
storageKey: "ACCESS_STORAGE",
storagePrefix: "__VTJ_",
unauthorized: void 0,
auth: "/#/login",
redirectParam: "r",
unauthorizedCode: 401,
unauthorizedMessage: "登录已经失效,请重新登录!",
noPermissionMessage: "无权限访问该页面",
appName: "",
statusKey: "code"
}, Oe = Symbol("access");
class pe {
options;
data = null;
mode = w.Raw;
interceptResponse = !0;
isTipShowing = !1;
constructor(e) {
this.options = Object.assign({}, bt, 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 !== w.Design && this.setGuard(s), r && this.setRequest(r);
}
login(e) {
const { storageKey: t, storagePrefix: s, session: r, authKey: i } = this.options;
this.setData(e), this.data && (X.save(t, e, {
type: "local",
prefix: s
}), r && Y.set(i, 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) : ve(e).every((i) => s[i] || s[t + "." + i]);
}
some(e) {
const { appName: t } = this.options, { permissions: s = {} } = this.data || {};
return ve(e).some((i) => s[i] || s[t + "." + i]);
}
install(e) {
e.config.globalProperties.$access = this, e.provide(Oe, 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 === x) {
const t = e.params.id;
return t && this.can(t);
}
return e.meta.__vtj__ ? this.can(e.meta.__vtj__) : e.meta.permission ? this.can(e.meta.permission) : !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)) : I(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 this.isTipShowing ? !1 : t ? (this.isTipShowing = !0, await J(150), await t(e, {
title: "提示",
type: "warning"
})?.catch(() => !0)?.finally(() => {
this.isTipShowing = !1;
})) : (window.alert(e), !0);
}
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 Et() {
return Pe(Oe, null);
}
function Cs(n = {}) {
const {
notify: e,
loading: t,
settings: s = {},
Startup: r,
access: i,
useTitle: a,
alert: o
} = n;
let l = null;
return {
request: je({
settings: {
type: "form",
validSuccess: !0,
originResponse: !1,
loading: !0,
validate: (f) => f.data?.code === 0 || !!f.data?.success,
failMessage: !0,
showError: (f) => {
e && e(f || "未知错误");
},
showLoading: () => {
l && l.close(), t && (l = t());
},
hideLoading: () => {
l && (l.close(), l = null);
},
...s
}
}),
jsonp: Re,
notify: e,
loading: t,
useTitle: a,
alert: o,
startupComponent: r,
access: i ? new pe({ alert: o, ...i }) : void 0
};
}
function As(n = {}) {
return new pe(n);
}
function jt(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, i = {
url: n.url,
method: n.method,
settings: {
...n.settings,
headers: r
}
};
return (a, o) => (delete i.data, s.send(We(i, o || {}, { data: a })));
}
}
function Rt(n, e) {
const { metaQuery: t } = e;
if (!t) return;
const { code: s, queryCode: r } = n;
return (i, a) => {
if (!t) {
console.warn("adapter.metaQuery is not defined!");
return;
}
return t(s, r, i, a);
};
}
function Pt(n = [], e = [], t) {
const s = {};
for (const r of n) {
const i = jt(r, t);
s[r.id] = i, s[r.name] = i;
}
for (const r of e)
s[r.id] = Rt(r, t);
return s;
}
async function Ct(n = [], e = window) {
const t = D(e);
t && (Me(e), n.forEach((s) => It(t, s)));
}
function At(n, e = window) {
const t = b(n.mockTemplate) && n.mockTemplate.value ? R(n.mockTemplate, {}, !0) : void 0, s = D(e);
return async (...r) => {
let i = {};
if (t)
try {
i = await t.apply(t, r);
} catch (a) {
O.warn("模拟数据模版异常", a);
}
return s?.mock(i);
};
}
function It(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, i = Qe(`(.*)${r}(.*)`), a = Xe(r, { decode: decodeURIComponent }), o = H(s, {}, !0);
n.mock(i, (l) => {
const c = F.parse(l.url) || {}, f = l.body instanceof FormData ? Ye(l.body) : l.body, u = se(l.url) ? new URL(l.url).pathname : l.url.split("?")[0], p = a(u)?.params;
Object.assign(l, { data: f, params: p, query: c });
try {
return n.mock(o(l));
} catch (h) {
return console.warn("[mockApi]", i, l, h), null;
}
});
} catch (r) {
console.warn("mockApi", r);
}
}
function Me(n = window) {
const e = D(n);
e && (e._mocked = {});
}
class kt {
__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 = {};
$provider = null;
__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 = G) {
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 && be.forEach((e) => {
this[e] = this.__instance?.[e];
});
}
__cleanup() {
be.forEach((e) => {
this[e] = null;
}), this.__reset();
}
__reset() {
this.__refs = {}, this.$refs = {}, this.__contextRefs = {}, this.context = {};
}
__parseFunction(e) {
if (e)
if (this.__mode === w.Runtime) {
const { id: t, type: s } = e, r = t ? this.__transform[t] ?? e.value : e.value;
return R({ type: s, value: r }, this);
} else
return R(e, this);
}
__parseExpression(e) {
if (e)
if (this.__mode === w.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 !== w.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, w.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 i = new Set([].concat(r, s));
return Array.from(i);
} 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 oe(n) {
const {
Vue: e = G,
mode: t = w.Runtime,
components: s = {},
libs: r = {},
apis: i = {},
loader: a
} = n, o = e.computed(() => n.dsl), l = {
$components: s,
$libs: r,
$apis: i
}, c = new kt({
mode: t,
dsl: o.value,
attrs: l
}), f = e.defineComponent({
name: o.value.name,
__scopeId: o.value.id ? `data-v-${o.value.id}` : void 0,
props: {
...Ot(o.value.props ?? [], c)
},
setup(u) {
c.$props = u, c.props = u, o.value.id && fe(
n.window || window,
o.value.id,
o.value.css || "",
!0
), c.state = Mt(e, o.value.state ?? {}, c);
const p = Tt(e, o.value.computed ?? {}, c), h = xt(o.value.methods ?? {}, c), d = Dt(e, o.value.inject, c);
for (const [y, _] of Object.entries(d || {}))
d[y] = e.inject(y, _);
const m = Ht(
o.value.dataSources || {},
c
), g = {
...d,
...p,
...h,
...m
};
return c.setup(g, e), Bt(e, o.value.watch ?? [], c), {
vtj: c,
state: c.state,
...p,
...h
};
},
emits: Ft(o.value.emits),
expose: ["vtj", ...o.value.expose || []],
render() {
if (!o.value.nodes) return null;
const u = o.value.nodes || [];
return u.length === 1 ? M(u[0], c, e, a, u) : u.map(
(p) => M(p, c, e, a, u)
);
},
...Lt(o.value.lifeCycles ?? {}, c)
});
return {
renderer: e.markRaw(f),
context: c
};
}
function Ft(n = []) {
return n.map((e) => I(e) ? e : e.name);
}
function Ot(n = [], e) {
const t = (s) => s ? (Array.isArray(s) ? s : [s]).map((i) => ot[i]) : void 0;
return n.map((s) => I(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 Mt(n, e, t) {
return n.reactive(
Object.keys(e || {}).reduce(
(s, r) => {
let i = e[r];
return j(i) ? i = t.__parseExpression(i) : b(i) && (i = t.__parseFunction(i)), s[r] = i, s;
},
{}
)
);
}
function Tt(n, e, t) {
return Object.entries(e ?? {}).reduce(
(s, [r, i]) => (s[r] = n.computed(t.__parseFunction(i)), s),
{}
);
}
function xt(n, e) {
return Object.entries(n ?? {}).reduce(
(t, [s, r]) => (t[s] = e.__parseFunction(r), t),
{}
);
}
function Dt(n, e = [], t) {
return e.reduce(
(s, r) => {
const { name: i, from: a } = r || {};
r.default;
const o = j(a) ? t.__parseExpression(a) || i : a ?? i, l = j(r.default) ? t.__parseExpression(r.default) : r.default ?? null;
return s[i] = n.inject(o, l), s;
},
{}
);
}
function Ht(n, e) {
return Object.keys(n).reduce(
(t, s) => {
const r = n[s];
if (r.type === "mock")
t[s] = At(r);
else if (r.ref) {
const i = e.$apis[r.ref], a = b(r.transform) ? r.transform.value ? e.__parseFunction(r.transform) : void 0 : r.transform;
t[s] = async (...o) => {
const l = await i.apply(e, o);
return a ? a(l) : l;
};
}
return t;
},
{}
);
}
function Bt(n, e = [], t) {
e.forEach((s) => {
n.watch(
t.__parseExpression(s.source),
t.__parseFunction(s.handler),
{
deep: s.deep,
immediate: s.immediate
}
);
});
}
function Lt(n, e) {
return Object.entries(n ?? {}).reduce(
(t, [s, r]) => {
const i = e.__parseFunction(r);
return t[s] = async () => {
await J(0), q(i) && i();
}, t;
},
{}
);
}
const Te = new Ze();
let Z = [], k = {};
const Nt = (n) => n;
async function xe(n, e = window) {
const { urls: t = [], library: s } = n, r = t.filter((o) => V(o));
if (r.length === 0 || !s) return null;
const i = t.filter((o) => z(o));
return i.length && ke(i, e), await Fe(r, s, e).catch(
(o) => (console.warn("loadScriptUrl error", r, s, o), null)
);
}
function ae(n) {
const { getDsl: e, getDslByUrl: t, options: s } = n;
return s.window && (Z.forEach((r) => {
delete s.window[r];
}), Z = []), (r, i, a = G) => {
if (!i || typeof i == "string") return r;
if (i.type === "Schema" && i.id)
return a.defineAsyncComponent(async () => {
const o = k[i.id] || await Te.add(
i.id,
() => e(i.id)
);
return o && (o.name = r, k[i.id] = o), o ? oe({
...s,
Vue: a,
dsl: we(o),
mode: w.Runtime,
loader: ae(n)
}).renderer : null;
});
if (i.type === "UrlSchema" && i.url)
return a.defineAsyncComponent(async () => {
const o = k[i.url] || await t(i.url);
return o && (o.name = r, k[i.url] = o), o ? oe({
...s,
Vue: a,
dsl: we(o),
mode: w.Runtime,
loader: ae(n)
}).renderer : null;
});
if (i.type === "Plugin") {
let o = i.library ? k[i.library] : null;
return o || (i.library && Z.push(i.library), o = k[i.library || Symbol()] = a.defineAsyncComponent(
async () => {
const l = await xe(i, s.window);
return l || (console.warn("getPlugin result is null", i), null);
}
), o);
}
return r;
};
}
function Is() {
k = {}, Te.clearAllCache();
}
function M(n, e, t = G, s = Nt, r = [], i = !1) {
if (!n || !n.name || n.invisible) return null;
const a = t.getCurrentInstance()?.appContext, { id: o = null, directives: l = [] } = n, { vIf: c, vElseIf: f, vElse: u, vFor: p, vShow: h, vModels: d, vBind: m, vHtml: g, others: y } = De(l);
if (!i && (f || u))
return null;
if (c && !qt(c, e))
return zt(n, e, t, s, r);
const _ = (v, S = 0) => {
const P = v.$components, W = (() => {
if (n.name === "component")
return Jt(v, n.props?.is);
if (n.name === "slot") return n.name;
const E = s(n.name, n.from, t);
if (I(E))
return wt(E) || St(E) ? E : P[E] ?? a?.app?.component(E) ?? E;
if (et(E) && n.id) {
const ge = `Loader${n.id}_${S}`, ye = P[ge];
return ye || (P[ge] = E);
}
return E;
})(), C = Kt(o, n.props ?? {}, v), qe = Gt(t, n.events ?? {}, v);
if (n.name === "slot")
return Vt(t, n, C, v, s);
m && Object.assign(C, v.__parseExpression(m.value)), h && (C.style = Object.assign(
C.style ?? {},
Qt(h, v)
)), g && Object.assign(C, Xt(g, v)), d.forEach((E) => {
Object.assign(C, Yt(t, E, v));
});
const Je = Zt(
t,
n.children ?? [],
v,
s,
n
), he = v?.__id ? `data-v-${v.__id}` : void 0, Ke = he ? { [he]: "" } : {};
let Q = t.createVNode(
W,
{ key: `${o}_${S}`, ...Ke, ...C, ...qe },
Je
);
const me = a ? Ut(a, y, v) : [];
return me.length && (Q = t.withDirectives(Q, me)), Q;
};
return p ? ss(p, _, e) : _(e);
}
function Ut(n, e, t) {
const s = n.app;
return e.map((r) => {
const i = typeof r.name == "string" ? s.directive(r.name) : t.__parseExpression(r.name);
if (!i) return null;
const a = [i];
return r.value && a.push(t.__parseExpression(r.value)), r.arg && a.push(r.arg), r.modifiers && a.push(r.modifiers), a;
}).filter((r) => !!r);
}
function De(n = []) {
const e = n.find((f) => A(f.name) === "vIf"), t = n.find(
(f) => A(f.name) === "vElseIf"
), s = n.find((f) => A(f.name) === "vElse"), r = n.find((f) => A(f.name) === "vFor"), i = n.find((f) => A(f.name) === "vShow"), a = n.find((f) => A(f.name) === "vBind"), o = n.find((f) => A(f.name) === "vHtml"), l = n.filter(
(f) => A(f.name) === "vModel"
), c = n.filter(
(f) => !it.includes(A(f.name))
);
return {
vIf: e,
vElseIf: t,
vElse: s,
vFor: r,
vShow: i,
vModels: l,
vBind: a,
others: c,
vHtml: o
};
}
function qt(n, e) {
return !!e.__parseExpression(n.value);
}
function Jt(n, e) {
return e ? j(e) ? n.__parseExpression(e) : e : "div";
}
function Kt(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) : b(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 Gt(n, e, t) {
const s = ["passive", "capture", "once"], r = {
capture: "Capture",
once: "Once",
passive: "OnceCapture"
};
return Object.keys(e || {}).reduce(
(i, a) => {
const o = e[a], l = He(o.modifiers), c = l.find((p) => s.includes(p)), f = "on" + tt(a) + (c && r[c] || ""), u = t.__parseFunction(o.handler);
return u && (i[f] = n.withModifiers(u, l)), i;
},
{}
);
}
function zt(n, e, t, s, r = []) {
let i = r.findIndex((a) => a.id === n.id);
for (let a = ++i; a < r.length; a++) {
const { directives: o = [] } = r[a], { vElseIf: l, vElse: c } = De(o);
if (l) {
if (e.__parseExpression(l.value))
return M(r[a], e, t, s, r, !0);
continue;
}
if (c)
return M(r[a], e, t, s, r, !0);
}
return null;
}
function He(n = {}, e = !1) {
const t = Object.keys(n);
return e ? t.map((s) => "." + s) : t;
}
function Vt(n, e, t, s, r) {
const { children: i } = e, a = Wt(e, s), o = s.$slots?.[a.name];
return o ? o(t) : i ? I(i) ? n.createTextVNode(i) : j(i) ? n.createTextVNode(
Ie(s.__parseExpression(i))
) : Array.isArray(i) ? i.map(
(l) => M(l, s, n, r, i)
) : null : null;
}
function Wt(n, e) {
const { props: t } = n, s = t?.name || "default";
return {
name: j(s) ? e.__parseExpression(s) : s,
params: []
};
}
function Qt(n, e) {
return e.__parseExpression(n.value) ? {} : {
display: "none"
};
}
function Xt(n, e) {
return {
innerHTML: e.__parseExpression(n.value) || ""
};
}
function Yt(n, e, t) {
const s = {
type: "JSFunction",
value: e.value?.value ? `(v) => {
${e.value.value} = v;
}` : "(v) => {}"
}, r = t.__parseFunction(s), i = He(
j(e.modifiers) ? t.__parseExpression(e.modifiers) : e.modifiers
), a = j(e.arg) ? t.__parseExpression(e.arg) : e.arg || "modelValue";
return {
[a]: t.__parseExpression(e.value),
[`onUpdate:${a}`]: i.length && r ? n.withModifiers(r, i) : r
};
}
function Zt(n, e, t, s, r) {
if (!e) return null;
if (I(e))
return { default: () => e };
if (j(e))
return {
default: () => Ie(t.__parseExpression(e))
};
if (Array.isArray(e) && e.length > 0) {
const i = es(e), a = (o, l) => !o || !r ? {} : r?.id && Object.keys(o).length ? l ? {
[l]: o
} : {
[`scope_${r.id}`]: o
} : l ? { [l]: /* @__PURE__ */ Object.create(null) } : {};
return Object.entries(i).reduce(
(o, [l, { nodes: c, params: f, scope: u }]) => (o[l] = (p) => {
const h = f.length ? st(p ?? {}, f) : a(p, u);
return c.map(
(d) => M(d, t.__clone(h), n, s, c)
);
}, o),
{}
);
}
return null;
}
function es(n) {
const e = {};
for (const t of n) {
const s = ts(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 ts(n = "default") {
return I(n) ? { name: n, params: [], scope: "" } : { params: [], scope: "", ...n };
}
function ss(n, e, t) {
const { value: s, iterator: r } = n, { item: i = "item", index: a = "index" } = r || {};
let o = t.__parseExpression(s) || [];
return Number.isInteger(o) && (o = new Array(o).fill(!0).map((l, c) => c + 1)), Array.isArray(o) ? o.map((l, c) => e(t.__clone({ [i]: l, [a]: 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, i = ie(Symbol());
if (s) {
Object.assign(e.meta, s.meta || {}, { cache: s.cache });
const { useTitle: a } = n?.adapter;
if (a) {
const o = e.meta.title || s.title || "VTJ.PRO";
a(o);
}
}
return {
provider: n,
component: r,
file: s,
query: e.query,
meta: e.meta,
sid: i,
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());
}
}), ns = Ce({
name: "VtjStartupContainer",
render() {
return re("div", "page not found!");
}
});
function K(n, e, t = []) {
const s = [];
for (const r of t) {
const { id: i, title: a, icon: o, children: l, hidden: c, layout: f } = r;
if (f) {
const u = K(n, e, l || []);
s.push(...u);
} else {
const u = {
id: i,
title: a,
icon: o,
hidden: c,
url: `${n}/${e}/${i}`,
children: l && l.length ? K(n, e, l) : void 0
};
s.push(u);
}
}
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 ks(n) {
const {
menuPathPrefix: e = "",
pageRouteName: t = "page",
disableMenusFilter: s = !1
} = n || {}, r = Ne(), i = Ae(), a = Et(), o = ie(!1), l = ie(!1), c = r.project, f = (h, d) => {
o.value = !h?.mask, l.value = d?.pure ?? !!h?.pure;
};
rt(() => {
const { name: h, params: d, meta: m } = i;
if (h === x) {
const g = r.getPage(d.id);
f(g, m);
} else if (h === N) {
const g = r.getHomepage();
f(g, m);
} else {
const g = m.__vtj__;
if (g) {
const y = r.getPage(g);
f(y, m);
} else
o.value = !m.mask, l.value = !!m.pure;
}
});
const u = K(
e,
t,
c?.pages
), p = c?.config;
return {
disabled: o,
logo: p?.logo,
themeSwitchable: p?.themeSwitchable,
title: p?.title || c?.description || c?.name || "VTJ App",
menus: s ? u : Be(u, a),
pure: l
};
}
function te(n, e) {
const { id: t, title: s, meta: r } = n, { name: i = "page", prefix: a = "", component: o, routeMeta: l } = e;
return {
name: t,
path: `${a}${i}/${t}`,
component: o,
meta: {
title: s,
...l,
...r,
__vtj__: t
}
};
}
function le(n) {
const {
name: e = "page",
prefix: t = "",
pages: s = [],
component: r,
loader: i,
routeMeta: a,
homepage: o
} = n, l = [];
for (const c of s) {
const { id: f, title: u, dir: p, layout: h, children: d, meta: m } = c;
if (p) {
const g = le({
name: e,
prefix: t,
component: r,
routeMeta: a,
homepage: o,
loader: i,
pages: d || []
});
l.push(...g);
} else if (h) {
const g = le({
name: e,
prefix: t,
component: r,
routeMeta: a,
homepage: o,
loader: i,
pages: d || []
}), y = {
name: `layout_${f}`,
path: t,
component: () => i(f),
meta: {
title: u,
...a,
...m,
__vtj__: f
},
children: g
};
l.push(y), l.push(te(c, n));
} else if (l.push(te(c, n)), o === f) {
const g = te(c, n);
g.path = "", g.name = `home_${f}`, l.push(g);
}
}
return l;
}
function rs(n = {}, e) {
const { css: t, store: s, enhance: r } = n, { window: i, app: a, library: o = {}, adapter: l, mode: c } = e, { Pinia: f } = o;
a.config.globalProperties.$libs = o, fe(i, "global-css", t || ""), f && s && is(s, a, f), as(a, l, n), !l.access && n.access && os(n.access, a, c, l), cs(a, n), r && ls(r, a, o);
}
function is(n, e, t) {
const s = t.createPinia();
if (e.use(s), b(n) && n.value) {
const r = R(n, {}, !1, !1, !0), i = t.defineStore("$store", r(e) || {});
e.config.globalProperties.$store = i();
}
}
function os(n, e, t, s) {
if (b(n) && n.value) {
const r = R(n, {}, !1, !1, !0), { alert: i, request: a } = s, o = new pe({
alert: i,
storagePrefix: "__VTJ_APP_",
...r(e)
}), l = e.config.globalProperties.$router;
o.connect({ mode: t, router: l, request: a }), e.use(o);
}
}
function as(n, e, t) {
if (!e.request) return;
const { axios: s, request: r, response: i } = t;
if (s && b(s) && s.value) {
const a = R(s, {}, !1, !1, !0);
e.request.setConfig(a(n));
}
if (r && b(r) && r.value) {
const a = R(r, {}, !1, !1, !0), o = e.request;
o.__unReq && o.__unReq(), o.__unReq = e.request.useRequest((l) => a(l, n));
}
if (i && b(i) && i.value) {
const a = R(i, {}, !1, !1, !0), o = e.request;
o.__unRes && o.__unRes(), o.__unRes = e.request.useResponse((l) => a(l, n));
}
}
function cs(n, e) {
const { beforeEach: t, afterEach: s } = e, r = n.config.globalProperties.$router;
if (t && b(t) && t.value) {
const i = R(t, {}, !1, !1, !0);
r && r.beforeEach((a, o, l) => i(a, o, l, n));
}
if (s && b(s) && s.value) {
const i = R(s, {}, !1, !1, !0);
r && r.afterEach((a, o, l) => i(a, o, l, n));
}
}
function ls(n, e, t = {}) {
b(n) && n.value && R(n, {}, !1, !1, !0)(e, t);
}
function us(n, e, t) {
if (!n || !e || !t) return;
const { VueI18n: s } = e;
if (s) {
const { locale: r, fallbackLocale: i, messages: a = [] } = t, o = {};
for (let c of a) {
const f = Object.keys(c).filter((u) => u !== "key");
for (const u of f)
o[u] || (o[u] = {}), o[u][c.key] = c[u];
}
const l = s.createI18n({
legacy: !1,
locale: r,
fallbackLocale: i,
messages: o
});
n.use(l);
}
}
const Le = Symbol("Provider");
var fs = /* @__PURE__ */ ((n) => (n.Production = "production", n.Development = "development", n))(fs || {});
class ps extends Ge {
// DSL缓存
/**
* 创建Provider实例
* @param options 配置选项
*/
constructor(e) {
super(), this.options = e;
const {
service: t,
mode: s = w.Raw,
dependencies: r,
materials: i,
project: a = {},
adapter: o = {},
globals: l = {},
modules: c = {},
router: f = null,
materialPath: u = "./",
nodeEnv: p = "development"
/* Development */
} = e;
this.mode = s, this.modules = c, this.service = t, this.router = f, this.materialPath = u, this.nodeEnv = p, r && (this.dependencies = r), i && (this.materials = i), Object.assign(this.globals, l), Object.assign(this.adapter, o);
const { access: h, request: d } = this.adapter;
h && h.connect({ mode: s, router: f, request: d }), a && s !== w.Design ? this.load(a) : this.project = a;
}
mode;
// 当前运行模式(设计/源码/预览等)
globals = {};
// 全局变量
modules = {};
// 异步模块加载器
adapter = { request: ne, jsonp: Re };
// 适配器接口
apis = {};
// API集合
dependencies = {};
// 依赖项
materials = {};
// 物料资源
library = {};
// 第三方库
libraryLocales = {};
// 第三方库语言包
libraryLocaleMap = {};
// 库名称->语言包映射
service;
// 核心服务
project = null;
// 当前项目配置
components = {};
// 组件集合
nodeEnv = "development";
// 运行环境
env = {};
// 环境变量
router = null;
// 路由实例
materialPath = "./";
// 物料路径
urlDslCaches = {};
createMock(e) {
return async (...t) => {
let s = {};
if (e)
try {
s = await e.apply(e, t);
} catch (i) {
O.warn("模拟数据模版异常", i);
}
return D()?.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: i = [], env: a = [] } = this.project, o = window;
o && (o.CKEDITOR_VERSION = void 0), this.initEnv(a), this.mode === w.Raw ? await this.loadDependencies(o) : await this.loadAssets(o), this.initMock(o), this.apis = Pt(r, i, this.adapter), Me(o), Ct(r, o), e.platform !== "uniapp" && this.initRouter(), this.triggerReady();
}
initMock(e) {
const t = D(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: i,
materialPath: a,
nodeEnv: o,
libraryLocales: l
} = this, {
libraryExports: c,
libraryMap: f,
materials: u,
materialExports: p,
materialMapLibrary: h,
libraryLocaleMap: d
} = ft(
t,
a,
o === "development"
/* Development */
);
Object.assign(this.libraryLocaleMap, d);
for (const m of c) {
const g = s[m], y = e[m];
if (y)
r[m] = y;
else if (g)
e[m] = r[m] = await g();
else {
const v = f[m] || [];
for (const S of v)
z(S) && await vt(S, F.append(S, { v: T })), V(S) && await Se(F.append(S, { v: T }));
r[m] = e[m];
}
const _ = d[m];
if (_) {
const v = s[_];
l[_] = v ? await v() : e[_];
}
}
if (o === "development") {
for (const g of u)
await Se(F.append(g, { v: T }));
const m = this.materials || {};
for (const g of p) {
const y = e[h[g]], _ = y?.default || y, v = ze[g];
if (v)
_ && v.forEach((S) => {
i[S] = _[S];
});
else {
const S = m[g] ? (await m[g]()).default : e[g];
S && _ && (S.components || []).forEach((P) => {
i[P.name] = pt(P, _);
});
}
}
}
}
initRouter() {
const { router: e, project: t, options: s, adapter: r } = this;
if (!e) return;
const i = t?.platform === "uniapp" ? "pages" : "page", {
routeAppendTo: a,
pageRouteName: o = i,
routeMeta: l
} = s, c = a ? "" : "/", f = {
path: `${c}${o}/:id`,
name: x,
component: ee
}, u = {
path: c,
name: N,
component: t?.homepage ? ee : r.startupComponent || ns,
meta: l
};
if (e.hasRoute(x) && e.removeRoute(x), e.hasRoute(N) && e.removeRoute(N), s.enableStaticRoute) {
const p = t?.pages || [];
le({
name: o,
prefix: c,
pages: p,
component: ee,
loader: this.getRenderComponent.bind(this),
homepage: t?.homepage
}).forEach((d) => {
a ? e.addRoute(a, d) : e.addRoute(d);
}), t?.homepage || (a ? e.addRoute(a, u) : e.addRoute(u));
} else
a ? (e.addRoute(a, f), e.addRoute(a, u)) : (e.addRoute(f), e.addRoute(u));
}
/**
* Vue 插件安装方法
* 1. 安装所有第三方库插件
* 2. 执行自定义安装函数(如果提供)
* 3. 安装访问适配器
* 4. 提供全局 Provider 实例
* 5. 设计模式下设置错误处理器
* 6. 执行增强函数(如果提供)
* @param app Vue 应用实例
*/
install(e) {
const { libraryLocaleMap: t, libraryLocales: s } = this, { libraryOptions: r = {} } = this.options, i = e.config.globalProperties.installed || {};
for (const [a, o] of Object.entries(this.library))
if (!i[a] && _t(o)) {
const c = { locale: s[t[a]] }, f = r[a] || {}, u = { ...c, ...f };
e.use(o, u), i[a] = !0;
}
e.provide(Le, this), e.config.globalProperties.$provider = this, e.config.globalProperties.$request = this.adapter?.request, this.options.install && e.use(this.options.install), this.adapter.access && e.use(this.adapter.access), this.project?.platform !== "uniapp" && this.mode !== w.Design && this.initGlobals(this.project?.globals || {}, {
app: e,
window,
adapter: this.adapter,
library: this.library,
mode: this.mode
}), this.mode !== w.Design && this.project?.i18n && this.initI18n(e, this.library, this.project.i18n), this.options.enhance && e.use(this.options.enhance, this), this.mode === w.Design && (e.config.errorHandler = (a, o, l) => {
const c = o?.$options.name, f = typeof a == "string" ? a : a?.message || a?.msg || "未知错误", u = `[ ${c} ] ${f} ${l}`;
console.error(
"[VTJ Error]:",
{
err: a,
instance: o,
info: l
},
a?.stack
), this.adapter.notify && this.adapter.notify(u, "组件渲染错误", "error");
}), e.config.globalProperties.installed = i;
}
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, i = []) => {
for (const a of i) {
if (a.id === r)
return a;
if (a.children && a.children.length) {
const o = s(r, a.children);
if (o)
return o;
}
}
};
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