cc1-vue3 1.0.1 → 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";const n="__scopeObjFun";class o{static map={};static get(e,n){const r=o,s=t.getCurrentInstance();return s?(r.map[e]||(r.map[e]={value:n(),refs:new Set}),r.map[e].refs.add(s),t.onUnmounted(()=>{r.map[e]?.refs.delete(s),0===r.map[e]?.refs.size&&delete r.map[e]}),r.map[e].value):n()}}const r=window.Scope||class{static setConf=(e,o)=>{o||"string"==typeof e||(o=e,e="conf");const r=t.getCurrentInstance();let s=o;if("function"!=typeof s&&(s=()=>o),r){let t=r[n];t||(t=[]),t.push({key:e,fun:s}),r[n]=t}};static getConf=(e,o)=>{e?"number"==typeof e&&(o=e,e="conf"):e="conf",o||(o=1);let r=t.getCurrentInstance(),s=0,c=()=>null;for(;r=r.parent;){const t=r[n];if(t)for(let n=0;n<t.length;n++){const r=t[n];if(r.key===e&&(s++,c=r.fun,s===o))return r.fun()}}return c()};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 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||{},s={},c=e.pathHook||(e=>e),i=(n,o)=>{Object.keys(o).forEach(r=>{let s=r.replace(t,"").replace(".vue","");const i=e.mapKeyPathHook?.(s)||r;n[i]={path:c(s),component:o[r],useNum:0}})};i(o,n),i(s,r);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,s);const a=e.children||[],u=[],p=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=p(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=p(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 l=t=>{t.path=o[t.path].path,e.setInfoHook?.(t),t.children&&t.children.forEach(e=>{l(e)})};u.forEach(e=>{l(e)});const d={};return Object.keys(o).forEach(e=>{d[o[e].path]=o[e]}),{array:u,map:d}}},e.CVue3=class{static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,r=!1;const s=setInterval(()=>{if(r)return void clearInterval(s);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(s),void e()):void 0},50);t.onUnmounted(()=>{r=!0,e()})};static createCom=e=>{let n=e.domOrIdOrClass||document.body;"string"==typeof n&&(n=document.querySelector(n));const o=(...e)=>{r.unmount(),r=void 0,e.forEach(e=>{e&&n.removeChild(e)}),n.removeChild(s)};e.props||(e.props={}),e.props.remove=o;let r=t.createApp(e.component,e.props);const s=document.createElement("div");return e.beforeMount&&e.beforeMount(r),r.mount(s),e.first?n.insertBefore(s,n.firstChild):n.appendChild(s),{vm:r,remove:o}}},e.Minxins=o,e.Scope=r});
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
  */
@@ -1,5 +1,7 @@
1
1
  import { App } from 'vue';
2
2
  export default class CVue3 {
3
+ private static id;
4
+ private static getId;
3
5
  /**
4
6
  * 注册销毁事件
5
7
  */
@@ -29,9 +31,9 @@ export default class CVue3 {
29
31
  /**
30
32
  * 挂载前处理
31
33
  */
32
- beforeMount?: (vm: App<Element>) => void;
34
+ beforeMount?: (vm: App<Element>, tempDiv: HTMLDivElement) => void;
33
35
  }) => {
34
36
  vm: App<Element>;
35
- remove: (..._domitem: any) => void;
37
+ remove: () => void;
36
38
  };
37
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc1-vue3",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "dist/cc1-vue3.js",
5
5
  "license": "MIT",
6
6
  "author": "VeigarChen",
