cc1-vue3 1.0.2 → 1.0.3

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/cc1-vue3.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["cc1-vue3"]={},e.vue)}(this,function(e,t){"use strict";class n{static id=1e3;static getId=()=>(this.id++,this.id+"");static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,r=!1;const c=setInterval(()=>{if(r)return void clearInterval(c);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(c),void e()):void 0},50);t.onUnmounted(()=>{r=!0,e()})};static createCom=e=>{let o=e.domOrIdOrClass||document.body;"string"==typeof o&&(o=document.querySelector(o));const r=document.createElement("div");r.id="com-custom-"+n.getId(),e.first?o.insertBefore(r,o.firstChild):o.appendChild(r);let c=null;const s=()=>{try{r.parentElement?.removeChild(r),c&&c.unmount(),c=null}catch(e){}};return c=t.createApp({render:()=>t.h(e.component,{...e.props,show:!0,remove:s})}),e.beforeMount?.(c,r),c.mount(r),{vm:c,remove:s}}}const o="__scopeObjFun";class r{static map={};static get(e,n){const o=r,c=t.getCurrentInstance();return c?(o.map[e]||(o.map[e]={value:n(),refs:new Set}),o.map[e].refs.add(c),t.onUnmounted(()=>{o.map[e]?.refs.delete(c),0===o.map[e]?.refs.size&&delete o.map[e]}),o.map[e].value):n()}}const c=window.Scope||class{static setConf=(e,n)=>{n||"string"==typeof e||(n=e,e="conf");const r=t.getCurrentInstance();let c=n;if("function"!=typeof c&&(c=()=>n),r){let t=r[o];t||(t=[]),t.push({key:e,fun:c}),r[o]=t}};static getConf=(e,n)=>{e?"number"==typeof e&&(n=e,e="conf"):e="conf",n||(n=1);let r=t.getCurrentInstance(),c=0,s=()=>null;for(;r=r.parent;){const t=r[o];if(t)for(let o=0;o<t.length;o++){const r=t[o];if(r.key===e&&(c++,s=r.fun,c===n))return r.fun()}}return s()};static CEventBean=null;static CEventBeanDeactivated=!1;static Event=()=>{if(!this.CEventBean)return null;const e=t.getCurrentInstance(),n=new this.CEventBean;return n.vm=()=>()=>e.isDeactivated?this.CEventBeanDeactivated:!e.isUnmounted,n};static TimerBean=null;static TimerBeanDeactivated="pause";static Timer=()=>{if(!this.TimerBean)return null;const e=new this.TimerBean,n=t.getCurrentInstance();return e.vm=()=>()=>n.isDeactivated?this.TimerBeanDeactivated:!n.isUnmounted,e}};window.TimerBean&&(c.TimerBean=window.TimerBean),window.CEventBean&&(c.CEventBean=window.CEventBean),window.Scope||(window.Scope=c),e.CRouter=class{static init=e=>{const t=e.root||"/src/views";if(!e.modules)throw new Error("modules is required");const n=e.modules,o={},r=e.diffModules||{},c={},s=e.pathHook||(e=>e),i=(n,o)=>{Object.keys(o).forEach(r=>{let c=r.replace(t,"").replace(".vue","");const i=e.mapKeyPathHook?.(c)||r;n[i]={path:s(c),component:o[r],useNum:0}})};i(o,n),i(c,r);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,c);const a=e.children||[],u=[],l=e=>{const t=Object.keys(o);for(let n=0;n<t.length;n++)if(o[t[n]].path===e)return o[t[n]]};if(a.length){const e=t=>{if(t.children=t.children||[],t.childrenList&&t.childrenList.forEach(e=>{const n=l(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=l(t.component);e&&(t.component=e.component,e.useNum++)}if(t.childrenReg){const e=(n=t.childrenReg,Array.isArray(n)?n.map(e=>e instanceof RegExp?e:new RegExp(e)):n instanceof RegExp?[n]:n?[new RegExp(n)]:[]);Object.keys(o).forEach(n=>{e.some(e=>e.test(n))&&(t.children.push({path:n,component:o[n].component}),o[n].useNum++)})}var n};for(let t=0;t<a.length;t++){const n=a[t];e(n),u.push(n)}}Object.keys(o).forEach(e=>{0===o[e].useNum&&u.push({path:e,component:o[e].component})});const p=t=>{t.path=o[t.path].path,e.setInfoHook?.(t),t.children&&t.children.forEach(e=>{p(e)})};u.forEach(e=>{p(e)});const d={};return Object.keys(o).forEach(e=>{d[o[e].path]=o[e]}),{array:u,map:d}}},e.CVue3=n,e.Minxins=r,e.Scope=c});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue")):"function"==typeof define&&define.amd?define(["exports","vue"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["cc1-vue3"]={},e.vue)}(this,function(e,t){"use strict";class n{static id=1e3;static getId=()=>(this.id++,this.id+"");static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,s=!1;const r=setInterval(()=>{if(s)return void clearInterval(r);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(r),void e()):void 0},50);t.onUnmounted(()=>{s=!0,e()})};static createCom=e=>{let o=e.domOrIdOrClass||document.body;"string"==typeof o&&(o=document.querySelector(o));const s=document.createElement("div");s.id="com-custom-"+n.getId(),e.first?o.insertBefore(s,o.firstChild):o.appendChild(s);let r=null;const a=()=>{try{s.parentElement?.removeChild(s),r&&r.unmount(),r=null}catch(e){}};return r=t.createApp({render:()=>t.h(e.component,{...e.props,show:!0,remove:a})}),e.beforeMount?.(r,s),r.mount(s),{vm:r,remove:a}}}const o="__scopeObjFun";class s{static map={};static get(e,n){const o=s,r=t.getCurrentInstance();return r?(o.map[e]||(o.map[e]={value:n(),refs:new Set}),o.map[e].refs.add(r),t.onUnmounted(()=>{o.map[e]?.refs.delete(r),0===o.map[e]?.refs.size&&delete o.map[e]}),o.map[e].value):n()}}const r=window.Scope||class{static setConf=(e,n)=>{n||"string"==typeof e||(n=e,e="conf");const s=t.getCurrentInstance();let r=n;if("function"!=typeof r&&(r=()=>n),s){let t=s[o];t||(t=[]),t.push({key:e,fun:r}),s[o]=t}};static getConf=(e,n)=>{e?"number"==typeof e&&(n=e,e="conf"):e="conf",n||(n=1);let s=t.getCurrentInstance(),r=0,a=()=>null;for(;s=s.parent;){const t=s[o];if(t)for(let o=0;o<t.length;o++){const s=t[o];if(s.key===e&&(r++,a=s.fun,r===n))return s.fun()}}return a()};static CEventBean=null;static CEventBeanDeactivated=!1;static Event=()=>{if(!this.CEventBean)return null;const e=t.getCurrentInstance(),n=new this.CEventBean;return n.vm=()=>()=>e.isDeactivated?this.CEventBeanDeactivated:!e.isUnmounted,n};static TimerBean=null;static TimerBeanDeactivated="pause";static Timer=()=>{if(!this.TimerBean)return null;const e=new this.TimerBean,n=t.getCurrentInstance();return e.vm=()=>()=>n.isDeactivated?this.TimerBeanDeactivated:!n.isUnmounted,e}};window.TimerBean&&(r.TimerBean=window.TimerBean),window.CEventBean&&(r.CEventBean=window.CEventBean),window.Scope||(window.Scope=r),e.CRouter=class{static getDefaultModules=(e,t)=>(t=t||[{}]).map(t=>{const n={};let{haveWeb:o=!1,isH5:s=!1,webField:r="web",path:a="/src/views",ptfun:c=e=>s?e[0]:e[1]??e[0],pathTo:i="/"}=t;a=a.replace(/\/+$/,"");const p=[[{test:e=>o?e.startsWith(`${a}/`)&&!e.startsWith(`${a}/${r}/`):e.startsWith(`${a}/`),replace:new RegExp(`^${a}/`),to:i}]];return o&&p.push([{test:e=>e.startsWith(`${a}/${r}/`),replace:new RegExp(`^${a}/${r}/`),to:i}]),Object.keys(e).forEach(t=>{c(p).forEach(({test:o,replace:s,to:r})=>{if(o(t)){const o=t.replace(s,r);n[o]=e[t]}})}),n}).reduce((e,t)=>({...e,...t}),{});static init=e=>{const t=e.root||"/src/views";if(!e.modules)throw new Error("modules is required");const n=e.modules,o={},s=e.diffModules||{},r={},a=e.pathHook||(e=>e),c=(n,o)=>{Object.keys(o).forEach(s=>{let r=s.replace(t,"").replace(".vue","");const c=e.mapKeyPathHook?.(r)||s;n[c]={path:a(r),component:o[s],useNum:0}})};c(o,n),c(r,s);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,r);const i=e.children||[],p=[],l=e=>{const t=Object.keys(o);for(let n=0;n<t.length;n++)if(o[t[n]].path===e)return o[t[n]]};if(i.length){const e=t=>{if(t.children=t.children||[],t.childrenList&&t.childrenList.forEach(e=>{const n=l(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=l(t.component);e&&(t.component=e.component,e.useNum++)}if(t.childrenReg){const e=(n=t.childrenReg,Array.isArray(n)?n.map(e=>e instanceof RegExp?e:new RegExp(e)):n instanceof RegExp?[n]:n?[new RegExp(n)]:[]);Object.keys(o).forEach(n=>{e.some(e=>e.test(n))&&(t.children.push({path:n,component:o[n].component}),o[n].useNum++)})}var n};for(let t=0;t<i.length;t++){const n=i[t];e(n),p.push(n)}}Object.keys(o).forEach(e=>{0===o[e].useNum&&p.push({path:e,component:o[e].component})});const u=t=>{t.path=o[t.path]?.path||t.path,e.setInfoHook?.(t);const n=e.alias?.[t.path];n&&("string"==typeof n?t.path=n:(t.path=n.path||t.path,t.meta=n.meta||t.meta)),t.children&&t.children.forEach(e=>{u(e)})};p.forEach(e=>{u(e)});const d={};return Object.keys(o).forEach(e=>{d[o[e].path]=o[e]}),{array:p,map:d}}},e.CVue3=n,e.Minxins=s,e.Scope=r});
@@ -2,6 +2,45 @@
2
2
  * 路由工具-示例阅读README.md
