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