js_ryl 1.0.10 → 1.0.13

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,141 +1,167 @@
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
4
 
13
5
  ## Build Setup
14
-
15
6
  ``` bash
16
7
  # install dependencies
17
- npm install
8
+ # npm install
18
9
 
19
- # serve with hot reload at localhost:8080
20
- 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
21
18
 
22
- # build for production with minification
23
19
  # 使用方法:
24
20
 
25
21
  #1.正则表达式 -- reg
26
22
 
27
- # 所有方法:
28
-
29
- # 这是验证
30
-
31
- # Email() -- 邮箱
32
- # Phone() -- 手机
33
- # IdCard() -- 身份证号码
34
- # Common() -- 只能包含数字、字母以及下划线
35
- # QQ() -- QQ
36
- # Money() -- 金额
37
-
38
- # 这是方法
39
-
40
- # PhoneCode() -- 手机验证码 (注:当调用这个方法后,离开页面时需要调用 PhoneCodeClear() 这个方法)
41
- # PhoneCodeClear() -- 清除手机验证码计时器
42
- # phoneCodeStatus() -- 发送状态,是否已经发送
23
+ Email() #邮箱
24
+ Phone() #手机
25
+ IdCard() #身份证号码
26
+ Common() #只能包含数字、字母以及下划线
27
+ QQ() #QQ
28
+ Money() #金额
43
29
 
44
30
  # 使用方法
45
31
 
46
- # const regPhone = reg.Money(this.name);
47
- # if (regPhone == true) {
48
- # console.log("正确", this.name);
49
- # } else {
50
- # console.log("错误",regPhone); -- 默认错误内容
51
- # console.log("错误",reg.Phone(this.name, "空手机", "手机唧唧了")); -- 自定义错误内容
52
- # }
53
-
54
- # 手机验证码调用
55
- # methods: {
56
- # getInfo(e){
57
- # if (reg.phoneCodeStatus()) {
58
- # console.log('已经发送了')
59
- # return false
60
- # }
61
- # reg.PhoneCode(e,60,'就爆炸了') -- 3个参数,第一个是按钮本身(必传),第二个是秒数,默认60秒(可不传),第三个是提示,默认 重新发送(可不传)
62
- # }
63
- # },
64
- # destroyed(){
65
- # //离开时,清空计时器
66
- # reg.PhoneCodeClear()
67
- # }
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
+
68
40
 
69
41
  #2.时间戳与时间的转化 -- time
70
42
 
71
- # 日期转时间戳
72
- # 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)
73
48
 
74
- # 时间戳转日期
75
- # time.toDate(第一个参数(表示时间戳),第二个参数(表示类型,默认 yyyy-MM-dd HH:mm:ss 可选 yyyy-MM-dd or yyyy-MM-dd HH:mm ))
49
+ # 获取系统当前时间 -- 无参数
50
+ time.getNow()
76
51
 
77
52
  #3.cookie的存储使用 -- cookie
78
53
 
79
- # 设置cookie
80
- # cookie.set("name", "value", {path:'/',expires:1622709902}); -- 第三个对象的参数,path基本不管,传入过期日期就行了
54
+ # 设置cookie -- 第三个对象的参数,path基本不管,传入过期日期就行了
55
+ cookie.set("name", "value", {path:'/',expires:1622709902});
81
56
 
82
57
  # 获取cookie
83
- # cookie.get("name")
58
+ cookie.get("name")
84
59
 
85
60
  # 删除cookie
86
- # cookie.remove("name");
61
+ cookie.remove("name");
87
62
 
88
63
  #4.函数的节流和防抖 -- fun
89
64
 
90
65
  # 节流函数(有个需要频繁触发的函数,处于性能的优化,在规定时间内,只让函数的第一次生效,后面的不生效)
91
66
  # 应用场景 -- 频繁触发、onrize,onscroll滚动条
92
67
 
93
- # initScroll: fun.throole(function () {
94
- # console.log("触发了几次了" + Date.now());
95
- # })
68
+ initScroll: fun.throole(function () {
69
+ console.log("触发了几次了" + Date.now());
70
+ })
96
71
 
97
72
  # 防抖函数(规定时间内,只让最后一次生效,其他的不生效)
98
73
  # 应用场景 -- 频繁触发、输入框搜索
99
74
 
100
- # inputsLk: fun.debounce(function () {
101
- # console.log(this.name);
102
- # })
75
+ inputsLk: fun.debounce(function () {
76
+ console.log(this.name);
77
+ })
103
78
 
104
79
  #5.运算符 -- num
105
80
 
106
81
  # 加法 num.add(1,2)
107
82
  # 当多个数相加时,推荐用法:
108
- # let arr = [729.3, 72, 6.3, 1];
109
- # let arr3 = arr.reduce((v, n) => {
110
- # return num.add(v, n);
111
- # });
83
+ let arr = [729.3, 72, 6.3, 1];
84
+ let arr3 = arr.reduce((v, n) => {
85
+ return num.add(v, n);
86
+ });
112
87
 
113
- # 减法 num.sub(1,2)
88
+ 减法 num.sub(1,2)
114
89
 
115
- # 乘法 num.mul(1,2)
90
+ 乘法 num.mul(1,2)
116
91
 
117
- # 除法 num.div(1,2)
92
+ 除法 num.div(1,2)
118
93
 
119
94
  #6.复制文本信息 -- copy
120
95
 
121
- # copy(第一个参数(复制的内容),第二个参数(回调函数,判断结果,code为200,成功,code为100,失败))
96
+ copy("这是复制的内容", (res) => {
97
+ if (res.code == 200) {
98
+ # 默认提示 -- 复制成功
99
+ alert(res.msg);
100
+ } else {
101
+ # 默认提示 -- 当前浏览器不支持,请更换浏览器后重试
102
+ alert(res.msg);
103
+ }
104
+ });
105
+
106
+ #7. 对象或数组的深拷贝 -- deepCopy
107
+
108
+ let obj2 = deepCopy({},obj)
109
+
110
+ # 如:
111
+ # let obj = {
112
+ # name: '张三',
113
+ # age:12,
114
+ # info: {
115
+ # sex: '男',
116
+ # like: ['电影','游戏']
117
+ # }
118
+ # }
119
+ # let obj2 = deepCopy({},obj)
120
+ # obj2.age = 18
121
+ # obj2.info.sex = '女'
122
+ # obj2.info.like = ['耍']
123
+
124
+ # console.log(obj2,obj,'深拷贝后的值变化')
125
+
126
+ #8 获取验证码 -- verCode
122
127
 
123
- # copy("这是复制的内容", (res) => {
124
- # if (res.code == 200) {
125
- # // 成功
126
- # alert(res.msg); 默认提示 -- 复制成功
127
- # } else {
128
- # // 失败
129
- # alert(res.msg); 默认提示 -- 当前浏览器不支持,请更换浏览器后重试
130
- # }
131
- # });
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
132
157
 
133
158
  #1.0.04: 函数防抖和节流,添加 可传入参数
134
159
  #1.0.05: 添加获取验证码效果
135
160
  #1.0.09: 添加获取验证码效果 逻辑调整
136
161
  #1.0.10: cookie 过期时间转化 toGMTString()
137
-
138
- npm run build
162
+ #1.0.11: 添加对象或数组的深拷贝方法
163
+ #1.0.12: number 方法 加 减 小数点后2位调整
164
+ #1.0.13: 结构调整,把验证码效果,从 正则 中提取出来
139
165
  ```