3
3
  */
4
4
  export default class CRouter {
5
+ /**
6
+ *
7
+ * @param _modules 模块列表
8
+ * @param configList 配置列表
9
+ * @param haveWeb 是否存在web目录
10
+ * @param path 路径
11
+ * @param ptfun 处理函数-用来处理path和to的匹配
12
+ * @param isH5 是否是h5
13
+ * @param webField web目录名称 默认web
14
+ * @param pathTo 路径to 默认/
15
+ * @returns
16
+ */
17
+ static getDefaultModules: <T extends {
18
+ /**
19
+ * 是否存在web目录
20
+ */
21
+ haveWeb?: boolean;
22
+ /**
23
+ * 扫描路径-默认/src/views
24
+ */
25
+ path: string;
26
+ /**
27
+ * 处理函数
28
+ */
29
+ ptfun?: (ptest: any[]) => any[];
30
+ /**
31
+ * 是否是h5
32
+ */
33
+ isH5?: boolean;
34
+ /**
35
+ * web目录名称 默认web
36
+ */
37
+ webField?: string;
38
+ /**
39
+ /**
40
+ * 路径to 默认/
41
+ */
42
+ pathTo?: string;
43
+ }>(_modules: any, configList?: T[]) => any;
5
44
  /**
6
45
  * 初始化路由列表
7
46
  * @returns
@@ -36,6 +75,21 @@ export type CRouterParam = {
36
75
  * 路由地址修改钩子-用来修改最终的path地址使用名称 如/modules/home/index/index修改为/home
37
76
  */
38
77
  pathHook: (path: string) => string;
78
+ /**
79
+ * 路由别名和meta信息设置-用来修改最终的path地址使用名称 如/user/login修改为/login
80
+ */
81
+ alias: {
82
+ [key: string]: {
83
+ /**
84
+ * 修改后的路径
85
+ */
86
+ path?: string;
87
+ /**
88
+ * 修改后的meta信息
89
+ */
90
+ meta?: any;
91
+ } | string;
92
+ };
39
93
  /**
40
94
  * 设置初始化信息,比如设置meta信息和title信息
41
95
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc1-vue3",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "main": "dist/cc1-vue3.js",
5
5
  "license": "MIT",
6
6
  "author": "VeigarChen",