@@ -1,135 +0,0 @@
1
- /**
2
- * 事件管理对象
3
- */
4
- interface CEventBeanInter {
5
- /**
6
- * 提供默认的挂载验证事件,默认为通过,需要手动销毁事件
7
- * @returns
8
- * @example
9
- * //在vue3中使用
10
- import { getCurrentInstance } from 'vue'
11
- const findTopTag = (el: any, tag: string = 'html'): any => {
12
- if (!el?.parentElement) return null
13
- if (el.parentElement.tagName.toLocaleLowerCase() === tag) return el.parentElement
14
- else return findTopTag(el.parentElement, tag)
15
- }
16
- CEvent.eventbean.vm = function () {
17
- const _vm = getCurrentInstance()
18
- return () => findTopTag(_vm?.vnode.el?.parentElement)
19
- }
20
- */
21
- vm: () => () => boolean
22
- eventMap: Map<any, any>
23
- id: string
24
- tag: string
25
- /**
26
- * 注册
27
- * @param key 注册名称
28
- * @param callback 执行回调
29
- * @param target 附带信息
30
- * @returns 返回唯一注册id
31
- */
32
- on: (key: any, callback: (data: any) => any, vm?: any) => string
33
- /**
34
- * 调用
35
- * @param key 注册名称
36
- * @param data 回调函数传入参数
37
- * @param emitAll 通知所有事件对象(CEvent和所有new CEventBean()),默认为true
38
- */
39
- emit: (key: any, data?: any, emitAll?: boolean) => void
40
- /**
41
- * 销毁
42
- * @mode 模式1:多id或者key名称传入-off('onid1')、off('onid1','getData'...)
43
- * @mode 模式2:on方法传入的key和方法-off('getData',fun)
44
- * @param uids-传入的是id或者key加方法清理的是key的单个注册,传入的是key清理key所有注册
45
- */
46
- off: (...uids: any) => void
47
- clear: () => void
48
- }
49
- interface CEventBeanObj {
50
- new (): CEventBeanInter
51
- }
52
-
53
- /**
54
- * 定时器对象
55
- */
56
- interface TimerBeanInter {
57
- map: {
58
- [key: string]: TimerInfo
59
- }
60
- /**
61
- * 提供默认的挂载验证事件,默认为通过,需要手动销毁定时时间对象
62
- * @returns
63
- * @example
64
- * //在vue3中使用
65
- import { getCurrentInstance } from 'vue'
66
- const findTopTag = (el: any, tag: string = 'html'): any => {
67
- if (!el?.parentElement) return null
68
- if (el.parentElement.tagName.toLocaleLowerCase() === tag) return el.parentElement
69
- else return findTopTag(el.parentElement, tag)
70
- }
71
- const timer = new TimerBean()
72
- timer.vm = function () {
73
- const _vm = getCurrentInstance()
74
- return () => findTopTag(_vm?.vnode.el?.parentElement)
75
- }
76
- */
77
- vm: () => () => boolean
78
- /**
79
- * 添加一个延时任务
80
- * @param fun
81
- * @param timeGap -延迟时间
82
- */
83
- once: (fun: () => void, timeGap?: number, vm?: any) => any
84
- /**
85
- * 清空任务-仅能清理TimerBean中的任务
86
- */
87
- clear: () => void
88
- /**
89
- * 等待时间单位 1-毫秒 1000-秒
90
- */
91
- delayUnit: number
92
- /**
93
- * 等待时间
94
- * @param millisecond
95
- * @returns
96
- */
97
- delay: (millisecond?: number, delayUnit?: number) => Promise<void>
98
- /**
99
- * 添加一个循环任务
100
- * @param fun
101
- * @param timeGap -循环时间
102
- * @param firstRun -立即执行一次
103
- *
104
- */
105
- on: (fun: () => void, timeGap: number, firstRun?: boolean, vm?: any) => any
106
- /**
107
- * 清理循环-仅能清理TimerBean中的任务
108
- */
109
- un: (...ids: any[]) => void
110
- }
111
- interface TimerBeanObj {
112
- new (): TimerBeanInter
113
- }
114
-
115
- type TimerInfo = {
116
- /**
117
- * 任务内容
118
- * @returns
119
- */
120
- fun: () => void
121
- /**
122
- * 挂载节点验证
123
- */
124
- vm: any
125
-
126
- /**
127
- * 任务id
128
- */
129
- id: string
130
-
131
- /**
132
- * 清理
133
- */
134
- remove: () => void
135
- }
@@ -1 +0,0 @@
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";const n="__scopeObjFun";class o{static map={};static get(e,n){const r=o,s=t.getCurrentInstance();return s?(r.map[e]||(r.map[e]={value:n(),refs:new Set}),r.map[e].refs.add(s),t.onUnmounted(()=>{r.map[e]?.refs.delete(s),0===r.map[e]?.refs.size&&delete r.map[e]}),r.map[e].value):n()}}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||{},s={},c=e.pathHook||(e=>e),a=(n,o)=>{Object.keys(o).forEach(r=>{let s=r.replace(t,"").replace(".vue","");const a=e.mapKeyPathHook?.(s)||r;n[a]={path:c(s),component:o[r],useNum:0}})};a(o,n),a(s,r);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(o,s);const i=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(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),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 f={};return Object.keys(o).forEach(e=>{f[o[e].path]=o[e]}),{array:u,map:f}}},e.CVue3=class{static onDispose=e=>{const n=t.getCurrentInstance();let o=n.vnode.el?.parentElement?.parentElement,r=!1;const s=setInterval(()=>{if(r)return void clearInterval(s);const t=n.vnode.el?.parentElement?.parentElement;return void 0===o&&(o=t),o&&!t?(clearInterval(s),void e()):void 0},50);t.onUnmounted(()=>{r=!0,e()})};static createCom=e=>{let n=e.domOrIdOrClass||document.body;"string"==typeof n&&(n=document.querySelector(n));const o=(...e)=>{r.unmount(),r=void 0,e.forEach(e=>{e&&n.removeChild(e)}),n.removeChild(s)};e.props||(e.props={}),e.props.remove=o;let r=t.createApp(e.component,e.props);const s=document.createElement("div");return e.beforeMount&&e.beforeMount(r),r.mount(s),e.first?n.insertBefore(s,n.firstChild):n.appendChild(s),{vm:r,remove:o}}},e.Minxins=o,e.Scope=class{static setConf=(e,o)=>{o||"string"==typeof e||(o=e,e="conf");const r=t.getCurrentInstance();let s=o;if("function"!=typeof s&&(s=()=>o),r){let t=r[n];t||(t=[]),t.push({key:e,fun:s}),r[n]=t}};static getConf=(e,o)=>{e?"number"==typeof e&&(o=e,e="conf"):e="conf",o||(o=1);let r=t.getCurrentInstance(),s=0,c=()=>null;for(;r=r.parent;){const t=r[n];if(t)for(let n=0;n<t.length;n++){const r=t[n];if(r.key===e&&(s++,c=r.fun,s===o))return r.fun()}}return c()};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}}});