140
166
 
141
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),a=n(4),i=n(0),u=n(5),c=n(6);e.default={reg:r.a,time:o.a,cookie:a.a,fun:i.a,num:u.a,copy:c.a}},function(t,e,n){"use strict";var r=!1,o=null,a="",i=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(a=t.target.innerText,i=t,!r){r=!0,t.target.innerText=n-1+"s"+u;var c=n-1;o=setInterval(function(){c--,c<=0?(t.target.innerText=a,e.PhoneCodeClear()):t.target.innerText=c+"s"+u},1e3)}},PhoneCodeClear:function(){r=!1,i&&(i.target.innerText=a),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(),a=n.getMonth()+1,i=n.getDate(),u=n.getHours(),c=n.getMinutes(),l=n.getSeconds();return"yyyy-MM-dd"==e?o+"-"+r(a)+"-"+r(i):"yyyy-MM-dd HH:mm"==e?o+"-"+r(a)+"-"+r(i)+" "+r(u)+":"+r(c):o+"-"+r(a)+"-"+r(i)+" "+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(".",""))},a=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},i={add:function(t,e){t=Number(t),e=Number(e);var n,o,i;try{n=r(t)+1}catch(t){n=0}try{o=r(e)+1}catch(t){o=0}i=Math.pow(10,Math.max(n,o));var u=(this.mul(t,i)+this.mul(e,i))/i;return a("add",t,e,u)},sub:function(t,e){t=Number(t),e=Number(e);var n,o,i;try{n=r(t)+1}catch(t){n=0}try{o=r(e)+1}catch(t){o=0}i=Math.pow(10,Math.max(n,o));var u=Number((this.mul(t,i)-this.mul(e,i))/i);return a("sub",t,e,u)},div:function(t,e){t=Number(t),e=Number(e);var n,i,u=0,c=0;try{u=r(t)}catch(t){}try{c=r(e)}catch(t){}n=o(t),i=o(e);var l=this.mul(n/i,Math.pow(10,c-u));return a("div",t,e,l)},mul:function(t,e){t=Number(t),e=Number(e);var n=0,i=t.toString(),u=e.toString();try{n+=r(i)}catch(t){}try{n+=r(u)}catch(t){}var c=o(i)*o(u)/Math.pow(10,n);return a("mul",t,e,c)}};e.a=i},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}])});
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),s=n(7);e.default={reg:r.a,time:o.a,cookie:i.a,fun:u.a,num:a.a,copy:c.a,deepCopy: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(),s=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(s)},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 s=this.mul(n/u,Math.pow(10,c-a));return i("div",t,e,s)},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}}])});
package/index.html CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  <head>
5
5
  <meta charset="utf-8">
