js_ryl 1.0.11 → 1.0.14

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/README.md CHANGED
@@ -1,137 +1,113 @@
1
- # judadingsheng_ryl
1
+ # js_ryl
2
2
 
3
3
  > 通用js
4
- > 方法序列:
5
-
6
- >1.正则表达式 -- reg
7
- >2.时间戳与时间的转化 -- time
8
- >3.cookie的存储使用 -- cookie
9
- >4.函数的节流和防抖 -- fun
10
- >5.运算符 -- num
11
- >6.复制文本信息 -- copy
12
- >7.对象深拷贝 -- deepCopy
13
4
 
14
5
  ## Build Setup
15
-
16
6
  ``` bash
17
7
  # install dependencies
18
- npm install
8
+ # npm install
19
9
 
20
- # serve with hot reload at localhost:8080
21
- npm run dev
10
+ #方法列表
11
+ 1.正则表达式 -- reg
12
+ 2.时间戳与时间的转化 -- time
13
+ 3.cookie的存储使用 -- cookie
14
+ 4.函数的节流和防抖 -- fun //这是js版本,如果有 componen_ryl,可直接使用防抖指令 v-debounce
15
+ 5.运算符 -- num
16
+ 6.复制文本信息 -- copy //这是js版本,如果有 componen_ryl,可直接使用指令 v-copy
17
+ 7.对象深拷贝 -- deepCopy
22
18
 
23
- # build for production with minification
24
19
  # 使用方法:
25
20
 
26
21
  #1.正则表达式 -- reg
27
22
 
28
- # 所有方法:
29
-
30
- # 这是验证
31
-
32
- # Email() -- 邮箱
33
- # Phone() -- 手机
34
- # IdCard() -- 身份证号码
35
- # Common() -- 只能包含数字、字母以及下划线
36
- # QQ() -- QQ
37
- # Money() -- 金额
38
-
39
- # 这是方法
40
-
41
- # PhoneCode() -- 手机验证码 (注:当调用这个方法后,离开页面时需要调用 PhoneCodeClear() 这个方法)
42
- # PhoneCodeClear() -- 清除手机验证码计时器
43
- # phoneCodeStatus() -- 发送状态,是否已经发送
23
+ Email() #邮箱
24
+ Phone() #手机
25
+ IdCard() #身份证号码
26
+ Common() #只能包含数字、字母以及下划线
27
+ QQ() #QQ
28
+ Money() #金额
44
29
 
45
30
  # 使用方法
46
31
 
47
- # const regPhone = reg.Money(this.name);
48
- # if (regPhone == true) {
49
- # console.log("正确", this.name);
50
- # } else {
51
- # console.log("错误",regPhone); -- 默认错误内容
52
- # console.log("错误",reg.Phone(this.name, "空手机", "手机唧唧了")); -- 自定义错误内容
53
- # }
54
-
55
- # 手机验证码调用
56
- # methods: {
57
- # getInfo(e){
58
- # if (reg.phoneCodeStatus()) {
59
- # console.log('已经发送了')
60
- # return false
61
- # }
62
- # reg.PhoneCode(e,60,'就爆炸了') -- 3个参数,第一个是按钮本身(必传),第二个是秒数,默认60秒(可不传),第三个是提示,默认 重新发送(可不传)
63
- # }
64
- # },
65
- # destroyed(){
66
- # //离开时,清空计时器
67
- # reg.PhoneCodeClear()
68
- # }
32
+ const regPhone = reg.Phone(this.phone);
33
+ if (regPhone == true) {
34
+ console.log("正确", this.phone);
35
+ } else {
36
+ console.log("错误",regPhone); -- 默认错误内容
37
+ console.log("错误",reg.Phone(this.phone, "空手机", "手机唧唧了")); -- 自定义错误内容, 基本不用
38
+ }
39
+
69
40
 
70
41
  #2.时间戳与时间的转化 -- time
71
42
 
72
- # 日期转时间戳
73
- # time.toStamp(第一个参数(表示时间,默认当前),第二个参数(表示时间戳长度,默认10位))
43
+ # 日期转时间戳 -- 参数 a(时间,默认当前),b(时间戳长度,默认10位)
44
+ time.toStamp(a,b)
45
+
46
+ # 时间戳转日期 -- 参数 a(时间戳),b(类型,默认 yyyy-MM-dd HH:mm:ss 可选 yyyy-MM-dd or yyyy-MM-dd HH:mm )
47
+ time.toDate(a,b)
74
48
 
75
- # 时间戳转日期
76
- # time.toDate(第一个参数(表示时间戳),第二个参数(表示类型,默认 yyyy-MM-dd HH:mm:ss 可选 yyyy-MM-dd or yyyy-MM-dd HH:mm ))
49
+ # 获取系统当前时间 -- 无参数
50
+ time.getNow()
77
51
 
78
52
  #3.cookie的存储使用 -- cookie
79
53
 
80
- # 设置cookie
81
- # cookie.set("name", "value", {path:'/',expires:1622709902}); -- 第三个对象的参数,path基本不管,传入过期日期就行了
54
+ # 设置cookie -- 第三个对象的参数,path基本不管,传入过期日期就行了
55
+ cookie.set("name", "value", {path:'/',expires:1622709902});
82
56
 
83
57
  # 获取cookie
84
- # cookie.get("name")
58
+ cookie.get("name")
85
59
 
86
60
  # 删除cookie
87
- # cookie.remove("name");
61
+ cookie.remove("name");
88
62
 
89
63
  #4.函数的节流和防抖 -- fun
90
64
 
91
65
  # 节流函数(有个需要频繁触发的函数,处于性能的优化,在规定时间内,只让函数的第一次生效,后面的不生效)
92
66
  # 应用场景 -- 频繁触发、onrize,onscroll滚动条
93
67
 
94
- # initScroll: fun.throole(function () {
95
- # console.log("触发了几次了" + Date.now());
96
- # })
68
+ initScroll: fun.throole(function () {
69
+ console.log("触发了几次了" + Date.now());
70
+ })
97
71
 
98
72
  # 防抖函数(规定时间内,只让最后一次生效,其他的不生效)
99
73
  # 应用场景 -- 频繁触发、输入框搜索
100
74
 
101
- # inputsLk: fun.debounce(function () {
102
- # console.log(this.name);
103
- # })
75
+ inputsLk: fun.debounce(function () {
76
+ console.log(this.name);
77
+ })
104
78
 
105
79
  #5.运算符 -- num
106
80
 
107
81
  # 加法 num.add(1,2)
108
82
  # 当多个数相加时,推荐用法:
109
- # let arr = [729.3, 72, 6.3, 1];
110
- # let arr3 = arr.reduce((v, n) => {
111
- # return num.add(v, n);
112
- # });
83
+ let arr = [729.3, 72, 6.3, 1];
84
+ let arr3 = arr.reduce((v, n) => {
85
+ return num.add(v, n);
86
+ });
113
87
 
114
- # 减法 num.sub(1,2)
88
+ 减法 num.sub(1,2)
115
89
 
116
- # 乘法 num.mul(1,2)
90
+ 乘法 num.mul(1,2)
117
91
 
118
- # 除法 num.div(1,2)
92
+ 除法 num.div(1,2)
119
93
 
120
94
  #6.复制文本信息 -- copy
121
95
 
122
- # copy(第一个参数(复制的内容),第二个参数(回调函数,判断结果,code为200,成功,code为100,失败))
123
-
124
- # copy("这是复制的内容", (res) => {
125
- # if (res.code == 200) {
126
- # // 成功
127
- # alert(res.msg); 默认提示 -- 复制成功
128
- # } else {
129
- # // 失败
130
- # alert(res.msg); 默认提示 -- 当前浏览器不支持,请更换浏览器后重试
131
- # }
132
- # });
96
+ copy("这是复制的内容", (res) => {
97
+ if (res.code == 200) {
98
+ # 默认提示 -- 复制成功
99
+ alert(res.msg);
100
+ } else {
101
+ # 默认提示 -- 当前浏览器不支持,请更换浏览器后重试
102
+ alert(res.msg);
103
+ }
104
+ });
105
+
133
106
  #7. 对象或数组的深拷贝 -- deepCopy
134
107
 
108
+ let obj2 = deepCopy({},obj)
109
+
110
+ # 如:
135
111
  # let obj = {
136
112
  # name: '张三',
137
113
  # age:12,
@@ -144,15 +120,48 @@ npm run dev
144
120
  # obj2.age = 18
145
121
  # obj2.info.sex = '女'
146
122
  # obj2.info.like = ['耍']
123
+
147
124
  # console.log(obj2,obj,'深拷贝后的值变化')
125
+
126
+ #8 获取验证码 -- verCode
127
+
128
+ # 方法明细
129
+
130
+ # PhoneCode() -- 手机验证码 (注:当调用这个方法后,离开页面时需要调用 PhoneCodeClear() 这个方法)
131
+ # PhoneCodeClear() -- 清除手机验证码计时器
132
+ # phoneCodeStatus() -- 发送状态,是否已经发送
133
+
134
+ # 方法调用
135
+ methods: {
136
+ getInfo(e){
137
+ # 判断是否已经发送
138
+ if (verCode.phoneCodeStatus()) {
139
+ console.log('已经发送了')
140
+ return false
141
+ }
142
+ # 3个参数,第一个是按钮本身(必传),第二个是秒数,默认60秒(可不传),第三个是提示,默认是重新发送(可不传)
143
+ verCode.PhoneCode(e,60,'就爆炸了')
144
+ }
145
+ },
146
+ destroyed(){
147
+ # 离开时,清空计时器
148
+ verCode.PhoneCodeClear()
149
+ }
150
+
151
+
152
+ # serve with hot reload at localhost:8080
153
+ # npm run dev
154
+
155
+ # build for production with minification
156
+ # npm run build
148
157
 
149
158
  #1.0.04: 函数防抖和节流,添加 可传入参数
150
159
  #1.0.05: 添加获取验证码效果
151
160
  #1.0.09: 添加获取验证码效果 逻辑调整
152
161
  #1.0.10: cookie 过期时间转化 toGMTString()
153
162
  #1.0.11: 添加对象或数组的深拷贝方法
154
-
155
- npm run build
163
+ #1.0.12: number 方法 加 减 小数点后2位调整
164
+ #1.0.13: 结构调整,把验证码效果,从 正则 中提取出来
156
165
  ```
