cc1-vue3 1.0.11 → 1.0.12
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 +2 -1
- package/dist/utils/CStore.d.ts +39 -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 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 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 s=null;const a=()=>{try{r.parentElement?.removeChild(r),s&&s.unmount(),s=null}catch(e){}};return s=t.createApp({render:()=>t.h(e.component,{...e.props,show:!0,remove:a})}),e.beforeMount?.(s,r),s.mount(r),{vm:s,remove:a}}}const o="__scopeObjFun";let r=class{static setConf=(e,n)=>{n||"string"==typeof e||(n=e,e="conf");const r=t.getCurrentInstance();let s=n;if("function"!=typeof s&&(s=()=>n),r){let t=r[o];t||(t=[]),t.push({key:e,fun:s}),r[o]=t}};static getConf=(e,n)=>{e?"number"==typeof e&&(n=e,e="conf"):e="conf",n||(n=1);let r=t.getCurrentInstance(),s=0,a=()=>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&&(s++,a=r.fun,s===n))return r.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}};const s={getRule:(e,t,n)=>{const o={};void 0===n&&(n=s.inputVal);for(const r in t)o[r]=o=>{e[r]=null,n({val:"string"==typeof o||"number"==typeof o?o:o.target?.value||o.value,after:t=>{e[r]=t},...t[r]})};return o},inputVal:e=>{let{val:t,length:n,trim:o=!0,fixed:r=2,min:s=0,max:a=1e9}=e;o&&(t=t.replace(/\s+|\s+$/g,""));const i={int:e=>(e=e.replace(/[^\d]/g,""),e=Number(e)||0,e=s&&e<s?s: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{${r}}).*`),"$1.$2"),e=s&&e<s?s: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 o=[],r=[],s=(t,n,o)=>{t===n?Array.isArray(e[t])?o.push(...e[t]):o.push(e[t]):o.push(i[t.substring(3)])};Object.keys(e).forEach(e=>{e.startsWith("get")?s(e,"getCustom",o):e.startsWith("del")?s(e,"delCustom",r):i[e]&&(t=i[e](t))}),o.length&&(t=t.replace(new RegExp(`[^${o.join("")}]`,"g"),"")),r.length&&(t=t.replace(new RegExp(`[${r.join("")}]`,"g"),""))}return e.after(t),t}};const a=window,i=a.Scope||r;a.Scope||(a.Scope=i);const c=a.CMinxins||class e{static map={};static get(n,o,r){if(r||(r=t.getCurrentInstance()),!r)return e.map[n]?e.map[n].value:o();let s=e.map[n];if(!s)try{s={value:o(),refs:new Set},e.map[n]=s}catch(e){throw new Error(`Minxins.get: Failed to initialize '${n}': ${e}`)}return s.refs.has(r)||(s.refs.add(r),t.onUnmounted(()=>{const t=e.map[n];t&&(t.refs.delete(r),0===t.refs.size&&delete e.map[n])})),s.value}};a.CMinxins||(a.CMinxins=c),a.TimerBean&&(i.TimerBean=a.TimerBean),a.CEventBean&&(i.CEventBean=a.CEventBean),e.CRouter=class{static getDefaultModules=(e,t)=>(t=t||[{}]).map(t=>{const n={};let{haveWeb:o=!1,isH5:r=!1,webField:s="web",path:a="/src/views",ptfun:i=e=>r?e[0]:e[1]??e[0],pathTo:c="/"}=t;a=a.replace(/\/+$/,"");const l=[[{test:e=>o?e.startsWith(`${a}/`)&&!e.startsWith(`${a}/${s}/`):e.startsWith(`${a}/`),replace:new RegExp(`^${a}/`),to:c}]];return o&&l.push([{test:e=>e.startsWith(`${a}/${s}/`),replace:new RegExp(`^${a}/${s}/`),to:c}]),Object.keys(e).forEach(t=>{i(l).forEach(({test:o,replace:r,to:s})=>{if(o(t)){const o=t.replace(r,s);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={},r=e.diffModules||{},s={},a=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:a(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 c=e.children||[],l=[],u=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(c.length){const e=t=>{if(t.children=t.children||[],t.childrenList&&t.childrenList.forEach(e=>{const n=u(e);n&&(t.children.push({path:e,component:n.component}),n.useNum++)}),t.children&&t.children.forEach(t=>{e(t)}),t.component){const e=u(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<c.length;t++){const n=c[t];e(n),l.push(n)}}Object.keys(o).forEach(e=>{0===o[e].useNum&&l.push({path:e,component:o[e].component})});const p=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=>{p(e)})};l.forEach(e=>{p(e)});const f={};return Object.keys(o).forEach(e=>{f[o[e].path]=o[e]}),{array:l,map:f}}},e.CRule=class{static form(e){const n=t.reactive({getForm:()=>e.form,rules:e.rules,obj:s.getRule(e.form,e.rules),input:(e,t)=>{n.obj[t](e)},init:t=>{n.rules=t?.rules||e.rules,n.getForm=()=>t?.form||e.form,n.obj=s.getRule(n.getForm(),n.rules)},test:(t=!0)=>{const o=Array.isArray(e.testField)?e.testField:e.testField?.()||Object.keys(n.rules),r=[];for(let e=0;e<o.length;e++){const s=o[e];n.testField(s,t)||r.push({name:s,errmsg:n.rules[s]?.test?.errmsg||""})}return r},testField:(t,o=!0)=>{const r=n.rules[t]?.test;let s=!0;const a=n.getForm();if(r&&(s="string"==typeof r.reg?new RegExp(r.reg).test(a[t]):"function"==typeof r.reg?r.reg(a).test(a[t]):r.reg.test(a[t])),!s&&(e.toast?.(r?.errmsg||"",t),o))throw new Error("field:--\x3e "+t+" <-- "+r?.errmsg);return s}});return n}},e.CStore=class{static toLocal=e=>{e.forEach(async e=>{if(!("key"in e)||!("value"in e)){const t=Object.keys(e)[0];e.key=t,e.value=e[t],e.cookieObj=Cookie}e.cookieObj||(e.cookieObj=Cookie);try{const t=await e.cookieObj.get(e.key);t&&Object.keys(t).forEach(n=>{e.value[n]=ObjectUtil.deepAssign(e.value[n],t[n])})}catch(t){e.cookieObj.remove(e.key)}t.watch(()=>e.value,t=>{e.cookieObj.set(e.key,e.value)},{deep:!0})})}},e.CVue3=n,e.Countdown=class{static init=(...e)=>{const n=r.Timer();if(!window.Cookie)throw new Error("No install cc1-js, please install it first");const o=t.reactive({prefix:"countdown_",names:e,value:{},getCountDownValue:e=>{let t=e-Date.now();t<0&&(t=0);let n=Math.floor(t/1e3);return[n%60,Math.floor(n/60)%60,Math.floor(n/3600)%24,Math.floor(n/86400),n]},getEndTime:(t=!1)=>{Object.keys(n.map).length>0||n.on(()=>{let r=!1;e.forEach(e=>{let n=o.value[e]?.endTime||0;t&&(n=Number(window.Cookie.get(o.prefix+e))||0);const s=o.getCountDownValue(n),a=s[s.length-1];o.value[e]={endTime:n,value:s,totalSec:a},a>0&&(r=!0)}),r||n.clear()},500,t)},start:(e,t=60)=>{const n=Date.now()+1e3*t;window.Cookie.set(o.prefix+e,n.toString());const r=o.getCountDownValue(n);o.value[e]={endTime:n,value:r,totalSec:r.at(-1)},o.getEndTime()},isEnd:e=>!(o.value[e]?.totalSec>0),clear:e=>{window.Cookie.remove(o.prefix+e),o.value[e]=void 0},clearAll:()=>{e.forEach(e=>{o.clear(e)})},destroy:()=>{n.clear(),o.value={}}});return o.getEndTime(!0),o}},e.Minxins=c,e.Scope=i});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import CRouter from './utils/CRouter';
|
|
|
4
4
|
import MinxinsMain from './utils/Minxins';
|
|
5
5
|
import CRule from './utils/CRule';
|
|
6
6
|
import Countdown from './utils/Countdown';
|
|
7
|
+
import CStore from './utils/CStore';
|
|
7
8
|
declare const Scope: typeof ScopeMain;
|
|
8
9
|
declare const Minxins: typeof MinxinsMain;
|
|
9
|
-
export { Scope, CVue3, CRouter, Minxins, CRule, Countdown };
|
|
10
|
+
export { Scope, CVue3, CRouter, Minxins, CRule, Countdown, CStore };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** 状态管理工具 */
|
|
2
|
+
export default class CStore {
|
|
3
|
+
/** 将reactive对象中的值持久化到localStorage(可自定义实现cookieObj)
|
|
4
|
+
* @example
|
|
5
|
+
* export const user = reactive({
|
|
6
|
+
* name: 'John',
|
|
7
|
+
* })
|
|
8
|
+
* import CStore from 'cc1-vue3'
|
|
9
|
+
* CStore.toLocal([{
|
|
10
|
+
* key: 'user',
|
|
11
|
+
* value: user,
|
|
12
|
+
* }])
|
|
13
|
+
* //默认key为对象的key,value为对象
|
|
14
|
+
* CStore.toLocal([{
|
|
15
|
+
* user,
|
|
16
|
+
* }])
|
|
17
|
+
* CStore.toLocal([{
|
|
18
|
+
* key: 'user',
|
|
19
|
+
* value: user,
|
|
20
|
+
* }, {
|
|
21
|
+
* key: 'config',
|
|
22
|
+
* value: config,
|
|
23
|
+
* cookieObj: Cookie / CookieI / CookieC / { set: (key: string, value: any) => any, get: (key: string) => any }
|
|
24
|
+
* }])
|
|
25
|
+
*/
|
|
26
|
+
static toLocal: (params: {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
/** 存储的key */
|
|
29
|
+
key: string;
|
|
30
|
+
/** 存储的reactive对象 */
|
|
31
|
+
value: any;
|
|
32
|
+
/** 自定义实现cookieObj */
|
|
33
|
+
cookieObj?: {
|
|
34
|
+
set: (key: string, value: any) => any;
|
|
35
|
+
get: (key: string) => any;
|
|
36
|
+
remove: (key: string) => any;
|
|
37
|
+
};
|
|
38
|
+
}[]) => void;
|
|
39
|
+
}
|