6
- <title>judadingsheng_ryl</title>
6
+ <title>myJS_ryl</title>
7
7
  </head>
8
8
 
9
9
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_ryl",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "private": false,
5
5
  "description": "自定义通用js",
6
6
  "author": "renyuliang <785788909@qq.com>",
@@ -21,11 +21,11 @@
21
21
  "babel-preset-env": "^1.6.0",
22
22
  "babel-preset-stage-3": "^6.24.1",
23
23
  "cross-env": "^5.0.5",
24
- "css-loader": "^0.28.7",
24
+ "css-loader": "^0.28.11",
25
25
  "file-loader": "^1.1.11",
26
- "node-sass": "^4.14.1",
26
+ "sass": "^1.52.3",
27
27
  "sass-loader": "^7.3.1",
28
- "style-loader": "^1.3.0",
28
+ "style-loader": "^0.23.1",
29
29
  "url-loader": "^0.6.2",
30
30
  "vue-cli-plugin-element": "~1.0.1",
31
31
  "vue-loader": "^13.0.5",
package/src/App.vue CHANGED
@@ -30,6 +30,8 @@ import cookie from "./cookie";
30
30
  import fun from "./function";
31
31
  import num from "./number";
32
32
  import copy from "./copy";
33
+ import deepCopy from "./deepCopy";
34
+ import verCode from "./verCode";
33
35
  export default {
34
36
  data() {
35
37
  return {
@@ -40,75 +42,70 @@ export default {
40
42
  // LazyLoad,
41
43
  // },
42
44
  mounted() {
43
- // console.log(time.toStamp("2021-06-02 18:17:02"), "当前时间戳");
44
- // console.log(time.toDate(1622623502), "当前时间");
45
- // cookie.set("test1", "abcde", {
46
- // path: "/device",
47
- // expires: 1622882702,
48
- // });
49
- // cookie.set("test2", "abcdefghi", { expires: 1622623502 });
50
- // setTimeout(() => {
51
- // console.log(cookie.get("test2"));
52
- // }, 1000);
53
- // setTimeout(() => {
54
- // cookie.remove("test2");
55
- // }, 3000);
56
- // document.onscroll = fun.throole(function () {
57
- // console.log("触发了几次了" + Date.now());
58
- // }, 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);
59
62
  // let arr = [729.396, 72.6353, 6.3343, 1.1695];
60
- let arr = [729.6986, 72.6, 6.119, 23.03];
63
+ let arr = [729.6986, 72.6, 6.119, 23.03,0.502];
61
64
  let arr2 = arr.reduce((pre, next) => {
62
65
  return pre + next;
63
66
  });
64
67
  let arr3 = arr.reduce((v, n) => {
65
68
  return num.add(v, n);
66
69
  });
67
- let arr4 = arr.reduce((v, n) => {
68
- // 数字相加时,可能会出现多余2位数的
69
- var x = String(v).indexOf(".")+1;//得到小数点的位置
70
- var y = String(v).length - x;//小数点的位数
71
- if(y > 0 && y >=3 ) {
72
- v = Math.floor(v * 100) / 100
73
- }
74
- var x1 = String(n).indexOf(".")+1;//得到小数点的位置
75
- var y1 = String(n).length - x1;//小数点的位数
76
- if(y1 > 0 && y1 >=3 ) {
77
- n = Math.floor(n * 100) / 100
78
- }
79
- return num.add(v, n);
80
70
 
81
- // return num.add((v).toFixed(2), (n).toFixed(2));
82
- });
83
-
84
- // var num11 = 1.1298;
85
- // var x = String(num11).indexOf(".")+1;//得到小数点的位置
86
- // var y = String(num11).length - x;//小数点的位数
87
- // if(y > 0 && y >=3 ) {
88
- // console.log(num11+":有" + y+ "位小数",x);
89
- // let num22 = Math.floor(num11 * 100) / 100
90
- // console.log(num22)
91
- // console.log(typeof num22);
92
- // }
93
71
 
94
72
  console.log(arr2,'22');
95
73
  console.log(arr3,'33');
96
- console.log(arr4,'44');
97
- console.log(num.add(3.29555556,2.63));
98
- console.log(num.sub(0.11, 0.306));
99
- console.log(num.mul(0.1, 0.3231));
100
- 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
+
79
+
80
+ let obj = {
81
+ name: '张三',
82
+ age:12,
83
+ info: {
84
+ sex: '男',
85
+ like: ['电影','游戏']
86
+ }
87
+ }
88
+ let obj2 = deepCopy({},obj)
89
+ obj2.age = 18
90
+ obj2.info.sex = '女'
91
+ obj2.info.like = ['耍']
92
+ console.log(obj2,obj,'深拷贝后的值变化')
93
+
94
+ let arr00 = [1,2,3,4,5]
95
+ let arr002 = deepCopy([],arr00)
96
+ arr002[0]=111
97
+ console.log(arr002,arr00)
101
98
  },
102
99
  methods: {
103
100
  phoneCode(e){
104
- if (reg.phoneCodeStatus()) {
101
+ if (verCode.phoneCodeStatus()) {
105
102
  console.log('已经发送了')
106
103
  return false
107
104
  }
108
- reg.PhoneCode(e,10)
105
+ verCode.PhoneCode(e,10)
109
106
  },
110
107
  phoneCodeExit(){
111
- reg.PhoneCodeClear()
108
+ verCode.PhoneCodeClear()
112
109
  },
113
110
  longpress() {
114
111
  console.log(112233);
package/src/App1.vue ADDED
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <div id="app"></div>
3
+ </template>
@@ -0,0 +1,13 @@
1
+ // 深拷贝
2
+ export default function deepCopy(obj, tar) {
3
+ var dest = obj || {}
4
+ for (const key in tar) {
5
+ if (typeof tar[key] === 'object') {
6
+ dest[key] = (tar[key].constructor === Array) ? []:{}
7
+ deepCopy(dest[key],tar[key])
8
+ } else {
9
+ dest[key] = tar[key]
10
+ }
11
+ }
12
+ return dest
13
+ }
package/src/index.js CHANGED
@@ -11,6 +11,8 @@ import fun from "./function";
11
11
  import num from "./number";
12
12
  // 复制文本信息
13
13
  import copy from "./copy";
14
+ // 深拷贝
15
+ import deepCopy from "./deepCopy";
14
16
 
15
17
  export default {
16
18
  reg,
@@ -18,5 +20,6 @@ export default {
18
20
  cookie,
19
21
  fun,
20
22
  num,
21
- copy
23
+ copy,
24
+ deepCopy
22
25
  };
@@ -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;