js_ryl 1.0.9 → 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/README.md +25 -6
- package/dist/build.js +1 -1
- package/index.html +1 -1
- package/package.json +4 -4
- package/src/App.vue +3 -157
- package/src/App2.vue +152 -0
- package/src/cookie/index.js +4 -2
- package/src/deepCopy/index.js +13 -0
- package/src/index.js +4 -1
- package/src/number/index.js +17 -41
package/README.md
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
> 通用js
|
|
4
4
|
> 方法序列:
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
# 1.正则表达式 -- reg
|
|
7
|
+
# 2.时间戳与时间的转化 -- time
|
|
8
|
+
# 3.cookie的存储使用 -- cookie
|
|
9
|
+
# 4.函数的节流和防抖 -- fun
|
|
10
|
+
# 5.运算符 -- num
|
|
11
|
+
# 6.复制文本信息 -- copy
|
|
12
|
+
# 7.对象深拷贝 -- deepCopy
|
|
12
13
|
|
|
13
14
|
## Build Setup
|
|
14
15
|
|
|
@@ -129,10 +130,28 @@ npm run dev
|
|
|
129
130
|
# alert(res.msg); 默认提示 -- 当前浏览器不支持,请更换浏览器后重试
|
|
130
131
|
# }
|
|
131
132
|
# });
|
|
133
|
+
#7. 对象或数组的深拷贝 -- deepCopy
|
|
134
|
+
|
|
135
|
+
# let obj = {
|
|
136
|
+
# name: '张三',
|
|
137
|
+
# age:12,
|
|
138
|
+
# info: {
|
|
139
|
+
# sex: '男',
|
|
140
|
+
# like: ['电影','游戏']
|
|
141
|
+
# }
|
|
142
|
+
# }
|
|
143
|
+
# let obj2 = deepCopy({},obj)
|
|
144
|
+
# obj2.age = 18
|
|
145
|
+
# obj2.info.sex = '女'
|
|
146
|
+
# obj2.info.like = ['耍']
|
|
147
|
+
# console.log(obj2,obj,'深拷贝后的值变化')
|
|
132
148
|
|
|
133
149
|
#1.0.04: 函数防抖和节流,添加 可传入参数
|
|
134
150
|
#1.0.05: 添加获取验证码效果
|
|
135
151
|
#1.0.09: 添加获取验证码效果 逻辑调整
|
|
152
|
+
#1.0.10: cookie 过期时间转化 toGMTString()
|
|
153
|
+
#1.0.11: 添加对象或数组的深拷贝方法
|
|
154
|
+
#1.0.12: number 方法 加 减 小数点后2位调整
|
|
136
155
|
|
|
137
156
|
npm run build
|
|
138
157
|
```
|
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),
|
|
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);e.default={reg:r.a,time:o.a,cookie:i.a,fun:u.a,num:a.a,copy:c.a,deepCopy:l.a}},function(t,e,n){"use strict";var r=!1,o=null,i="",u=null,a={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,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},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)}};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}}])});
|
package/index.html
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "js_ryl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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.
|
|
24
|
+
"css-loader": "^0.28.11",
|
|
25
25
|
"file-loader": "^1.1.11",
|
|
26
|
-
"
|
|
26
|
+
"sass": "^1.52.3",
|
|
27
27
|
"sass-loader": "^7.3.1",
|
|
28
|
-
"style-loader": "^
|
|
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
|
@@ -1,157 +1,3 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type="text"
|
|
5
|
-
id="input"
|
|
6
|
-
v-model="name"
|
|
7
|
-
@blur="inputBlur"
|
|
8
|
-
@keydown="inputsLk({id:'11',name:'实力坑爹'},12123)"
|
|
9
|
-
/>
|
|
10
|
-
<button @click="getCookie">点击</button>
|
|
11
|
-
<div
|
|
12
|
-
style="height: 300px; border: 1px solid red; overflow-y: auto"
|
|
13
|
-
@scroll="initScroll"
|
|
14
|
-
>
|
|
15
|
-
<div style="height: 800px">滚动区域</div>
|
|
16
|
-
</div>
|
|
17
|
-
<button @click="copyCli()">Copy</button>
|
|
18
|
-
<br />
|
|
19
|
-
<br>
|
|
20
|
-
<br>
|
|
21
|
-
<!-- <button @click="phoneCode($event)">验证码</button> -->
|
|
22
|
-
<a href="javascript:;" @click="phoneCode($event)">验证码</a>
|
|
23
|
-
<a href="javascript:;" @click="phoneCodeExit()">清空验证码</a>
|
|
24
|
-
</div>
|
|
25
|
-
</template>
|
|
26
|
-
<script>
|
|
27
|
-
import reg from "./reg";
|
|
28
|
-
import time from "./time";
|
|
29
|
-
import cookie from "./cookie";
|
|
30
|
-
import fun from "./function";
|
|
31
|
-
import num from "./number";
|
|
32
|
-
import copy from "./copy";
|
|
33
|
-
export default {
|
|
34
|
-
data() {
|
|
35
|
-
return {
|
|
36
|
-
name: "",
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
// directives: {
|
|
40
|
-
// LazyLoad,
|
|
41
|
-
// },
|
|
42
|
-
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);
|
|
59
|
-
// let arr = [729.396, 72.6353, 6.3343, 1.1695];
|
|
60
|
-
let arr = [729.6986, 72.6, 6.119, 23.03];
|
|
61
|
-
let arr2 = arr.reduce((pre, next) => {
|
|
62
|
-
return pre + next;
|
|
63
|
-
});
|
|
64
|
-
let arr3 = arr.reduce((v, n) => {
|
|
65
|
-
return num.add(v, n);
|
|
66
|
-
});
|
|
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
|
-
|
|
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
|
-
|
|
94
|
-
console.log(arr2,'22');
|
|
95
|
-
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));
|
|
101
|
-
},
|
|
102
|
-
methods: {
|
|
103
|
-
phoneCode(e){
|
|
104
|
-
if (reg.phoneCodeStatus()) {
|
|
105
|
-
console.log('已经发送了')
|
|
106
|
-
return false
|
|
107
|
-
}
|
|
108
|
-
reg.PhoneCode(e,10)
|
|
109
|
-
},
|
|
110
|
-
phoneCodeExit(){
|
|
111
|
-
reg.PhoneCodeClear()
|
|
112
|
-
},
|
|
113
|
-
longpress() {
|
|
114
|
-
console.log(112233);
|
|
115
|
-
},
|
|
116
|
-
copyCli() {
|
|
117
|
-
copy("good哈哈哈失败", (res) => {
|
|
118
|
-
if (res.code == 200) {
|
|
119
|
-
// 成功
|
|
120
|
-
alert(res.msg);
|
|
121
|
-
} else {
|
|
122
|
-
// 失败
|
|
123
|
-
alert(res.msg);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
},
|
|
127
|
-
inputsLk: fun.debounce(function (v,v2) {
|
|
128
|
-
console.log(this.name,v,v2);
|
|
129
|
-
}),
|
|
130
|
-
initScroll: fun.throole(function () {
|
|
131
|
-
console.log("触发了几次了" + Date.now());
|
|
132
|
-
}),
|
|
133
|
-
getCookie() {
|
|
134
|
-
console.log(cookie.get("test2"));
|
|
135
|
-
},
|
|
136
|
-
inputBlur() {
|
|
137
|
-
const regPhone = reg.Phone(this.name);
|
|
138
|
-
if (regPhone == true) {
|
|
139
|
-
console.log("正确", this.name);
|
|
140
|
-
} else {
|
|
141
|
-
console.log("错误", regPhone, "///");
|
|
142
|
-
console.log(
|
|
143
|
-
"错误",
|
|
144
|
-
reg.Phone(this.name, "空手机", "手机唧唧了"),
|
|
145
|
-
"///"
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
};
|
|
151
|
-
</script>
|
|
152
|
-
<style lang="scss" scoped>
|
|
153
|
-
.img {
|
|
154
|
-
width: 100px;
|
|
155
|
-
height: 100px;
|
|
156
|
-
}
|
|
157
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div id="app"></div>
|
|
3
|
+
</template>
|
package/src/App2.vue
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div id="app">
|
|
3
|
+
<input
|
|
4
|
+
type="text"
|
|
5
|
+
id="input"
|
|
6
|
+
v-model="name"
|
|
7
|
+
@blur="inputBlur"
|
|
8
|
+
@keydown="inputsLk({id:'11',name:'实力坑爹'},12123)"
|
|
9
|
+
/>
|
|
10
|
+
<button @click="getCookie">点击</button>
|
|
11
|
+
<div
|
|
12
|
+
style="height: 300px; border: 1px solid red; overflow-y: auto"
|
|
13
|
+
@scroll="initScroll"
|
|
14
|
+
>
|
|
15
|
+
<div style="height: 800px">滚动区域</div>
|
|
16
|
+
</div>
|
|
17
|
+
<button @click="copyCli()">Copy</button>
|
|
18
|
+
<br />
|
|
19
|
+
<br>
|
|
20
|
+
<br>
|
|
21
|
+
<!-- <button @click="phoneCode($event)">验证码</button> -->
|
|
22
|
+
<a href="javascript:;" @click="phoneCode($event)">验证码</a>
|
|
23
|
+
<a href="javascript:;" @click="phoneCodeExit()">清空验证码</a>
|
|
24
|
+
</div>
|
|
25
|
+
</template>
|
|
26
|
+
<script>
|
|
27
|
+
import reg from "./reg";
|
|
28
|
+
import time from "./time";
|
|
29
|
+
import cookie from "./cookie";
|
|
30
|
+
import fun from "./function";
|
|
31
|
+
import num from "./number";
|
|
32
|
+
import copy from "./copy";
|
|
33
|
+
import deepCopy from "./deepCopy";
|
|
34
|
+
export default {
|
|
35
|
+
data() {
|
|
36
|
+
return {
|
|
37
|
+
name: "",
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
// directives: {
|
|
41
|
+
// LazyLoad,
|
|
42
|
+
// },
|
|
43
|
+
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);
|
|
60
|
+
// let arr = [729.396, 72.6353, 6.3343, 1.1695];
|
|
61
|
+
let arr = [729.6986, 72.6, 6.119, 23.03,0.502];
|
|
62
|
+
let arr2 = arr.reduce((pre, next) => {
|
|
63
|
+
return pre + next;
|
|
64
|
+
});
|
|
65
|
+
let arr3 = arr.reduce((v, n) => {
|
|
66
|
+
return num.add(v, n);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
console.log(arr2,'22');
|
|
71
|
+
console.log(arr3,'33');
|
|
72
|
+
console.log(num.add(3.29555556,2.63),'+');
|
|
73
|
+
console.log(num.sub(0.11, 0.306),'-');
|
|
74
|
+
console.log(num.mul(0.1, 0.3231),'*');
|
|
75
|
+
console.log(num.div(0.893, 0.3),'/');
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
let obj = {
|
|
79
|
+
name: '张三',
|
|
80
|
+
age:12,
|
|
81
|
+
info: {
|
|
82
|
+
sex: '男',
|
|
83
|
+
like: ['电影','游戏']
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let obj2 = deepCopy({},obj)
|
|
87
|
+
obj2.age = 18
|
|
88
|
+
obj2.info.sex = '女'
|
|
89
|
+
obj2.info.like = ['耍']
|
|
90
|
+
console.log(obj2,obj,'深拷贝后的值变化')
|
|
91
|
+
|
|
92
|
+
let arr00 = [1,2,3,4,5]
|
|
93
|
+
let arr002 = deepCopy([],arr00)
|
|
94
|
+
arr002[0]=111
|
|
95
|
+
console.log(arr002,arr00)
|
|
96
|
+
},
|
|
97
|
+
methods: {
|
|
98
|
+
phoneCode(e){
|
|
99
|
+
if (reg.phoneCodeStatus()) {
|
|
100
|
+
console.log('已经发送了')
|
|
101
|
+
return false
|
|
102
|
+
}
|
|
103
|
+
reg.PhoneCode(e,10)
|
|
104
|
+
},
|
|
105
|
+
phoneCodeExit(){
|
|
106
|
+
reg.PhoneCodeClear()
|
|
107
|
+
},
|
|
108
|
+
longpress() {
|
|
109
|
+
console.log(112233);
|
|
110
|
+
},
|
|
111
|
+
copyCli() {
|
|
112
|
+
copy("good哈哈哈失败", (res) => {
|
|
113
|
+
if (res.code == 200) {
|
|
114
|
+
// 成功
|
|
115
|
+
alert(res.msg);
|
|
116
|
+
} else {
|
|
117
|
+
// 失败
|
|
118
|
+
alert(res.msg);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
},
|
|
122
|
+
inputsLk: fun.debounce(function (v,v2) {
|
|
123
|
+
console.log(this.name,v,v2);
|
|
124
|
+
}),
|
|
125
|
+
initScroll: fun.throole(function () {
|
|
126
|
+
console.log("触发了几次了" + Date.now());
|
|
127
|
+
}),
|
|
128
|
+
getCookie() {
|
|
129
|
+
console.log(cookie.get("test2"));
|
|
130
|
+
},
|
|
131
|
+
inputBlur() {
|
|
132
|
+
const regPhone = reg.Phone(this.name);
|
|
133
|
+
if (regPhone == true) {
|
|
134
|
+
console.log("正确", this.name);
|
|
135
|
+
} else {
|
|
136
|
+
console.log("错误", regPhone, "///");
|
|
137
|
+
console.log(
|
|
138
|
+
"错误",
|
|
139
|
+
reg.Phone(this.name, "空手机", "手机唧唧了"),
|
|
140
|
+
"///"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
</script>
|
|
147
|
+
<style lang="scss" scoped>
|
|
148
|
+
.img {
|
|
149
|
+
width: 100px;
|
|
150
|
+
height: 100px;
|
|
151
|
+
}
|
|
152
|
+
</style>
|
package/src/cookie/index.js
CHANGED
|
@@ -9,8 +9,10 @@ const cookie = {
|
|
|
9
9
|
// 处理默认有效期
|
|
10
10
|
let expires = "";
|
|
11
11
|
if (ops.expires) {
|
|
12
|
-
ops.expires = String(ops.expires).length == 10 ? new Date(ops.expires * 1000) : new Date(ops.expires)
|
|
13
|
-
expires = ";expires=" + ops.expires;
|
|
12
|
+
// ops.expires = String(ops.expires).length == 10 ? new Date(ops.expires * 1000) : new Date(ops.expires)
|
|
13
|
+
// expires = ";expires=" + ops.expires;
|
|
14
|
+
let exp = String(ops.expires).length == 10 ? new Date(ops.expires * 1000) : new Date(ops.expires)
|
|
15
|
+
expires = ";expires=" + exp.toGMTString();
|
|
14
16
|
}
|
|
15
17
|
// 设置cookie
|
|
16
18
|
document.cookie = `${key}=${val}${path}${expires}`;
|
|
@@ -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
|
};
|
package/src/number/index.js
CHANGED
|
@@ -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
|
|