157
166
 
158
167
  For detailed explanation on how things work, consult the [docs for vue-loader](http://vuejs.github.io/vue-loader).
package/dist/build.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("js_ryl",[],e):"object"==typeof exports?exports.js_ryl=e():t.js_ryl=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/dist/",e(e.s=1)}([function(t,e,n){"use strict";var r={throole:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,n=0;return function(){var r=this,o=Date.now();o-n>e&&(t.call(r,arguments),n=o)}},debounce:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,n=null;return function(){var r=arguments,o=this;clearTimeout(n),n=setTimeout(function(){t.apply(o,r)},e)}}};e.a=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=n(3),i=n(4),a=n(0),u=n(5),c=n(6),l=n(7);e.default={reg:r.a,time:o.a,cookie:i.a,fun:a.a,num:u.a,copy:c.a,deepCopy:l.a}},function(t,e,n){"use strict";var r=!1,o=null,i="",a=null,u={Email:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入邮箱",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"邮箱格式有误",r=/^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;return t?!!r.test(t)||n:e},IdCard:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入身份证号码",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"身份证号码格式有误",r=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;return t?!!r.test(t)||n:e},Common:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入包含数字、字母以及下划线的内容",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"只能包含数字、字母以及下划线",r=/^[a-zA-Z0-9_]+$/;return t?!!r.test(t)||n:e},QQ:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入QQ号码",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"QQ号码格式错误",r=/^[1-9][0-9]{4,10}$/gim;return t?!!r.test(t)||n:e},Money:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入金额(最多保留2位小数点)",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"金额格式错误",r=/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;return t?!!r.test(t)||n:e},Phone:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入手机号码",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"手机号码格式有误",r=/^[1][3,4,5,7,8,9][0-9]{9}$/;return t?!!r.test(t)||n:e},PhoneCode:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:60,u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"后重新获取";if(i=t.target.innerText,a=t,!r){r=!0,t.target.innerText=n-1+"s"+u;var c=n-1;o=setInterval(function(){c--,c<=0?(t.target.innerText=i,e.PhoneCodeClear()):t.target.innerText=c+"s"+u},1e3)}},PhoneCodeClear:function(){r=!1,a&&(a.target.innerText=i),clearInterval(o)},phoneCodeStatus:function(){return r}};e.a=u},function(t,e,n){"use strict";function r(t){return t<10?"0"+t:t}var o={toDate:function(t,e){var n="";n=10==String(t).length?new Date(1e3*t):new Date(t);var o=n.getFullYear(),i=n.getMonth()+1,a=n.getDate(),u=n.getHours(),c=n.getMinutes(),l=n.getSeconds();return"yyyy-MM-dd"==e?o+"-"+r(i)+"-"+r(a):"yyyy-MM-dd HH:mm"==e?o+"-"+r(i)+"-"+r(a)+" "+r(u)+":"+r(c):o+"-"+r(i)+"-"+r(a)+" "+r(u)+":"+r(c)+":"+r(l)},toStamp:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,n=new Date(t.replace(/-/g,"/")).getTime().toString();return 10==e&&(n=n.substr(0,10)),parseInt(n)}};e.a=o},function(t,e,n){"use strict";var r={set:function(t,e,n){n=n||{};var r=n.path?";Path="+n.path:"",o="";if(n.expires){o=";expires="+(10==String(n.expires).length?new Date(1e3*n.expires):new Date(n.expires)).toGMTString()}document.cookie=t+"="+e+r+o},get:function(t){for(var e=document.cookie,n=e.split("; "),r=0;r<n.length;r++)if(n[r].split("=")[0]===t)return n[r].split("=")[1];return""},remove:function(t,e){e=e||{},e.expires=-1,r.set(t,null,e)}};e.a=r},function(t,e,n){"use strict";var r=(n(0),function(t){var e=0;try{t=Number(t);var n=t.toString().toUpperCase();if(2===n.split("E").length){var r=!1;2===n.split(".").length&&(n=n.split(".")[1],0!==parseInt(n.split("E")[0])&&(r=!0));var o=n.split("E");r&&(e=o[0].length),e-=parseInt(o[1])}else 2===n.split(".").length&&0!==parseInt(n.split(".")[1])&&(e=n.split(".")[1].length)}catch(t){throw t}finally{return(isNaN(e)||e<0)&&(e=0),e}}),o=function(t){t=Number(t);var e=r(t),n=t.toString().toUpperCase();return 2===n.split("E").length?Math.round(t*Math.pow(10,e)):Number(n.replace(".",""))},i=function(t,e,n,r){var o=0;switch(t){case"add":o=e+n;break;case"sub":o=e-n;break;case"div":o=e/n;break;case"mul":o=e*n}return Math.abs(r-o)>1?o:r},a={add:function(t,e){t=Number(t),e=Number(e);var n,o,a;try{n=r(t)+1}catch(t){n=0}try{o=r(e)+1}catch(t){o=0}a=Math.pow(10,Math.max(n,o));var u=(this.mul(t,a)+this.mul(e,a))/a;return i("add",t,e,u)},sub:function(t,e){t=Number(t),e=Number(e);var n,o,a;try{n=r(t)+1}catch(t){n=0}try{o=r(e)+1}catch(t){o=0}a=Math.pow(10,Math.max(n,o));var u=Number((this.mul(t,a)-this.mul(e,a))/a);return i("sub",t,e,u)},div:function(t,e){t=Number(t),e=Number(e);var n,a,u=0,c=0;try{u=r(t)}catch(t){}try{c=r(e)}catch(t){}n=o(t),a=o(e);var l=this.mul(n/a,Math.pow(10,c-u));return i("div",t,e,l)},mul:function(t,e){t=Number(t),e=Number(e);var n=0,a=t.toString(),u=e.toString();try{n+=r(a)}catch(t){}try{n+=r(u)}catch(t){}var c=o(a)*o(u)/Math.pow(10,n);return i("mul",t,e,c)}};e.a=a},function(t,e,n){"use strict";function r(t,e){var n=document.createElement("input");n.setAttribute("readonly","readonly"),n.setAttribute("value",t),document.body.appendChild(n),document.execCommand("copy")?(n.select(),document.execCommand("copy"),e({code:200,msg:"复制成功"})):e({code:100,msg:"当前浏览器不支持,请更换浏览器后重试"}),document.body.removeChild(n)}e.a=r},function(t,e,n){"use strict";function r(t,e){var n=t||{};for(var i in e)"object"===o(e[i])?(n[i]=e[i].constructor===Array?[]:{},r(n[i],e[i])):n[i]=e[i];return n}e.a=r;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t}}])});
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("js_ryl",[],e):"object"==typeof exports?exports.js_ryl=e():t.js_ryl=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="/dist/",e(e.s=1)}([function(t,e,n){"use strict";var r={throole:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,n=0;return function(){var r=this,o=Date.now();o-n>e&&(t.call(r,arguments),n=o)}},debounce:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,n=null;return function(){var r=arguments,o=this;clearTimeout(n),n=setTimeout(function(){t.apply(o,r)},e)}}};e.a=r},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(2),o=n(3),i=n(4),u=n(0),a=n(5),c=n(6),l=n(7),s=n(8);e.default={reg:r.a,time:o.a,cookie:i.a,fun:u.a,num:a.a,copy:c.a,deepCopy:l.a,verCode:s.a}},function(t,e,n){"use strict";var r={Phone:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入手机号码",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"手机号码格式有误",r=/^[1][3,4,5,7,8,9][0-9]{9}$/;return t?r.test(t)?200:n:e},Email:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入邮箱",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"邮箱格式有误",r=/^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;return t?!!r.test(t)||n:e},IdCard:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入身份证号码",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"身份证号码格式有误",r=/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;return t?!!r.test(t)||n:e},Common:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入包含数字、字母以及下划线的内容",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"只能包含数字、字母以及下划线",r=/^[a-zA-Z0-9_]+$/;return t?!!r.test(t)||n:e},QQ:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入QQ号码",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"QQ号码格式错误",r=/^[1-9][0-9]{4,10}$/gim;return t?!!r.test(t)||n:e},Money:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"请输入金额(最多保留2位小数点)",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"金额格式错误",r=/(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;return t?!!r.test(t)||n:e}};e.a=r},function(t,e,n){"use strict";function r(t){return t<10?"0"+t:t}var o={toDate:function(t,e){var n="";n=10==String(t).length?new Date(1e3*t):new Date(t);var o=n.getFullYear(),i=n.getMonth()+1,u=n.getDate(),a=n.getHours(),c=n.getMinutes(),l=n.getSeconds();return"yyyy-MM-dd"==e?o+"-"+r(i)+"-"+r(u):"yyyy-MM-dd HH:mm"==e?o+"-"+r(i)+"-"+r(u)+" "+r(a)+":"+r(c):o+"-"+r(i)+"-"+r(u)+" "+r(a)+":"+r(c)+":"+r(l)},toStamp:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:10,n=new Date(t.replace(/-/g,"/")).getTime().toString();return 10==e&&(n=n.substr(0,10)),parseInt(n)},getNow:function(){var t=(new Date).getTime();return o.toDate(t)}};e.a=o},function(t,e,n){"use strict";var r={set:function(t,e,n){n=n||{};var r=n.path?";Path="+n.path:"",o="";if(n.expires){o=";expires="+(10==String(n.expires).length?new Date(1e3*n.expires):new Date(n.expires)).toGMTString()}document.cookie=t+"="+e+r+o},get:function(t){for(var e=document.cookie,n=e.split("; "),r=0;r<n.length;r++)if(n[r].split("=")[0]===t)return n[r].split("=")[1];return""},remove:function(t,e){e=e||{},e.expires=-1,r.set(t,null,e)}};e.a=r},function(t,e,n){"use strict";var r=(n(0),function(t){var e=0;try{t=Number(t);var n=t.toString().toUpperCase();if(2===n.split("E").length){var r=!1;2===n.split(".").length&&(n=n.split(".")[1],0!==parseInt(n.split("E")[0])&&(r=!0));var o=n.split("E");r&&(e=o[0].length),e-=parseInt(o[1])}else 2===n.split(".").length&&0!==parseInt(n.split(".")[1])&&(e=n.split(".")[1].length)}catch(t){throw t}finally{return(isNaN(e)||e<0)&&(e=0),e}}),o=function(t){t=Number(t);var e=r(t),n=t.toString().toUpperCase();return 2===n.split("E").length?Math.round(t*Math.pow(10,e)):Number(n.replace(".",""))},i=function(t,e,n,r){var o=0;switch(t){case"add":o=e+n;break;case"sub":o=e-n;break;case"div":o=e/n;break;case"mul":o=e*n}return Math.abs(r-o)>1?o:r},u={NumFilter:function(t){var e=String(t).indexOf(".")+1,n=String(t).length-e;return n>0&&n>=3&&(t=Math.floor(100*t)/100),t},add:function(t,e){t=this.NumFilter(Number(t)),e=this.NumFilter(Number(e));var n,o,u;try{n=r(t)+1}catch(t){n=0}try{o=r(e)+1}catch(t){o=0}u=Math.pow(10,Math.max(n,o));var a=(this.mul(t,u)+this.mul(e,u))/u;return i("add",t,e,a)},sub:function(t,e){t=this.NumFilter(Number(t)),e=this.NumFilter(Number(e));var n,o,u;try{n=r(t)+1}catch(t){n=0}try{o=r(e)+1}catch(t){o=0}u=Math.pow(10,Math.max(n,o));var a=Number((this.mul(t,u)-this.mul(e,u))/u);return i("sub",t,e,a)},div:function(t,e){t=Number(t),e=Number(e);var n,u,a=0,c=0;try{a=r(t)}catch(t){}try{c=r(e)}catch(t){}n=o(t),u=o(e);var l=this.mul(n/u,Math.pow(10,c-a));return i("div",t,e,l)},mul:function(t,e){t=Number(t),e=Number(e);var n=0,u=t.toString(),a=e.toString();try{n+=r(u)}catch(t){}try{n+=r(a)}catch(t){}var c=o(u)*o(a)/Math.pow(10,n);return i("mul",t,e,c)}};e.a=u},function(t,e,n){"use strict";function r(t,e){var n=document.createElement("input");n.setAttribute("readonly","readonly"),n.setAttribute("value",t),document.body.appendChild(n),document.execCommand("copy")?(n.select(),document.execCommand("copy"),e({code:200,msg:"复制成功"})):e({code:100,msg:"当前浏览器不支持,请更换浏览器后重试"}),document.body.removeChild(n)}e.a=r},function(t,e,n){"use strict";function r(t,e){var n=t||{};for(var i in e)"object"===o(e[i])?(n[i]=e[i].constructor===Array?[]:{},r(n[i],e[i])):n[i]=e[i];return n}e.a=r;var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t}},function(t,e,n){"use strict";var r=!1,o=null,i="",u=null,a={PhoneCode:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:60,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"后重新获取";if(i=t.target.innerText,u=t,!r){r=!0,t.target.innerText=n-1+"s"+a;var c=n-1;o=setInterval(function(){c--,c<=0?(t.target.innerText=i,e.PhoneCodeClear()):t.target.innerText=c+"s"+a},1e3)}},PhoneCodeClear:function(){r=!1,u&&(u.target.innerText=i),clearInterval(o)},phoneCodeStatus:function(){return r}};e.a=a}])});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_ryl",
3
- "version": "1.0.11",
3
+ "version": "1.0.14",
4
4
  "private": false,
