cc1-vue3 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 落叶
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # vue3 工具
2
+
3
+ ## CRouter 复杂示例
4
+
5
+ ```javascript
6
+ import System from '@/utils/System'
7
+ import { createRouter, createWebHashHistory } from 'vue-router'
8
+ import CRouter from './CRouter'
9
+
10
+ /**
11
+ * 默认主题
12
+ */
13
+ const themeList = ['light', 'dark'] as any[]
14
+ const defaultTheme = 'light' as any
15
+ const diffTheme = 'dark' as any
16
+
17
+ /**
18
+ * 路由目录/src/views/light/home/index.vue、/src/views/dark/home/index.vue
19
+ */
20
+ export const initRouter = () => {
21
+ let _modules = import.meta.glob([
22
+ '@/views/**/*.vue',
23
+ '!@/views/**/*-com/**/*.vue',
24
+ '!@/views/**/com/**/*.vue',
25
+ '!@/views/**/components/**/*.vue'
26
+ ])
27
+
28
+ const _defaultModules = {} as any
29
+ const _diffModules = {} as any
30
+ Object.keys(_modules).forEach((key) => {
31
+ themeList.forEach((item) => {
32
+ if (defaultTheme != item) {
33
+ if (!new RegExp(`^/src/views/${item}`).test(key)) {
34
+ _defaultModules[key] = _modules[key]
35
+ }
36
+ if (diffTheme != defaultTheme && new RegExp(`^/src/views/${diffTheme}`).test(key)) {
37
+ _diffModules[key] = _modules[key]
38
+ }
39
+ }
40
+ })
41
+ })
42
+
43
+ const pathHook = (path: string) => {
44
+ return path
45
+ .replace(/\/index$/, '')
46
+ .replace(new RegExp(`/${defaultTheme}/`), '/')
47
+ .replace(new RegExp(`/${diffTheme}/`), '/')
48
+ }
49
+
50
+ const _routes = CRouter.init({
51
+ modules: _defaultModules,
52
+ diffModules: _diffModules,
53
+
54
+ children: [
55
+ {
56
+ path: '/layout',
57
+ component: '/layout',
58
+ childrenReg: ['^/pages']
59
+ }
60
+ ],
61
+ setInfoHook(item) {
62
+ item.meta = {
63
+ title: item.path
64
+ }
65
+ },
66
+ mapKeyPathHook(path) {
67
+ return pathHook(path)
68
+ },
69
+ pathHook(path) {
70
+ return pathHook(path).replace(/^\/pages/, '')
71
+ }
72
+ })
73
+
74
+ const router = createRouter({
75
+ history: createWebHashHistory(),
76
+ routes: [
77
+ ..._routes.array,
78
+ {
79
+ path: '/',
80
+ redirect: '/home'
81
+ }
82
+ ]
83
+ })
84
+
85
+ System.router = router
86
+
87
+ return router
88
+ }
89
+ ```
@@ -0,0 +1,135 @@
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
+ }
@@ -0,0 +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});
@@ -0,0 +1,6 @@
1
+ import CVue3 from './utils/CVue3';
2
+ import ScopeMain from './utils/Scope';
3
+ import CRouter from './utils/CRouter';
4
+ import Minxins from './utils/Minxins';
5
+ declare const Scope: ScopeMain;
6
+ export { Scope, CVue3, CRouter, Minxins };
@@ -0,0 +1,135 @@
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
+ }
@@ -0,0 +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()}}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}}});
@@ -0,0 +1,73 @@
1
+ /**
2
+ * 路由工具-示例阅读README.md
3
+ */
4
+ export default class CRouter {
5
+ /**
6
+ * 初始化路由列表
7
+ * @returns
8
+ */
9
+ static init: (param: Partial<CRouterParam>) => {
10
+ array: any[];
11
+ map: any;
12
+ };
13
+ }
14
+ export type CRouterParam = {
15
+ /**
16
+ * 显示页面列表
17
+ */
18
+ modules: any;
19
+ /**
20
+ * 补齐页面列表,如果modules的页面少于diffModules,将缺少的diffModules的页面添加到modules中
21
+ */
22
+ diffModules?: any;
23
+ /**
24
+ * 根路径-默认'/src/views'
25
+ */
26
+ root: string;
27
+ /**
28
+ * 页面配置
29
+ */
30
+ children: Partial<CRouterParamChildren>[];
31
+ /**
32
+ * map地址勾子,用来处理map数据管理,参与处理path、component、children,一般留存标记方便children处理,比如正则pages下的所有路由,但是最终地址不使用pages,所以在这个勾子单独处理不对pages替换
33
+ */
34
+ mapKeyPathHook?: (path: string) => string;
35
+ /**
36
+ * 路由地址修改钩子-用来修改最终的path地址使用名称 如/modules/home/index/index修改为/home
37
+ */
38
+ pathHook: (path: string) => string;
39
+ /**
40
+ * 设置初始化信息,比如设置meta信息和title信息
41
+ */
42
+ setInfoHook?: (item: CRouterParamChildren & {
43
+ [key: string]: any;
44
+ }) => void;
45
+ };
46
+ export type CRouterParamChildren = {
47
+ /**
48
+ * 页面路径-如/home/index
49
+ */
50
+ path: string;
51
+ /**
52
+ * 页面组件-填vue文件地址
53
+ * @a 如/src/views/home/index.vue填/home/index
54
+ * @a 如/src/views/home/card.vue填/home/card
55
+ */
56
+ component: string;
57
+ /**
58
+ * 跳转路径-如/home/index
59
+ */
60
+ redirect: string;
61
+ /**
62
+ * 子路由
63
+ */
64
+ children: Partial<CRouterParamChildren>[];
65
+ /**
66
+ * 子路由地址列表
67
+ */
68
+ childrenList: string[];
69
+ /**
70
+ * 子路由包含正则
71
+ */
72
+ childrenReg: string | string[] | RegExp | RegExp[];
73
+ };
@@ -0,0 +1,37 @@
1
+ import { App } from 'vue';
2
+ export default class CVue3 {
3
+ /**
4
+ * 注册销毁事件
5
+ */
6
+ static onDispose: (fun: () => void) => void;
7
+ /**
8
+ * 将组件创建到指定位置-返回的remove方法可以手动销毁,传入的组件中props必须存在remove属性在手动关闭时进行调用
9
+ * @param option
10
+ * @returns
11
+ */
12
+ static createCom: (param: {
13
+ /**
14
+ * 组件
15
+ */
16
+ component: any;
17
+ /**
18
+ * 节点-默认是document.body
19
+ */
20
+ domOrIdOrClass?: string | Element;
21
+ /**
22
+ * 属性-始终传入onUnmounted属性,调用后销毁组件
23
+ */
24
+ props?: any;
25
+ /**
26
+ * 是否从前面挂载
27
+ */
28
+ first?: boolean;
29
+ /**
30
+ * 挂载前处理
31
+ */
32
+ beforeMount?: (vm: App<Element>) => void;
33
+ }) => {
34
+ vm: App<Element>;
35
+ remove: (..._domitem: any) => void;
36
+ };
37
+ }
@@ -0,0 +1,37 @@
1
+ import { ComponentInternalInstance } from 'vue';
2
+ /**
3
+ * 同vue2中的minxins功能
4
+ *
5
+ * 应用场景:多个父子组件引用同一个对象,当组件无任何引用时,对象自动销毁,下一次访问触发初始化
6
+ *
7
+ * @example
8
+ *
9
+ * import { reactive } from 'vue'
10
+ * import Minxins from 'cc1-vue3'
11
+
12
+ * const getIndex = () => {
13
+ * const conf = reactive({
14
+ * name: 'index',
15
+ * num: 1,
16
+ * add: () => {
17
+ * conf.num++
18
+ * }
19
+ * })
20
+ * return conf
21
+ * }
22
+ *
23
+ * export const index = () => Minxins.get('/main', getIndex)
24
+ */
25
+ export default class Minxins {
26
+ static map: Record<string, {
27
+ value: any;
28
+ refs: Set<ComponentInternalInstance>;
29
+ }>;
30
+ /**
31
+ * 获取一个对象
32
+ * @param name 名称-全局唯一或者保证同一页面唯一存在
33
+ * @param fun 获取对象的方法-方法只能返回对象
34
+ * @returns 对象
35
+ */
36
+ static get<T>(name: string, fun: () => T): T;
37
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 局部成员
3
+ */
4
+ export default class Scope {
5
+ /**
6
+ * 创建组件内共享变量
7
+ * @param key 共享名称 -默认取conf
8
+ * @param getObjFun 返回reactive对象或者返回reactive对象的方法
9
+ * @example
10
+ * Scope.setConf(reactive({name:1}))
11
+ * ||
12
+ * Scope.setConf('conf',reactive({name:1}))
13
+ *
14
+ * Scope.setConf('mconf',reactive({name:2}))
15
+ * @returns
16
+ */
17
+ static setConf: (key?: any, getObjFun?: any) => void;
18
+ /**
19
+ * 获取组件内共享变量
20
+ * @param key 共享名称-默认取conf
21
+ * @param index 级别-存在多个时用到,默认为1
22
+ * @example
23
+ * const mconf = Scope.getConf()
24
+ * ||
25
+ * const mconf = Scope.getConf('conf')
26
+ *
27
+ * const mconf = Scope.getConf('conf',2)
28
+ * @returns
29
+ */
30
+ static getConf: <T = any>(key?: any, index?: number) => T;
31
+ static CEventBean: CEventBeanObj;
32
+ /**
33
+ * 控制事件管理器在组件被keep-alive缓存时是否暂停,如果需要暂停,修改值为1,0,true,false以外的值,默认为不暂停
34
+ */
35
+ static CEventBeanDeactivated: any;
36
+ /**
37
+ * 获取一个页面销毁不再触发的事件管理器(使用前先赋值CEventBean)
38
+ * @example
39
+ * @returns
40
+ */
41
+ static Event: <T = CEventBeanInter>() => T;
42
+ static TimerBean: TimerBeanObj;
43
+ /**
44
+ * 控制定时器管理器在组件被keep-alive缓存时是否暂停,如果需要暂停,修改值为1,0,true,false以外的值,默认为暂停
45
+ */
46
+ static TimerBeanDeactivated: any;
47
+ /**
48
+ * 获取一个定时器(使用前先赋值TimerBean)
49
+ * @returns
50
+ */
51
+ static Timer: <T = TimerBeanInter>() => T;
52
+ }
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "cc1-vue3",
3
+ "version": "1.0.0",
4
+ "main": "dist/cc1-vue3.js",
5
+ "license": "MIT",
6
+ "author": "VeigarChen",
7
+ "types": "dist/index.d.ts",
8
+ "scripts": {
9
+ "dev": "ts-node ./src/dev.ts",
10
+ "format": "prettier --write . ",
11
+ "buildN": "npx tsc -p ./tsconfig.json",
12
+ "build": "rollup -c rollup.config.cjs"
13
+ },
14
+ "description": "我来助你-vue3工具库",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "keywords": [
19
+ "vue",
20
+ "vue3",
21
+ "framework",
22
+ "frontend"
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://cc1.cc"
27
+ },
28
+ "homepage": "https://cc1.cc",
29
+ "devDependencies": {
30
+ "@rollup/plugin-commonjs": "^25.0.7",
31
+ "@rollup/plugin-terser": "^0.4.3",
32
+ "prettier": "^2.8.3",
33
+ "rollup": "^3.29.2",
34
+ "rollup-plugin-typescript2": "^0.36.0",
35
+ "tools-javascript": "^1.1.25",
36
+ "ts-node": "^10.9.2",
37
+ "tslib": "^2.6.2",
38
+ "typescript": "^5.3.3",
39
+ "vue": "^3.4.29"
40
+ }
41
+ }