cc1-vue3 1.0.2 → 1.0.4
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 +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/utils/CRouter.d.ts +54 -0
- package/dist/utils/CRule.d.ts +124 -0
- package/package.json +1 -1
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
|
|
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 r=n.vnode.el?.parentElement?.parentElement,s=!1;const o=setInterval(()=>{if(s)return void clearInterval(o);const t=n.vnode.el?.parentElement?.parentElement;return void 0===r&&(r=t),r&&!t?(clearInterval(o),void e()):void 0},50);t.onUnmounted(()=>{s=!0,e()})};static createCom=e=>{let r=e.domOrIdOrClass||document.body;"string"==typeof r&&(r=document.querySelector(r));const s=document.createElement("div");s.id="com-custom-"+n.getId(),e.first?r.insertBefore(s,r.firstChild):r.appendChild(s);let o=null;const a=()=>{try{s.parentElement?.removeChild(s),o&&o.unmount(),o=null}catch(e){}};return o=t.createApp({render:()=>t.h(e.component,{...e.props,show:!0,remove:a})}),e.beforeMount?.(o,s),o.mount(s),{vm:o,remove:a}}}const r="__scopeObjFun";const s={getRule:(e,t,n)=>{const r={};void 0===n&&(n=s.inputVal);for(const s in t)r[s]=r=>{e[s]=null,n({val:r.target.value,after:t=>{e[s]=t},...t[s]})};return r},inputVal:e=>{let{val:t,length:n,trim:r=!0,fixed:s=2,min:o=0,max:a=1e9}=e;r&&(t=t.replace(/\s+|\s+$/g,""));const c={int:e=>(e=e.replace(/[^\d]/g,""),e=Number(e)||0,e=o&&e<o?o:e,e=a&&e>a?a:e),float:e=>(e=e.replace(/^0(\d)/,"$1").replace(/^\./,"0").replace(/[^\d.]/g,"").replace(/^(\d*\.?\d*).*$/,"$1").replace(new RegExp(`^(\\d+)\\.(\\d{${s}}).*`),"$1.$2"),e=o&&e<o?o:e,e=a&&e>a?a:e),hanzi:e=>e=e.replace(/[^\u4e00-\u9fa5]/g,""),Num:"0-9",En:"a-zA-Z",Hanzi:"一-龥"};if(t.length){n&&t.length>n&&(t=t.substring(0,n));const r=[],s=[],o=(t,n,r)=>{t===n?Array.isArray(e[t])?r.push(...e[t]):r.push(e[t]):r.push(c[t.substring(3)])};Object.keys(e).forEach(e=>{e.startsWith("get")?o(e,"getCustom",r):e.startsWith("del")?o(e,"delCustom",s):c[e]&&(t=c[e](t))}),r.length&&(t=t.replace(new RegExp(`[^${r.join("")}]`,"g"),"")),s.length&&(t=t.replace(new RegExp(`[${s.join("")}]`,"g"),""))}return e.after(t),t}};const o=window,a=o.Scope||class{static setConf=(e,n)=>{n||"string"==typeof e||(n=e,e="conf");const s=t.getCurrentInstance();let o=n;if("function"!=typeof o&&(o=()=>n),s){let t=s[r];t||(t=[]),t.push({key:e,fun:o}),s[r]=t}};static getConf=(e,n)=>{e?"number"==typeof e&&(n=e,e="conf"):e="conf",n||(n=1);let s=t.getCurrentInstance(),o=0,a=()=>null;for(;s=s.parent;){const t=s[r];if(t)for(let r=0;r<t.length;r++){const s=t[r];if(s.key===e&&(o++,a=s.fun,o===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}};o.Scope||(o.Scope=a);const c=o.CMinxins||class e{static map={};static get(n,r){const s=e,o=t.getCurrentInstance();return o?(s.map[n]||(s.map[n]={value:r(),refs:new Set}),s.map[n].refs.add(o),t.onUnmounted(()=>{s.map[n]?.refs.delete(o),0===s.map[n]?.refs.size&&delete s.map[n]}),s.map[n].value):r()}};o.CMinxins||(o.CMinxins=c),o.TimerBean&&(a.TimerBean=o.TimerBean),o.CEventBean&&(a.CEventBean=o.CEventBean),e.CRouter=class{static getDefaultModules=(e,t)=>(t=t||[{}]).map(t=>{const n={};let{haveWeb:r=!1,isH5:s=!1,webField:o="web",path:a="/src/views",ptfun:c=e=>s?e[0]:e[1]??e[0],pathTo:i="/"}=t;a=a.replace(/\/+$/,"");const l=[[{test:e=>r?e.startsWith(`${a}/`)&&!e.startsWith(`${a}/${o}/`):e.startsWith(`${a}/`),replace:new RegExp(`^${a}/`),to:i}]];return r&&l.push([{test:e=>e.startsWith(`${a}/${o}/`),replace:new RegExp(`^${a}/${o}/`),to:i}]),Object.keys(e).forEach(t=>{c(l).forEach(({test:r,replace:s,to:o})=>{if(r(t)){const r=t.replace(s,o);n[r]=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,r={},s=e.diffModules||{},o={},a=e.pathHook||(e=>e),c=(n,r)=>{Object.keys(r).forEach(s=>{let o=s.replace(t,"").replace(".vue","");const c=e.mapKeyPathHook?.(o)||s;n[c]={path:a(o),component:r[s],useNum:0}})};c(r,n),c(o,s);((e,t)=>{for(const n in t)n in e||(e[n]=t[n])})(r,o);const i=e.children||[],l=[],p=e=>{const t=Object.keys(r);for(let n=0;n<t.length;n++)if(r[t[n]].path===e)return r[t[n]]};if(i.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(r).forEach(n=>{e.some(e=>e.test(n))&&(t.children.push({path:n,component:r[n].component}),r[n].useNum++)})}var n};for(let t=0;t<i.length;t++){const n=i[t];e(n),l.push(n)}}Object.keys(r).forEach(e=>{0===r[e].useNum&&l.push({path:e,component:r[e].component})});const u=t=>{t.path=r[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)})};l.forEach(e=>{u(e)});const f={};return Object.keys(r).forEach(e=>{f[r[e].path]=r[e]}),{array:l,map:f}}},e.CRule=class{static form(e){const n=t.reactive({obj:s.getRule(e.form,e.rules),input:(e,t)=>{n.obj[t](e)},test:()=>{const t=Array.isArray(e.testField)?e.testField:e.testField?.()||Object.keys(e.rules);for(let e=0;e<t.length;e++){const r=t[e];n.testField(r)}},testField:t=>{const n=e.rules[t]?.test;let r=!0;if(n&&(r="string"==typeof n.reg?new RegExp(n.reg).test(e.form[t]):"function"==typeof n.reg?n.reg(e.form).test(e.form[t]):n.reg.test(e.form[t])),!r)throw e.toast?.(n?.errmsg||""),new Error("field:--\x3e "+t+" <-- "+n?.errmsg)}});return n}},e.CVue3=n,e.Minxins=c,e.Scope=a});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import CVue3 from './utils/CVue3';
|
|
2
2
|
import ScopeMain from './utils/Scope';
|
|
3
3
|
import CRouter from './utils/CRouter';
|
|
4
|
-
import
|
|
4
|
+
import MinxinsMain from './utils/Minxins';
|
|
5
|
+
import CRule from './utils/CRule';
|
|
5
6
|
declare const Scope: typeof ScopeMain;
|
|
6
|
-
|
|
7
|
+
declare const Minxins: typeof MinxinsMain;
|
|
8
|
+
export { Scope, CVue3, CRouter, Minxins, CRule };
|
package/dist/utils/CRouter.d.ts
CHANGED
|
@@ -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
|
*/
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 校验工具
|
|
3
|
+
*/
|
|
4
|
+
export default class CRule {
|
|
5
|
+
/**
|
|
6
|
+
* 表单校验
|
|
7
|
+
* @param config 配置
|
|
8
|
+
* @example
|
|
9
|
+
* const rule = CRule.form({
|
|
10
|
+
form: conf.form,
|
|
11
|
+
toast(errmsg) {
|
|
12
|
+
System.toast(errmsg)
|
|
13
|
+
},
|
|
14
|
+
rules: {
|
|
15
|
+
username: {
|
|
16
|
+
delHanzi: true,
|
|
17
|
+
length: 20,
|
|
18
|
+
test: {
|
|
19
|
+
reg: /^[a-zA-Z0-9._-]{6,20}$/,
|
|
20
|
+
errmsg: '用户名为6-20位字母数字组合'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
static form<F extends Record<string, any>>(config: {
|
|
28
|
+
/**
|
|
29
|
+
* 表单
|
|
30
|
+
*/
|
|
31
|
+
form: F;
|
|
32
|
+
/**
|
|
33
|
+
* 校验规则
|
|
34
|
+
*/
|
|
35
|
+
rules: {
|
|
36
|
+
[K in keyof F]?: Partial<inputReg & {
|
|
37
|
+
test?: {
|
|
38
|
+
reg: ((form: F) => RegExp) | RegExp;
|
|
39
|
+
errmsg: string;
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* 提示信息函数
|
|
45
|
+
*/
|
|
46
|
+
toast?: (errmsg: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* 需要校验的字段
|
|
49
|
+
* 如果为空,则校验所有字段
|
|
50
|
+
* 如果为函数,则调用函数返回需要校验的字段
|
|
51
|
+
* 如果为数组,则直接返回需要校验的字段
|
|
52
|
+
*/
|
|
53
|
+
testField?: (() => (keyof F)[]) | (keyof F)[];
|
|
54
|
+
}): {
|
|
55
|
+
obj: import("vue").UnwrapRef<{ [key in keyof F]: (e: any) => void; }>;
|
|
56
|
+
input: (e: Event, name: keyof F) => void;
|
|
57
|
+
test: () => void;
|
|
58
|
+
testField: (name: keyof F) => void;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
type inputReg = {
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
/**
|
|
64
|
+
* 去除换行回车空格(默认为true)
|
|
65
|
+
*/
|
|
66
|
+
trim: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* 只要整数
|
|
69
|
+
*/
|
|
70
|
+
int: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* 只要小数
|
|
73
|
+
*/
|
|
74
|
+
float: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* 保留小数后n位(默认为2)
|
|
77
|
+
*/
|
|
78
|
+
fixed: number;
|
|
79
|
+
/**
|
|
80
|
+
* 数字最小-小于更改为最小(默认为undefined)
|
|
81
|
+
*/
|
|
82
|
+
min: number;
|
|
83
|
+
/**
|
|
84
|
+
* 数字最大-大于更改为最大(默认为undefined)
|
|
85
|
+
*/
|
|
86
|
+
max: number;
|
|
87
|
+
/**
|
|
88
|
+
* 长度限制(默认为undefined)
|
|
89
|
+
*/
|
|
90
|
+
length: number;
|
|
91
|
+
/**
|
|
92
|
+
* 需要汉字
|
|
93
|
+
*/
|
|
94
|
+
getHanzi: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* 需要数字
|
|
97
|
+
*/
|
|
98
|
+
getNum: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* 需要字母
|
|
101
|
+
*/
|
|
102
|
+
getEn: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* 自定义需要内容(如-_.等)
|
|
105
|
+
*/
|
|
106
|
+
getCustom: string;
|
|
107
|
+
/**
|
|
108
|
+
* 去除汉字
|
|
109
|
+
*/
|
|
110
|
+
delHanzi: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* 去除数字
|
|
113
|
+
*/
|
|
114
|
+
delNum: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* 去除字母
|
|
117
|
+
*/
|
|
118
|
+
delEn: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* 自定义去除内容(如-_.等)
|
|
121
|
+
*/
|
|
122
|
+
delCustom: string;
|
|
123
|
+
};
|
|
124
|
+
export {};
|