5
5
  "description": "自定义通用js",
6
6
  "author": "renyuliang <785788909@qq.com>",
package/src/App2.vue CHANGED
@@ -31,6 +31,7 @@ import fun from "./function";
31
31
  import num from "./number";
32
32
  import copy from "./copy";
33
33
  import deepCopy from "./deepCopy";
34
+ import verCode from "./verCode";
34
35
  export default {
35
36
  data() {
36
37
  return {
@@ -41,64 +42,40 @@ export default {
41
42
  // LazyLoad,
42
43
  // },
43
44
  mounted() {
44
- // console.log(time.toStamp("2021-06-02 18:17:02"), "当前时间戳");
45
- // console.log(time.toDate(1622623502), "当前时间");
46
- // cookie.set("test1", "abcde", {
47
- // path: "/device",
48
- // expires: 1622882702,
49
- // });
50
- // cookie.set("test2", "abcdefghi", { expires: 1622623502 });
51
- // setTimeout(() => {
52
- // console.log(cookie.get("test2"));
53
- // }, 1000);
54
- // setTimeout(() => {
55
- // cookie.remove("test2");
56
- // }, 3000);
57
- // document.onscroll = fun.throole(function () {
58
- // console.log("触发了几次了" + Date.now());
59
- // }, 200);
45
+ console.log(time.toStamp("2021-06-02 18:17:02"), "当前时间戳");
46
+ console.log(time.toDate(1622623502), "当前时间");
47
+ console.log(time.getNow(), "系统当前时间");
48
+ cookie.set("test1", "abcde", {
49
+ path: "/device",
50
+ expires: 1622882702,
51
+ });
52
+ cookie.set("test2", "abcdefghi", { expires: 1622623502 });
53
+ setTimeout(() => {
54
+ console.log(cookie.get("test2"));
55
+ }, 1000);
56
+ setTimeout(() => {
57
+ cookie.remove("test2");
58
+ }, 3000);
59
+ document.onscroll = fun.throole(function () {
60
+ console.log("触发了几次了" + Date.now());
61
+ }, 200);
60
62
  // let arr = [729.396, 72.6353, 6.3343, 1.1695];
61
- let arr = [729.6986, 72.6, 6.119, 23.03];
63
+ let arr = [729.6986, 72.6, 6.119, 23.03,0.502];
62
64
  let arr2 = arr.reduce((pre, next) => {
63
65
  return pre + next;
64
66
  });
65
67
  let arr3 = arr.reduce((v, n) => {
66
68
  return num.add(v, n);
67
69
  });
68
- let arr4 = arr.reduce((v, n) => {
69
- // 数字相加时,可能会出现多余2位数的
70
- var x = String(v).indexOf(".")+1;//得到小数点的位置
71
- var y = String(v).length - x;//小数点的位数
72
- if(y > 0 && y >=3 ) {
73
- v = Math.floor(v * 100) / 100
74
- }
75
- var x1 = String(n).indexOf(".")+1;//得到小数点的位置
76
- var y1 = String(n).length - x1;//小数点的位数
77
- if(y1 > 0 && y1 >=3 ) {
78
- n = Math.floor(n * 100) / 100
79
- }
80
- return num.add(v, n);
81
-
82
- // return num.add((v).toFixed(2), (n).toFixed(2));
83
- });
84
70
 
85
- // var num11 = 1.1298;
86
- // var x = String(num11).indexOf(".")+1;//得到小数点的位置
87
- // var y = String(num11).length - x;//小数点的位数
88
- // if(y > 0 && y >=3 ) {
89
- // console.log(num11+":有" + y+ "位小数",x);
90
- // let num22 = Math.floor(num11 * 100) / 100
91
- // console.log(num22)
92
- // console.log(typeof num22);
93
- // }
94
71
 
95
72
  console.log(arr2,'22');
96
73
  console.log(arr3,'33');
97
- console.log(arr4,'44');
98
- console.log(num.add(3.29555556,2.63));
99
- console.log(num.sub(0.11, 0.306));
100
- console.log(num.mul(0.1, 0.3231));
101
- console.log(num.div(0.93, 0.3));
74
+ console.log(num.add(3.29555556,2.63),'+');
75
+ console.log(num.sub(0.11, 0.306),'-');
76
+ console.log(num.mul(0.1, 0.3231),'*');
77
+ console.log(num.div(0.893, 0.3),'/');
78
+
102
79
 
103
80
  let obj = {
104
81
  name: '张三',
@@ -121,14 +98,14 @@ export default {
121
98
  },
122
99
  methods: {
123
100
  phoneCode(e){
124
- if (reg.phoneCodeStatus()) {
101
+ if (verCode.phoneCodeStatus()) {
125
102
  console.log('已经发送了')
126
103
  return false
127
104
  }
128
- reg.PhoneCode(e,10)
105
+ verCode.PhoneCode(e,10)
129
106
  },
130
107
  phoneCodeExit(){
131
- reg.PhoneCodeClear()
108
+ verCode.PhoneCodeClear()
132
109
  },
133
110
  longpress() {
134
111
  console.log(112233);
package/src/index.js CHANGED
@@ -13,6 +13,8 @@ import num from "./number";
13
13
  import copy from "./copy";
14
14
  // 深拷贝
15
15
  import deepCopy from "./deepCopy";
16
+ // 验证码
17
+ import verCode from "./verCode";
16
18
 
17
19
  export default {
18
20
  reg,
@@ -21,5 +23,6 @@ export default {
21
23
  fun,
22
24
  num,
23
25
  copy,
24
- deepCopy
26
+ deepCopy,
27
+ verCode
25
28
  };
@@ -69,63 +69,41 @@ var getCorrectResult = function (type, num1, num2, result) {
69
69
  };
70
70
 
71
71
  let num = {
72
+ NumFilter(v) {
73
+ // 数字相加时,可能会出现多余2位数的
74
+ var x = String(v).indexOf(".")+1;//得到小数点的位置
75
+ var y = String(v).length - x;//小数点的位数
76
+ if(y > 0 && y >=3 ) {
77
+ v = Math.floor(v * 100) / 100
78
+ }
79
+ return v
80
+ },
72
81
  //加法
73
- // add:fun.debounce(function(num1, num2){
74
- // num1 = Number(num1);
75
- // num2 = Number(num2);
76
- // var dec1, dec2, times;
77
- // try { dec1 = countDecimals(num1) + 1; } catch (e) { dec1 = 0; }
78
- // try { dec2 = countDecimals(num2) + 1; } catch (e) { dec2 = 0; }
79
- // times = Math.pow(10, Math.max(dec1, dec2));
80
- // // var result = (num1 * times + num2 * times) / times;
81
- // var result = (this.mul(num1, times) + this.mul(num2, times)) / times;
82
- // console.log(getCorrectResult("add", num1, num2, result),'////')
83
- // return getCorrectResult("add", num1, num2, result);
84
- // }),
85
82
  add(num1, num2) {
86
- num1 = Number(num1);
87
- num2 = Number(num2);
83
+ num1 = this.NumFilter(Number(num1));
84
+ num2 = this.NumFilter(Number(num2));
88
85
  var dec1, dec2, times;
89
86
  try { dec1 = countDecimals(num1) + 1; } catch (e) { dec1 = 0; }
90
87
  try { dec2 = countDecimals(num2) + 1; } catch (e) { dec2 = 0; }
91
88
  times = Math.pow(10, Math.max(dec1, dec2));
92
- // var result = (num1 * times + num2 * times) / times;
93
89
  var result = (this.mul(num1, times) + this.mul(num2, times)) / times;
94
- // console.log(result,'---')
95
- // result = result.toFixed(2)
96
90
  return getCorrectResult("add", num1, num2, result);
97
- // return result;
98
91
  },
99
- // add(num1, num2) {
100
- // num1 = Number(num1);
101
- // num2 = Number(num2);
102
- // var dec1, dec2, times;
103
- // try { dec1 = countDecimals(num1) + 1; } catch (e) { dec1 = 0; }
104
- // try { dec2 = countDecimals(num2) + 1; } catch (e) { dec2 = 0; }
105
- // times = Math.pow(10, Math.max(dec1, dec2));
106
- // // var result = (num1 * times + num2 * times) / times;
107
- // var result = (this.mul(num1, times) + this.mul(num2, times)) / times;
108
- // console.log(getCorrectResult("add", num1, num2, result),'////')
109
- // return getCorrectResult("add", num1, num2, result);
110
- // // return result;
111
- // },
112
92
  //减法
113
93
  sub(num1, num2) {
114
- num1 = Number(num1);
115
- num2 = Number(num2);
94
+ num1 = this.NumFilter(Number(num1));
95
+ num2 = this.NumFilter(Number(num2));
116
96
  var dec1, dec2, times;
117
97
  try { dec1 = countDecimals(num1) + 1; } catch (e) { dec1 = 0; }
118
98
  try { dec2 = countDecimals(num2) + 1; } catch (e) { dec2 = 0; }
119
99
  times = Math.pow(10, Math.max(dec1, dec2));
120
- // var result = Number(((num1 * times - num2 * times) / times);
121
100
  var result = Number((this.mul(num1, times) - this.mul(num2, times)) / times);
122
101
  return getCorrectResult("sub", num1, num2, result);
123
- // return result;
124
102
  },
125
103
  //除法
126
104
  div(num1, num2) {
127
- num1 = Number(num1);
128
- num2 = Number(num2);
105
+ num1 = Number(num1)
106
+ num2 = Number(num2)
129
107
  var t1 = 0,
130
108
  t2 = 0,
131
109
  dec1, dec2;
@@ -135,12 +113,11 @@ let num = {
135
113
  dec2 = convertToInt(num2);
136
114
  var result = this.mul((dec1 / dec2), Math.pow(10, t2 - t1));
137
115
  return getCorrectResult("div", num1, num2, result);
138
- // return result;
139
116
  },
140
117
  //乘法
141
118
  mul(num1, num2) {
142
- num1 = Number(num1);
143
- num2 = Number(num2);
119
+ num1 = Number(num1)
120
+ num2 = Number(num2)
144
121
  var times = 0,
145
122
  s1 = num1.toString(),
146
123
  s2 = num2.toString();
@@ -148,7 +125,6 @@ let num = {
148
125
  try { times += countDecimals(s2); } catch (e) { }
149
126
  var result = convertToInt(s1) * convertToInt(s2) / Math.pow(10, times);
150
127
  return getCorrectResult("mul", num1, num2, result);
151
- // return result;
152
128
  }
153
129
  }
154
130
 
package/src/reg/index.js CHANGED
@@ -1,13 +1,22 @@
1
- // 验证码状态是否已经发送
2
- var phoneCodeStatus = false
3
- // 验证码计时器
4
- var phoneCodeTimer = null
5
- // 验证码的文本
6
- var phoneCodeName = ''
7
- // 验证码按钮本身
8
- var phoneCodeSelf = null
9
1
  // 正则匹配
10
2
  let reg = {
3
+ // 手机号验证
4
+ Phone(
5
+ value,
6
+ noValueMsg = "请输入手机号码",
7
+ errValueMsg = "手机号码格式有误"
8
+ ) {
9
+ let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
10
+ if (value) {
11
+ if (reg.test(value)) {
12
+ return 200;
13
+ } else {
14
+ return errValueMsg;
15
+ }
16
+ } else {
17
+ return noValueMsg;
18
+ }
19
+ },
11
20
  // 邮箱验证
12
21
  Email(value, noValueMsg = "请输入邮箱", errValueMsg = "邮箱格式有误") {
13
22
  let reg = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
@@ -88,56 +97,7 @@ let reg = {
88
97
  } else {
89
98
  return noValueMsg;
90
99
  }
91
- },
92
- // 手机号验证
93
- Phone(
94
- value,
95
- noValueMsg = "请输入手机号码",
96
- errValueMsg = "手机号码格式有误"
97
- ) {
98
- let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
99
- if (value) {
100
- if (reg.test(value)) {
101
- return true;
102
- } else {
103
- return errValueMsg;
104
- }
105
- } else {
106
- return noValueMsg;
107
- }
108
- },
109
- // 手机验证码
110
- PhoneCode(e,ss=60,cc='后重新获取'){
111
- // 存储按钮文案
112
- phoneCodeName = e.target.innerText
113
- // 存储按钮本身
114
- phoneCodeSelf = e
115
- if (!phoneCodeStatus) {
116
- phoneCodeStatus = true
117
- e.target.innerText = `${ss-1}s${cc}`
118
- let timer = ss-1
119
- phoneCodeTimer = setInterval(()=>{
120
- timer--
121
- if (timer <= 0) {
122
- // 时间归0后,设置按钮名称
123
- e.target.innerText = phoneCodeName
124
- this.PhoneCodeClear()
125
- } else {
126
- e.target.innerText = `${timer}s${cc}`
127
- }
128
- },1000)
129
- }
130
- },
131
- // 清除手机验证码
132
- PhoneCodeClear(){
133
- phoneCodeStatus = false
134
- if (phoneCodeSelf) {
135
- phoneCodeSelf.target.innerText = phoneCodeName
136
- }
137
- clearInterval(phoneCodeTimer)
138
- },
139
- // 验证码状态是否已经发送
140
- phoneCodeStatus: ()=> phoneCodeStatus
100
+ }
141
101
  };
142
102
 
143
103
  export default reg;
package/src/time/index.js CHANGED
@@ -32,6 +32,11 @@ let time = {
32
32
  tmp = tmp.substr(0, 10);
33
33
  }
34
34
  return parseInt(tmp);
35
+ },
36
+ // 获取当前时间
37
+ getNow(){
38
+ let ts = new Date().getTime()
39
+ return time.toDate(ts)
35
40
  }
36
41
  }
37
42
  // 补0
@@ -0,0 +1,46 @@
1
+ // 验证码相关
2
+ // 验证码状态是否已经发送
3
+ var phoneCodeStatus = false
4
+ // 验证码计时器
5
+ var phoneCodeTimer = null
6
+ // 验证码的文本
7
+ var phoneCodeName = ''
8
+ // 验证码按钮本身
9
+ var phoneCodeSelf = null
10
+ // 正则匹配
11
+ let verCode = {
12
+ // 手机验证码
13
+ PhoneCode(e,ss=60,cc='后重新获取'){
14
+ // 存储按钮文案
15
+ phoneCodeName = e.target.innerText
16
+ // 存储按钮本身
17
+ phoneCodeSelf = e
18
+ if (!phoneCodeStatus) {
19
+ phoneCodeStatus = true
20
+ e.target.innerText = `${ss-1}s${cc}`
21
+ let timer = ss-1
22
+ phoneCodeTimer = setInterval(()=>{
23
+ timer--
24
+ if (timer <= 0) {
25
+ // 时间归0后,设置按钮名称
26
+ e.target.innerText = phoneCodeName
27
+ this.PhoneCodeClear()
28
+ } else {
29
+ e.target.innerText = `${timer}s${cc}`
30
+ }
31
+ },1000)
32
+ }
33
+ },
34
+ // 清除手机验证码
35
+ PhoneCodeClear(){
36
+ phoneCodeStatus = false
37
+ if (phoneCodeSelf) {
38
+ phoneCodeSelf.target.innerText = phoneCodeName
39
+ }
40
+ clearInterval(phoneCodeTimer)
41
+ },
42
+ // 验证码状态是否已经发送
43
+ phoneCodeStatus: ()=> phoneCodeStatus
44
+ };
45
+
46
+ export default verCode;