@vtj/renderer 0.16.20 → 0.16.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +8 -8
- package/dist/index.mjs +477 -463
- package/package.json +5 -5
- package/types/render/cache.d.ts +3 -0
- package/types/render/node.d.ts +1 -1
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@vtj/core"),f=require("@vtj/utils"),$=require("vue"),Ee=require("vue-router");function ot(n){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const t in n)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(n,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>n[t]})}}return e.default=n,Object.freeze(e)}const W=ot($);/**!
|
|
2
2
|
* Copyright (c) 2026, VTJ.PRO All rights reserved.
|
|
3
3
|
* @name @vtj/renderer
|
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
|
5
|
-
* @version 0.16.
|
|
5
|
+
* @version 0.16.21
|
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
|
7
|
-
*/const
|
|
8
|
-
`),l=t(c),p=a(l);return u(p)}catch(c){return console.error("CSS scoping failed:",c),console.error("Input CSS:",n),n.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(@keyframes\s+[^{]+\s*{[^{}]*(?:{[^}]*}[^{}]*)*})/g,l=>l).replace(/([^{}@]+)(?=\s*{)/g,l=>{const p=l.trim();return!p||p.startsWith("@")||p.includes(`[${e}]`)||s(p)?l:`${p}[${e}]`})}}const
|
|
9
|
-
`}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
|
|
7
|
+
*/const D="0.16.21";var S=(n=>(n.Runtime="Runtime",n.Design="Design",n.Raw="Raw",n.VNode="VNode",n))(S||{});const ie=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],it=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],$e=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"],be={String,Number,Boolean,Array,Object,Function,Date},x="VtjPage",U="VtjHomepage",le="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(","),je="component,slot".split(","),at=["h","t","t","p","s",":","/","/","a","p","p",".","v","t","j",".","p","r","o"].join(""),ct={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 N(n,e){return n.map(t=>f.isUrl(t)||t.startsWith("/")?t:`${e}${t}`)}function B(n){return/\.css$/.test(n)}function J(n){return/\.js$/.test(n)}function Ce(n){return/\.json$/.test(n)}function lt(n){return n.map(e=>`<script src="${f.url.append(e,{v:D})}"><\/script>`).join("")}function ut(n=[]){return n.map(e=>`<link rel="stylesheet" href="${f.url.append(e,{v:D})}" />`).join("")}function Re(n,e=!1){return e&&n.endsWith(".prod.js")?n.replace(".prod.js",".js"):n}function Pe(n,e,t=!1){const s=n.filter(d=>!!d.enabled),r=[],o=[],i=[],a=[],u={},c={},l=[],p={};return s.forEach(({urls:d,assetsUrl:h,library:g,assetsLibrary:m,localeLibrary:_})=>{d?.forEach(y=>{J(y)&&r.push(Re(y,t)),B(y)&&o.push(y)}),g&&(a.push(g),u[g]=N(d||[],e),_&&(c[g]=_)),h&&i.push(h),m&&l.push(m),g&&m&&(p[m]=g)}),{scripts:N(r,e),css:N(o,e),materials:N(i,e),libraryExports:a,materialExports:f.dedupArray(l),materialMapLibrary:p,libraryMap:u,libraryLocaleMap:c}}function Ae(n,e){const{name:t,parent:s,alias:r}=n;return s?e[s]?.[r||t]:e[r||t]}function Ie(n=[]){const e=n.filter(s=>B(s)),t=n.filter(s=>J(s));return{css:e,js:t}}function Te(n,e){const t=c=>{const l=[];let p=0;for(;p<c.length;){if(/\s/.test(c[p])){p++;continue}if(c.substring(p,p+2)==="/*"){const y=c.indexOf("*/",p+2);if(y!==-1){p=y+2;continue}}if(c[p]==="@"){const y=p;for(;p<c.length&&c[p]!=="{"&&c[p]!==";";)p++;const w=c.substring(y,p).trim(),C=w.includes("@keyframes");if(c[p]===";")l.push({type:"simple-at-rule",content:c.substring(y,p+1)}),p++;else if(c[p]==="{"){const v=p+1;let A=1;for(p++;p<c.length&&A>0;)c[p]==="{"?A++:c[p]==="}"&&A--,p++;const Z=c.substring(y,p),ee=c.substring(v,p-1);l.push({type:C?"keyframes":"at-rule",rule:w,content:Z,inner:ee})}continue}const d=p;for(;p<c.length&&c[p]!=="{";)p++;if(p>=c.length)break;const h=c.substring(d,p).trim();if(!h){p++;continue}const g=p+1;let m=1;for(p++;p<c.length&&m>0;)c[p]==="{"?m++:c[p]==="}"&&m--,p++;const _=c.substring(g,p-1);l.push({type:"rule",selector:h,content:_.trim()})}return l},s=c=>{const l=c.trim();return/^(from|to|\d+(\.\d+)?%)$/.test(l)},r=c=>c.replace(/::v-deep\(/g,":deep(").replace(/::v-deep\s+/g,":deep(").replace(/\/deep\//g," ").replace(/>>>/g," ").replace(/(.*?):deep\(([^)]+)\)/g,(l,p,d)=>{const h=p.trim(),g=d.trim();return h?`${h}[${e}] ${g}`:g}),o=c=>{const l=c.trim();if(!l||l.includes(`[${e}]`)||/^(:root|:host|html|body)(\s|$|:|\.|\#|\[)/.test(l)||s(l))return l;const p=l.match(/^(.+?)((?:::?[\w-]+(?:\([^)]*\))?)*)\s*$/);if(p){const[,d,h=""]=p,g=d.trim();return g?`${g}[${e}]${h}`:l}return`${l}[${e}]`},i=c=>r(c).split(",").map(p=>o(p)).filter(p=>p.trim()).join(", "),a=c=>c.map(l=>{switch(l.type){case"simple-at-rule":return l.content;case"keyframes":return l.content;case"at-rule":try{const d=t(l.inner),h=a(d);return`${l.rule} { ${h} }`}catch{return l.content}case"rule":if(!l.selector||!l.content)return"";const p=i(l.selector);return p.trim()?`${p} { ${l.content} }`:"";default:return""}}).filter(l=>l.trim()).join(" "),u=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,`
|
|
8
|
+
`),l=t(c),p=a(l);return u(p)}catch(c){return console.error("CSS scoping failed:",c),console.error("Input CSS:",n),n.replace(/\/\*[\s\S]*?\*\//g,"").replace(/(@keyframes\s+[^{]+\s*{[^{}]*(?:{[^}]*}[^{}]*)*})/g,l=>l).replace(/([^{}@]+)(?=\s*{)/g,l=>{const p=l.trim();return!p||p.startsWith("@")||p.includes(`[${e}]`)||s(p)?l:`${p}[${e}]`})}}const pt=750;function Me(n,e,t){let s;typeof n<"u"?s=n.innerWidth||n.document.documentElement.clientWidth:(console.warn("无法获取屏幕宽度,使用默认值375"),s=375);const r=t||pt;return e*s/r}function Oe(n,e){let t=!1,s=!1,r=!1,o="";for(let i=0;i<e.length;i++){const a=e[i];if(a==="'"&&!s&&!r?t=!t:a==='"'&&!t&&!r?s=!s:e.substr(i,4).toLowerCase()==="url("&&!t&&!s?r=!0:a===")"&&r&&(r=!1),!t&&!s&&!r){const u=e.substr(i).match(/^(-?\d+(?:\.\d+)?)\s*rpx/);if(u){const c=u[1],l=parseFloat(c),d=`${Me(n,l).toFixed(6).replace(/\.?0+$/,"")}px`;o+=d,i+=u[0].length-1;continue}}o+=a}return o}function ue(n){return f.isString(n)?n:JSON.stringify(n)}function Q(n,e,t,s=!1){const r=n.CSSStyleSheet,o=s?`data-v-${e}`:e,i=n.__uniConfig?Oe(n,t):t,a=s?Te(i,o):i,u=!!n.__uniConfig;if(r.prototype.replaceSync&&!u){const c=new r;c.id=e,c.replaceSync(a);const l=n.document,p=l.adoptedStyleSheets,d=Array.from(p).filter(h=>h.id!==e);l.adoptedStyleSheets=[...d,c]}else{const c=n.document;let l=c.getElementById(e);l?l.innerHTML=a:(l=c.createElement("style"),l.id=e,l.innerHTML=a,c.head.appendChild(l))}}function ft(n){const e=n.adoptedStyleSheets||[];let t="";if(e.forEach(s=>{try{for(const r of s.cssRules)t+=r.cssText+`
|
|
9
|
+
`}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 Fe(n,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&Q(window,n,t)}function pe(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 fe(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 u of n){const c=s.createElement("script");c.src=u,c.onload=()=>{o=t[e],o?i(o.default||o):a(null)},c.onerror=l=>{a(l)},r.appendChild(c)}})}function De(n){return f.isFunction(n)&&Object.getOwnPropertyNames(n.prototype||{}).length===0||f.isFunction(n?.install)}function xe(n){return je.includes(n)}function ke(n){return le.includes(n)}function k(n=window){const e=window?.Mock;if(e)return e;const t=n?.Mock;if(t&&window)return window.Mock=t,t}function dt(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,(u,c)=>`__self${c}`)),i=o.join(`
|
|
10
10
|
`)+i;const a=r?`
|
|
11
11
|
${i}
|
|
12
|
-
`:`with(${t?"{}":"$scope || {}"}) { ${i} }`;return new Function("$scope",a)(e)}catch(o){if(f.logger.error("parseExpression.error",o,n,e?.__self??e),s)throw o}}function R(n,e,t=!1,s=!1,r=!1){const o=H(n,e,t,s,r);if(typeof o!="function"&&(f.logger.error("parseFunction.error","not a function",n,e?.__self??e),s))throw new Error(`"${n.value}" not a function`);return o}function C(n){return n&&n.type==="JSExpression"}function j(n){return typeof n=="object"&&n&&n.type==="JSFunction"}function xe(n){return C(n)||j(n)}function dt(n){return xe(n)?n.value:JSON.stringify(n)}const ht={session:!1,authKey:"Authorization",storageKey:"ACCESS_STORAGE",storagePrefix:"__VTJ_",unauthorized:void 0,auth:"/#/login",redirectParam:"r",unauthorizedCode:401,unauthorizedMessage:"登录已经失效,请重新登录!",noPermissionMessage:"无权限访问该页面",appName:"",statusKey:"code"},fe=Symbol("access");class Q{options;data=null;mode=S.Raw;interceptResponse=!0;isTipShowing=!1;constructor(e){this.options=Object.assign({},ht,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!==S.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&&(f.storage.save(t,e,{type:"local",prefix:s}),r&&f.cookie.set(o,this.data.token))}clear(){const{storageKey:e,storagePrefix:t,session:s,authKey:r}=this.options;this.data=null,f.storage.remove(e,{type:"local",prefix:t}),s&&f.cookie.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):f.toArray(e).every(o=>s[o]||s[t+"."+o])}some(e){const{appName:t}=this.options,{permissions:s={}}=this.data||{};return f.toArray(e).some(o=>s[o]||s[t+"."+o])}install(e){e.config.globalProperties.$access=this,e.provide(fe,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=>f.unRSA(r,t));try{this.data=JSON.parse(s.join(""))}catch(r){console.warn(r)}return}if(typeof e=="string")try{const s=t?f.unRSA(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=f.storage.get(e,{type:"local",prefix:t});this.setData(s||null)}isLogined(){const{session:e,authKey:t}=this.options;return e&&t?!!f.cookie.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__):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),f.isFunction(r)?(r(),t(!1)):f.isString(r)?t(r):t(!1)}}t(!1),await f.delay(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 f.delay(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 He(){return b.inject(fe,null)}function mt(n={}){const{notify:e,loading:t,settings:s={},Startup:r,access:o,useTitle:i,alert:a}=n;let u=null;return{request:f.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:l=>l.data?.code===0||!!l.data?.success,failMessage:!0,showError:l=>{e&&e(l||"未知错误")},showLoading:()=>{u&&u.close(),t&&(u=t())},hideLoading:()=>{u&&(u.close(),u=null)},...s}}),jsonp:f.jsonp,notify:e,loading:t,useTitle:i,alert:a,startupComponent:r,access:o?new Q({alert:a,...o}):void 0}}function gt(n={}){return new Q(n)}function Ne(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(f.merge(o,a||{},{data:i})))}}function Le(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 Ue(n=[],e=[],t){const s={};for(const r of n){const o=Ne(r,t);s[r.id]=o,s[r.name]=o}for(const r of e)s[r.id]=Le(r,t);return s}async function Be(n=[],e=window){const t=x(e);t&&(de(e),n.forEach(s=>Je(t,s)))}function qe(n,e=window){const t=j(n.mockTemplate)&&n.mockTemplate.value?R(n.mockTemplate,{},!0):void 0,s=x(e);return async(...r)=>{let o={};if(t)try{o=await t.apply(t,r)}catch(i){f.logger.warn("模拟数据模版异常",i)}return s?.mock(o)}}function Je(n,e){if(!e.mock)return;const{url:t,mockTemplate:s}=e;if(t&&s)try{const r=f.isUrl(t)?new URL(t).pathname:t,o=f.pathToRegexp(`(.*)${r}(.*)`),i=f.pathToRegexpMatch(r,{decode:decodeURIComponent}),a=H(s,{},!0);n.mock(o,u=>{const c=f.url.parse(u.url)||{},l=u.body instanceof FormData?f.formDataToJson(u.body):u.body,p=f.isUrl(u.url)?new URL(u.url).pathname:u.url.split("?")[0],d=i(p)?.params;Object.assign(u,{data:l,params:d,query:c});try{return n.mock(a(u))}catch(h){return console.warn("[mockApi]",o,u,h),null}})}catch(r){console.warn("mockApi",r)}}function de(n=window){const e=x(n);e&&(e._mocked={})}class Ke{__id=null;__mode;__instance=null;__contextRefs={};__refs={};__refCaches={};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=V){const s=t.getCurrentInstance();if(!s)return;this.__refs={},this.__refCaches={},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&&oe.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){oe.forEach(e=>{this[e]=null}),this.__reset()}__reset(){this.__refs={},this.__refCaches={},this.$refs={},this.__contextRefs={},this.context={}}__parseFunction(e){if(e)if(this.__mode===S.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===S.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===S.VNode)return;e&&e!==this.__id&&(this.__contextRefs[e]=this);let s=e?this.__refCaches[e]:null;return s||(s=async r=>{await f.delay(0);let o=r?.$vtjEl||r?.$el||r?._?.vnode?.el||r;if(!o){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}return o.nodeType===3&&o.nextSibling&&(o=o.nextSibling),o.__vtj__=e,S.Design===this.__mode&&(o.__context__=this,o.draggable=!0),e&&(this.__refs[e]=this.__getRefEl(this.__refs,e,r)),typeof t=="function"?t(r):t&&(this.$refs[t]=this.__getRefEl(this.$refs,t,r)),r},e&&(this.__refCaches[e]=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 G(n){const{Vue:e=V,mode:t=S.Runtime,components:s={},libs:r={},apis:o={},loader:i}=n,a=e.computed(()=>n.dsl),u={$components:s,$libs:r,$apis:o},c=new Ke({mode:t,dsl:a.value,attrs:u}),l=e.defineComponent({name:a.value.name,__scopeId:a.value.id?`data-v-${a.value.id}`:void 0,props:{...vt(a.value.props??[],c)},async setup(p){c.$props=p,c.props=p,a.value.id&&W(n.window||window,a.value.id,a.value.css||"",!0),c.state=yt(e,a.value.state??{},c);const d=St(e,a.value.computed??{},c),h=wt(a.value.methods??{},c),g=Et(e,a.value.inject,c);for(const[v,w]of Object.entries(g||{}))g[v]=e.inject(v,w);const m=Ge(a.value.dataSources||{},c),_={...g,...d,...h,...m};return c.setup(_,e),$t(e,a.value.watch??[],c),{vtj:c,state:c.state,...d,...h}},emits:_t(a.value.emits),expose:["vtj",...a.value.expose||[]],render(){if(!a.value.nodes)return null;const p=a.value.nodes||[];if(p.length===1)return F(p[0],c,e,i,p);{const d=p.map(h=>F(h,c,e,i,p));return e.createVNode("div",{},d)}},...bt(a.value.lifeCycles??{},c)});return{renderer:e.markRaw(l),context:c}}function _t(n=[]){return n.map(e=>f.isString(e)?e:e.name)}function vt(n=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(o=>$e[o]):void 0;return n.map(s=>f.isString(s)?{name:s}:{name:s.name,type:s.type,required:s.required,default:C(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 yt(n,e,t){return n.reactive(Object.keys(e||{}).reduce((s,r)=>{let o=e[r];return C(o)?o=t.__parseExpression(o):j(o)&&(o=t.__parseFunction(o)),s[r]=o,s},{}))}function St(n,e,t){return Object.entries(e??{}).reduce((s,[r,o])=>(s[r]=n.computed(t.__parseFunction(o)),s),{})}function wt(n,e){return Object.entries(n??{}).reduce((t,[s,r])=>(t[s]=e.__parseFunction(r),t),{})}function Et(n,e=[],t){return e.reduce((s,r)=>{const{name:o,from:i}=r||{};r.default;const a=C(i)?t.__parseExpression(i)||o:i??o,u=C(r.default)?t.__parseExpression(r.default):r.default??null;return s[o]=n.inject(a,u),s},{})}function Ge(n,e){return Object.keys(n).reduce((t,s)=>{const r=n[s];if(r.type==="mock")t[s]=qe(r);else if(r.ref){const o=e.$apis[r.ref],i=j(r.transform)?r.transform.value?e.__parseFunction(r.transform):void 0:r.transform;t[s]=async(...a)=>{const u=await o.apply(e,a);return i?i(u):u}}return t},{})}function $t(n,e=[],t){e.forEach(s=>{n.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function bt(n,e){return Object.entries(n??{}).reduce((t,[s,r])=>{const o=e.__parseFunction(r);return t[s]=async()=>{f.isFunction(o)&&(await f.delay(0),await o())},t},{})}class jt{__props={};__events={};__nodes={};constructor(){}setProps(e,t){this.__props[e]=t}getProps(e){return this.__props[e]}setEvents(e,t){}getEvents(e){return this.__events[e]}setNode(e,t){this.__nodes[e]=t}getNode(e){return this.__nodes[e]}isEqual(e,t){return f.isEqual(e,t)}clear(){this.__props={},this.__events={},this.__nodes={}}}const I=new jt,ze=new f.Queue;let se=[],O={},L={};const Ve=(n,e)=>e;async function he(n,e=window){const{urls:t=[],library:s}=n,r=t.filter(a=>J(a));if(r.length===0||!s)return null;const o=t.filter(a=>q(a));return o.length&&ue(o,e),await pe(r,s,e).catch(a=>(console.warn("loadScriptUrl error",r,s,a),null))}function z(n){const{getDsl:e,getDslByUrl:t,options:s}=n;return s.window&&(se.forEach(r=>{delete s.window[r]}),se=[]),(r,o,i,a=V)=>{if(!i||typeof i=="string")return o;let u="";if(i.type==="Schema"&&i.id)return u=i.id+"_"+r,L[u]||(L[u]=a.defineAsyncComponent(async()=>{const c=O[i.id]||await ze.add(i.id,()=>e(i.id));return c&&(c.name=o,O[i.id]=c),c?G({Vue:a,mode:S.Runtime,...s,dsl:f.cloneDeep(c),loader:z(n)}).renderer:null}));if(i.type==="UrlSchema"&&i.url)return u=i.url+"_"+r,L[u]||(L[u]=a.defineAsyncComponent(async()=>{const c=O[i.url]||await t(i.url);return c&&(c.name=o,O[i.url]=c),c?G({...s,Vue:a,dsl:f.cloneDeep(c),mode:S.Runtime,loader:z(n)}).renderer:null}));if(i.type==="Plugin"){let c=i.library?O[i.library]:null;return c||(i.library&&se.push(i.library),c=O[i.library||Symbol()]=a.defineAsyncComponent(async()=>{const l=await he(i,s.window);return l||(console.warn("getPlugin result is null",i),null)}),c)}return o}}function Ct(){O={},L={},ze.clearAllCache(),I.clear()}function F(n,e,t=V,s=Ve,r=[],o=!1){if(!n||!n.name||n.invisible)return null;const i=t.getCurrentInstance()?.appContext,{id:a=null,directives:u=[]}=n,{vIf:c,vElseIf:l,vElse:p,vFor:d,vShow:h,vModels:g,vBind:m,vHtml:_,others:v}=We(u);if(!o&&(l||p))return null;if(c&&!Pt(c,e))return Ot(n,e,t,s,r);const w=(y,E=0)=>{const T=y.$components,X=(()=>{if(n.name==="component")return At(y,n.props?.is);if(n.name==="slot")return n.name;const P=s(`${n.id}_${E}`,n.name,n.from,t);return f.isString(P)?ke(P)||De(P)?P:T[P]??i?.app?.component(P)??P:P})(),A=It(a,n.props??{},y),et=Mt(t,n.id,n.events??{},y);if(n.name==="slot")return Ft(t,n,A,y,s);m&&Object.assign(A,y.__parseExpression(m.value)),h&&(A.style=Object.assign(A.style??{},Dt(h,y))),_&&Object.assign(A,xt(_,y)),g.forEach(P=>{ce.includes(n.name)?Object.assign(A,Ht(P,y)):Object.assign(A,Nt(t,P,y))});const tt=Lt(t,n.children??[],y,s,n),ye=y?.__id?`data-v-${y.__id}`:void 0,st=ye?{[ye]:""}:{},nt=y.__mode===S.Design?{"data-vtj":a}:{},Z=`${a}_${E}`,ee={key:`${a}_${E}`,...st,...nt,...A,...et};I.isEqual(ee,I.getNode(Z))||I.setNode(Z,ee);let te=t.createVNode(X,I.getNode(Z)||ee||{},tt);const Se=i?Rt(i,v,y):[];return Se.length&&(te=t.withDirectives(te,Se)),te};return d?qt(d,w,e):w(e)}function Rt(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 We(n=[]){const e=n.find(l=>f.camelCase(l.name)==="vIf"),t=n.find(l=>f.camelCase(l.name)==="vElseIf"),s=n.find(l=>f.camelCase(l.name)==="vElse"),r=n.find(l=>f.camelCase(l.name)==="vFor"),o=n.find(l=>f.camelCase(l.name)==="vShow"),i=n.find(l=>f.camelCase(l.name)==="vBind"),a=n.find(l=>f.camelCase(l.name)==="vHtml"),u=n.filter(l=>f.camelCase(l.name)==="vModel"),c=n.filter(l=>!Ee.includes(f.camelCase(l.name)));return{vIf:e,vElseIf:t,vElse:s,vFor:r,vShow:o,vModels:u,vBind:i,others:c,vHtml:a}}function Pt(n,e){return!!e.__parseExpression(n.value)}function At(n,e){return e?C(e)?n.__parseExpression(e):e:"div"}function It(n,e,t){const s=n?I.getProps(n):null;if(s)return s;const r=ie(e,t);return r.ref=t.__ref(n,r.ref),n&&I.setProps(n,r),r}function ie(n,e){return C(n)?e.__parseExpression(n):j(n)?e.__parseFunction(n):Array.isArray(n)?n.map(t=>ie(t,e)):typeof n=="object"?Object.keys(n||{}).reduce((t,s)=>{let r=n[s];return t[s]=ie(r,e),t},{}):n}function Tt(n,e){return t=>{t?.key?.toLowerCase()===e.toLowerCase()&&n(t)}}function Mt(n,e,t,s){const r=e?I.getEvents(e):null;if(r)return r;const o=["passive","capture","once"],i={capture:"Capture",once:"Once",passive:"OnceCapture"},a=Object.keys(t||{}).reduce((u,c)=>{const l=t[c],p=me(l.modifiers),d=p.find(m=>o.includes(m)),h="on"+f.upperFirstCamelCase(c)+(d&&i[d]||""),g=s.__parseFunction(l.handler);return g&&(u[h]=n.withModifiers(p.includes("enter")?Tt(g,"enter"):g,p)),u},{});return e&&I.setEvents(e,a),a}function Ot(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:u,vElse:c}=We(a);if(u){if(e.__parseExpression(u.value))return F(r[i],e,t,s,r,!0);continue}if(c)return F(r[i],e,t,s,r,!0)}return null}function me(n={},e=!1){const t=Object.keys(n);return e?t.map(s=>"."+s):t}function Ft(n,e,t,s,r){const{children:o}=e,i=kt(e,s),a=s.$slots?.[i.name];return a?a(t):o?f.isString(o)?n.createTextVNode(o):C(o)?n.createTextVNode(le(s.__parseExpression(o))):Array.isArray(o)?o.map(u=>F(u,s,n,r,o)):null:null}function kt(n,e){const{props:t}=n,s=t?.name||"default";return{name:C(s)?e.__parseExpression(s):s,params:[]}}function Dt(n,e){return e.__parseExpression(n.value)?{}:{display:"none"}}function xt(n,e){return{innerHTML:e.__parseExpression(n.value)||""}}function Ht(n,e){const t={type:"JSFunction",value:n.value?.value?`(v) => {
|
|
12
|
+
`:`with(${t?"{}":"$scope || {}"}) { ${i} }`;return new Function("$scope",a)(e)}catch(o){if(f.logger.error("parseExpression.error",o,n,e?.__self??e),s)throw o}}function R(n,e,t=!1,s=!1,r=!1){const o=H(n,e,t,s,r);if(typeof o!="function"&&(f.logger.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 b(n){return typeof n=="object"&&n&&n.type==="JSFunction"}function He(n){return j(n)||b(n)}function ht(n){return He(n)?n.value:JSON.stringify(n)}const mt={session:!1,authKey:"Authorization",storageKey:"ACCESS_STORAGE",storagePrefix:"__VTJ_",unauthorized:void 0,auth:"/#/login",redirectParam:"r",unauthorizedCode:401,unauthorizedMessage:"登录已经失效,请重新登录!",noPermissionMessage:"无权限访问该页面",appName:"",statusKey:"code"},de=Symbol("access");class Y{options;data=null;mode=S.Raw;interceptResponse=!0;isTipShowing=!1;constructor(e){this.options=Object.assign({},mt,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!==S.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&&(f.storage.save(t,e,{type:"local",prefix:s}),r&&f.cookie.set(o,this.data.token))}clear(){const{storageKey:e,storagePrefix:t,session:s,authKey:r}=this.options;this.data=null,f.storage.remove(e,{type:"local",prefix:t}),s&&f.cookie.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):f.toArray(e).every(o=>s[o]||s[t+"."+o])}some(e){const{appName:t}=this.options,{permissions:s={}}=this.data||{};return f.toArray(e).some(o=>s[o]||s[t+"."+o])}install(e){e.config.globalProperties.$access=this,e.provide(de,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=>f.unRSA(r,t));try{this.data=JSON.parse(s.join(""))}catch(r){console.warn(r)}return}if(typeof e=="string")try{const s=t?f.unRSA(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=f.storage.get(e,{type:"local",prefix:t});this.setData(s||null)}isLogined(){const{session:e,authKey:t}=this.options;return e&&t?!!f.cookie.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),f.isFunction(r)?(r(),t(!1)):f.isString(r)?t(r):t(!1)}}t(!1),await f.delay(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 f.delay(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 Ne(){return $.inject(de,null)}function gt(n={}){const{notify:e,loading:t,settings:s={},Startup:r,access:o,useTitle:i,alert:a}=n;let u=null;return{request:f.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:l=>l.data?.code===0||!!l.data?.success,failMessage:!0,showError:l=>{e&&e(l||"未知错误")},showLoading:()=>{u&&u.close(),t&&(u=t())},hideLoading:()=>{u&&(u.close(),u=null)},...s}}),jsonp:f.jsonp,notify:e,loading:t,useTitle:i,alert:a,startupComponent:r,access:o?new Y({alert:a,...o}):void 0}}function _t(n={}){return new Y(n)}function Le(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(f.merge(o,a||{},{data:i})))}}function Ue(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 qe(n=[],e=[],t){const s={};for(const r of n){const o=Le(r,t);s[r.id]=o,s[r.name]=o}for(const r of e)s[r.id]=Ue(r,t);return s}async function Be(n=[],e=window){const t=k(e);t&&(he(e),n.forEach(s=>Ke(t,s)))}function Je(n,e=window){const t=b(n.mockTemplate)&&n.mockTemplate.value?R(n.mockTemplate,{},!0):void 0,s=k(e);return async(...r)=>{let o={};if(t)try{o=await t.apply(t,r)}catch(i){f.logger.warn("模拟数据模版异常",i)}return s?.mock(o)}}function Ke(n,e){if(!e.mock)return;const{url:t,mockTemplate:s}=e;if(t&&s)try{const r=f.isUrl(t)?new URL(t).pathname:t,o=f.pathToRegexp(`(.*)${r}(.*)`),i=f.pathToRegexpMatch(r,{decode:decodeURIComponent}),a=H(s,{},!0);n.mock(o,u=>{const c=f.url.parse(u.url)||{},l=u.body instanceof FormData?f.formDataToJson(u.body):u.body,p=f.isUrl(u.url)?new URL(u.url).pathname:u.url.split("?")[0],d=i(p)?.params;Object.assign(u,{data:l,params:d,query:c});try{return n.mock(a(u))}catch(h){return console.warn("[mockApi]",o,u,h),null}})}catch(r){console.warn("mockApi",r)}}function he(n=window){const e=k(n);e&&(e._mocked={})}class Ge{__id=null;__mode;__instance=null;__contextRefs={};__refs={};__refCaches={};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=W){const s=t.getCurrentInstance();if(!s)return;this.__refs={},this.__refCaches={},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&&ie.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){ie.forEach(e=>{this[e]=null}),this.__reset()}__reset(){this.__refs={},this.__refCaches={},this.$refs={},this.__contextRefs={},this.context={}}__parseFunction(e){if(e)if(this.__mode===S.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===S.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===S.VNode)return;e&&e!==this.__id&&(this.__contextRefs[e]=this);let s=e?this.__refCaches[e]:null;return s||(s=async r=>{await f.delay(0);let o=r?.$vtjEl||r?.$el||r?._?.vnode?.el||r;if(!o){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}return o.nodeType===3&&o.nextSibling&&(o=o.nextSibling),o.__vtj__=e,S.Design===this.__mode&&(o.__context__=this,o.draggable=!0),e&&(this.__refs[e]=this.__getRefEl(this.__refs,e,r)),typeof t=="function"?t(r):t&&(this.$refs[t]=this.__getRefEl(this.$refs,t,r)),r},e&&(this.__refCaches[e]=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 z(n){const{Vue:e=W,mode:t=S.Runtime,components:s={},libs:r={},apis:o={},loader:i}=n,a=e.computed(()=>n.dsl),u={$components:s,$libs:r,$apis:o},c=new Ge({mode:t,dsl:a.value,attrs:u}),l=e.defineComponent({name:a.value.name,__scopeId:a.value.id?`data-v-${a.value.id}`:void 0,props:{...yt(a.value.props??[],c)},async setup(p){c.$props=p,c.props=p,a.value.id&&Q(n.window||window,a.value.id,a.value.css||"",!0),c.state=St(e,a.value.state??{},c);const d=wt(e,a.value.computed??{},c),h=Et(a.value.methods??{},c),g=$t(e,a.value.inject,c);for(const[y,w]of Object.entries(g||{}))g[y]=e.inject(y,w);const m=ze(a.value.dataSources||{},c),_={...g,...d,...h,...m};return c.setup(_,e),bt(e,a.value.watch??[],c),{vtj:c,state:c.state,...d,...h}},emits:vt(a.value.emits),expose:["vtj",...a.value.expose||[]],render(){if(!a.value.nodes)return null;const p=a.value.nodes||[];if(p.length===1)return O(p[0],c,e,i,p);{const d=p.map(h=>O(h,c,e,i,p));return e.createVNode("div",{},d)}},...jt(a.value.lifeCycles??{},c)});return{renderer:e.markRaw(l),context:c}}function vt(n=[]){return n.map(e=>f.isString(e)?e:e.name)}function yt(n=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(o=>be[o]):void 0;return n.map(s=>f.isString(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 St(n,e,t){return n.reactive(Object.keys(e||{}).reduce((s,r)=>{let o=e[r];return j(o)?o=t.__parseExpression(o):b(o)&&(o=t.__parseFunction(o)),s[r]=o,s},{}))}function wt(n,e,t){return Object.entries(e??{}).reduce((s,[r,o])=>(s[r]=n.computed(t.__parseFunction(o)),s),{})}function Et(n,e){return Object.entries(n??{}).reduce((t,[s,r])=>(t[s]=e.__parseFunction(r),t),{})}function $t(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,u=j(r.default)?t.__parseExpression(r.default):r.default??null;return s[o]=n.inject(a,u),s},{})}function ze(n,e){return Object.keys(n).reduce((t,s)=>{const r=n[s];if(r.type==="mock")t[s]=Je(r);else if(r.ref){const o=e.$apis[r.ref],i=b(r.transform)?r.transform.value?e.__parseFunction(r.transform):void 0:r.transform;t[s]=async(...a)=>{const u=await o.apply(e,a);return i?i(u):u}}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 jt(n,e){return Object.entries(n??{}).reduce((t,[s,r])=>{const o=e.__parseFunction(r);return t[s]=async()=>{f.isFunction(o)&&(await f.delay(0),await o())},t},{})}class Ct{__props={};__events={};__nodes={};constructor(){}setProps(e,t){this.__props[e]=t}getProps(e){return this.__props[e]}loadProps(e,t){const s=e?this.getProps(e):null;return s||(e&&this.setProps(e,t),t)}setEvents(e,t){}getEvents(e){return this.__events[e]}loadEvents(e,t){const s=e?this.getEvents(e):null;return s||(e&&this.setEvents(e,t),t)}setNode(e,t){this.__nodes[e]=t}getNode(e){return this.__nodes[e]}loadNode(e,t){const s=e?this.getNode(e):null;return s||(e&&this.setNode(e,t),t)}isEqual(e,t){return f.isEqual(e,t)}clear(){this.__props={},this.__events={},this.__nodes={}}}const F=new Ct,Ve=new f.Queue;let ne=[],M={},L={};const We=(n,e)=>e;async function me(n,e=window){const{urls:t=[],library:s}=n,r=t.filter(a=>J(a));if(r.length===0||!s)return null;const o=t.filter(a=>B(a));return o.length&&pe(o,e),await fe(r,s,e).catch(a=>(console.warn("loadScriptUrl error",r,s,a),null))}function V(n){const{getDsl:e,getDslByUrl:t,options:s}=n;return s.window&&(ne.forEach(r=>{delete s.window[r]}),ne=[]),(r,o,i,a=W)=>{if(!i||typeof i=="string")return o;let u="";if(i.type==="Schema"&&i.id)return u=i.id+"_"+r,L[u]||(L[u]=a.defineAsyncComponent(async()=>{const c=M[i.id]||await Ve.add(i.id,()=>e(i.id));return c&&(c.name=o,M[i.id]=c),c?z({Vue:a,mode:S.Runtime,...s,dsl:f.cloneDeep(c),loader:V(n)}).renderer:null}));if(i.type==="UrlSchema"&&i.url)return u=i.url+"_"+r,L[u]||(L[u]=a.defineAsyncComponent(async()=>{const c=M[i.url]||await t(i.url);return c&&(c.name=o,M[i.url]=c),c?z({...s,Vue:a,dsl:f.cloneDeep(c),mode:S.Runtime,loader:V(n)}).renderer:null}));if(i.type==="Plugin"){let c=i.library?M[i.library]:null;return c||(i.library&&ne.push(i.library),c=M[i.library||Symbol()]=a.defineAsyncComponent(async()=>{const l=await me(i,s.window);return l||(console.warn("getPlugin result is null",i),null)}),c)}return o}}function Rt(){M={},L={},Ve.clearAllCache(),F.clear()}function O(n,e,t=W,s=We,r=[],o=!1,i=0){if(!n||!n.name||n.invisible)return null;const a=t.getCurrentInstance()?.appContext,{id:u=null,directives:c=[]}=n,{vIf:l,vElseIf:p,vElse:d,vFor:h,vShow:g,vModels:m,vBind:_,vHtml:y,others:w}=Qe(c);if(!o&&(p||d))return null;if(l&&!At(l,e))return Ft(n,e,t,s,r);const C=(v,A=0)=>{const Z=v.$components,ee=(()=>{if(n.name==="component")return It(v,n.props?.is);if(n.name==="slot")return n.name;const P=s(`${n.id}_${A}`,n.name,n.from,t);return f.isString(P)?xe(P)||ke(P)?P:Z[P]??a?.app?.component(P)??P:P})(),I=Tt(u,n.props??{},v),tt=Ot(t,n.id,n.events??{},v);if(n.name==="slot")return Dt(t,n,I,v,s);_&&Object.assign(I,v.__parseExpression(_.value)),g&&(I.style=Object.assign(I.style??{},kt(g,v))),y&&Object.assign(I,Ht(y,v)),m.forEach(P=>{le.includes(n.name)?Object.assign(I,Nt(P,v)):Object.assign(I,Lt(t,P,v))});const st=Ut(t,n.children??[],v,s,n),Se=v?.__id?`data-v-${v.__id}`:void 0,nt=Se?{[Se]:""}:{},rt=v.__mode===S.Design?{"data-vtj":u}:{},K=`${u}_${A}`,te={key:K,...nt,...rt,...I,...tt};F.isEqual(te,F.getNode(K))||F.setNode(K,te);let se=t.createVNode(ee,F.getNode(K)||te||{},st);const we=a?Pt(a,w,v):[];return we.length&&(se=t.withDirectives(se,we)),se};return h?Jt(h,C,e):C(e,i)}function Pt(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 Qe(n=[]){const e=n.find(l=>f.camelCase(l.name)==="vIf"),t=n.find(l=>f.camelCase(l.name)==="vElseIf"),s=n.find(l=>f.camelCase(l.name)==="vElse"),r=n.find(l=>f.camelCase(l.name)==="vFor"),o=n.find(l=>f.camelCase(l.name)==="vShow"),i=n.find(l=>f.camelCase(l.name)==="vBind"),a=n.find(l=>f.camelCase(l.name)==="vHtml"),u=n.filter(l=>f.camelCase(l.name)==="vModel"),c=n.filter(l=>!$e.includes(f.camelCase(l.name)));return{vIf:e,vElseIf:t,vElse:s,vFor:r,vShow:o,vModels:u,vBind:i,others:c,vHtml:a}}function At(n,e){return!!e.__parseExpression(n.value)}function It(n,e){return e?j(e)?n.__parseExpression(e):e:"div"}function Tt(n,e,t){const s=ae(e,t);return s.ref=t.__ref(n,s.ref),s}function ae(n,e){return j(n)?e.__parseExpression(n):b(n)?e.__parseFunction(n):Array.isArray(n)?n.map(t=>ae(t,e)):typeof n=="object"?Object.keys(n||{}).reduce((t,s)=>{let r=n[s];return t[s]=ae(r,e),t},{}):n}function Mt(n,e){return t=>{t?.key?.toLowerCase()===e.toLowerCase()&&n(t)}}function Ot(n,e,t,s){const r=["passive","capture","once"],o={capture:"Capture",once:"Once",passive:"OnceCapture"};return Object.keys(t||{}).reduce((a,u)=>{const c=t[u],l=ge(c.modifiers),p=l.find(g=>r.includes(g)),d="on"+f.upperFirstCamelCase(u)+(p&&o[p]||""),h=s.__parseFunction(c.handler);return h&&(a[d]=n.withModifiers(l.includes("enter")?Mt(h,"enter"):h,l)),a},{})}function Ft(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:u,vElse:c}=Qe(a);if(u){if(e.__parseExpression(u.value))return O(r[i],e,t,s,r,!0);continue}if(c)return O(r[i],e,t,s,r,!0)}return null}function ge(n={},e=!1){const t=Object.keys(n);return e?t.map(s=>"."+s):t}function Dt(n,e,t,s,r){const{children:o}=e,i=xt(e,s),a=s.$slots?.[i.name];return a?a(t):o?f.isString(o)?n.createTextVNode(o):j(o)?n.createTextVNode(ue(s.__parseExpression(o))):Array.isArray(o)?o.map((u,c)=>O(u,s,n,r,o,!1,c)):null:null}function xt(n,e){const{props:t}=n,s=t?.name||"default";return{name:j(s)?e.__parseExpression(s):s,params:[]}}function kt(n,e){return e.__parseExpression(n.value)?{}:{display:"none"}}function Ht(n,e){return{innerHTML:e.__parseExpression(n.value)||""}}function Nt(n,e){const t={type:"JSFunction",value:n.value?.value?`(v) => {
|
|
13
13
|
${n.value.value} = v?.target.value;
|
|
14
|
-
}`:"(v) => {}"};return{[
|
|
14
|
+
}`:"(v) => {}"};return{[j(n.arg)?e.__parseExpression(n.arg):n.arg||"value"]:e.__parseExpression(n.value),onInput:e.__parseFunction(t)}}function Lt(n,e,t){const s={type:"JSFunction",value:e.value?.value?`(v) => {
|
|
15
15
|
${e.value.value} = v;
|
|
16
|
-
}`:"(v) => {}"},r=t.__parseFunction(s),o=me(C(e.modifiers)?t.__parseExpression(e.modifiers):e.modifiers),i=C(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 Lt(n,e,t,s,r){if(!e)return null;if(f.isString(e))return{default:()=>e};if(C(e))return{default:()=>le(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const o=Ut(e),i=(a,u)=>!a||!r?{}:r?.id&&Object.keys(a).length?u?{[u]:a}:{[`scope_${r.id}`]:a}:u?{[u]:Object.create(null)}:{};return Object.entries(o).reduce((a,[u,{nodes:c,params:l,scope:p}])=>(a[u]=d=>{const h=l.length?f.pick(d??{},l):i(d,p);return c.map(g=>F(g,t.__clone(h),n,s,c))},a),{})}return null}function Ut(n){const e={};for(const t of n){const s=Bt(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 Bt(n="default"){return f.isString(n)?{name:n,params:[],scope:""}:{params:[],scope:"",...n}}function qt(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((u,c)=>c+1)),Array.isArray(a)?a.map((u,c)=>e(t.__clone({[o]:u,[i]:c}),c)):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const ne=b.defineComponent({name:"VtjPageContainer",async setup(){const n=ve(),e=we.useRoute(),t=e.meta.__vtj__||e.params.id,s=t?n.getPage(t):n.getHomepage(),r=s?await n.getRenderComponent(s.id):null,o=b.ref(Symbol());if(s){Object.assign(e.meta,s.meta||{},{cache:s.cache});const{useTitle:i}=n?.adapter;if(i){const a=e.meta.title||s.title||"VTJ.PRO";i(a)}}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?b.h(n,{...e,key:t}):b.h("div",{style:{padding:"10px"}},"找不到组件,组件不存在或未发布!")},activated(){this.meta.cache===!1&&(this.sid=Symbol())}}),Jt=b.defineComponent({name:"VtjStartupContainer",render(){return b.h("div","page not found!")}});function B(n,e,t=[]){const s=[];for(const r of t){const{id:o,title:i,icon:a,children:u,hidden:c,layout:l}=r;if(l){const p=B(n,e,u||[]);s.push(...p)}else{const p={id:o,title:i,icon:a,hidden:c,url:`${n}/${e}/${o}`,children:u&&u.length?B(n,e,u):void 0};s.push(p)}}return s}function ge(n,e){if(!e)return n;let t=[];for(const s of n)if(s.children&&s.children.length){const r=ge(s.children,e);r.length&&(s.children=r,t.push(s))}else e.can(s.id.toString())&&t.push(s);return t}function Kt(n){const{menuPathPrefix:e="",pageRouteName:t="page",disableMenusFilter:s=!1}=n||{},r=ve(),o=we.useRoute(),i=He(),a=b.ref(!1),u=b.ref(!1),c=r.project,l=(h,g)=>{a.value=!h?.mask,u.value=g?.pure??!!h?.pure};b.watchEffect(()=>{const{name:h,params:g,meta:m}=o;if(h===D){const _=r.getPage(g.id);l(_,m)}else if(h===U){const _=r.getHomepage();l(_,m)}else{const _=m.__vtj__;if(_){const v=r.getPage(_);l(v,m)}else a.value=!m.mask,u.value=!!m.pure}});const p=B(e,t,c?.pages),d=c?.config;return{disabled:a,logo:d?.logo,themeSwitchable:d?.themeSwitchable,title:d?.title||c?.description||c?.name||"VTJ App",menus:s?p:ge(p,i),pure:u}}function re(n,e){const{id:t,title:s,meta:r}=n,{name:o="page",prefix:i="",component:a,routeMeta:u}=e;return{name:t,path:`${i}${o}/${t}`,component:a,meta:{title:s,...u,...r,__vtj__:t}}}function ae(n){const{name:e="page",prefix:t="",pages:s=[],component:r,loader:o,routeMeta:i,homepage:a}=n,u=[];for(const c of s){const{id:l,title:p,dir:d,layout:h,children:g,meta:m}=c;if(d){const _=ae({name:e,prefix:t,component:r,routeMeta:i,homepage:a,loader:o,pages:g||[]});u.push(..._)}else if(h){const _=ae({name:e,prefix:t,component:r,routeMeta:i,homepage:a,loader:o,pages:g||[]}),v={name:`layout_${l}`,path:t,component:()=>o(l),meta:{title:p,...i,...m,__vtj__:l},children:_};u.push(v),u.push(re(c,n))}else if(u.push(re(c,n)),a===l){const _=re(c,n);_.path="",_.name=`home_${l}`,u.push(_)}}return u}function Gt(n={},e){const{css:t,store:s,enhance:r}=n,{window:o,app:i,library:a={},adapter:u,mode:c}=e,{Pinia:l}=a;i.config.globalProperties.$libs=a,W(o,"global-css",t||""),l&&s&&zt(s,i,l),Wt(i,u,n),!u.access&&n.access&&Vt(n.access,i,c,u),Qt(i,n),r&&Yt(r,i,a)}function zt(n,e,t){const s=t.createPinia();if(e.use(s),j(n)&&n.value){const r=R(n,{},!1,!1,!0),o=t.defineStore("$store",r(e)||{});e.config.globalProperties.$store=o()}}function Vt(n,e,t,s){if(j(n)&&n.value){const r=R(n,{},!1,!1,!0),{alert:o,request:i}=s,a=new Q({alert:o,storagePrefix:"__VTJ_APP_",...r(e)}),u=e.config.globalProperties.$router;a.connect({mode:t,router:u,request:i}),e.use(a)}}function Wt(n,e,t){if(!e.request)return;const{axios:s,request:r,response:o}=t;if(s&&j(s)&&s.value){const i=R(s,{},!1,!1,!0);e.request.setConfig(i(n))}if(r&&j(r)&&r.value){const i=R(r,{},!1,!1,!0),a=e.request;a.__unReq&&a.__unReq(),a.__unReq=e.request.useRequest(u=>i(u,n))}if(o&&j(o)&&o.value){const i=R(o,{},!1,!1,!0),a=e.request;a.__unRes&&a.__unRes(),a.__unRes=e.request.useResponse(u=>i(u,n))}}function Qt(n,e){const{beforeEach:t,afterEach:s}=e,r=n.config.globalProperties.$router;if(t&&j(t)&&t.value){const o=R(t,{},!1,!1,!0);r&&r.beforeEach((i,a,u)=>o(i,a,u,n))}if(s&&j(s)&&s.value){const o=R(s,{},!1,!1,!0);r&&r.afterEach((i,a,u)=>o(i,a,u,n))}}function Yt(n,e,t={}){j(n)&&n.value&&R(n,{},!1,!1,!0)(e,t)}function Xt(n,e,t){if(!n||!e||!t)return;const{VueI18n:s}=e;if(s){const{locale:r,fallbackLocale:o,messages:i=[]}=t,a={};for(let c of i){const l=Object.keys(c).filter(p=>p!=="key");for(const p of l)a[p]||(a[p]={}),a[p][c.key]=c[p]}const u=s.createI18n({legacy:!1,locale:r,fallbackLocale:o,messages:a});n.use(u)}}const _e=Symbol("Provider");var Qe=(n=>(n.Production="production",n.Development="development",n))(Qe||{});class Ye extends M.Base{constructor(e){super(),this.options=e;const{service:t,mode:s=S.Raw,dependencies:r,materials:o,project:i={},adapter:a={},globals:u={},modules:c={},router:l=null,materialPath:p="./",nodeEnv:d="development"}=e;this.mode=s,this.modules=c,this.service=t,this.router=l,this.materialPath=p,this.nodeEnv=d,r&&(this.dependencies=r),o&&(this.materials=o),Object.assign(this.globals,u),Object.assign(this.adapter,a);const{access:h,request:g}=this.adapter;h&&h.connect({mode:s,router:l,request:g}),i&&s!==S.Design?this.load(i):this.project=i}mode;globals={};modules={};adapter={request:f.request,jsonp:f.jsonp};apis={};dependencies={};materials={};library={};libraryLocales={};libraryLocaleMap={};service;project=null;components={};nodeEnv="development";env={};router=null;materialPath="./";urlDslCaches={};errorHandler=null;createMock(e){return async(...t)=>{let s={};if(e)try{s=await e.apply(e,t)}catch(o){f.logger.warn("模拟数据模版异常",o)}return x()?.mock(s)}}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=[],env:i=[]}=this.project,a=window;a&&(a.CKEDITOR_VERSION=void 0),this.initEnv(i),this.mode===S.Raw?await this.loadDependencies(a):await this.loadAssets(a),this.initMock(a),this.apis=Ue(r,o,this.adapter),de(a),Be(r,a),e.platform!=="uniapp"&&this.initRouter(),this.triggerReady()}initMock(e){const t=x(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,libraryLocales:u}=this,{libraryExports:c,libraryMap:l,materials:p,materialExports:d,materialMapLibrary:h,libraryLocaleMap:g}=Re(t,i,a==="development");Object.assign(this.libraryLocaleMap,g);for(const m of c){const _=s[m],v=e[m];if(v)r[m]=v;else if(_)e[m]=r[m]=await _();else{const y=l[m]||[];for(const E of y)q(E)&&await Oe(E,f.url.append(E,{v:k})),J(E)&&await f.loadScript(f.url.append(E,{v:k}));r[m]=e[m]}const w=g[m];if(w){const y=s[w];u[w]=y?await y():e[w]}}if(a==="development"){for(const _ of p)await f.loadScript(f.url.append(_,{v:k}));const m=this.materials||{};for(const _ of d){const v=e[h[_]],w=v?.default||v,y=M.BUILT_IN_COMPONENTS[_];if(y)w&&y.forEach(E=>{o[E]=w[E]});else{const E=m[_]?(await m[_]()).default:e[_];E&&w&&(E.components||[]).forEach(T=>{o[T.name]=Pe(T,w)})}}}}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:u}=s,c=i?"":"/",l={path:`${c}${a}/:id`,name:D,component:ne},p=this.getHomepage(),d={path:c,name:U,component:p?ne:r.startupComponent||Jt,meta:u};if(e.hasRoute(D)&&e.removeRoute(D),e.hasRoute(U)&&e.removeRoute(U),s.enableStaticRoute){const h=t?.pages||[];ae({name:a,prefix:c,pages:h,component:ne,loader:this.getRenderComponent.bind(this),homepage:p?.id}).forEach(m=>{i?e.addRoute(i,m):e.addRoute(m)}),p||(i?e.addRoute(i,d):e.addRoute(d))}else i?(e.addRoute(i,l),e.addRoute(i,d)):(e.addRoute(l),e.addRoute(d))}setErrorHandler(e){e.config.errorHandler=f.debounce((t,s,r)=>{const o=s?.$options.name,i=typeof t=="string"?t:t?.message||t?.msg||"未知错误",a=`[ ${o} ] ${i} ${r}`;["getComputedStyle","ResizeObserver"].some(c=>a.includes(c))||(console.error("[VTJ Error]:",{err:t,instance:s,info:r},t?.stack),this.errorHandler&&this.errorHandler(t),this.adapter.notify&&this.adapter.notify(a,"组件渲染错误","error"))},300)}install(e){const{libraryLocaleMap:t,libraryLocales:s}=this,{libraryOptions:r={}}=this.options,o=e.config.globalProperties.installed||{};for(const[i,a]of Object.entries(this.library))if(!o[i]&&Fe(a)){const c={locale:s[t[i]]},l=r[i]||{},p={...c,...l};e.use(a,p),o[i]=!0}e.provide(_e,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!==S.Design&&this.initGlobals(this.project?.globals||{},{app:e,window,adapter:this.adapter,library:this.library,mode:this.mode}),this.mode!==S.Design&&this.project?.i18n&&this.initI18n(e,this.library,this.project.i18n),this.options.enhance&&e.use(this.options.enhance,this),this.mode===S.Design&&this.setErrorHandler(e),e.config.globalProperties.installed=o}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}getFirstPage(){const{pages:e=[]}=this.project||{};if(!e.length)return null;const t=(s=[])=>{for(const r of s){if(r.type==="page"&&!r.dir&&!r.layout)return r;if(r.children&&r.children.length){const o=t(r.children);if(o)return o}}};return t(e)||null}getMenus(e="page",t=""){return B(t,e,this.project?.pages||[])}getHomepage(){const{homepage:e}=this.project||{};return e?this.getPage(e):this.getFirstPage()}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)}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},u=z({getDsl:async c=>await this.getDsl(c)||null,getDslByUrl:async c=>await this.getDslByUrl(c)||null,options:a});return G({...a,dsl:e,loader:u})}async getRenderComponent(e,t){const s=this.getFile(e);if(!s)return f.logger.warn(`Can not find file: ${e}`),null;if(t&&t(s),this.mode===S.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:(f.logger.warn(`Can not find dsl: ${e}`),null)}defineUrlSchemaComponent(e,t){return b.defineAsyncComponent(async()=>{const s=await this.getDslByUrl(e);return s?(s.name=t||s.name,this.createDslRenderer(s).renderer):null})}definePluginComponent(e){return b.defineAsyncComponent(async()=>await he(e,window))}initGlobals(e,t){const s=Object.assign({adapter:this.adapter,window},t);Gt(e,s)}initI18n(e,t,s){Xt(e,t,s)}initEnv(e=[]){this.env=e.reduce((t,s)=>(t[s.name]=s[this.nodeEnv],t),{})}}function Zt(n){const e=new Ye(n);return{provider:e,onReady:s=>e.ready(s)}}function ve(n={}){const e=b.inject(_e,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 es(n,e=""){const{name:t,urls:s=[]}=n||{},r=s.map(a=>e+a),{css:o,js:i}=Ae(r);if(o.length&&ue(o),i.length)return await pe(i,t).catch(()=>{})}const Xe={type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:n=>n.data?.code===0},ts=(n,e="/__vtj__/api/:type.json")=>(t,s,r)=>n.send({url:e,method:"post",params:{type:t},query:r,data:{type:t,data:s},settings:Xe}),ss=(n,e="/__vtj__/api/uploader.json")=>async(t,s)=>await n.send({url:e,method:"post",data:{files:t,projectId:s},settings:{...Xe,type:"data"}}).then(r=>r&&r[0]?r[0]:null).catch(()=>null);function ns(n){return f.createRequest({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:e=>e.data?.code===0,showError:e=>{n&&n(e||"未知错误")}}})}class Y{constructor(e=f.request){this.req=e,this.api=ts(e),this.uploader=ss(e)}api;pluginCaches={};uploader;async getExtension(){console.log("BaseService.getExtension")}async init(e){return console.log("BaseService.init",e),{}}async saveProject(e,t){return!!await this.api("saveProject",e,{type:t}).catch(()=>!1)}async saveMaterials(e,t){return console.log("BaseService.saveMaterials",e,t),!1}async saveFile(e){return console.log("BaseService.saveFile",e),!1}async getFile(e){return console.log("BaseService.getFile",e),{}}async removeFile(e){return console.log("BaseService.removeFile",e),!1}async saveHistory(e){return console.log("BaseService.saveHistory",e),!1}async removeHistory(e){return console.log("BaseService.removeHistory",e),!1}async getHistory(e){return console.log("BaseService.getHistory",e),{}}async getHistoryItem(e,t){return console.log("BaseService.getHistoryItem",e,t),{}}async saveHistoryItem(e,t){return console.log("BaseService.saveHistoryItem",e,t),!1}async removeHistoryItem(e,t){return console.log("BaseService.removeHistoryItem",e,t),!1}async publish(e){return!!await this.api("publish",e).catch(()=>!1)}async publishFile(e,t){return!!await this.api("publishFile",{project:e,file:t}).catch(()=>!1)}async genVueContent(e,t){return await this.api("genVueContent",{project:e,dsl:t}).catch(()=>"")}async parseVue(e,t){return await this.api("parseVue",{project:e,...t})}async createRawPage(e){return await this.api("createRawPage",e).catch(()=>"")}async removeRawPage(e){return await this.api("removeRawPage",e).catch(()=>"")}async uploadStaticFile(e,t){return await this.uploader(e,t).catch(()=>null)}async getStaticFiles(e){return await this.api("getStaticFiles",e).catch(()=>[])}async removeStaticFile(e,t){return await this.api("removeStaticFile",{name:e,projectId:t}).catch(()=>"")}async clearStaticFiles(e){return await this.api("clearStaticFiles",e).catch(()=>"")}async getPluginMaterial(e){const{urls:t=[]}=e,s=t.filter(o=>je(o))[0];if(!s)return null;const r=this.pluginCaches[s];return r||(this.pluginCaches[s]=f.request.send({url:s,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(o=>o.data).catch(()=>null))}async genSource(e){return console.log("BaseService.genSource",e),""}}const $=new f.Storage({type:"local",expired:0,prefix:"__VTJ_"});class rs extends Y{init(e){const t=new M.ProjectModel(e),s=$.get(`project_${t.id}`),r=Object.assign(t.toDsl(),s||{});return $.save(`project_${t.id}`,r),Promise.resolve(r)}saveProject(e){const t=new M.ProjectModel(e);return $.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return $.save(`materials_${e.id}`,f.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return $.save(`file_${e.id}`,e),Promise.resolve(!0)}getFile(e){const t=$.get(`file_${e}`);return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return $.remove(`file_${e}`),Promise.resolve(!0)}saveHistory(e){return $.save(`history_${e.id}`,e),Promise.resolve(!0)}removeHistory(e){const t=$.get(`history_${e}`);if(t){const r=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,r),$.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=$.get(`history_${e}`),s=new M.HistoryModel(t||{id:e});return Promise.resolve(s.toDsl())}getHistoryItem(e,t){const s=$.get(`history_${e}_${t}`);return Promise.resolve(s)}saveHistoryItem(e,t){return $.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{$.remove(`history_${e}_${s}`)}),Promise.resolve(!0)}}class Ze extends Y{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new M.ProjectModel(e),s=this.projects[t.id]||{},r=Object.assign(t.toDsl(),s);return this.projects[r.id]=r,Promise.resolve(r)}saveProject(e){const t=new M.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=f.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return this.files[e.id]=e,Promise.resolve(!0)}getFile(e){const t=this.files[e];return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return delete this.files[e],Promise.resolve(!0)}saveHistory(e){return this.histories[e.id]=e,Promise.resolve(!0)}removeHistory(e){const t=this.histories[e];if(t){const r=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,r),delete this.historyItems[e]}return Promise.resolve(!0)}getHistory(e){const t=this.histories[e],s=new M.HistoryModel(t||{id:e});return Promise.resolve(s)}getHistoryItem(e,t){const s=`${e}_${t}`,r=this.historyItems[s]||{};return Promise.resolve(r)}saveHistoryItem(e,t){const s=`${e}_${t.id}`;return this.historyItems[s]=t,Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{const r=`${e}_${s}`;delete this.historyItems[r]}),Promise.resolve(!0)}}let K=null;function os(){return K||(K=new Ze,K)}class is extends Y{getFileCaches={};async getExtension(){return await this.api("getExtension",{}).catch(()=>{})}async init(e){return await this.api("init",e).catch(()=>null)||{}}async saveProject(e,t){return!!await this.api("saveProject",e,{type:t}).catch(()=>!1)}async saveMaterials(e,t){return!!await this.api("saveMaterials",{project:e,materials:f.mapToObject(t)}).catch(()=>!1)}async saveFile(e){return!!await this.api("saveFile",e).catch(()=>!1)}async getFile(e){const t=this.getFileCaches[e];return t||(this.getFileCaches[e]=this.api("getFile",e).catch(()=>null)).finally(()=>{delete this.getFileCaches[e]})}async removeFile(e){return!!await this.api("removeFile",e).catch(()=>!1)}async saveHistory(e){return!!await this.api("saveHistory",e).catch(()=>!1)}async removeHistory(e){return!!await this.api("removeHistory",e).catch(()=>!1)}async getHistory(e){return await this.api("getHistory",e).catch(()=>null)||{}}async getHistoryItem(e,t){return await this.api("getHistoryItem",{fId:e,id:t}).catch(()=>null)||{}}async saveHistoryItem(e,t){return!!await this.api("saveHistoryItem",{fId:e,item:t}).catch(()=>!1)}async removeHistoryItem(e,t){return!!await this.api("removeHistoryItem",{fId:e,ids:t}).catch(()=>!1)}}exports.ACCESS=at;exports.ACCESS_KEY=fe;exports.Access=Q;exports.BUILD_IN_TAGS=be;exports.BUILT_IN_DIRECTIVES=Ee;exports.BaseService=Y;exports.CONTEXT_HOST=oe;exports.Context=Ke;exports.ContextMode=S;exports.DATA_TYPES=$e;exports.HOMEPAGE_ROUTE_NAME=U;exports.HTML_TAGS=ce;exports.JSCodeToString=dt;exports.LIFE_CYCLES_LIST=ot;exports.LocalService=is;exports.MemoryService=Ze;exports.NodeEnv=Qe;exports.PAGE_ROUTE_NAME=D;exports.Provider=Ye;exports.REMOTE=it;exports.StorageService=rs;exports.VTJ_RENDERER_VERSION=k;exports.adoptStylesToInline=pt;exports.adoptedStyleSheets=W;exports.clearLoaderCache=Ct;exports.compileScopedCSS=Ie;exports.convertCssRpx=Me;exports.createAccess=gt;exports.createAdapter=mt;exports.createAssetScripts=ct;exports.createAssetsCss=lt;exports.createDataSources=Ge;exports.createLoader=z;exports.createMemoryService=os;exports.createMenus=B;exports.createMetaApi=Le;exports.createMock=qe;exports.createProvider=Zt;exports.createRenderer=G;exports.createSchemaApi=Ne;exports.createSchemaApis=Ue;exports.createServiceRequest=ns;exports.defaultLoader=Ve;exports.fillBasePath=N;exports.getMock=x;exports.getModifiers=me;exports.getPlugin=he;exports.getRawComponent=Pe;exports.isBuiltInTag=ke;exports.isCSSUrl=q;exports.isJSCode=xe;exports.isJSExpression=C;exports.isJSFunction=j;exports.isJSON=je;exports.isJSUrl=J;exports.isNativeTag=De;exports.isVuePlugin=Fe;exports.loadCss=Oe;exports.loadCssUrl=ue;exports.loadEnhance=es;exports.loadScriptUrl=pe;exports.menusFilter=ge;exports.mockApi=Je;exports.mockApis=Be;exports.mockCleanup=de;exports.nodeCache=I;exports.nodeRender=F;exports.parseDeps=Re;exports.parseExpression=H;exports.parseFunction=R;exports.parseUrls=Ae;exports.providerKey=_e;exports.removeProdFlag=Ce;exports.rpxToPx=Te;exports.setupPageSetting=ft;exports.toString=le;exports.useAccess=He;exports.useMask=Kt;exports.useProvider=ve;
|
|
16
|
+
}`:"(v) => {}"},r=t.__parseFunction(s),o=ge(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 Ut(n,e,t,s,r){if(!e)return null;if(f.isString(e))return{default:()=>e};if(j(e))return{default:()=>ue(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const o=qt(e),i=(a,u)=>!a||!r?{}:r?.id&&Object.keys(a).length?u?{[u]:a}:{[`scope_${r.id}`]:a}:u?{[u]:Object.create(null)}:{};return Object.entries(o).reduce((a,[u,{nodes:c,params:l,scope:p}])=>(a[u]=d=>{const h=l.length?f.pick(d??{},l):i(d,p);return c.map((g,m)=>O(g,t.__clone(h),n,s,c,!1,m))},a),{})}return null}function qt(n){const e={};for(const t of n){const s=Bt(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 Bt(n="default"){return f.isString(n)?{name:n,params:[],scope:""}:{params:[],scope:"",...n}}function Jt(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((u,c)=>c+1)),Array.isArray(a)?a.map((u,c)=>e(t.__clone({[o]:u,[i]:c}),c)):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const re=$.defineComponent({name:"VtjPageContainer",async setup(){const n=ye(),e=Ee.useRoute(),t=e.meta.__vtj__||e.params.id,s=t?n.getPage(t):n.getHomepage(),r=s?await n.getRenderComponent(s.id):null,o=$.ref(Symbol());if(s){Object.assign(e.meta,s.meta||{},{cache:s.cache});const{useTitle:i}=n?.adapter;if(i){const a=e.meta.title||s.title||"VTJ.PRO";i(a)}}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?$.h(n,{...e,key:t}):$.h("div",{style:{padding:"10px"}},"找不到组件,组件不存在或未发布!")},activated(){this.meta.cache===!1&&(this.sid=Symbol())}}),Kt=$.defineComponent({name:"VtjStartupContainer",render(){return $.h("div","page not found!")}});function q(n,e,t=[]){const s=[];for(const r of t){const{id:o,title:i,icon:a,children:u,hidden:c,layout:l}=r;if(l){const p=q(n,e,u||[]);s.push(...p)}else{const p={id:o,title:i,icon:a,hidden:c,url:`${n}/${e}/${o}`,children:u&&u.length?q(n,e,u):void 0};s.push(p)}}return s}function _e(n,e){if(!e)return n;let t=[];for(const s of n)if(s.children&&s.children.length){const r=_e(s.children,e);r.length&&(s.children=r,t.push(s))}else e.can(s.id.toString())&&t.push(s);return t}function Gt(n){const{menuPathPrefix:e="",pageRouteName:t="page",disableMenusFilter:s=!1}=n||{},r=ye(),o=Ee.useRoute(),i=Ne(),a=$.ref(!1),u=$.ref(!1),c=r.project,l=(h,g)=>{a.value=!h?.mask,u.value=g?.pure??!!h?.pure};$.watchEffect(()=>{const{name:h,params:g,meta:m}=o;if(h===x){const _=r.getPage(g.id);l(_,m)}else if(h===U){const _=r.getHomepage();l(_,m)}else{const _=m.__vtj__;if(_){const y=r.getPage(_);l(y,m)}else a.value=!m.mask,u.value=!!m.pure}});const p=q(e,t,c?.pages),d=c?.config;return{disabled:a,logo:d?.logo,themeSwitchable:d?.themeSwitchable,title:d?.title||c?.description||c?.name||"VTJ App",menus:s?p:_e(p,i),pure:u}}function oe(n,e){const{id:t,title:s,meta:r}=n,{name:o="page",prefix:i="",component:a,routeMeta:u}=e;return{name:t,path:`${i}${o}/${t}`,component:a,meta:{title:s,...u,...r,__vtj__:t}}}function ce(n){const{name:e="page",prefix:t="",pages:s=[],component:r,loader:o,routeMeta:i,homepage:a}=n,u=[];for(const c of s){const{id:l,title:p,dir:d,layout:h,children:g,meta:m}=c;if(d){const _=ce({name:e,prefix:t,component:r,routeMeta:i,homepage:a,loader:o,pages:g||[]});u.push(..._)}else if(h){const _=ce({name:e,prefix:t,component:r,routeMeta:i,homepage:a,loader:o,pages:g||[]}),y={name:`layout_${l}`,path:t,component:()=>o(l),meta:{title:p,...i,...m,__vtj__:l},children:_};u.push(y),u.push(oe(c,n))}else if(u.push(oe(c,n)),a===l){const _=oe(c,n);_.path="",_.name=`home_${l}`,u.push(_)}}return u}function zt(n={},e){const{css:t,store:s,enhance:r}=n,{window:o,app:i,library:a={},adapter:u,mode:c}=e,{Pinia:l}=a;i.config.globalProperties.$libs=a,Q(o,"global-css",t||""),l&&s&&Vt(s,i,l),Qt(i,u,n),!u.access&&n.access&&Wt(n.access,i,c,u),Yt(i,n),r&&Xt(r,i,a)}function Vt(n,e,t){const s=t.createPinia();if(e.use(s),b(n)&&n.value){const r=R(n,{},!1,!1,!0),o=t.defineStore("$store",r(e)||{});e.config.globalProperties.$store=o()}}function Wt(n,e,t,s){if(b(n)&&n.value){const r=R(n,{},!1,!1,!0),{alert:o,request:i}=s,a=new Y({alert:o,storagePrefix:"__VTJ_APP_",...r(e)}),u=e.config.globalProperties.$router;a.connect({mode:t,router:u,request:i}),e.use(a)}}function Qt(n,e,t){if(!e.request)return;const{axios:s,request:r,response:o}=t;if(s&&b(s)&&s.value){const i=R(s,{},!1,!1,!0);e.request.setConfig(i(n))}if(r&&b(r)&&r.value){const i=R(r,{},!1,!1,!0),a=e.request;a.__unReq&&a.__unReq(),a.__unReq=e.request.useRequest(u=>i(u,n))}if(o&&b(o)&&o.value){const i=R(o,{},!1,!1,!0),a=e.request;a.__unRes&&a.__unRes(),a.__unRes=e.request.useResponse(u=>i(u,n))}}function Yt(n,e){const{beforeEach:t,afterEach:s}=e,r=n.config.globalProperties.$router;if(t&&b(t)&&t.value){const o=R(t,{},!1,!1,!0);r&&r.beforeEach((i,a,u)=>o(i,a,u,n))}if(s&&b(s)&&s.value){const o=R(s,{},!1,!1,!0);r&&r.afterEach((i,a,u)=>o(i,a,u,n))}}function Xt(n,e,t={}){b(n)&&n.value&&R(n,{},!1,!1,!0)(e,t)}function Zt(n,e,t){if(!n||!e||!t)return;const{VueI18n:s}=e;if(s){const{locale:r,fallbackLocale:o,messages:i=[]}=t,a={};for(let c of i){const l=Object.keys(c).filter(p=>p!=="key");for(const p of l)a[p]||(a[p]={}),a[p][c.key]=c[p]}const u=s.createI18n({legacy:!1,locale:r,fallbackLocale:o,messages:a});n.use(u)}}const ve=Symbol("Provider");var Ye=(n=>(n.Production="production",n.Development="development",n))(Ye||{});class Xe extends T.Base{constructor(e){super(),this.options=e;const{service:t,mode:s=S.Raw,dependencies:r,materials:o,project:i={},adapter:a={},globals:u={},modules:c={},router:l=null,materialPath:p="./",nodeEnv:d="development"}=e;this.mode=s,this.modules=c,this.service=t,this.router=l,this.materialPath=p,this.nodeEnv=d,r&&(this.dependencies=r),o&&(this.materials=o),Object.assign(this.globals,u),Object.assign(this.adapter,a);const{access:h,request:g}=this.adapter;h&&h.connect({mode:s,router:l,request:g}),i&&s!==S.Design?this.load(i):this.project=i}mode;globals={};modules={};adapter={request:f.request,jsonp:f.jsonp};apis={};dependencies={};materials={};library={};libraryLocales={};libraryLocaleMap={};service;project=null;components={};nodeEnv="development";env={};router=null;materialPath="./";urlDslCaches={};errorHandler=null;createMock(e){return async(...t)=>{let s={};if(e)try{s=await e.apply(e,t)}catch(o){f.logger.warn("模拟数据模版异常",o)}return k()?.mock(s)}}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=[],env:i=[]}=this.project,a=window;a&&(a.CKEDITOR_VERSION=void 0),this.initEnv(i),this.mode===S.Raw?await this.loadDependencies(a):await this.loadAssets(a),this.initMock(a),this.apis=qe(r,o,this.adapter),he(a),Be(r,a),e.platform!=="uniapp"&&this.initRouter(),this.triggerReady()}initMock(e){const t=k(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,libraryLocales:u}=this,{libraryExports:c,libraryMap:l,materials:p,materialExports:d,materialMapLibrary:h,libraryLocaleMap:g}=Pe(t,i,a==="development");Object.assign(this.libraryLocaleMap,g);for(const m of c){const _=s[m],y=e[m];if(y)r[m]=y;else if(_)e[m]=r[m]=await _();else{const C=l[m]||[];for(const v of C)B(v)&&await Fe(v,f.url.append(v,{v:D})),J(v)&&await f.loadScript(f.url.append(v,{v:D}));r[m]=e[m]}const w=g[m];if(w){const C=s[w];u[w]=C?await C():e[w]}}if(a==="development"){for(const _ of p)await f.loadScript(f.url.append(_,{v:D}));const m=this.materials||{};for(const _ of d){const y=e[h[_]],w=y?.default||y,C=T.BUILT_IN_COMPONENTS[_];if(C)w&&C.forEach(v=>{o[v]=w[v]});else{const v=m[_]?(await m[_]()).default:e[_];v&&w&&(v.components||[]).forEach(A=>{o[A.name]=Ae(A,w)})}}}}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:u}=s,c=i?"":"/",l={path:`${c}${a}/:id`,name:x,component:re},p=this.getHomepage(),d={path:c,name:U,component:p?re:r.startupComponent||Kt,meta:u};if(e.hasRoute(x)&&e.removeRoute(x),e.hasRoute(U)&&e.removeRoute(U),s.enableStaticRoute){const h=t?.pages||[];ce({name:a,prefix:c,pages:h,component:re,loader:this.getRenderComponent.bind(this),homepage:p?.id}).forEach(m=>{i?e.addRoute(i,m):e.addRoute(m)}),p||(i?e.addRoute(i,d):e.addRoute(d))}else i?(e.addRoute(i,l),e.addRoute(i,d)):(e.addRoute(l),e.addRoute(d))}setErrorHandler(e){e.config.errorHandler=f.debounce((t,s,r)=>{const o=s?.$options.name,i=typeof t=="string"?t:t?.message||t?.msg||"未知错误",a=`[ ${o} ] ${i} ${r}`;["getComputedStyle","ResizeObserver"].some(c=>a.includes(c))||(console.error("[VTJ Error]:",{err:t,instance:s,info:r},t?.stack),this.errorHandler&&this.errorHandler(t),this.adapter.notify&&this.adapter.notify(a,"组件渲染错误","error"))},300)}install(e){const{libraryLocaleMap:t,libraryLocales:s}=this,{libraryOptions:r={}}=this.options,o=e.config.globalProperties.installed||{};for(const[i,a]of Object.entries(this.library))if(!o[i]&&De(a)){const c={locale:s[t[i]]},l=r[i]||{},p={...c,...l};e.use(a,p),o[i]=!0}e.provide(ve,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!==S.Design&&this.initGlobals(this.project?.globals||{},{app:e,window,adapter:this.adapter,library:this.library,mode:this.mode}),this.mode!==S.Design&&this.project?.i18n&&this.initI18n(e,this.library,this.project.i18n),this.options.enhance&&e.use(this.options.enhance,this),this.mode===S.Design&&this.setErrorHandler(e),e.config.globalProperties.installed=o}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}getFirstPage(){const{pages:e=[]}=this.project||{};if(!e.length)return null;const t=(s=[])=>{for(const r of s){if(r.type==="page"&&!r.dir&&!r.layout)return r;if(r.children&&r.children.length){const o=t(r.children);if(o)return o}}};return t(e)||null}getMenus(e="page",t=""){return q(t,e,this.project?.pages||[])}getHomepage(){const{homepage:e}=this.project||{};return e?this.getPage(e):this.getFirstPage()}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)}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},u=V({getDsl:async c=>await this.getDsl(c)||null,getDslByUrl:async c=>await this.getDslByUrl(c)||null,options:a});return z({...a,dsl:e,loader:u})}async getRenderComponent(e,t){const s=this.getFile(e);if(!s)return f.logger.warn(`Can not find file: ${e}`),null;if(t&&t(s),this.mode===S.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:(f.logger.warn(`Can not find dsl: ${e}`),null)}defineUrlSchemaComponent(e,t){return $.defineAsyncComponent(async()=>{const s=await this.getDslByUrl(e);return s?(s.name=t||s.name,this.createDslRenderer(s).renderer):null})}definePluginComponent(e){return $.defineAsyncComponent(async()=>await me(e,window))}initGlobals(e,t){const s=Object.assign({adapter:this.adapter,window},t);zt(e,s)}initI18n(e,t,s){Zt(e,t,s)}initEnv(e=[]){this.env=e.reduce((t,s)=>(t[s.name]=s[this.nodeEnv],t),{})}}function es(n){const e=new Xe(n);return{provider:e,onReady:s=>e.ready(s)}}function ye(n={}){const e=$.inject(ve,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 ts(n,e=""){const{name:t,urls:s=[]}=n||{},r=s.map(a=>e+a),{css:o,js:i}=Ie(r);if(o.length&&pe(o),i.length)return await fe(i,t).catch(()=>{})}const Ze={type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:n=>n.data?.code===0},ss=(n,e="/__vtj__/api/:type.json")=>(t,s,r)=>n.send({url:e,method:"post",params:{type:t},query:r,data:{type:t,data:s},settings:Ze}),ns=(n,e="/__vtj__/api/uploader.json")=>async(t,s)=>await n.send({url:e,method:"post",data:{files:t,projectId:s},settings:{...Ze,type:"data"}}).then(r=>r&&r[0]?r[0]:null).catch(()=>null);function rs(n){return f.createRequest({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:e=>e.data?.code===0,showError:e=>{n&&n(e||"未知错误")}}})}class X{constructor(e=f.request){this.req=e,this.api=ss(e),this.uploader=ns(e)}api;pluginCaches={};uploader;async getExtension(){console.log("BaseService.getExtension")}async init(e){return console.log("BaseService.init",e),{}}async saveProject(e,t){return!!await this.api("saveProject",e,{type:t}).catch(()=>!1)}async saveMaterials(e,t){return console.log("BaseService.saveMaterials",e,t),!1}async saveFile(e){return console.log("BaseService.saveFile",e),!1}async getFile(e){return console.log("BaseService.getFile",e),{}}async removeFile(e){return console.log("BaseService.removeFile",e),!1}async saveHistory(e){return console.log("BaseService.saveHistory",e),!1}async removeHistory(e){return console.log("BaseService.removeHistory",e),!1}async getHistory(e){return console.log("BaseService.getHistory",e),{}}async getHistoryItem(e,t){return console.log("BaseService.getHistoryItem",e,t),{}}async saveHistoryItem(e,t){return console.log("BaseService.saveHistoryItem",e,t),!1}async removeHistoryItem(e,t){return console.log("BaseService.removeHistoryItem",e,t),!1}async publish(e){return!!await this.api("publish",e).catch(()=>!1)}async publishFile(e,t){return!!await this.api("publishFile",{project:e,file:t}).catch(()=>!1)}async genVueContent(e,t){return await this.api("genVueContent",{project:e,dsl:t}).catch(()=>"")}async parseVue(e,t){return await this.api("parseVue",{project:e,...t})}async createRawPage(e){return await this.api("createRawPage",e).catch(()=>"")}async removeRawPage(e){return await this.api("removeRawPage",e).catch(()=>"")}async uploadStaticFile(e,t){return await this.uploader(e,t).catch(()=>null)}async getStaticFiles(e){return await this.api("getStaticFiles",e).catch(()=>[])}async removeStaticFile(e,t){return await this.api("removeStaticFile",{name:e,projectId:t}).catch(()=>"")}async clearStaticFiles(e){return await this.api("clearStaticFiles",e).catch(()=>"")}async getPluginMaterial(e){const{urls:t=[]}=e,s=t.filter(o=>Ce(o))[0];if(!s)return null;const r=this.pluginCaches[s];return r||(this.pluginCaches[s]=f.request.send({url:s,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(o=>o.data).catch(()=>null))}async genSource(e){return console.log("BaseService.genSource",e),""}}const E=new f.Storage({type:"local",expired:0,prefix:"__VTJ_"});class os extends X{init(e){const t=new T.ProjectModel(e),s=E.get(`project_${t.id}`),r=Object.assign(t.toDsl(),s||{});return E.save(`project_${t.id}`,r),Promise.resolve(r)}saveProject(e){const t=new T.ProjectModel(e);return E.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return E.save(`materials_${e.id}`,f.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return E.save(`file_${e.id}`,e),Promise.resolve(!0)}getFile(e){const t=E.get(`file_${e}`);return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return E.remove(`file_${e}`),Promise.resolve(!0)}saveHistory(e){return E.save(`history_${e.id}`,e),Promise.resolve(!0)}removeHistory(e){const t=E.get(`history_${e}`);if(t){const r=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,r),E.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=E.get(`history_${e}`),s=new T.HistoryModel(t||{id:e});return Promise.resolve(s.toDsl())}getHistoryItem(e,t){const s=E.get(`history_${e}_${t}`);return Promise.resolve(s)}saveHistoryItem(e,t){return E.save(`history_${e}_${t.id}`,t),Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{E.remove(`history_${e}_${s}`)}),Promise.resolve(!0)}}class et extends X{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new T.ProjectModel(e),s=this.projects[t.id]||{},r=Object.assign(t.toDsl(),s);return this.projects[r.id]=r,Promise.resolve(r)}saveProject(e){const t=new T.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=f.mapToObject(t)),Promise.resolve(!0)}saveFile(e){return this.files[e.id]=e,Promise.resolve(!0)}getFile(e){const t=this.files[e];return t?Promise.resolve(t):Promise.reject(null)}removeFile(e){return delete this.files[e],Promise.resolve(!0)}saveHistory(e){return this.histories[e.id]=e,Promise.resolve(!0)}removeHistory(e){const t=this.histories[e];if(t){const r=(t.items||[]).map(o=>o.id);this.removeHistoryItem(e,r),delete this.historyItems[e]}return Promise.resolve(!0)}getHistory(e){const t=this.histories[e],s=new T.HistoryModel(t||{id:e});return Promise.resolve(s)}getHistoryItem(e,t){const s=`${e}_${t}`,r=this.historyItems[s]||{};return Promise.resolve(r)}saveHistoryItem(e,t){const s=`${e}_${t.id}`;return this.historyItems[s]=t,Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{const r=`${e}_${s}`;delete this.historyItems[r]}),Promise.resolve(!0)}}let G=null;function is(){return G||(G=new et,G)}class as extends X{getFileCaches={};async getExtension(){return await this.api("getExtension",{}).catch(()=>{})}async init(e){return await this.api("init",e).catch(()=>null)||{}}async saveProject(e,t){return!!await this.api("saveProject",e,{type:t}).catch(()=>!1)}async saveMaterials(e,t){return!!await this.api("saveMaterials",{project:e,materials:f.mapToObject(t)}).catch(()=>!1)}async saveFile(e){return!!await this.api("saveFile",e).catch(()=>!1)}async getFile(e){const t=this.getFileCaches[e];return t||(this.getFileCaches[e]=this.api("getFile",e).catch(()=>null)).finally(()=>{delete this.getFileCaches[e]})}async removeFile(e){return!!await this.api("removeFile",e).catch(()=>!1)}async saveHistory(e){return!!await this.api("saveHistory",e).catch(()=>!1)}async removeHistory(e){return!!await this.api("removeHistory",e).catch(()=>!1)}async getHistory(e){return await this.api("getHistory",e).catch(()=>null)||{}}async getHistoryItem(e,t){return await this.api("getHistoryItem",{fId:e,id:t}).catch(()=>null)||{}}async saveHistoryItem(e,t){return!!await this.api("saveHistoryItem",{fId:e,item:t}).catch(()=>!1)}async removeHistoryItem(e,t){return!!await this.api("removeHistoryItem",{fId:e,ids:t}).catch(()=>!1)}}exports.ACCESS=ct;exports.ACCESS_KEY=de;exports.Access=Y;exports.BUILD_IN_TAGS=je;exports.BUILT_IN_DIRECTIVES=$e;exports.BaseService=X;exports.CONTEXT_HOST=ie;exports.Context=Ge;exports.ContextMode=S;exports.DATA_TYPES=be;exports.HOMEPAGE_ROUTE_NAME=U;exports.HTML_TAGS=le;exports.JSCodeToString=ht;exports.LIFE_CYCLES_LIST=it;exports.LocalService=as;exports.MemoryService=et;exports.NodeEnv=Ye;exports.PAGE_ROUTE_NAME=x;exports.Provider=Xe;exports.REMOTE=at;exports.StorageService=os;exports.VTJ_RENDERER_VERSION=D;exports.adoptStylesToInline=ft;exports.adoptedStyleSheets=Q;exports.clearLoaderCache=Rt;exports.compileScopedCSS=Te;exports.convertCssRpx=Oe;exports.createAccess=_t;exports.createAdapter=gt;exports.createAssetScripts=lt;exports.createAssetsCss=ut;exports.createDataSources=ze;exports.createLoader=V;exports.createMemoryService=is;exports.createMenus=q;exports.createMetaApi=Ue;exports.createMock=Je;exports.createProvider=es;exports.createRenderer=z;exports.createSchemaApi=Le;exports.createSchemaApis=qe;exports.createServiceRequest=rs;exports.defaultLoader=We;exports.fillBasePath=N;exports.getMock=k;exports.getModifiers=ge;exports.getPlugin=me;exports.getRawComponent=Ae;exports.isBuiltInTag=xe;exports.isCSSUrl=B;exports.isJSCode=He;exports.isJSExpression=j;exports.isJSFunction=b;exports.isJSON=Ce;exports.isJSUrl=J;exports.isNativeTag=ke;exports.isVuePlugin=De;exports.loadCss=Fe;exports.loadCssUrl=pe;exports.loadEnhance=ts;exports.loadScriptUrl=fe;exports.menusFilter=_e;exports.mockApi=Ke;exports.mockApis=Be;exports.mockCleanup=he;exports.nodeCache=F;exports.nodeRender=O;exports.parseDeps=Pe;exports.parseExpression=H;exports.parseFunction=R;exports.parseUrls=Ie;exports.providerKey=ve;exports.removeProdFlag=Re;exports.rpxToPx=Me;exports.setupPageSetting=dt;exports.toString=ue;exports.useAccess=Ne;exports.useMask=Gt;exports.useProvider=ye;
|