@vtj/renderer 0.12.20 → 0.12.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 +4 -4
- package/dist/index.mjs +166 -90
- package/package.json +5 -5
- package/types/provider/enhance.d.ts +10 -0
- package/types/provider/provider.d.ts +78 -0
- package/types/version.d.ts +2 -2
package/dist/index.cjs
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
3
3
|
* @name @vtj/renderer
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
5
|
-
* @version 0.12.
|
5
|
+
* @version 0.12.21
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
7
|
-
*/const
|
8
|
-
`)+i;const a=`with(${t?"{}":"$scope || {}"}) { ${i} }`;return new Function("$scope",a)(e)}catch(n){if(c.logger.error("parseExpression.error",n,r,e?.__self??e),s)throw n}}function U(r,e,t=!1,s=!1){const n=k(r,e,t,s);if(typeof n!="function"&&(c.logger.error("parseFunction.error","not a function",r,e?.__self??e),s))throw new Error(`"${r.value}" not a function`);return n}function w(r){return r&&r.type==="JSExpression"}function I(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function Ee(r){return w(r)||I(r)}function We(r){return Ee(r)?r.value:JSON.stringify(r)}const Ye={session:!1,authKey:"Authorization",storageKey:"ACCESS_STORAGE",storagePrefix:"__VTJ_",unauthorized:void 0,auth:"/#/login",redirectParam:"r",unauthorizedCode:401,unauthorizedMessage:"登录已经失效,请重新登录!",noPermissionMessage:"无权限访问该页面",appName:"",statusKey:"code"},Z=Symbol("access");class ee{options;data=null;mode=y.Raw;interceptResponse=!0;constructor(e){this.options=Object.assign({},Ye,e),this.loadData()}enableIntercept(){this.interceptResponse=!0}disableIntercept(){this.interceptResponse=!1}connect(e){const{mode:t,router:s,request:n}=e;this.mode=t,s&&this.mode===y.Raw&&this.setGuard(s),n&&this.setRequest(n)}login(e){const{storageKey:t,storagePrefix:s,session:n,authKey:i}=this.options;this.setData(e),this.data&&(c.storage.save(t,e,{type:"local",prefix:s}),n&&c.cookie.set(i,this.data.token))}clear(){const{storageKey:e,storagePrefix:t,session:s,authKey:n}=this.options;this.data=null,c.storage.remove(e,{type:"local",prefix:t}),s&&c.cookie.remove(n)}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):c.toArray(e).every(i=>s[i]||s[t+"."+i])}some(e){const{appName:t}=this.options,{permissions:s={}}=this.data||{};return c.toArray(e).some(i=>s[i]||s[t+"."+i])}install(e){e.config.globalProperties.$access=this,e.provide(Z,this)}isAuthPath(e){const{auth:t,isAuth:s}=this.options;if(s)return s(e);if(e.path&&typeof t=="string"){const n=t.split("#")[1]||t;return e.path===n}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(n=>c.unRSA(n,t));try{this.data=JSON.parse(s.join(""))}catch(n){console.warn(n)}return}if(typeof e=="string")try{const s=t?c.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=c.storage.get(e,{type:"local",prefix:t});this.setData(s||null)}isLogined(){const{session:e,authKey:t}=this.options;return e&&t?!!c.cookie.get(t):!!this.getToken()}hasRoutePermission(e){if(e.name===M){const t=e.params.id;return t&&this.can(t)}return!0}setGuard(e){e.beforeEach((t,s,n)=>this.guard(t,n))}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:n=!1}=this.options;return await this.showTip(s),c.isFunction(n)?(n(),t(!1)):c.isString(n)?t(n):t(!1)}}t(!1),this.toLogin()}isWhiteList(e){const{whiteList:t}=this.options;return t?Array.isArray(t)?t.some(s=>e.fullPath.startsWith(s)):t(e):!1}isUnauthorized(e){const{unauthorizedCode:t=401,statusKey:s="code"}=this.options;return e.status===t||e.data?.[s]===t}async showUnauthorizedAlert(e){const{unauthorizedMessage:t="登录已失效"}=this.options;this.isUnauthorized(e)&&(await this.showTip(t),this.toLogin())}async showTip(e){const{alert:t}=this.options;return t?(await c.delay(150),await t(e,{title:"提示",type:"warning"}).catch(()=>!1)):!1}setRequest(e){e.useRequest(t=>(this.data?.token&&(t.headers[this.options.authKey]=this.data?.token),t)),e.useResponse(async t=>(this.interceptResponse&&await this.showUnauthorizedAlert(t),t),async t=>{if(!this.interceptResponse)return Promise.reject(t);const s=t.response||t||{};return await this.showUnauthorizedAlert(s),Promise.reject(t)})}}function je(){return S.inject(Z,null)}function Qe(r={}){const{notify:e,loading:t,settings:s={},Startup:n,access:i,useTitle:a,alert:o}=r;let l=null;return{request:c.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:p=>p.data?.code===0||!!p.data?.success,failMessage:!0,showError:p=>{e&&e(p||"未知错误")},showLoading:()=>{l&&l.close(),t&&(l=t())},hideLoading:()=>{l&&(l.close(),l=null)},...s}}),jsonp:c.jsonp,notify:e,loading:t,useTitle:a,startupComponent:n,access:i?new ee({alert:o,...i}):void 0}}function Xe(r={}){return new ee(r)}function Pe(r,e){const{jsonp:t,request:s}=e;if(r.method==="jsonp")return(n={})=>t(r.url,{...r.jsonpOptions,query:n});{const n=r.headers?k(r.headers,{},!0):void 0,i={url:r.url,method:r.method,settings:{...r.settings,headers:n}};return(a,o)=>(delete i.data,s.send(c.merge(i,o||{},{data:a})))}}function $e(r,e){const{metaQuery:t}=e;if(!t)return;const{code:s,queryCode:n}=r;return(i,a)=>{if(!t){console.warn("adapter.metaQuery is not defined!");return}return t(s,n,i,a)}}function Re(r=[],e=[],t){const s={};for(const n of r)s[n.id]=Pe(n,t);for(const n of e)s[n.id]=$e(n,t);return s}async function be(r=[],e=window){const t=T(e);t&&(te(e),r.forEach(s=>Ae(t,s)))}function Ce(r,e=window){const t=I(r.mockTemplate)&&r.mockTemplate.value?U(r.mockTemplate,{},!0):void 0,s=T(e);return async(...n)=>{let i={};if(t)try{i=await t.apply(t,n)}catch(a){c.logger.warn("模拟数据模版异常",a)}return s?.mock(i)}}function Ae(r,e){if(!e.mock)return;const{url:t,mockTemplate:s}=e;if(t&&s){const n=c.pathToRegexp(`${t}(.*)`),i=c.pathToRegexpMatch(t,{decode:decodeURIComponent}),a=k(s,{},!0);r.mock(n,o=>{const l=c.url.parse(o.url)||{},u=o.body instanceof FormData?c.formDataToJson(o.body):o.body,p=i(o.url)?.params;return Object.assign(o,{data:u,params:l,query:p}),r.mock(a(o))})}}function te(r=window){const e=T(r);e&&(e._mocked={})}class Me{__id=null;__mode;__instance=null;__contextRefs={};__refs={};context={};state={};props={};$props={};$refs={};$el=null;$emit=null;$nextTick=null;$parent=null;$root=null;$attrs=null;$slots=null;$watch=null;$options=null;$forceUpdate=null;$components={};$libs={};$apis={};__transform={};constructor(e){const{mode:t,dsl:s,attrs:n}=e;this.__mode=t,s&&(this.__id=s.id||null,this.__transform=s.transform||{}),n&&Object.assign(this,n)}setup(e,t=q){const s=t.getCurrentInstance();if(!s)return;this.__refs={},this.$refs={},this.context={},this.__contextRefs={},this.__instance=s.proxy;const n=s.appContext.config.globalProperties;Object.assign(this,n),Object.assign(this,e||{}),this.__proxy(),t.onMounted(()=>{this.__proxy()}),t.onUnmounted(()=>{this.__cleanup()}),t.onBeforeUpdate(()=>{this.__reset()})}__proxy(){this.__instance&&z.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){z.forEach(e=>{this[e]=null}),this.__reset()}__reset(){this.__refs={},this.$refs={},this.__contextRefs={},this.context={}}__parseFunction(e){if(e)if(this.__mode===y.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return U({type:s,value:n},this)}else return U(e,this)}__parseExpression(e){if(e)if(this.__mode===y.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return k({type:s,value:n},this)}else return k(e,this)}__ref(e=null,t){if(this.__mode!==y.VNode)return e&&e!==this.__id&&(this.__contextRefs[e]=this),async s=>{await c.delay(0);let n=s?.$vtjEl||s?.$el||s?._?.vnode?.el||s;if(!n){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}return n.nodeType===3&&n.nextSibling&&(n=n.nextSibling),n.__vtj__=e,y.Design===this.__mode&&(n.__context__=this,n.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 n=e[t];if(n&&s!==n){const i=new Set([].concat(n,s));return Array.from(i)}else return s}__clone(e={}){const t={...this.context,...e},s={...t,context:t};return s.context.__proto__=this.context,s.__proto__=this,s}}function B(r){const{Vue:e=q,mode:t=y.Runtime,components:s={},libs:n={},apis:i={},loader:a}=r,o=e.computed(()=>r.dsl),l={$components:s,$libs:n,$apis:i},u=new Me({mode:t,dsl:o.value,attrs:l}),p=e.defineComponent({name:o.value.name,props:{...et(o.value.props??[],u)},setup(d){u.$props=d,u.props=d,o.value.id&&Y(r.window||window,o.value.id,o.value.css||""),u.state=tt(e,o.value.state??{},u);const g=st(e,o.value.computed??{},u),f=rt(o.value.methods??{},u),h=nt(e,o.value.inject,u),m=Te(o.value.dataSources||{},u),E={...h,...g,...f,...m};return u.setup(E,e),it(e,o.value.watch??[],u),{vtj:u}},emits:Ze(o.value.emits),expose:["vtj"],render(){if(!o.value.nodes)return null;const d=o.value.nodes||[];return d.length===1?C(d[0],u,e,a,d):d.map(g=>C(g,u,e,a,d))},...ot(o.value.lifeCycles??{},u)});return{renderer:e.markRaw(p),context:u}}function Ze(r=[]){return r.map(e=>c.isString(e)?e:e.name)}function et(r=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(i=>ue[i]):void 0;return r.map(s=>c.isString(s)?{name:s}:{name:s.name,type:s.type,required:s.required,default:w(s.default)?e.__parseExpression(s.default):s.default}).reduce((s,n)=>(s[n.name]={type:t(n.type),required:n.required,default:n.default},s),{})}function tt(r,e,t){return r.reactive(Object.keys(e||{}).reduce((s,n)=>{let i=e[n];return w(i)?i=t.__parseExpression(i):I(i)&&(i=t.__parseFunction(i)),s[n]=i,s},{}))}function st(r,e,t){return Object.entries(e??{}).reduce((s,[n,i])=>(s[n]=r.computed(t.__parseFunction(i)),s),{})}function rt(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}function nt(r,e=[],t){return e.reduce((s,n)=>{const{name:i,from:a}=n||{};n.default;const o=w(a)?t.__parseExpression(a)||i:a??i,l=w(n.default)?t.__parseExpression(n.default):n.default??null;return s[i]=r.inject(o,l),s},{})}function Te(r,e){return Object.keys(r).reduce((t,s)=>{const n=r[s];if(n.type==="mock")t[s]=Ce(n);else if(n.ref){const i=e.$apis[n.ref],a=I(n.transform)?n.transform.value?e.__parseFunction(n.transform):void 0:n.transform;t[s]=async(...o)=>{const l=await i.apply(e,o);return a?a(l):l}}return t},{})}function it(r,e=[],t){e.forEach(s=>{r.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function ot(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}let V=[],b={};const ke=r=>r;async function se(r,e=window){const{urls:t=[],library:s}=r,n=t.filter(o=>x(o));if(n.length===0||!s)return null;const i=t.filter(o=>H(o));return i.length&&Q(i,e),await X(n,s,e).catch(o=>(console.warn("loadScriptUrl error",n,s,o),null))}function L(r){const{getDsl:e,getDslByUrl:t,options:s}=r;return s.window&&(V.forEach(n=>{delete s.window[n]}),V=[]),(n,i,a=q)=>{if(!i||typeof i=="string")return n;if(i.type==="Schema"&&i.id)return a.defineAsyncComponent(async()=>{const o=b[i.id]||await e(i.id);return o&&(o.name=n,b[i.id]=o),o?B({...s,Vue:a,dsl:c.cloneDeep(o),mode:y.Runtime,loader:L(r)}).renderer:null});if(i.type==="UrlSchema"&&i.url)return a.defineAsyncComponent(async()=>{const o=b[i.url]||await t(i.url);return o&&(o.name=n,b[i.url]=o),o?B({...s,Vue:a,dsl:c.cloneDeep(o),mode:y.Runtime,loader:L(r)}).renderer:null});if(i.type==="Plugin"){let o=i.library?b[i.library]:null;return o||(i.library&&V.push(i.library),o=b[i.library||Symbol()]=a.defineAsyncComponent(async()=>{const l=await se(i,s.window);return l||(console.warn("getPlugin result is null",i),null)}),o)}return n}}function at(){b={}}function C(r,e,t=q,s=ke,n=[],i=!1){if(!r||!r.name||r.invisible)return null;const a=t.getCurrentInstance()?.appContext,{id:o=null,directives:l=[]}=r,{vIf:u,vElseIf:p,vElse:d,vFor:g,vShow:f,vModels:h,vBind:m,vHtml:E,others:v}=Ie(l);if(!i&&(p||d))return null;if(u&&!lt(u,e))return ft(r,e,t,s,n);const F=j=>{const Ue=j.$components,Be=(()=>{if(r.name==="component")return ut(j,r.props?.is);if(r.name==="slot")return r.name;const P=s(r.name,r.from,t);return c.isString(P)?Se(P)||we(P)?P:Ue[P]??a?.app?.component(P)??P:P})(),R=pt(o,r.props??{},j),Le=dt(t,r.events??{},j);if(r.name==="slot")return ht(t,r,R,j,s);m&&Object.assign(R,j.__parseExpression(m.value)),f&&(R.style=Object.assign(R.style??{},gt(f,j))),E&&Object.assign(R,vt(E,j)),h.forEach(P=>{Object.assign(R,yt(t,P,j))});const qe=_t(t,r.children??[],j,s,r);let K=t.createVNode(Be,{...R,...Le},qe);const oe=a?ct(a,v,j):[];return oe.length&&(K=t.withDirectives(K,oe)),K};return g?Et(g,F,e):F(e)}function ct(r,e,t){const s=r.app;return e.map(n=>{const i=typeof n.name=="string"?s.directive(n.name):t.__parseExpression(n.name);if(!i)return null;const a=[i];return n.value&&a.push(t.__parseExpression(n.value)),n.arg&&a.push(n.arg),n.modifiers&&a.push(n.modifiers),a}).filter(n=>!!n)}function Ie(r=[]){const e=r.find(p=>c.camelCase(p.name)==="vIf"),t=r.find(p=>c.camelCase(p.name)==="vElseIf"),s=r.find(p=>c.camelCase(p.name)==="vElse"),n=r.find(p=>c.camelCase(p.name)==="vFor"),i=r.find(p=>c.camelCase(p.name)==="vShow"),a=r.find(p=>c.camelCase(p.name)==="vBind"),o=r.find(p=>c.camelCase(p.name)==="vHtml"),l=r.filter(p=>c.camelCase(p.name)==="vModel"),u=r.filter(p=>!le.includes(c.camelCase(p.name)));return{vIf:e,vElseIf:t,vElse:s,vFor:n,vShow:i,vModels:l,vBind:a,others:u,vHtml:o}}function lt(r,e){return!!e.__parseExpression(r.value)}function ut(r,e){return e?w(e)?r.__parseExpression(e):e:"div"}function pt(r,e,t){const s=G(e,t);return s.ref=t.__ref(r,s.ref),s}function G(r,e){return w(r)?e.__parseExpression(r):I(r)?e.__parseFunction(r):Array.isArray(r)?r.map(t=>G(t,e)):typeof r=="object"?Object.keys(r||{}).reduce((t,s)=>{let n=r[s];return t[s]=G(n,e),t},{}):r}function dt(r,e,t){const s=["passive","capture","once"],n={capture:"Capture",once:"Once",passive:"OnceCapture"};return Object.keys(e||{}).reduce((i,a)=>{const o=e[a],l=re(o.modifiers),u=l.find(g=>s.includes(g)),p="on"+c.upperFirst(a)+(u&&n[u]||""),d=t.__parseFunction(o.handler);return d&&(i[p]=r.withModifiers(d,l)),i},{})}function ft(r,e,t,s,n=[]){let i=n.findIndex(a=>a.id===r.id);for(let a=++i;a<n.length;a++){const{directives:o=[]}=n[a],{vElseIf:l,vElse:u}=Ie(o);if(l){if(e.__parseExpression(l.value))return C(n[a],e,t,s,n,!0);continue}if(u)return C(n[a],e,t,s,n,!0)}return null}function re(r={},e=!1){const t=Object.keys(r);return e?t.map(s=>"."+s):t}function ht(r,e,t,s,n){const{children:i}=e,a=mt(e,s),o=s.$slots?.[a.name];return o?o(t):i?c.isString(i)?r.createTextVNode(i):w(i)?r.createTextVNode(W(s.__parseExpression(i))):Array.isArray(i)?i.map(l=>C(l,s,r,n,i)):null:null}function mt(r,e){const{props:t}=r,s=t?.name||"default";return{name:w(s)?e.__parseExpression(s):s,params:[]}}function gt(r,e){return e.__parseExpression(r.value)?{}:{display:"none"}}function vt(r,e){return{innerHTML:e.__parseExpression(r.value)||""}}function yt(r,e,t){const s={type:"JSFunction",value:e.value?.value?`(v) => {
|
7
|
+
*/const M="0.12.21";var y=(r=>(r.Runtime="Runtime",r.Design="Design",r.Raw="Raw",r.VNode="VNode",r))(y||{});const z=["$el","$emit","$nextTick","$parent","$root","$attrs","$slots","$watch","$props","$options","$forceUpdate"],Ke=["beforeCreate","created","beforeMount","mounted","beforeUpdate","updated","beforeUnmount","unmounted","errorCaptured","renderTracked","renderTriggered","activated","deactivated"],le=["vIf","vElseIf","vElse","vShow","vModel","vFor","vBind","vHtml"],ue={String,Number,Boolean,Array,Object,Function,Date},k="VtjPage",D="VtjHomepage",pe="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".split(","),de="component,slot".split(",");function O(r,e){return r.map(t=>c.isUrl(t)||t.startsWith("/")?t:`${e}${t}`)}function H(r){return/\.css$/.test(r)}function x(r){return/\.js$/.test(r)}function fe(r){return/\.json$/.test(r)}function Ve(r){return r.map(e=>`<script src="${c.url.append(e,{v:M})}"><\/script>`).join("")}function ze(r=[]){return r.map(e=>`<link rel="stylesheet" href="${c.url.append(e,{v:M})}" />`).join("")}function he(r,e=!1){return e&&r.endsWith(".prod.js")?r.replace(".prod.js",".js"):r}function me(r,e,t=!1){const s=r.filter(g=>!!g.enabled),n=[],i=[],a=[],o=[],l={},u={},p=[],d={};return s.forEach(({urls:g,assetsUrl:h,library:f,assetsLibrary:m,localeLibrary:E})=>{g?.forEach(v=>{x(v)&&n.push(he(v,t)),H(v)&&i.push(v)}),f&&(o.push(f),l[f]=O(g||[],e),E&&(u[f]=E)),h&&a.push(h),m&&p.push(m),f&&m&&(d[m]=f)}),{scripts:O(n,e),css:O(i,e),materials:O(a,e),libraryExports:o,materialExports:c.dedupArray(p),materialMapLibrary:d,libraryMap:l,libraryLocaleMap:u}}function ge(r,e){const{name:t,parent:s,alias:n}=r;return s?e[s]?.[n||t]:e[n||t]}function ve(r=[]){const e=r.filter(s=>H(s)),t=r.filter(s=>x(s));return{css:e,js:t}}function W(r){return c.isString(r)?r:JSON.stringify(r)}function Y(r,e,t){const s=r.CSSStyleSheet;if(s.prototype.replaceSync){const n=new s;n.id=e,n.replaceSync(t);const i=r.document,a=i.adoptedStyleSheets,o=Array.from(a).filter(l=>l.id!==e);i.adoptedStyleSheets=[...o,n]}else{const n=r.document;let i=n.getElementById(e);i?i.innerHTML=t:(i=n.createElement("style"),i.id=e,i.innerHTML=t,n.head.appendChild(i))}}async function ye(r,e){const t=await window.fetch(e).then(s=>s.text()).catch(()=>"");t&&Y(window,r,t)}function Q(r,e=window){const t=e.document,s=e.document.head;for(const n of r)if(!t.getElementById(n)){const a=t.createElement("link");a.rel="stylesheet",a.id=n,a.href=n,s.appendChild(a)}}async function X(r,e,t=window){const s=t.document,n=t.document.head;let i=t[e];return i?i.default||i:new Promise((a,o)=>{for(const l of r){const u=s.createElement("script");u.src=l,u.onload=()=>{i=t[e],i?a(i.default||i):o(null)},u.onerror=p=>{o(p)},n.appendChild(u)}})}function _e(r){return c.isFunction(r)||c.isFunction(r?.install)}function Se(r){return de.includes(r)}function we(r){return pe.includes(r)}function T(r=window){const e=window?.Mock;if(e)return e;const t=r?.Mock;if(t&&window)return window.Mock=t,t}function Ge(r,e,t){Object.assign(e.meta,t.meta);const s=r?._container;t?.type==="page"&&s.classList.add("is-page"),t?.pure&&s.classList.add("is-pure")}function I(r,e,t=!1,s=!1){try{const n=['"use strict";',"var __self = arguments[0];"];n.push("return ");let i=(r.value||"").trim();i=i.replace(/this(\W|$)/g,(o,l)=>`__self${l}`),i=n.join(`
|
8
|
+
`)+i;const a=`with(${t?"{}":"$scope || {}"}) { ${i} }`;return new Function("$scope",a)(e)}catch(n){if(c.logger.error("parseExpression.error",n,r,e?.__self??e),s)throw n}}function U(r,e,t=!1,s=!1){const n=I(r,e,t,s);if(typeof n!="function"&&(c.logger.error("parseFunction.error","not a function",r,e?.__self??e),s))throw new Error(`"${r.value}" not a function`);return n}function w(r){return r&&r.type==="JSExpression"}function F(r){return typeof r=="object"&&r&&r.type==="JSFunction"}function Ee(r){return w(r)||F(r)}function We(r){return Ee(r)?r.value:JSON.stringify(r)}const Ye={session:!1,authKey:"Authorization",storageKey:"ACCESS_STORAGE",storagePrefix:"__VTJ_",unauthorized:void 0,auth:"/#/login",redirectParam:"r",unauthorizedCode:401,unauthorizedMessage:"登录已经失效,请重新登录!",noPermissionMessage:"无权限访问该页面",appName:"",statusKey:"code"},Z=Symbol("access");class ee{options;data=null;mode=y.Raw;interceptResponse=!0;constructor(e){this.options=Object.assign({},Ye,e),this.loadData()}enableIntercept(){this.interceptResponse=!0}disableIntercept(){this.interceptResponse=!1}connect(e){const{mode:t,router:s,request:n}=e;this.mode=t,s&&this.mode===y.Raw&&this.setGuard(s),n&&this.setRequest(n)}login(e){const{storageKey:t,storagePrefix:s,session:n,authKey:i}=this.options;this.setData(e),this.data&&(c.storage.save(t,e,{type:"local",prefix:s}),n&&c.cookie.set(i,this.data.token))}clear(){const{storageKey:e,storagePrefix:t,session:s,authKey:n}=this.options;this.data=null,c.storage.remove(e,{type:"local",prefix:t}),s&&c.cookie.remove(n)}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):c.toArray(e).every(i=>s[i]||s[t+"."+i])}some(e){const{appName:t}=this.options,{permissions:s={}}=this.data||{};return c.toArray(e).some(i=>s[i]||s[t+"."+i])}install(e){e.config.globalProperties.$access=this,e.provide(Z,this)}isAuthPath(e){const{auth:t,isAuth:s}=this.options;if(s)return s(e);if(e.path&&typeof t=="string"){const n=t.split("#")[1]||t;return e.path===n}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(n=>c.unRSA(n,t));try{this.data=JSON.parse(s.join(""))}catch(n){console.warn(n)}return}if(typeof e=="string")try{const s=t?c.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=c.storage.get(e,{type:"local",prefix:t});this.setData(s||null)}isLogined(){const{session:e,authKey:t}=this.options;return e&&t?!!c.cookie.get(t):!!this.getToken()}hasRoutePermission(e){if(e.name===k){const t=e.params.id;return t&&this.can(t)}return!0}setGuard(e){e.beforeEach((t,s,n)=>this.guard(t,n))}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:n=!1}=this.options;return await this.showTip(s),c.isFunction(n)?(n(),t(!1)):c.isString(n)?t(n):t(!1)}}t(!1),this.toLogin()}isWhiteList(e){const{whiteList:t}=this.options;return t?Array.isArray(t)?t.some(s=>e.fullPath.startsWith(s)):t(e):!1}isUnauthorized(e){const{unauthorizedCode:t=401,statusKey:s="code"}=this.options;return e.status===t||e.data?.[s]===t}async showUnauthorizedAlert(e){const{unauthorizedMessage:t="登录已失效"}=this.options;this.isUnauthorized(e)&&(await this.showTip(t),this.toLogin())}async showTip(e){const{alert:t}=this.options;return t?(await c.delay(150),await t(e,{title:"提示",type:"warning"}).catch(()=>!1)):!1}setRequest(e){e.useRequest(t=>(this.data?.token&&(t.headers[this.options.authKey]=this.data?.token),t)),e.useResponse(async t=>(this.interceptResponse&&await this.showUnauthorizedAlert(t),t),async t=>{if(!this.interceptResponse)return Promise.reject(t);const s=t.response||t||{};return await this.showUnauthorizedAlert(s),Promise.reject(t)})}}function je(){return S.inject(Z,null)}function Qe(r={}){const{notify:e,loading:t,settings:s={},Startup:n,access:i,useTitle:a,alert:o}=r;let l=null;return{request:c.createRequest({settings:{type:"form",validSuccess:!0,originResponse:!1,loading:!0,validate:p=>p.data?.code===0||!!p.data?.success,failMessage:!0,showError:p=>{e&&e(p||"未知错误")},showLoading:()=>{l&&l.close(),t&&(l=t())},hideLoading:()=>{l&&(l.close(),l=null)},...s}}),jsonp:c.jsonp,notify:e,loading:t,useTitle:a,startupComponent:n,access:i?new ee({alert:o,...i}):void 0}}function Xe(r={}){return new ee(r)}function Pe(r,e){const{jsonp:t,request:s}=e;if(r.method==="jsonp")return(n={})=>t(r.url,{...r.jsonpOptions,query:n});{const n=r.headers?I(r.headers,{},!0):void 0,i={url:r.url,method:r.method,settings:{...r.settings,headers:n}};return(a,o)=>(delete i.data,s.send(c.merge(i,o||{},{data:a})))}}function $e(r,e){const{metaQuery:t}=e;if(!t)return;const{code:s,queryCode:n}=r;return(i,a)=>{if(!t){console.warn("adapter.metaQuery is not defined!");return}return t(s,n,i,a)}}function Re(r=[],e=[],t){const s={};for(const n of r)s[n.id]=Pe(n,t);for(const n of e)s[n.id]=$e(n,t);return s}async function be(r=[],e=window){const t=T(e);t&&(te(e),r.forEach(s=>Ae(t,s)))}function Ce(r,e=window){const t=F(r.mockTemplate)&&r.mockTemplate.value?U(r.mockTemplate,{},!0):void 0,s=T(e);return async(...n)=>{let i={};if(t)try{i=await t.apply(t,n)}catch(a){c.logger.warn("模拟数据模版异常",a)}return s?.mock(i)}}function Ae(r,e){if(!e.mock)return;const{url:t,mockTemplate:s}=e;if(t&&s){const n=c.pathToRegexp(`${t}(.*)`),i=c.pathToRegexpMatch(t,{decode:decodeURIComponent}),a=I(s,{},!0);r.mock(n,o=>{const l=c.url.parse(o.url)||{},u=o.body instanceof FormData?c.formDataToJson(o.body):o.body,p=i(o.url)?.params;return Object.assign(o,{data:u,params:l,query:p}),r.mock(a(o))})}}function te(r=window){const e=T(r);e&&(e._mocked={})}class Me{__id=null;__mode;__instance=null;__contextRefs={};__refs={};context={};state={};props={};$props={};$refs={};$el=null;$emit=null;$nextTick=null;$parent=null;$root=null;$attrs=null;$slots=null;$watch=null;$options=null;$forceUpdate=null;$components={};$libs={};$apis={};__transform={};constructor(e){const{mode:t,dsl:s,attrs:n}=e;this.__mode=t,s&&(this.__id=s.id||null,this.__transform=s.transform||{}),n&&Object.assign(this,n)}setup(e,t=q){const s=t.getCurrentInstance();if(!s)return;this.__refs={},this.$refs={},this.context={},this.__contextRefs={},this.__instance=s.proxy;const n=s.appContext.config.globalProperties;Object.assign(this,n),Object.assign(this,e||{}),this.__proxy(),t.onMounted(()=>{this.__proxy()}),t.onUnmounted(()=>{this.__cleanup()}),t.onBeforeUpdate(()=>{this.__reset()})}__proxy(){this.__instance&&z.forEach(e=>{this[e]=this.__instance?.[e]})}__cleanup(){z.forEach(e=>{this[e]=null}),this.__reset()}__reset(){this.__refs={},this.$refs={},this.__contextRefs={},this.context={}}__parseFunction(e){if(e)if(this.__mode===y.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return U({type:s,value:n},this)}else return U(e,this)}__parseExpression(e){if(e)if(this.__mode===y.Runtime){const{id:t,type:s}=e,n=t?this.__transform[t]??e.value:e.value;return I({type:s,value:n},this)}else return I(e,this)}__ref(e=null,t){if(this.__mode!==y.VNode)return e&&e!==this.__id&&(this.__contextRefs[e]=this),async s=>{await c.delay(0);let n=s?.$vtjEl||s?.$el||s?._?.vnode?.el||s;if(!n){typeof t=="string"&&(delete this.$refs[t],e&&delete this.__refs[e]);return}return n.nodeType===3&&n.nextSibling&&(n=n.nextSibling),n.__vtj__=e,y.Design===this.__mode&&(n.__context__=this,n.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 n=e[t];if(n&&s!==n){const i=new Set([].concat(n,s));return Array.from(i)}else return s}__clone(e={}){const t={...this.context,...e},s={...t,context:t};return s.context.__proto__=this.context,s.__proto__=this,s}}function B(r){const{Vue:e=q,mode:t=y.Runtime,components:s={},libs:n={},apis:i={},loader:a}=r,o=e.computed(()=>r.dsl),l={$components:s,$libs:n,$apis:i},u=new Me({mode:t,dsl:o.value,attrs:l}),p=e.defineComponent({name:o.value.name,props:{...et(o.value.props??[],u)},setup(d){u.$props=d,u.props=d,o.value.id&&Y(r.window||window,o.value.id,o.value.css||""),u.state=tt(e,o.value.state??{},u);const g=st(e,o.value.computed??{},u),h=rt(o.value.methods??{},u),f=nt(e,o.value.inject,u);for(const[v,R]of Object.entries(f||{}))f[v]=e.inject(v,R);const m=ke(o.value.dataSources||{},u),E={...f,...g,...h,...m};return u.setup(E,e),it(e,o.value.watch??[],u),{vtj:u}},emits:Ze(o.value.emits),expose:["vtj"],render(){if(!o.value.nodes)return null;const d=o.value.nodes||[];return d.length===1?A(d[0],u,e,a,d):d.map(g=>A(g,u,e,a,d))},...ot(o.value.lifeCycles??{},u)});return{renderer:e.markRaw(p),context:u}}function Ze(r=[]){return r.map(e=>c.isString(e)?e:e.name)}function et(r=[],e){const t=s=>s?(Array.isArray(s)?s:[s]).map(i=>ue[i]):void 0;return r.map(s=>c.isString(s)?{name:s}:{name:s.name,type:s.type,required:s.required,default:w(s.default)?e.__parseExpression(s.default):s.default}).reduce((s,n)=>(s[n.name]={type:t(n.type),required:n.required,default:n.default},s),{})}function tt(r,e,t){return r.reactive(Object.keys(e||{}).reduce((s,n)=>{let i=e[n];return w(i)?i=t.__parseExpression(i):F(i)&&(i=t.__parseFunction(i)),s[n]=i,s},{}))}function st(r,e,t){return Object.entries(e??{}).reduce((s,[n,i])=>(s[n]=r.computed(t.__parseFunction(i)),s),{})}function rt(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}function nt(r,e=[],t){return e.reduce((s,n)=>{const{name:i,from:a}=n||{};n.default;const o=w(a)?t.__parseExpression(a)||i:a??i,l=w(n.default)?t.__parseExpression(n.default):n.default??null;return s[i]=r.inject(o,l),s},{})}function ke(r,e){return Object.keys(r).reduce((t,s)=>{const n=r[s];if(n.type==="mock")t[s]=Ce(n);else if(n.ref){const i=e.$apis[n.ref],a=F(n.transform)?n.transform.value?e.__parseFunction(n.transform):void 0:n.transform;t[s]=async(...o)=>{const l=await i.apply(e,o);return a?a(l):l}}return t},{})}function it(r,e=[],t){e.forEach(s=>{r.watch(t.__parseExpression(s.source),t.__parseFunction(s.handler),{deep:s.deep,immediate:s.immediate})})}function ot(r,e){return Object.entries(r??{}).reduce((t,[s,n])=>(t[s]=e.__parseFunction(n),t),{})}let V=[],C={};const Te=r=>r;async function se(r,e=window){const{urls:t=[],library:s}=r,n=t.filter(o=>x(o));if(n.length===0||!s)return null;const i=t.filter(o=>H(o));return i.length&&Q(i,e),await X(n,s,e).catch(o=>(console.warn("loadScriptUrl error",n,s,o),null))}function L(r){const{getDsl:e,getDslByUrl:t,options:s}=r;return s.window&&(V.forEach(n=>{delete s.window[n]}),V=[]),(n,i,a=q)=>{if(!i||typeof i=="string")return n;if(i.type==="Schema"&&i.id)return a.defineAsyncComponent(async()=>{const o=C[i.id]||await e(i.id);return o&&(o.name=n,C[i.id]=o),o?B({...s,Vue:a,dsl:c.cloneDeep(o),mode:y.Runtime,loader:L(r)}).renderer:null});if(i.type==="UrlSchema"&&i.url)return a.defineAsyncComponent(async()=>{const o=C[i.url]||await t(i.url);return o&&(o.name=n,C[i.url]=o),o?B({...s,Vue:a,dsl:c.cloneDeep(o),mode:y.Runtime,loader:L(r)}).renderer:null});if(i.type==="Plugin"){let o=i.library?C[i.library]:null;return o||(i.library&&V.push(i.library),o=C[i.library||Symbol()]=a.defineAsyncComponent(async()=>{const l=await se(i,s.window);return l||(console.warn("getPlugin result is null",i),null)}),o)}return n}}function at(){C={}}function A(r,e,t=q,s=Te,n=[],i=!1){if(!r||!r.name||r.invisible)return null;const a=t.getCurrentInstance()?.appContext,{id:o=null,directives:l=[]}=r,{vIf:u,vElseIf:p,vElse:d,vFor:g,vShow:h,vModels:f,vBind:m,vHtml:E,others:v}=Ie(l);if(!i&&(p||d))return null;if(u&&!lt(u,e))return ft(r,e,t,s,n);const R=j=>{const Ue=j.$components,Be=(()=>{if(r.name==="component")return ut(j,r.props?.is);if(r.name==="slot")return r.name;const P=s(r.name,r.from,t);return c.isString(P)?Se(P)||we(P)?P:Ue[P]??a?.app?.component(P)??P:P})(),b=pt(o,r.props??{},j),Le=dt(t,r.events??{},j);if(r.name==="slot")return ht(t,r,b,j,s);m&&Object.assign(b,j.__parseExpression(m.value)),h&&(b.style=Object.assign(b.style??{},gt(h,j))),E&&Object.assign(b,vt(E,j)),f.forEach(P=>{Object.assign(b,yt(t,P,j))});const qe=_t(t,r.children??[],j,s,r);let K=t.createVNode(Be,{...b,...Le},qe);const oe=a?ct(a,v,j):[];return oe.length&&(K=t.withDirectives(K,oe)),K};return g?Et(g,R,e):R(e)}function ct(r,e,t){const s=r.app;return e.map(n=>{const i=typeof n.name=="string"?s.directive(n.name):t.__parseExpression(n.name);if(!i)return null;const a=[i];return n.value&&a.push(t.__parseExpression(n.value)),n.arg&&a.push(n.arg),n.modifiers&&a.push(n.modifiers),a}).filter(n=>!!n)}function Ie(r=[]){const e=r.find(p=>c.camelCase(p.name)==="vIf"),t=r.find(p=>c.camelCase(p.name)==="vElseIf"),s=r.find(p=>c.camelCase(p.name)==="vElse"),n=r.find(p=>c.camelCase(p.name)==="vFor"),i=r.find(p=>c.camelCase(p.name)==="vShow"),a=r.find(p=>c.camelCase(p.name)==="vBind"),o=r.find(p=>c.camelCase(p.name)==="vHtml"),l=r.filter(p=>c.camelCase(p.name)==="vModel"),u=r.filter(p=>!le.includes(c.camelCase(p.name)));return{vIf:e,vElseIf:t,vElse:s,vFor:n,vShow:i,vModels:l,vBind:a,others:u,vHtml:o}}function lt(r,e){return!!e.__parseExpression(r.value)}function ut(r,e){return e?w(e)?r.__parseExpression(e):e:"div"}function pt(r,e,t){const s=G(e,t);return s.ref=t.__ref(r,s.ref),s}function G(r,e){return w(r)?e.__parseExpression(r):F(r)?e.__parseFunction(r):Array.isArray(r)?r.map(t=>G(t,e)):typeof r=="object"?Object.keys(r||{}).reduce((t,s)=>{let n=r[s];return t[s]=G(n,e),t},{}):r}function dt(r,e,t){const s=["passive","capture","once"],n={capture:"Capture",once:"Once",passive:"OnceCapture"};return Object.keys(e||{}).reduce((i,a)=>{const o=e[a],l=re(o.modifiers),u=l.find(g=>s.includes(g)),p="on"+c.upperFirst(a)+(u&&n[u]||""),d=t.__parseFunction(o.handler);return d&&(i[p]=r.withModifiers(d,l)),i},{})}function ft(r,e,t,s,n=[]){let i=n.findIndex(a=>a.id===r.id);for(let a=++i;a<n.length;a++){const{directives:o=[]}=n[a],{vElseIf:l,vElse:u}=Ie(o);if(l){if(e.__parseExpression(l.value))return A(n[a],e,t,s,n,!0);continue}if(u)return A(n[a],e,t,s,n,!0)}return null}function re(r={},e=!1){const t=Object.keys(r);return e?t.map(s=>"."+s):t}function ht(r,e,t,s,n){const{children:i}=e,a=mt(e,s),o=s.$slots?.[a.name];return o?o(t):i?c.isString(i)?r.createTextVNode(i):w(i)?r.createTextVNode(W(s.__parseExpression(i))):Array.isArray(i)?i.map(l=>A(l,s,r,n,i)):null:null}function mt(r,e){const{props:t}=r,s=t?.name||"default";return{name:w(s)?e.__parseExpression(s):s,params:[]}}function gt(r,e){return e.__parseExpression(r.value)?{}:{display:"none"}}function vt(r,e){return{innerHTML:e.__parseExpression(r.value)||""}}function yt(r,e,t){const s={type:"JSFunction",value:e.value?.value?`(v) => {
|
9
9
|
${e.value.value} = v;
|
10
|
-
}`:"(v) => {}"},n=t.__parseFunction(s),i=re(w(e.modifiers)?t.__parseExpression(e.modifiers):e.modifiers),a=w(e.arg)?t.__parseExpression(e.arg):e.arg||"modelValue";return{[a]:t.__parseExpression(e.value),[`onUpdate:${a}`]:i.length&&n?r.withModifiers(n,i):n}}function _t(r,e,t,s,n){if(!e)return null;if(c.isString(e))return{default:()=>e};if(w(e))return{default:()=>W(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const i=St(e),a=o=>!o||!n?{}:n?.id&&Object.keys(o).length?{[`scope_${n.id}`]:o}:{};return Object.entries(i).reduce((o,[l,{nodes:u,params:p}])=>(o[l]=d=>{const g=p.length?c.pick(d??{},p):a(d);return u.map(f=>C(f,t.__clone(g),r,s,u))},o),{})}return null}function St(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=wt(t.slot),n=s.name;e[n]?(e[n].nodes.push(t),e[n].params=e[n].params.concat(s.params)):e[n]={nodes:[t],params:s.params}}return e}function wt(r="default"){return c.isString(r)?{name:r,params:[]}:{params:[],...r}}function Et(r,e,t){const{value:s,iterator:n}=r,{item:i="item",index:a="index"}=n||{};let o=t.__parseExpression(s)||[];return Number.isInteger(o)&&(o=new Array(o).fill(!0).map((l,u)=>u+1)),Array.isArray(o)?o.map((l,u)=>e(t.__clone({[i]:l,[a]:u}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const ae=S.defineComponent({name:"VtjPageContainer",async setup(){const r=ie(),e=ce.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null,i=S.ref(Symbol());if(s){Object.assign(e.meta,s.meta||{},{cache:s.cache});const{useTitle:a}=r?.adapter;a&&a(s.title||"VTJ")}return{provider:r,component:n,file:s,query:e.query,meta:e.meta,sid:i,route:e}},render(){const{component:r,query:e,sid:t}=this;return r?S.h(r,{...e,key:t}):S.h("div","页面不存在")},activated(){this.meta.cache===!1&&(this.sid=Symbol())}}),jt=S.defineComponent({name:"VtjStartupContainer",render(){return S.h("div","page not found!")}}),ne=Symbol("Provider");var Fe=(r=>(r.Production="production",r.Development="development",r))(Fe||{});class Oe extends $.Base{constructor(e){super(),this.options=e;const{service:t,mode:s=y.Raw,dependencies:n,materials:i,project:a={},adapter:o={},globals:l={},modules:u={},router:p=null,materialPath:d="./",nodeEnv:g="development"}=e;this.mode=s,this.modules=u,this.service=t,this.router=p,this.materialPath=d,this.nodeEnv=g,n&&(this.dependencies=n),i&&(this.materials=i),Object.assign(this.globals,l),Object.assign(this.adapter,o);const{access:f,request:h}=this.adapter;f&&f.connect({mode:s,router:p,request:h}),a&&s!==y.Design?this.load(a):this.project=a}mode;globals={};modules={};adapter={request:c.request,jsonp:c.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};nodeEnv="development";router=null;materialPath="./";urlDslCaches={};createMock(e){return async(...t)=>{let s={};if(e)try{s=await e.apply(e,t)}catch(i){c.logger.warn("模拟数据模版异常",i)}return T()?.mock(s)}}async load(e){const t=this.modules[`.vtj/projects/${e.id}.json`]||this.modules[`/src/.vtj/projects/${e.id}.json`];if(this.project=t?await t():await this.service.init(e),!this.project)throw new Error("project is null");const{apis:s=[],meta:n=[]}=this.project,i=window;i&&(i.CKEDITOR_VERSION=void 0),this.mode===y.Raw?await this.loadDependencies(i):await this.loadAssets(i),this.initMock(i),this.apis=Re(s,n,this.adapter),te(i),be(s,i),e.platform!=="uniapp"&&this.initRouter(),this.triggerReady()}initMock(e){const t=T(e);t&&t.setup({timeout:"50-500"})}async loadDependencies(e){const t=Object.entries(this.dependencies);for(const[s,n]of t)e[s]||(e[s]=this.library[s]=await n())}async loadAssets(e){const{dependencies:t=[]}=this.project,{dependencies:s,library:n,components:i,materialPath:a,nodeEnv:o}=this,{libraryExports:l,libraryMap:u,materials:p,materialExports:d,materialMapLibrary:g}=me(t,a,o==="development");for(const f of l){const h=s[f],m=e[f];if(m)n[f]=m;else if(h)e[f]=n[f]=await h();else{const E=u[f]||[];for(const v of E)H(v)&&await ye(f,c.url.append(v,{v:A})),x(v)&&await c.loadScript(c.url.append(v,{v:A}));n[f]=e[f]}}if(o==="development"){for(const h of p)await c.loadScript(c.url.append(h,{v:A}));const f=this.materials||{};for(const h of d){const m=e[g[h]],E=$.BUILT_IN_COMPONENTS[h];if(E)m&&E.forEach(v=>{i[v]=m[v]});else{const v=f[h]?(await f[h]()).default:e[h];v&&m&&(v.components||[]).forEach(F=>{i[F.name]=ge(F,m)})}}}}initRouter(){const{router:e,project:t,options:s,adapter:n}=this;if(!e)return;const i=t?.platform==="uniapp"?"pages":"page",{routeAppendTo:a,pageRouteName:o=i,routeMeta:l}=s,u=a?"":"/",p={path:`${u}${o}/:id`,name:M,component:ae},d={path:u,name:D,component:t?.homepage?ae:n.startupComponent||jt,meta:l};e.hasRoute(M)&&e.removeRoute(M),e.hasRoute(D)&&e.removeRoute(D),a?(e.addRoute(a,p),e.addRoute(a,d)):(e.addRoute(p),e.addRoute(d))}install(e){const t=e.config.globalProperties.installed||{};for(const[s,n]of Object.entries(this.library))!t[s]&&_e(n)&&(e.use(n),t[s]=!0);this.options.install&&e.use(this.options.install),this.adapter.access&&e.use(this.adapter.access),e.provide(ne,this),e.config.globalProperties.$provider=this,e.config.globalProperties.installed=t,this.mode===y.Design&&(e.config.errorHandler=(s,n,i)=>{const a=n?.$options.name,o=typeof s=="string"?s:s?.message||s?.msg||"未知错误",l=`[ ${a} ] ${o} ${i}`;console.error("[VTJ Error]:",{err:s,instance:n,info:i},s?.stack),this.adapter.notify&&this.adapter.notify(l,"组件渲染错误","error")}),this.options.enhance&&e.use(this.options.enhance,this)}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=(n,i=[])=>{for(const a of i){if(a.id===n)return a;if(a.children&&a.children.length){const o=s(n,a.children);if(o)return o}}};return s(e,t)||null}getHomepage(){const{homepage:e}=this.project||{};return e?this.getPage(e):null}async getDsl(e){const t=this.modules[`.vtj/files/${e}.json`]||this.modules[`/src/.vtj/files/${e}.json`];return t?await t():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:n,mode:i,apis:a}=this,o={mode:i,Vue:s.Vue,components:n,libs:s,apis:a,window,...t},l=L({getDsl:async u=>await this.getDsl(u)||null,getDslByUrl:async u=>await this.getDslByUrl(u)||null,options:o});return B({...o,dsl:e,loader:l})}async getRenderComponent(e,t){const s=this.getFile(e);if(!s)return c.logger.warn(`Can not find file: ${e}`),null;t&&t(s);const n=`.vtj/vue/${e}.vue`,i=this.modules[n]||this.modules[`/src/pages/${e}.vue`];if(i)return(await i())?.default;const a=await this.getDsl(s.id);return a?this.createDslRenderer(a).renderer:(c.logger.warn(`Can not find dsl: ${e}`),null)}defineUrlSchemaComponent(e,t){return S.defineAsyncComponent(async()=>{const s=await this.getDslByUrl(e);return s?(s.name=t||s.name,this.createDslRenderer(s).renderer):null})}definePluginComponent(e){return S.defineAsyncComponent(async()=>await se(e,window))}}function Pt(r){const e=new Oe(r);return{provider:e,onReady:s=>e.ready(s)}}function ie(r={}){const e=S.inject(ne,null);if(!e)throw new Error("Can not find provider");if(e.nodeEnv==="development"){const{id:t,version:s}=r;t&&s&&(async()=>{const n=await e.getDsl(t);n?.__VERSION__!==s&&e.adapter.notify&&e.adapter.notify(`[ ${n?.name} ] 组件源码版本与运行时版本不一致,请重新发布组件`,"版本不一致","warning")})()}return e}async function $t(r,e=""){const{name:t,urls:s=[]}=r||{},n=s.map(o=>e+o),{css:i,js:a}=ve(n);if(i.length&&Q(i),a.length)return await X(a,t).catch(()=>{})}const De={type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0},Rt=(r,e="/__vtj__/api/:type.json")=>(t,s,n)=>r.send({url:e,method:"post",params:{type:t},query:n,data:{type:t,data:s},settings:De}),bt=(r,e="/__vtj__/api/uploader.json")=>async(t,s)=>await r.send({url:e,method:"post",data:{files:t,projectId:s},settings:{...De,type:"data"}}).then(n=>n&&n[0]?n[0]:null).catch(()=>null);function Ct(r){return c.createRequest({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:e=>e.data?.code===0,showError:e=>{r&&r(e||"未知错误")}}})}class J{constructor(e=c.request){this.req=e,this.api=Rt(e),this.uploader=bt(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(i=>fe(i))[0];if(!s)return null;const n=this.pluginCaches[s];return n||(this.pluginCaches[s]=c.request.send({url:s,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(i=>i.data).catch(()=>null))}async genSource(e){return console.log("BaseService.genSource",e),""}}const _=new c.Storage({type:"local",expired:0,prefix:"__VTJ_"});class At extends J{init(e){const t=new $.ProjectModel(e),s=_.get(`project_${t.id}`),n=Object.assign(t.toDsl(),s||{});return _.save(`project_${t.id}`,n),Promise.resolve(n)}saveProject(e){const t=new $.ProjectModel(e);return _.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return _.save(`materials_${e.id}`,c.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 n=(t.items||[]).map(i=>i.id);this.removeHistoryItem(e,n),_.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=_.get(`history_${e}`),s=new $.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 He extends J{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new $.ProjectModel(e),s=this.projects[t.id]||{},n=Object.assign(t.toDsl(),s);return this.projects[n.id]=n,Promise.resolve(n)}saveProject(e){const t=new $.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=c.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 n=(t.items||[]).map(i=>i.id);this.removeHistoryItem(e,n),delete this.historyItems[e]}return Promise.resolve(!0)}getHistory(e){const t=this.histories[e],s=new $.HistoryModel(t||{id:e});return Promise.resolve(s)}getHistoryItem(e,t){const s=`${e}_${t}`,n=this.historyItems[s]||{};return Promise.resolve(n)}saveHistoryItem(e,t){const s=`${e}_${t.id}`;return this.historyItems[s]=t,Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{const n=`${e}_${s}`;delete this.historyItems[n]}),Promise.resolve(!0)}}let N=null;function Mt(){return N||(N=new He,N)}class Tt extends J{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:c.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)}}function xe(r,e,t=[]){return t.map(s=>{const{id:n,title:i,icon:a,children:o,hidden:l}=s;return{id:n,title:i,icon:a,hidden:l,url:`${r}/${e}/${n}`,children:o&&o.length?xe(r,e,o):void 0}})}function Ne(r,e){if(!e)return r;let t=[];for(const s of r)if(s.children&&s.children.length){const n=Ne(s.children,e);n.length&&(s.children=n,t.push(s))}else e.can(s.id.toString())&&t.push(s);return t}function kt(r){const{menuPathPrefix:e="",pageRouteName:t="page",disableMenusFilter:s=!1}=r||{},n=ie(),i=ce.useRoute(),a=je(),o=S.ref(!1),l=S.ref(!1),u=n.project;S.watchEffect(()=>{const{name:g,params:f,meta:h}=i;if(g===M){const m=n.getPage(f.id);o.value=!m?.mask,l.value=!!m?.pure}else if(g===D){const m=n.getHomepage();o.value=!m?.mask,l.value=!!m?.pure}else o.value=!h.mask,l.value=!!h.pure});const p=xe(e,t,u?.pages),d=u?.config;return{disabled:o,logo:d?.logo,themeSwitchable:d?.themeSwitchable,title:d?.title||u?.description||u?.name||"VTJ App",menus:s?p:Ne(p,a),pure:l}}exports.ACCESS_KEY=Z;exports.Access=ee;exports.BUILD_IN_TAGS=de;exports.BUILT_IN_DIRECTIVES=le;exports.BaseService=J;exports.CONTEXT_HOST=z;exports.Context=Me;exports.ContextMode=y;exports.DATA_TYPES=ue;exports.HOMEPAGE_ROUTE_NAME=D;exports.HTML_TAGS=pe;exports.JSCodeToString=We;exports.LIFE_CYCLES_LIST=Ke;exports.LocalService=Tt;exports.MemoryService=He;exports.NodeEnv=Fe;exports.PAGE_ROUTE_NAME=M;exports.Provider=Oe;exports.StorageService=At;exports.VTJ_RENDERER_VERSION=A;exports.adoptedStyleSheets=Y;exports.clearLoaderCache=at;exports.createAccess=Xe;exports.createAdapter=Qe;exports.createAssetScripts=Ve;exports.createAssetsCss=ze;exports.createDataSources=Te;exports.createLoader=L;exports.createMemoryService=Mt;exports.createMetaApi=$e;exports.createMock=Ce;exports.createProvider=Pt;exports.createRenderer=B;exports.createSchemaApi=Pe;exports.createSchemaApis=Re;exports.createServiceRequest=Ct;exports.defaultLoader=ke;exports.fillBasePath=O;exports.getMock=T;exports.getModifiers=re;exports.getPlugin=se;exports.getRawComponent=ge;exports.isBuiltInTag=Se;exports.isCSSUrl=H;exports.isJSCode=Ee;exports.isJSExpression=w;exports.isJSFunction=I;exports.isJSON=fe;exports.isJSUrl=x;exports.isNativeTag=we;exports.isVuePlugin=_e;exports.loadCss=ye;exports.loadCssUrl=Q;exports.loadEnhance=$t;exports.loadScriptUrl=X;exports.mockApi=Ae;exports.mockApis=be;exports.mockCleanup=te;exports.nodeRender=C;exports.parseDeps=me;exports.parseExpression=k;exports.parseFunction=U;exports.parseUrls=ve;exports.providerKey=ne;exports.removeProdFlag=he;exports.setupPageSetting=Ge;exports.toString=W;exports.useAccess=je;exports.useMask=kt;exports.useProvider=ie;
|
10
|
+
}`:"(v) => {}"},n=t.__parseFunction(s),i=re(w(e.modifiers)?t.__parseExpression(e.modifiers):e.modifiers),a=w(e.arg)?t.__parseExpression(e.arg):e.arg||"modelValue";return{[a]:t.__parseExpression(e.value),[`onUpdate:${a}`]:i.length&&n?r.withModifiers(n,i):n}}function _t(r,e,t,s,n){if(!e)return null;if(c.isString(e))return{default:()=>e};if(w(e))return{default:()=>W(t.__parseExpression(e))};if(Array.isArray(e)&&e.length>0){const i=St(e),a=o=>!o||!n?{}:n?.id&&Object.keys(o).length?{[`scope_${n.id}`]:o}:{};return Object.entries(i).reduce((o,[l,{nodes:u,params:p}])=>(o[l]=d=>{const g=p.length?c.pick(d??{},p):a(d);return u.map(h=>A(h,t.__clone(g),r,s,u))},o),{})}return null}function St(r){const e={default:{params:[],nodes:[]}};for(const t of r){const s=wt(t.slot),n=s.name;e[n]?(e[n].nodes.push(t),e[n].params=e[n].params.concat(s.params)):e[n]={nodes:[t],params:s.params}}return e}function wt(r="default"){return c.isString(r)?{name:r,params:[]}:{params:[],...r}}function Et(r,e,t){const{value:s,iterator:n}=r,{item:i="item",index:a="index"}=n||{};let o=t.__parseExpression(s)||[];return Number.isInteger(o)&&(o=new Array(o).fill(!0).map((l,u)=>u+1)),Array.isArray(o)?o.map((l,u)=>e(t.__clone({[i]:l,[a]:u}))):(console.warn("[vForRender]:",`${s?.value} is not a Arrary`),[])}const ae=S.defineComponent({name:"VtjPageContainer",async setup(){const r=ie(),e=ce.useRoute(),t=e.params.id,s=t?r.getPage(t):r.getHomepage(),n=s?await r.getRenderComponent(s.id):null,i=S.ref(Symbol());if(s){Object.assign(e.meta,s.meta||{},{cache:s.cache});const{useTitle:a}=r?.adapter;a&&a(s.title||"VTJ")}return{provider:r,component:n,file:s,query:e.query,meta:e.meta,sid:i,route:e}},render(){const{component:r,query:e,sid:t}=this;return r?S.h(r,{...e,key:t}):S.h("div","页面不存在")},activated(){this.meta.cache===!1&&(this.sid=Symbol())}}),jt=S.defineComponent({name:"VtjStartupContainer",render(){return S.h("div","page not found!")}}),ne=Symbol("Provider");var Fe=(r=>(r.Production="production",r.Development="development",r))(Fe||{});class Oe extends $.Base{constructor(e){super(),this.options=e;const{service:t,mode:s=y.Raw,dependencies:n,materials:i,project:a={},adapter:o={},globals:l={},modules:u={},router:p=null,materialPath:d="./",nodeEnv:g="development"}=e;this.mode=s,this.modules=u,this.service=t,this.router=p,this.materialPath=d,this.nodeEnv=g,n&&(this.dependencies=n),i&&(this.materials=i),Object.assign(this.globals,l),Object.assign(this.adapter,o);const{access:h,request:f}=this.adapter;h&&h.connect({mode:s,router:p,request:f}),a&&s!==y.Design?this.load(a):this.project=a}mode;globals={};modules={};adapter={request:c.request,jsonp:c.jsonp};apis={};dependencies={};materials={};library={};service;project=null;components={};nodeEnv="development";router=null;materialPath="./";urlDslCaches={};createMock(e){return async(...t)=>{let s={};if(e)try{s=await e.apply(e,t)}catch(i){c.logger.warn("模拟数据模版异常",i)}return T()?.mock(s)}}async load(e){const t=this.modules[`.vtj/projects/${e.id}.json`]||this.modules[`/src/.vtj/projects/${e.id}.json`];if(this.project=t?await t():await this.service.init(e),!this.project)throw new Error("project is null");const{apis:s=[],meta:n=[]}=this.project,i=window;i&&(i.CKEDITOR_VERSION=void 0),this.mode===y.Raw?await this.loadDependencies(i):await this.loadAssets(i),this.initMock(i),this.apis=Re(s,n,this.adapter),te(i),be(s,i),e.platform!=="uniapp"&&this.initRouter(),this.triggerReady()}initMock(e){const t=T(e);t&&t.setup({timeout:"50-500"})}async loadDependencies(e){const t=Object.entries(this.dependencies);for(const[s,n]of t)e[s]||(e[s]=this.library[s]=await n())}async loadAssets(e){const{dependencies:t=[]}=this.project,{dependencies:s,library:n,components:i,materialPath:a,nodeEnv:o}=this,{libraryExports:l,libraryMap:u,materials:p,materialExports:d,materialMapLibrary:g}=me(t,a,o==="development");for(const h of l){const f=s[h],m=e[h];if(m)n[h]=m;else if(f)e[h]=n[h]=await f();else{const E=u[h]||[];for(const v of E)H(v)&&await ye(h,c.url.append(v,{v:M})),x(v)&&await c.loadScript(c.url.append(v,{v:M}));n[h]=e[h]}}if(o==="development"){for(const f of p)await c.loadScript(c.url.append(f,{v:M}));const h=this.materials||{};for(const f of d){const m=e[g[f]],E=$.BUILT_IN_COMPONENTS[f];if(E)m&&E.forEach(v=>{i[v]=m[v]});else{const v=h[f]?(await h[f]()).default:e[f];v&&m&&(v.components||[]).forEach(R=>{i[R.name]=ge(R,m)})}}}}initRouter(){const{router:e,project:t,options:s,adapter:n}=this;if(!e)return;const i=t?.platform==="uniapp"?"pages":"page",{routeAppendTo:a,pageRouteName:o=i,routeMeta:l}=s,u=a?"":"/",p={path:`${u}${o}/:id`,name:k,component:ae},d={path:u,name:D,component:t?.homepage?ae:n.startupComponent||jt,meta:l};e.hasRoute(k)&&e.removeRoute(k),e.hasRoute(D)&&e.removeRoute(D),a?(e.addRoute(a,p),e.addRoute(a,d)):(e.addRoute(p),e.addRoute(d))}install(e){const t=e.config.globalProperties.installed||{};for(const[s,n]of Object.entries(this.library))!t[s]&&_e(n)&&(e.use(n),t[s]=!0);this.options.install&&e.use(this.options.install),this.adapter.access&&e.use(this.adapter.access),e.provide(ne,this),e.config.globalProperties.$provider=this,e.config.globalProperties.installed=t,this.mode===y.Design&&(e.config.errorHandler=(s,n,i)=>{const a=n?.$options.name,o=typeof s=="string"?s:s?.message||s?.msg||"未知错误",l=`[ ${a} ] ${o} ${i}`;console.error("[VTJ Error]:",{err:s,instance:n,info:i},s?.stack),this.adapter.notify&&this.adapter.notify(l,"组件渲染错误","error")}),this.options.enhance&&e.use(this.options.enhance,this)}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=(n,i=[])=>{for(const a of i){if(a.id===n)return a;if(a.children&&a.children.length){const o=s(n,a.children);if(o)return o}}};return s(e,t)||null}getHomepage(){const{homepage:e}=this.project||{};return e?this.getPage(e):null}async getDsl(e){const t=this.modules[`.vtj/files/${e}.json`]||this.modules[`/src/.vtj/files/${e}.json`];return t?await t():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:n,mode:i,apis:a}=this,o={mode:i,Vue:s.Vue,components:n,libs:s,apis:a,window,...t},l=L({getDsl:async u=>await this.getDsl(u)||null,getDslByUrl:async u=>await this.getDslByUrl(u)||null,options:o});return B({...o,dsl:e,loader:l})}async getRenderComponent(e,t){const s=this.getFile(e);if(!s)return c.logger.warn(`Can not find file: ${e}`),null;t&&t(s);const n=`.vtj/vue/${e}.vue`,i=this.modules[n]||this.modules[`/src/pages/${e}.vue`];if(i)return(await i())?.default;const a=await this.getDsl(s.id);return a?this.createDslRenderer(a).renderer:(c.logger.warn(`Can not find dsl: ${e}`),null)}defineUrlSchemaComponent(e,t){return S.defineAsyncComponent(async()=>{const s=await this.getDslByUrl(e);return s?(s.name=t||s.name,this.createDslRenderer(s).renderer):null})}definePluginComponent(e){return S.defineAsyncComponent(async()=>await se(e,window))}}function Pt(r){const e=new Oe(r);return{provider:e,onReady:s=>e.ready(s)}}function ie(r={}){const e=S.inject(ne,null);if(!e)throw new Error("Can not find provider");if(e.nodeEnv==="development"){const{id:t,version:s}=r;t&&s&&(async()=>{const n=await e.getDsl(t);n?.__VERSION__!==s&&e.adapter.notify&&e.adapter.notify(`[ ${n?.name} ] 组件源码版本与运行时版本不一致,请重新发布组件`,"版本不一致","warning")})()}return e}async function $t(r,e=""){const{name:t,urls:s=[]}=r||{},n=s.map(o=>e+o),{css:i,js:a}=ve(n);if(i.length&&Q(i),a.length)return await X(a,t).catch(()=>{})}const De={type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:r=>r.data?.code===0},Rt=(r,e="/__vtj__/api/:type.json")=>(t,s,n)=>r.send({url:e,method:"post",params:{type:t},query:n,data:{type:t,data:s},settings:De}),bt=(r,e="/__vtj__/api/uploader.json")=>async(t,s)=>await r.send({url:e,method:"post",data:{files:t,projectId:s},settings:{...De,type:"data"}}).then(n=>n&&n[0]?n[0]:null).catch(()=>null);function Ct(r){return c.createRequest({settings:{type:"json",validSuccess:!0,originResponse:!1,failMessage:!0,validate:e=>e.data?.code===0,showError:e=>{r&&r(e||"未知错误")}}})}class J{constructor(e=c.request){this.req=e,this.api=Rt(e),this.uploader=bt(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(i=>fe(i))[0];if(!s)return null;const n=this.pluginCaches[s];return n||(this.pluginCaches[s]=c.request.send({url:s,method:"get",settings:{validSuccess:!1,originResponse:!0}}).then(i=>i.data).catch(()=>null))}async genSource(e){return console.log("BaseService.genSource",e),""}}const _=new c.Storage({type:"local",expired:0,prefix:"__VTJ_"});class At extends J{init(e){const t=new $.ProjectModel(e),s=_.get(`project_${t.id}`),n=Object.assign(t.toDsl(),s||{});return _.save(`project_${t.id}`,n),Promise.resolve(n)}saveProject(e){const t=new $.ProjectModel(e);return _.save(`project_${t.id}`,t.toDsl()),Promise.resolve(!0)}saveMaterials(e,t){return _.save(`materials_${e.id}`,c.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 n=(t.items||[]).map(i=>i.id);this.removeHistoryItem(e,n),_.remove(`history_${e}`)}return Promise.resolve(!0)}getHistory(e){const t=_.get(`history_${e}`),s=new $.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 He extends J{projects={};materials={};files={};histories={};historyItems={};init(e){const t=new $.ProjectModel(e),s=this.projects[t.id]||{},n=Object.assign(t.toDsl(),s);return this.projects[n.id]=n,Promise.resolve(n)}saveProject(e){const t=new $.ProjectModel(e);return this.projects[t.id]=t.toDsl(),Promise.resolve(!0)}saveMaterials(e,t){return e.id&&(this.materials[e.id]=c.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 n=(t.items||[]).map(i=>i.id);this.removeHistoryItem(e,n),delete this.historyItems[e]}return Promise.resolve(!0)}getHistory(e){const t=this.histories[e],s=new $.HistoryModel(t||{id:e});return Promise.resolve(s)}getHistoryItem(e,t){const s=`${e}_${t}`,n=this.historyItems[s]||{};return Promise.resolve(n)}saveHistoryItem(e,t){const s=`${e}_${t.id}`;return this.historyItems[s]=t,Promise.resolve(!0)}removeHistoryItem(e,t){return t.forEach(s=>{const n=`${e}_${s}`;delete this.historyItems[n]}),Promise.resolve(!0)}}let N=null;function Mt(){return N||(N=new He,N)}class kt extends J{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:c.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)}}function xe(r,e,t=[]){return t.map(s=>{const{id:n,title:i,icon:a,children:o,hidden:l}=s;return{id:n,title:i,icon:a,hidden:l,url:`${r}/${e}/${n}`,children:o&&o.length?xe(r,e,o):void 0}})}function Ne(r,e){if(!e)return r;let t=[];for(const s of r)if(s.children&&s.children.length){const n=Ne(s.children,e);n.length&&(s.children=n,t.push(s))}else e.can(s.id.toString())&&t.push(s);return t}function Tt(r){const{menuPathPrefix:e="",pageRouteName:t="page",disableMenusFilter:s=!1}=r||{},n=ie(),i=ce.useRoute(),a=je(),o=S.ref(!1),l=S.ref(!1),u=n.project;S.watchEffect(()=>{const{name:g,params:h,meta:f}=i;if(g===k){const m=n.getPage(h.id);o.value=!m?.mask,l.value=!!m?.pure}else if(g===D){const m=n.getHomepage();o.value=!m?.mask,l.value=!!m?.pure}else o.value=!f.mask,l.value=!!f.pure});const p=xe(e,t,u?.pages),d=u?.config;return{disabled:o,logo:d?.logo,themeSwitchable:d?.themeSwitchable,title:d?.title||u?.description||u?.name||"VTJ App",menus:s?p:Ne(p,a),pure:l}}exports.ACCESS_KEY=Z;exports.Access=ee;exports.BUILD_IN_TAGS=de;exports.BUILT_IN_DIRECTIVES=le;exports.BaseService=J;exports.CONTEXT_HOST=z;exports.Context=Me;exports.ContextMode=y;exports.DATA_TYPES=ue;exports.HOMEPAGE_ROUTE_NAME=D;exports.HTML_TAGS=pe;exports.JSCodeToString=We;exports.LIFE_CYCLES_LIST=Ke;exports.LocalService=kt;exports.MemoryService=He;exports.NodeEnv=Fe;exports.PAGE_ROUTE_NAME=k;exports.Provider=Oe;exports.StorageService=At;exports.VTJ_RENDERER_VERSION=M;exports.adoptedStyleSheets=Y;exports.clearLoaderCache=at;exports.createAccess=Xe;exports.createAdapter=Qe;exports.createAssetScripts=Ve;exports.createAssetsCss=ze;exports.createDataSources=ke;exports.createLoader=L;exports.createMemoryService=Mt;exports.createMetaApi=$e;exports.createMock=Ce;exports.createProvider=Pt;exports.createRenderer=B;exports.createSchemaApi=Pe;exports.createSchemaApis=Re;exports.createServiceRequest=Ct;exports.defaultLoader=Te;exports.fillBasePath=O;exports.getMock=T;exports.getModifiers=re;exports.getPlugin=se;exports.getRawComponent=ge;exports.isBuiltInTag=Se;exports.isCSSUrl=H;exports.isJSCode=Ee;exports.isJSExpression=w;exports.isJSFunction=F;exports.isJSON=fe;exports.isJSUrl=x;exports.isNativeTag=we;exports.isVuePlugin=_e;exports.loadCss=ye;exports.loadCssUrl=Q;exports.loadEnhance=$t;exports.loadScriptUrl=X;exports.mockApi=Ae;exports.mockApis=be;exports.mockCleanup=te;exports.nodeRender=A;exports.parseDeps=me;exports.parseExpression=I;exports.parseFunction=U;exports.parseUrls=ve;exports.providerKey=ne;exports.removeProdFlag=he;exports.setupPageSetting=Ge;exports.toString=W;exports.useAccess=je;exports.useMask=Tt;exports.useProvider=ie;
|
package/dist/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Base as xe, BUILT_IN_COMPONENTS as Oe, ProjectModel as N, HistoryModel as pe } from "@vtj/core";
|
2
|
-
import { isUrl as Ne, url as
|
2
|
+
import { isUrl as Ne, url as C, dedupArray as Be, isString as E, isFunction as V, logger as k, storage as J, cookie as K, toArray as re, unRSA as ie, delay as fe, createRequest as de, jsonp as he, merge as Ue, pathToRegexp as Le, pathToRegexpMatch as qe, formDataToJson as Je, cloneDeep as oe, camelCase as j, upperFirst as Ke, pick as ze, request as W, loadScript as ae, Storage as Ve, mapToObject as te } from "@vtj/utils";
|
3
3
|
import * as B from "vue";
|
4
4
|
import { inject as me, defineComponent as ve, h as G, ref as Y, defineAsyncComponent as ce, watchEffect as We } from "vue";
|
5
5
|
import { useRoute as ge } from "vue-router";
|
@@ -7,10 +7,10 @@ import { useRoute as ge } from "vue-router";
|
|
7
7
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
8
8
|
* @name @vtj/renderer
|
9
9
|
* @author CHC chenhuachun1549@dingtalk.com
|
10
|
-
* @version 0.12.
|
10
|
+
* @version 0.12.21
|
11
11
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
12
12
|
*/
|
13
|
-
const A = "0.12.
|
13
|
+
const A = "0.12.21";
|
14
14
|
var y = /* @__PURE__ */ ((n) => (n.Runtime = "Runtime", n.Design = "Design", n.Raw = "Raw", n.VNode = "VNode", n))(y || {});
|
15
15
|
const le = [
|
16
16
|
"$el",
|
@@ -72,12 +72,12 @@ function Ze(n) {
|
|
72
72
|
}
|
73
73
|
function es(n) {
|
74
74
|
return n.map(
|
75
|
-
(e) => `<script src="${
|
75
|
+
(e) => `<script src="${C.append(e, { v: A })}"><\/script>`
|
76
76
|
).join("");
|
77
77
|
}
|
78
78
|
function ts(n = []) {
|
79
79
|
return n.map(
|
80
|
-
(e) => `<link rel="stylesheet" href="${
|
80
|
+
(e) => `<link rel="stylesheet" href="${C.append(e, { v: A })}" />`
|
81
81
|
).join("");
|
82
82
|
}
|
83
83
|
function et(n, e = !1) {
|
@@ -86,10 +86,10 @@ function et(n, e = !1) {
|
|
86
86
|
function tt(n, e, t = !1) {
|
87
87
|
const s = n.filter((m) => !!m.enabled), r = [], i = [], a = [], o = [], c = {}, l = {}, u = [], p = {};
|
88
88
|
return s.forEach(
|
89
|
-
({ urls: m, assetsUrl:
|
89
|
+
({ urls: m, assetsUrl: d, library: f, assetsLibrary: h, localeLibrary: _ }) => {
|
90
90
|
m?.forEach((v) => {
|
91
91
|
L(v) && r.push(et(v, t)), U(v) && i.push(v);
|
92
|
-
}),
|
92
|
+
}), f && (o.push(f), c[f] = D(m || [], e), _ && (l[f] = _)), d && a.push(d), h && u.push(h), f && h && (p[h] = f);
|
93
93
|
}
|
94
94
|
), {
|
95
95
|
scripts: D(r, e),
|
@@ -114,7 +114,7 @@ function nt(n = []) {
|
|
114
114
|
};
|
115
115
|
}
|
116
116
|
function ye(n) {
|
117
|
-
return
|
117
|
+
return E(n) ? n : JSON.stringify(n);
|
118
118
|
}
|
119
119
|
function _e(n, e, t) {
|
120
120
|
const s = n.CSSStyleSheet;
|
@@ -188,13 +188,13 @@ function H(n, e, t = !1, s = !1) {
|
|
188
188
|
const a = `with(${t ? "{}" : "$scope || {}"}) { ${i} }`;
|
189
189
|
return new Function("$scope", a)(e);
|
190
190
|
} catch (r) {
|
191
|
-
if (
|
191
|
+
if (k.error("parseExpression.error", r, n, e?.__self ?? e), s)
|
192
192
|
throw r;
|
193
193
|
}
|
194
194
|
}
|
195
195
|
function Q(n, e, t = !1, s = !1) {
|
196
196
|
const r = H(n, e, t, s);
|
197
|
-
if (typeof r != "function" && (
|
197
|
+
if (typeof r != "function" && (k.error(
|
198
198
|
"parseFunction.error",
|
199
199
|
"not a function",
|
200
200
|
n,
|
@@ -229,7 +229,7 @@ const lt = {
|
|
229
229
|
appName: "",
|
230
230
|
statusKey: "code"
|
231
231
|
}, $e = Symbol("access");
|
232
|
-
class
|
232
|
+
class je {
|
233
233
|
options;
|
234
234
|
data = null;
|
235
235
|
mode = y.Raw;
|
@@ -347,7 +347,7 @@ class Ee {
|
|
347
347
|
return t();
|
348
348
|
{
|
349
349
|
const { noPermissionMessage: s = "无权限访问", unauthorized: r = !1 } = this.options;
|
350
|
-
return await this.showTip(s), V(r) ? (r(), t(!1)) :
|
350
|
+
return await this.showTip(s), V(r) ? (r(), t(!1)) : E(r) ? t(r) : t(!1);
|
351
351
|
}
|
352
352
|
}
|
353
353
|
t(!1), this.toLogin();
|
@@ -422,11 +422,11 @@ function rs(n = {}) {
|
|
422
422
|
loading: t,
|
423
423
|
useTitle: a,
|
424
424
|
startupComponent: r,
|
425
|
-
access: i ? new
|
425
|
+
access: i ? new je({ alert: o, ...i }) : void 0
|
426
426
|
};
|
427
427
|
}
|
428
428
|
function is(n = {}) {
|
429
|
-
return new
|
429
|
+
return new je(n);
|
430
430
|
}
|
431
431
|
function pt(n, e) {
|
432
432
|
const { jsonp: t, request: s } = e;
|
@@ -469,7 +469,7 @@ function dt(n = [], e = [], t) {
|
|
469
469
|
}
|
470
470
|
async function ht(n = [], e = window) {
|
471
471
|
const t = M(e);
|
472
|
-
t && (
|
472
|
+
t && (Ee(e), n.forEach((s) => vt(t, s)));
|
473
473
|
}
|
474
474
|
function mt(n, e = window) {
|
475
475
|
const t = T(n.mockTemplate) && n.mockTemplate.value ? Q(n.mockTemplate, {}, !0) : void 0, s = M(e);
|
@@ -479,7 +479,7 @@ function mt(n, e = window) {
|
|
479
479
|
try {
|
480
480
|
i = await t.apply(t, r);
|
481
481
|
} catch (a) {
|
482
|
-
|
482
|
+
k.warn("模拟数据模版异常", a);
|
483
483
|
}
|
484
484
|
return s?.mock(i);
|
485
485
|
};
|
@@ -490,12 +490,12 @@ function vt(n, e) {
|
|
490
490
|
if (t && s) {
|
491
491
|
const r = Le(`${t}(.*)`), i = qe(t, { decode: decodeURIComponent }), a = H(s, {}, !0);
|
492
492
|
n.mock(r, (o) => {
|
493
|
-
const c =
|
493
|
+
const c = C.parse(o.url) || {}, l = o.body instanceof FormData ? Je(o.body) : o.body, u = i(o.url)?.params;
|
494
494
|
return Object.assign(o, { data: l, params: c, query: u }), n.mock(a(o));
|
495
495
|
});
|
496
496
|
}
|
497
497
|
}
|
498
|
-
function
|
498
|
+
function Ee(n = window) {
|
499
499
|
const e = M(n);
|
500
500
|
e && (e._mocked = {});
|
501
501
|
}
|
@@ -625,13 +625,16 @@ function X(n) {
|
|
625
625
|
o.value.id,
|
626
626
|
o.value.css || ""
|
627
627
|
), l.state = wt(e, o.value.state ?? {}, l);
|
628
|
-
const m = St(e, o.value.computed ?? {}, l),
|
628
|
+
const m = St(e, o.value.computed ?? {}, l), d = $t(o.value.methods ?? {}, l), f = jt(e, o.value.inject, l);
|
629
|
+
for (const [v, P] of Object.entries(f || {}))
|
630
|
+
f[v] = e.inject(v, P);
|
631
|
+
const h = Et(
|
629
632
|
o.value.dataSources || {},
|
630
633
|
l
|
631
634
|
), _ = {
|
632
|
-
...d,
|
633
|
-
...m,
|
634
635
|
...f,
|
636
|
+
...m,
|
637
|
+
...d,
|
635
638
|
...h
|
636
639
|
};
|
637
640
|
return l.setup(_, e), Pt(e, o.value.watch ?? [], l), {
|
@@ -643,8 +646,8 @@ function X(n) {
|
|
643
646
|
render() {
|
644
647
|
if (!o.value.nodes) return null;
|
645
648
|
const p = o.value.nodes || [];
|
646
|
-
return p.length === 1 ?
|
647
|
-
(m) =>
|
649
|
+
return p.length === 1 ? F(p[0], l, e, a, p) : p.map(
|
650
|
+
(m) => F(m, l, e, a, p)
|
648
651
|
);
|
649
652
|
},
|
650
653
|
...Rt(o.value.lifeCycles ?? {}, l)
|
@@ -655,11 +658,11 @@ function X(n) {
|
|
655
658
|
};
|
656
659
|
}
|
657
660
|
function yt(n = []) {
|
658
|
-
return n.map((e) =>
|
661
|
+
return n.map((e) => E(e) ? e : e.name);
|
659
662
|
}
|
660
663
|
function _t(n = [], e) {
|
661
664
|
const t = (s) => s ? (Array.isArray(s) ? s : [s]).map((i) => Ye[i]) : void 0;
|
662
|
-
return n.map((s) =>
|
665
|
+
return n.map((s) => E(s) ? {
|
663
666
|
name: s
|
664
667
|
} : {
|
665
668
|
name: s.name,
|
@@ -698,7 +701,7 @@ function $t(n, e) {
|
|
698
701
|
{}
|
699
702
|
);
|
700
703
|
}
|
701
|
-
function
|
704
|
+
function jt(n, e = [], t) {
|
702
705
|
return e.reduce(
|
703
706
|
(s, r) => {
|
704
707
|
const { name: i, from: a } = r || {};
|
@@ -709,7 +712,7 @@ function Et(n, e = [], t) {
|
|
709
712
|
{}
|
710
713
|
);
|
711
714
|
}
|
712
|
-
function
|
715
|
+
function Et(n, e) {
|
713
716
|
return Object.keys(n).reduce(
|
714
717
|
(t, s) => {
|
715
718
|
const r = n[s];
|
@@ -745,7 +748,7 @@ function Rt(n, e) {
|
|
745
748
|
{}
|
746
749
|
);
|
747
750
|
}
|
748
|
-
let z = [],
|
751
|
+
let z = [], b = {};
|
749
752
|
const bt = (n) => n;
|
750
753
|
async function Pe(n, e = window) {
|
751
754
|
const { urls: t = [], library: s } = n, r = t.filter((o) => L(o));
|
@@ -763,8 +766,8 @@ function Z(n) {
|
|
763
766
|
if (!i || typeof i == "string") return r;
|
764
767
|
if (i.type === "Schema" && i.id)
|
765
768
|
return a.defineAsyncComponent(async () => {
|
766
|
-
const o =
|
767
|
-
return o && (o.name = r,
|
769
|
+
const o = b[i.id] || await e(i.id);
|
770
|
+
return o && (o.name = r, b[i.id] = o), o ? X({
|
768
771
|
...s,
|
769
772
|
Vue: a,
|
770
773
|
dsl: oe(o),
|
@@ -774,8 +777,8 @@ function Z(n) {
|
|
774
777
|
});
|
775
778
|
if (i.type === "UrlSchema" && i.url)
|
776
779
|
return a.defineAsyncComponent(async () => {
|
777
|
-
const o =
|
778
|
-
return o && (o.name = r,
|
780
|
+
const o = b[i.url] || await t(i.url);
|
781
|
+
return o && (o.name = r, b[i.url] = o), o ? X({
|
779
782
|
...s,
|
780
783
|
Vue: a,
|
781
784
|
dsl: oe(o),
|
@@ -784,8 +787,8 @@ function Z(n) {
|
|
784
787
|
}).renderer : null;
|
785
788
|
});
|
786
789
|
if (i.type === "Plugin") {
|
787
|
-
let o = i.library ?
|
788
|
-
return o || (i.library && z.push(i.library), o =
|
790
|
+
let o = i.library ? b[i.library] : null;
|
791
|
+
return o || (i.library && z.push(i.library), o = b[i.library || Symbol()] = a.defineAsyncComponent(
|
789
792
|
async () => {
|
790
793
|
const c = await Pe(i, s.window);
|
791
794
|
return c || (console.warn("getPlugin result is null", i), null);
|
@@ -796,30 +799,30 @@ function Z(n) {
|
|
796
799
|
};
|
797
800
|
}
|
798
801
|
function os() {
|
799
|
-
|
802
|
+
b = {};
|
800
803
|
}
|
801
|
-
function
|
804
|
+
function F(n, e, t = B, s = bt, r = [], i = !1) {
|
802
805
|
if (!n || !n.name || n.invisible) return null;
|
803
|
-
const a = t.getCurrentInstance()?.appContext, { id: o = null, directives: c = [] } = n, { vIf: l, vElseIf: u, vElse: p, vFor: m, vShow:
|
806
|
+
const a = t.getCurrentInstance()?.appContext, { id: o = null, directives: c = [] } = n, { vIf: l, vElseIf: u, vElse: p, vFor: m, vShow: d, vModels: f, vBind: h, vHtml: _, others: v } = Re(c);
|
804
807
|
if (!i && (u || p))
|
805
808
|
return null;
|
806
809
|
if (l && !kt(l, e))
|
807
810
|
return Mt(n, e, t, s, r);
|
808
|
-
const
|
811
|
+
const P = (S) => {
|
809
812
|
const Me = S.$components, He = (() => {
|
810
813
|
if (n.name === "component")
|
811
814
|
return Ft(S, n.props?.is);
|
812
815
|
if (n.name === "slot") return n.name;
|
813
816
|
const $ = s(n.name, n.from, t);
|
814
|
-
return
|
815
|
-
})(),
|
817
|
+
return E($) ? ot($) || at($) ? $ : Me[$] ?? a?.app?.component($) ?? $ : $;
|
818
|
+
})(), R = At(o, n.props ?? {}, S), Te = It(t, n.events ?? {}, S);
|
816
819
|
if (n.name === "slot")
|
817
|
-
return Ht(t, n,
|
818
|
-
h && Object.assign(
|
819
|
-
|
820
|
-
Dt(
|
821
|
-
)), _ && Object.assign(
|
822
|
-
Object.assign(
|
820
|
+
return Ht(t, n, R, S, s);
|
821
|
+
h && Object.assign(R, S.__parseExpression(h.value)), d && (R.style = Object.assign(
|
822
|
+
R.style ?? {},
|
823
|
+
Dt(d, S)
|
824
|
+
)), _ && Object.assign(R, xt(_, S)), f.forEach(($) => {
|
825
|
+
Object.assign(R, Ot(t, $, S));
|
823
826
|
});
|
824
827
|
const De = Nt(
|
825
828
|
t,
|
@@ -828,11 +831,11 @@ function k(n, e, t = B, s = bt, r = [], i = !1) {
|
|
828
831
|
s,
|
829
832
|
n
|
830
833
|
);
|
831
|
-
let q = t.createVNode(He, { ...
|
834
|
+
let q = t.createVNode(He, { ...R, ...Te }, De);
|
832
835
|
const ne = a ? Ct(a, v, S) : [];
|
833
836
|
return ne.length && (q = t.withDirectives(q, ne)), q;
|
834
837
|
};
|
835
|
-
return m ? Lt(m,
|
838
|
+
return m ? Lt(m, P, e) : P(e);
|
836
839
|
}
|
837
840
|
function Ct(n, e, t) {
|
838
841
|
const s = n.app;
|
@@ -844,12 +847,12 @@ function Ct(n, e, t) {
|
|
844
847
|
}).filter((r) => !!r);
|
845
848
|
}
|
846
849
|
function Re(n = []) {
|
847
|
-
const e = n.find((u) =>
|
848
|
-
(u) =>
|
849
|
-
), s = n.find((u) =>
|
850
|
-
(u) =>
|
850
|
+
const e = n.find((u) => j(u.name) === "vIf"), t = n.find(
|
851
|
+
(u) => j(u.name) === "vElseIf"
|
852
|
+
), s = n.find((u) => j(u.name) === "vElse"), r = n.find((u) => j(u.name) === "vFor"), i = n.find((u) => j(u.name) === "vShow"), a = n.find((u) => j(u.name) === "vBind"), o = n.find((u) => j(u.name) === "vHtml"), c = n.filter(
|
853
|
+
(u) => j(u.name) === "vModel"
|
851
854
|
), l = n.filter(
|
852
|
-
(u) => !Ge.includes(
|
855
|
+
(u) => !Ge.includes(j(u.name))
|
853
856
|
);
|
854
857
|
return {
|
855
858
|
vIf: e,
|
@@ -902,11 +905,11 @@ function Mt(n, e, t, s, r = []) {
|
|
902
905
|
const { directives: o = [] } = r[a], { vElseIf: c, vElse: l } = Re(o);
|
903
906
|
if (c) {
|
904
907
|
if (e.__parseExpression(c.value))
|
905
|
-
return
|
908
|
+
return F(r[a], e, t, s, r, !0);
|
906
909
|
continue;
|
907
910
|
}
|
908
911
|
if (l)
|
909
|
-
return
|
912
|
+
return F(r[a], e, t, s, r, !0);
|
910
913
|
}
|
911
914
|
return null;
|
912
915
|
}
|
@@ -916,10 +919,10 @@ function be(n = {}, e = !1) {
|
|
916
919
|
}
|
917
920
|
function Ht(n, e, t, s, r) {
|
918
921
|
const { children: i } = e, a = Tt(e, s), o = s.$slots?.[a.name];
|
919
|
-
return o ? o(t) : i ?
|
922
|
+
return o ? o(t) : i ? E(i) ? n.createTextVNode(i) : w(i) ? n.createTextVNode(
|
920
923
|
ye(s.__parseExpression(i))
|
921
924
|
) : Array.isArray(i) ? i.map(
|
922
|
-
(c) =>
|
925
|
+
(c) => F(c, s, n, r, i)
|
923
926
|
) : null : null;
|
924
927
|
}
|
925
928
|
function Tt(n, e) {
|
@@ -955,7 +958,7 @@ function Ot(n, e, t) {
|
|
955
958
|
}
|
956
959
|
function Nt(n, e, t, s, r) {
|
957
960
|
if (!e) return null;
|
958
|
-
if (
|
961
|
+
if (E(e))
|
959
962
|
return { default: () => e };
|
960
963
|
if (w(e))
|
961
964
|
return {
|
@@ -968,7 +971,7 @@ function Nt(n, e, t, s, r) {
|
|
968
971
|
return Object.entries(i).reduce((o, [c, { nodes: l, params: u }]) => (o[c] = (p) => {
|
969
972
|
const m = u.length ? ze(p ?? {}, u) : a(p);
|
970
973
|
return l.map(
|
971
|
-
(
|
974
|
+
(d) => F(d, t.__clone(m), n, s, l)
|
972
975
|
);
|
973
976
|
}, o), {});
|
974
977
|
}
|
@@ -991,7 +994,7 @@ function Bt(n) {
|
|
991
994
|
return e;
|
992
995
|
}
|
993
996
|
function Ut(n = "default") {
|
994
|
-
return
|
997
|
+
return E(n) ? { name: n, params: [] } : { params: [], ...n };
|
995
998
|
}
|
996
999
|
function Lt(n, e, t) {
|
997
1000
|
const { value: s, iterator: r } = n, { item: i = "item", index: a = "index" } = r || {};
|
@@ -1032,6 +1035,11 @@ const ue = ve({
|
|
1032
1035
|
}), Ce = Symbol("Provider");
|
1033
1036
|
var Jt = /* @__PURE__ */ ((n) => (n.Production = "production", n.Development = "development", n))(Jt || {});
|
1034
1037
|
class Kt extends xe {
|
1038
|
+
// DSL缓存
|
1039
|
+
/**
|
1040
|
+
* 创建Provider实例
|
1041
|
+
* @param options 配置选项
|
1042
|
+
*/
|
1035
1043
|
constructor(e) {
|
1036
1044
|
super(), this.options = e;
|
1037
1045
|
const {
|
@@ -1049,23 +1057,37 @@ class Kt extends xe {
|
|
1049
1057
|
/* Development */
|
1050
1058
|
} = e;
|
1051
1059
|
this.mode = s, this.modules = l, this.service = t, this.router = u, this.materialPath = p, this.nodeEnv = m, r && (this.dependencies = r), i && (this.materials = i), Object.assign(this.globals, c), Object.assign(this.adapter, o);
|
1052
|
-
const { access:
|
1053
|
-
|
1060
|
+
const { access: d, request: f } = this.adapter;
|
1061
|
+
d && d.connect({ mode: s, router: u, request: f }), a && s !== y.Design ? this.load(a) : this.project = a;
|
1054
1062
|
}
|
1055
1063
|
mode;
|
1064
|
+
// 当前运行模式(设计/源码/预览等)
|
1056
1065
|
globals = {};
|
1066
|
+
// 全局变量
|
1057
1067
|
modules = {};
|
1068
|
+
// 异步模块加载器
|
1058
1069
|
adapter = { request: W, jsonp: he };
|
1070
|
+
// 适配器接口
|
1059
1071
|
apis = {};
|
1072
|
+
// API集合
|
1060
1073
|
dependencies = {};
|
1074
|
+
// 依赖项
|
1061
1075
|
materials = {};
|
1076
|
+
// 物料资源
|
1062
1077
|
library = {};
|
1078
|
+
// 第三方库
|
1063
1079
|
service;
|
1080
|
+
// 核心服务
|
1064
1081
|
project = null;
|
1082
|
+
// 当前项目配置
|
1065
1083
|
components = {};
|
1084
|
+
// 组件集合
|
1066
1085
|
nodeEnv = "development";
|
1086
|
+
// 运行环境
|
1067
1087
|
router = null;
|
1088
|
+
// 路由实例
|
1068
1089
|
materialPath = "./";
|
1090
|
+
// 物料路径
|
1069
1091
|
urlDslCaches = {};
|
1070
1092
|
createMock(e) {
|
1071
1093
|
return async (...t) => {
|
@@ -1074,17 +1096,26 @@ class Kt extends xe {
|
|
1074
1096
|
try {
|
1075
1097
|
s = await e.apply(e, t);
|
1076
1098
|
} catch (i) {
|
1077
|
-
|
1099
|
+
k.warn("模拟数据模版异常", i);
|
1078
1100
|
}
|
1079
1101
|
return M()?.mock(s);
|
1080
1102
|
};
|
1081
1103
|
}
|
1104
|
+
/**
|
1105
|
+
* 加载项目配置并初始化
|
1106
|
+
* 1. 从模块或服务加载项目配置
|
1107
|
+
* 2. 根据运行模式加载依赖或资源
|
1108
|
+
* 3. 初始化Mock数据
|
1109
|
+
* 4. 创建API接口
|
1110
|
+
* 5. 初始化路由(非uniapp平台)
|
1111
|
+
* @param project 项目配置
|
1112
|
+
*/
|
1082
1113
|
async load(e) {
|
1083
1114
|
const t = this.modules[`.vtj/projects/${e.id}.json`] || this.modules[`/src/.vtj/projects/${e.id}.json`];
|
1084
1115
|
if (this.project = t ? await t() : await this.service.init(e), !this.project)
|
1085
1116
|
throw new Error("project is null");
|
1086
1117
|
const { apis: s = [], meta: r = [] } = this.project, i = window;
|
1087
|
-
i && (i.CKEDITOR_VERSION = void 0), this.mode === y.Raw ? await this.loadDependencies(i) : await this.loadAssets(i), this.initMock(i), this.apis = dt(s, r, this.adapter),
|
1118
|
+
i && (i.CKEDITOR_VERSION = void 0), this.mode === y.Raw ? await this.loadDependencies(i) : await this.loadAssets(i), this.initMock(i), this.apis = dt(s, r, this.adapter), Ee(i), ht(s, i), e.platform !== "uniapp" && this.initRouter(), this.triggerReady();
|
1088
1119
|
}
|
1089
1120
|
initMock(e) {
|
1090
1121
|
const t = M(e);
|
@@ -1110,33 +1141,33 @@ class Kt extends xe {
|
|
1110
1141
|
o === "development"
|
1111
1142
|
/* Development */
|
1112
1143
|
);
|
1113
|
-
for (const
|
1114
|
-
const
|
1144
|
+
for (const d of c) {
|
1145
|
+
const f = s[d], h = e[d];
|
1115
1146
|
if (h)
|
1116
|
-
r[
|
1117
|
-
else if (
|
1118
|
-
e[
|
1147
|
+
r[d] = h;
|
1148
|
+
else if (f)
|
1149
|
+
e[d] = r[d] = await f();
|
1119
1150
|
else {
|
1120
|
-
const _ = l[
|
1151
|
+
const _ = l[d] || [];
|
1121
1152
|
for (const v of _)
|
1122
|
-
U(v) && await rt(
|
1123
|
-
r[
|
1153
|
+
U(v) && await rt(d, C.append(v, { v: A })), L(v) && await ae(C.append(v, { v: A }));
|
1154
|
+
r[d] = e[d];
|
1124
1155
|
}
|
1125
1156
|
}
|
1126
1157
|
if (o === "development") {
|
1127
|
-
for (const
|
1128
|
-
await ae(
|
1129
|
-
const
|
1130
|
-
for (const
|
1131
|
-
const h = e[m[
|
1158
|
+
for (const f of u)
|
1159
|
+
await ae(C.append(f, { v: A }));
|
1160
|
+
const d = this.materials || {};
|
1161
|
+
for (const f of p) {
|
1162
|
+
const h = e[m[f]], _ = Oe[f];
|
1132
1163
|
if (_)
|
1133
1164
|
h && _.forEach((v) => {
|
1134
1165
|
i[v] = h[v];
|
1135
1166
|
});
|
1136
1167
|
else {
|
1137
|
-
const v = f
|
1138
|
-
v && h && (v.components || []).forEach((
|
1139
|
-
i[
|
1168
|
+
const v = d[f] ? (await d[f]()).default : e[f];
|
1169
|
+
v && h && (v.components || []).forEach((P) => {
|
1170
|
+
i[P.name] = st(P, h);
|
1140
1171
|
});
|
1141
1172
|
}
|
1142
1173
|
}
|
@@ -1161,6 +1192,16 @@ class Kt extends xe {
|
|
1161
1192
|
};
|
1162
1193
|
e.hasRoute(I) && e.removeRoute(I), e.hasRoute(O) && e.removeRoute(O), a ? (e.addRoute(a, u), e.addRoute(a, p)) : (e.addRoute(u), e.addRoute(p));
|
1163
1194
|
}
|
1195
|
+
/**
|
1196
|
+
* Vue 插件安装方法
|
1197
|
+
* 1. 安装所有第三方库插件
|
1198
|
+
* 2. 执行自定义安装函数(如果提供)
|
1199
|
+
* 3. 安装访问适配器
|
1200
|
+
* 4. 提供全局 Provider 实例
|
1201
|
+
* 5. 设计模式下设置错误处理器
|
1202
|
+
* 6. 执行增强函数(如果提供)
|
1203
|
+
* @param app Vue 应用实例
|
1204
|
+
*/
|
1164
1205
|
install(e) {
|
1165
1206
|
const t = e.config.globalProperties.installed || {};
|
1166
1207
|
for (const [s, r] of Object.entries(this.library))
|
@@ -1215,6 +1256,15 @@ class Kt extends xe {
|
|
1215
1256
|
}
|
1216
1257
|
}).then((s) => s.data).catch(() => null) : null);
|
1217
1258
|
}
|
1259
|
+
/**
|
1260
|
+
* 创建 DSL 渲染器
|
1261
|
+
* 1. 合并默认选项和自定义选项
|
1262
|
+
* 2. 创建 DSL 加载器
|
1263
|
+
* 3. 返回渲染器实例
|
1264
|
+
* @param dsl 区块 DSL 配置
|
1265
|
+
* @param opts 渲染选项
|
1266
|
+
* @returns 渲染器实例
|
1267
|
+
*/
|
1218
1268
|
createDslRenderer(e, t = {}) {
|
1219
1269
|
const { library: s, components: r, mode: i, apis: a } = this, o = {
|
1220
1270
|
mode: i,
|
@@ -1235,23 +1285,49 @@ class Kt extends xe {
|
|
1235
1285
|
loader: c
|
1236
1286
|
});
|
1237
1287
|
}
|
1288
|
+
/**
|
1289
|
+
* 获取渲染组件
|
1290
|
+
* 1. 根据ID查找文件(页面或区块)
|
1291
|
+
* 2. 如果找到文件且提供了output回调,则调用它
|
1292
|
+
* 3. 尝试从模块缓存加载原始Vue组件
|
1293
|
+
* 4. 如果找不到原始组件,则获取DSL并创建渲染器
|
1294
|
+
* @param id 文件ID
|
1295
|
+
* @param output 找到文件时的回调函数
|
1296
|
+
* @returns Promise<Vue组件>
|
1297
|
+
*/
|
1238
1298
|
async getRenderComponent(e, t) {
|
1239
1299
|
const s = this.getFile(e);
|
1240
1300
|
if (!s)
|
1241
|
-
return
|
1301
|
+
return k.warn(`Can not find file: ${e}`), null;
|
1242
1302
|
t && t(s);
|
1243
1303
|
const r = `.vtj/vue/${e}.vue`, i = this.modules[r] || this.modules[`/src/pages/${e}.vue`];
|
1244
1304
|
if (i)
|
1245
1305
|
return (await i())?.default;
|
1246
1306
|
const a = await this.getDsl(s.id);
|
1247
|
-
return a ? this.createDslRenderer(a).renderer : (
|
1248
|
-
}
|
1307
|
+
return a ? this.createDslRenderer(a).renderer : (k.warn(`Can not find dsl: ${e}`), null);
|
1308
|
+
}
|
1309
|
+
/**
|
1310
|
+
* 定义基于URL的异步组件
|
1311
|
+
* 1. 根据URL获取DSL配置
|
1312
|
+
* 2. 如果获取成功,设置组件名称
|
1313
|
+
* 3. 创建并返回DSL渲染器
|
1314
|
+
* @param url DSL配置URL
|
1315
|
+
* @param name 可选的自定义组件名称
|
1316
|
+
* @returns Vue异步组件
|
1317
|
+
*/
|
1249
1318
|
defineUrlSchemaComponent(e, t) {
|
1250
1319
|
return ce(async () => {
|
1251
1320
|
const s = await this.getDslByUrl(e);
|
1252
1321
|
return s ? (s.name = t || s.name, this.createDslRenderer(s).renderer) : null;
|
1253
1322
|
});
|
1254
1323
|
}
|
1324
|
+
/**
|
1325
|
+
* 定义基于插件的异步组件
|
1326
|
+
* 1. 根据插件来源获取插件实例
|
1327
|
+
* 2. 返回插件组件
|
1328
|
+
* @param from 插件来源配置
|
1329
|
+
* @returns Vue异步组件
|
1330
|
+
*/
|
1255
1331
|
definePluginComponent(e) {
|
1256
1332
|
return ce(async () => await Pe(e, window));
|
1257
1333
|
}
|
@@ -1636,15 +1712,15 @@ function ds(n) {
|
|
1636
1712
|
disableMenusFilter: s = !1
|
1637
1713
|
} = n || {}, r = ke(), i = ge(), a = ut(), o = Y(!1), c = Y(!1), l = r.project;
|
1638
1714
|
We(() => {
|
1639
|
-
const { name: m, params:
|
1715
|
+
const { name: m, params: d, meta: f } = i;
|
1640
1716
|
if (m === I) {
|
1641
|
-
const h = r.getPage(
|
1717
|
+
const h = r.getPage(d.id);
|
1642
1718
|
o.value = !h?.mask, c.value = !!h?.pure;
|
1643
1719
|
} else if (m === O) {
|
1644
1720
|
const h = r.getHomepage();
|
1645
1721
|
o.value = !h?.mask, c.value = !!h?.pure;
|
1646
1722
|
} else
|
1647
|
-
o.value = !
|
1723
|
+
o.value = !f.mask, c.value = !!f.pure;
|
1648
1724
|
});
|
1649
1725
|
const u = Ae(
|
1650
1726
|
e,
|
@@ -1662,7 +1738,7 @@ function ds(n) {
|
|
1662
1738
|
}
|
1663
1739
|
export {
|
1664
1740
|
$e as ACCESS_KEY,
|
1665
|
-
|
1741
|
+
je as Access,
|
1666
1742
|
Xe as BUILD_IN_TAGS,
|
1667
1743
|
Ge as BUILT_IN_DIRECTIVES,
|
1668
1744
|
se as BaseService,
|
@@ -1687,7 +1763,7 @@ export {
|
|
1687
1763
|
rs as createAdapter,
|
1688
1764
|
es as createAssetScripts,
|
1689
1765
|
ts as createAssetsCss,
|
1690
|
-
|
1766
|
+
Et as createDataSources,
|
1691
1767
|
Z as createLoader,
|
1692
1768
|
ps as createMemoryService,
|
1693
1769
|
ft as createMetaApi,
|
@@ -1718,8 +1794,8 @@ export {
|
|
1718
1794
|
Se as loadScriptUrl,
|
1719
1795
|
vt as mockApi,
|
1720
1796
|
ht as mockApis,
|
1721
|
-
|
1722
|
-
|
1797
|
+
Ee as mockCleanup,
|
1798
|
+
F as nodeRender,
|
1723
1799
|
tt as parseDeps,
|
1724
1800
|
H as parseExpression,
|
1725
1801
|
Q as parseFunction,
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vtj/renderer",
|
3
3
|
"private": false,
|
4
|
-
"version": "0.12.
|
4
|
+
"version": "0.12.21",
|
5
5
|
"type": "module",
|
6
6
|
"keywords": [
|
7
7
|
"低代码引擎",
|
@@ -21,15 +21,15 @@
|
|
21
21
|
"author": "chenhuachun",
|
22
22
|
"license": "MIT",
|
23
23
|
"dependencies": {
|
24
|
-
"@vtj/core": "~0.12.
|
25
|
-
"@vtj/utils": "~0.12.
|
24
|
+
"@vtj/core": "~0.12.21",
|
25
|
+
"@vtj/utils": "~0.12.21"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"vue": "~3.5.5",
|
29
29
|
"vue-router": "~4.5.0",
|
30
30
|
"@vtj/cli": "~0.12.2",
|
31
|
-
"@vtj/
|
32
|
-
"@vtj/
|
31
|
+
"@vtj/icons": "~0.12.21",
|
32
|
+
"@vtj/ui": "~0.12.21"
|
33
33
|
},
|
34
34
|
"exports": {
|
35
35
|
".": {
|
@@ -1,5 +1,15 @@
|
|
1
1
|
import { EnhanceConfig } from '@vtj/core';
|
2
2
|
import { App } from 'vue';
|
3
3
|
import { Provider } from '../provider';
|
4
|
+
/**
|
5
|
+
* 定义增强函数的返回类型
|
6
|
+
* 可以是一个接收Vue应用和Provider的函数,或者undefined
|
7
|
+
*/
|
4
8
|
export type LoadEnhanceReturn = ((app: App, provider: Provider) => void) | undefined;
|
9
|
+
/**
|
10
|
+
* 异步加载增强配置
|
11
|
+
* @param config - 增强配置对象
|
12
|
+
* @param base - URL基础路径,默认为空字符串
|
13
|
+
* @returns 返回一个增强函数或undefined
|
14
|
+
*/
|
5
15
|
export declare function loadEnhance(config: EnhanceConfig, base?: string): Promise<LoadEnhanceReturn>;
|
@@ -28,6 +28,13 @@ export declare enum NodeEnv {
|
|
28
28
|
Production = "production",
|
29
29
|
Development = "development"
|
30
30
|
}
|
31
|
+
/**
|
32
|
+
* Provider 类是应用的核心提供者,负责:
|
33
|
+
* - 管理项目配置和状态
|
34
|
+
* - 加载依赖和资源
|
35
|
+
* - 初始化路由
|
36
|
+
* - 提供全局API和服务
|
37
|
+
*/
|
31
38
|
export declare class Provider extends Base {
|
32
39
|
options: ProviderOptions;
|
33
40
|
mode: ContextMode;
|
@@ -45,27 +52,90 @@ export declare class Provider extends Base {
|
|
45
52
|
private router;
|
46
53
|
private materialPath;
|
47
54
|
private urlDslCaches;
|
55
|
+
/**
|
56
|
+
* 创建Provider实例
|
57
|
+
* @param options 配置选项
|
58
|
+
*/
|
48
59
|
constructor(options: ProviderOptions);
|
49
60
|
createMock(func: (...args: any) => any): (...args: any[]) => Promise<any>;
|
61
|
+
/**
|
62
|
+
* 加载项目配置并初始化
|
63
|
+
* 1. 从模块或服务加载项目配置
|
64
|
+
* 2. 根据运行模式加载依赖或资源
|
65
|
+
* 3. 初始化Mock数据
|
66
|
+
* 4. 创建API接口
|
67
|
+
* 5. 初始化路由(非uniapp平台)
|
68
|
+
* @param project 项目配置
|
69
|
+
*/
|
50
70
|
load(project: ProjectSchema): Promise<void>;
|
51
71
|
initMock(global?: any): void;
|
52
72
|
private loadDependencies;
|
53
73
|
private loadAssets;
|
54
74
|
private initRouter;
|
75
|
+
/**
|
76
|
+
* Vue 插件安装方法
|
77
|
+
* 1. 安装所有第三方库插件
|
78
|
+
* 2. 执行自定义安装函数(如果提供)
|
79
|
+
* 3. 安装访问适配器
|
80
|
+
* 4. 提供全局 Provider 实例
|
81
|
+
* 5. 设计模式下设置错误处理器
|
82
|
+
* 6. 执行增强函数(如果提供)
|
83
|
+
* @param app Vue 应用实例
|
84
|
+
*/
|
55
85
|
install(app: App): void;
|
56
86
|
getFile(id: string): PageFile | BlockFile | null;
|
57
87
|
getPage(id: string): PageFile | null;
|
58
88
|
getHomepage(): PageFile | null;
|
59
89
|
getDsl(id: string): Promise<BlockSchema | null>;
|
60
90
|
getDslByUrl(url: string): Promise<BlockSchema | null>;
|
91
|
+
/**
|
92
|
+
* 创建 DSL 渲染器
|
93
|
+
* 1. 合并默认选项和自定义选项
|
94
|
+
* 2. 创建 DSL 加载器
|
95
|
+
* 3. 返回渲染器实例
|
96
|
+
* @param dsl 区块 DSL 配置
|
97
|
+
* @param opts 渲染选项
|
98
|
+
* @returns 渲染器实例
|
99
|
+
*/
|
61
100
|
createDslRenderer(dsl: BlockSchema, opts?: Partial<CreateRendererOptions>): {
|
62
101
|
renderer: any;
|
63
102
|
context: Context;
|
64
103
|
};
|
104
|
+
/**
|
105
|
+
* 获取渲染组件
|
106
|
+
* 1. 根据ID查找文件(页面或区块)
|
107
|
+
* 2. 如果找到文件且提供了output回调,则调用它
|
108
|
+
* 3. 尝试从模块缓存加载原始Vue组件
|
109
|
+
* 4. 如果找不到原始组件,则获取DSL并创建渲染器
|
110
|
+
* @param id 文件ID
|
111
|
+
* @param output 找到文件时的回调函数
|
112
|
+
* @returns Promise<Vue组件>
|
113
|
+
*/
|
65
114
|
getRenderComponent(id: string, output?: (file: BlockFile | PageFile) => void): Promise<any>;
|
115
|
+
/**
|
116
|
+
* 定义基于URL的异步组件
|
117
|
+
* 1. 根据URL获取DSL配置
|
118
|
+
* 2. 如果获取成功,设置组件名称
|
119
|
+
* 3. 创建并返回DSL渲染器
|
120
|
+
* @param url DSL配置URL
|
121
|
+
* @param name 可选的自定义组件名称
|
122
|
+
* @returns Vue异步组件
|
123
|
+
*/
|
66
124
|
defineUrlSchemaComponent(url: string, name?: string): any;
|
125
|
+
/**
|
126
|
+
* 定义基于插件的异步组件
|
127
|
+
* 1. 根据插件来源获取插件实例
|
128
|
+
* 2. 返回插件组件
|
129
|
+
* @param from 插件来源配置
|
130
|
+
* @returns Vue异步组件
|
131
|
+
*/
|
67
132
|
definePluginComponent(from: NodeFromPlugin): any;
|
68
133
|
}
|
134
|
+
/**
|
135
|
+
* 创建 Provider 实例
|
136
|
+
* @param options Provider 配置选项
|
137
|
+
* @returns 包含 provider 实例和 onReady 回调的对象
|
138
|
+
*/
|
69
139
|
export declare function createProvider(options: ProviderOptions): {
|
70
140
|
provider: Provider;
|
71
141
|
onReady: (callback: () => void) => void;
|
@@ -74,4 +144,12 @@ export interface UseProviderOptions {
|
|
74
144
|
id?: string;
|
75
145
|
version?: string;
|
76
146
|
}
|
147
|
+
/**
|
148
|
+
* 在组件中使用 Provider 实例
|
149
|
+
* 1. 从Vue上下文中获取注入的Provider
|
150
|
+
* 2. 开发环境下检查组件版本一致性
|
151
|
+
* @param options 使用选项
|
152
|
+
* @returns Provider 实例
|
153
|
+
* @throws 如果找不到Provider会抛出错误
|
154
|
+
*/
|
77
155
|
export declare function useProvider(options?: UseProviderOptions): Provider;
|
package/types/version.d.ts
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
* Copyright (c) 2025, VTJ.PRO All rights reserved.
|
3
3
|
* @name @vtj/renderer
|
4
4
|
* @author CHC chenhuachun1549@dingtalk.com
|
5
|
-
* @version 0.12.
|
5
|
+
* @version 0.12.20
|
6
6
|
* @license <a href="https://vtj.pro/license.html">MIT License</a>
|
7
7
|
*/
|
8
|
-
export declare const version = "0.12.
|
8
|
+
export declare const version = "0.12.20";
|