js_ryl 1.0.2 → 1.0.6

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
@@ -25,12 +25,21 @@ npm run dev
25
25
  #1.正则表达式 -- reg
26
26
 
27
27
  # 所有方法:
28
- # Email() -- 邮箱
29
- # Phone() -- 手机
30
- # IdCard() -- 银行卡
31
- # Common() -- 只能包含数字、字母以及下划线
32
- # QQ() -- QQ
33
- # Money() -- 金额
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() -- 发送状态,是否已经发送
34
43
 
35
44
  # 使用方法
36
45
 
@@ -42,6 +51,21 @@ npm run dev
42
51
  # console.log("错误",reg.Phone(this.name, "空手机", "手机唧唧了")); -- 自定义错误内容
43
52
  # }
44
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
+ # }
68
+
45
69
  #2.时间戳与时间的转化 -- time
46
70
 
47
71
  # 日期转时间戳
@@ -106,7 +130,9 @@ npm run dev
106
130
  # }
107
131
  # });
108
132
 
109
-
133
+ #1.0.04: 函数防抖和节流,添加 可传入参数
134
+ #1.0.05: 添加获取验证码效果
135
+ #1.0.06: 添加获取验证码效果 逻辑调整
110
136
 
111
137
  npm run build
112
138
  ```
package/dist/build.js ADDED
@@ -0,0 +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={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=arguments.length>1&&void 0!==arguments[1]?arguments[1]:60,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"后重新获取",a=t.target.innerText;if(!r){r=!0,t.target.innerText=e-1+"s"+n;var i=e-1;o=setInterval(function(){i--,i<=0?(t.target.innerText=a,r=!1,clearInterval(o)):t.target.innerText=i+"s"+n},1e3)}},PhoneCodeClear:function(){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(),a=n.getMonth()+1,i=n.getDate(),u=n.getHours(),c=n.getMinutes(),s=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(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)}};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="";n.expires&&(n.expires=10==String(n.expires).length?new Date(1e3*n.expires):new Date(n.expires),o=";expires="+n.expires),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 s=this.mul(n/i,Math.pow(10,c-u));return a("div",t,e,s)},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}])});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js_ryl",
3
- "version": "1.0.2",
3
+ "version": "1.0.6",
4
4
  "private": false,
5
5
  "description": "自定义通用js",
6
6
  "author": "renyuliang <785788909@qq.com>",
package/src/App.vue ADDED
@@ -0,0 +1,157 @@
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
+ 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,5)
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>
@@ -0,0 +1,42 @@
1
+ // 原生cookie的使用
2
+ const cookie = {
3
+ // 设置cookie
4
+ set: (key, val, ops) => {
5
+ // 接收配置信息
6
+ ops = ops || {};
7
+ // 处理默认路径
8
+ let path = ops.path ? ";Path=" + ops.path : "";
9
+ // 处理默认有效期
10
+ let expires = "";
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;
14
+ }
15
+ // 设置cookie
16
+ document.cookie = `${key}=${val}${path}${expires}`;
17
+ },
18
+ // 获取cookie
19
+ get: (key) => {
20
+ // 获取所有的cookie
21
+ let str = document.cookie;
22
+ // 第一次分割,将每组名字和值分割出来
23
+ let arr = str.split("; ");
24
+ for (let i = 0; i < arr.length; i++) {
25
+ // 第二次分割将每个名字和值分割开
26
+ if (arr[i].split("=")[0] === key) {
27
+ // 将值返回
28
+ return arr[i].split("=")[1];
29
+ }
30
+ }
31
+ // 如果循环结束没有匹配项就返回空
32
+ return "";
33
+ },
34
+ // 移除cookie
35
+ remove: (key, ops) => {
36
+ ops = ops || {};
37
+ // 日期设为昨天即为失效
38
+ ops.expires = -1;
39
+ cookie.set(key, null, ops);
40
+ }
41
+ };
42
+ export default cookie;
@@ -0,0 +1,16 @@
1
+ // 复制文本
2
+ export default function copy(content, callback) {
3
+ var newInput = document.createElement("input");
4
+ newInput.setAttribute("readonly", "readonly");
5
+ newInput.setAttribute("value", content);
6
+ document.body.appendChild(newInput);
7
+ // 选取文本域中的内容
8
+ if (document.execCommand("copy")) {
9
+ newInput.select();
10
+ document.execCommand("copy");
11
+ callback({ code: 200, msg: "复制成功" });
12
+ } else {
13
+ callback({ code: 100, msg: "当前浏览器不支持,请更换浏览器后重试" });
14
+ }
15
+ document.body.removeChild(newInput);
16
+ }
@@ -0,0 +1,35 @@
1
+ // 函数节流和防抖
2
+ let fun = {
3
+ // 节流函数(有个需要频繁触发的函数,处于性能的优化,在规定时间内,只让函数的第一次生效,后面的不生效)
4
+ // 应用场景 -- 频繁触发、onrize,onscroll滚动条
5
+ throole(fn, delay = 500) {
6
+ // 上次记录时间
7
+ var lastTime = 0
8
+ return function () {
9
+ var that = this;
10
+ // 当前时间
11
+ var nowTime = Date.now()
12
+ if (nowTime - lastTime > delay) {
13
+ // 修改this指向问题
14
+ fn.call(that,arguments)
15
+ // 更新时间
16
+ lastTime = nowTime
17
+ }
18
+ }
19
+ },
20
+ // 防抖函数(规定时间内,只让最后一次生效,其他的不生效)
21
+ // 应用场景 -- 频繁触发、输入框搜索
22
+ debounce(fn, delay = 500) {
23
+ // 上次的延时器
24
+ var timer = null
25
+ return function () {
26
+ var that = this;
27
+ // 清除延时器
28
+ clearTimeout(timer)
29
+ timer = setTimeout(()=> {
30
+ fn.apply(that,arguments)
31
+ }, delay)
32
+ }
33
+ }
34
+ }
35
+ export default fun
package/src/index.js ADDED
@@ -0,0 +1,22 @@
1
+ // 引入所有组件然后统一导出
2
+ // 正则表达式
3
+ import reg from "./reg";
4
+ // 时间与时间戳
5
+ import time from "./time";
6
+ // cookie存储
7
+ import cookie from "./cookie";
8
+ // 函数节流和防抖
9
+ import fun from "./function";
10
+ // 加减乘除运算符
11
+ import num from "./number";
12
+ // 复制文本信息
13
+ import copy from "./copy";
14
+
15
+ export default {
16
+ reg,
17
+ time,
18
+ cookie,
19
+ fun,
20
+ num,
21
+ copy
22
+ };
package/src/main.js ADDED
@@ -0,0 +1,6 @@
1
+ import Vue from "vue";
2
+ import App from "./App.vue";
3
+ new Vue({
4
+ el: "#app",
5
+ render: h => h(App)
6
+ });
@@ -0,0 +1,155 @@
1
+ import fun from '../function/index'
2
+ // 处理精度丢失的加减乘除
3
+ var countDecimals = function (num) {
4
+ var len = 0;
5
+ try {
6
+ num = Number(num);
7
+ var str = num.toString().toUpperCase();
8
+ if (str.split('E').length === 2) { // scientific notation
9
+ var isDecimal = false;
10
+ if (str.split('.').length === 2) {
11
+ str = str.split('.')[1];
12
+ if (parseInt(str.split('E')[0]) !== 0) {
13
+ isDecimal = true;
14
+ }
15
+ }
16
+ let x = str.split('E');
17
+ if (isDecimal) {
18
+ len = x[0].length;
19
+ }
20
+ len -= parseInt(x[1]);
21
+ } else if (str.split('.').length === 2) { // decimal
22
+ if (parseInt(str.split('.')[1]) !== 0) {
23
+ len = str.split('.')[1].length;
24
+ }
25
+ }
26
+ } catch (e) {
27
+ throw e;
28
+ } finally {
29
+ if (isNaN(len) || len < 0) {
30
+ len = 0;
31
+ }
32
+ return len;
33
+ }
34
+ };
35
+
36
+ var convertToInt = function (num) {
37
+ num = Number(num);
38
+ var newNum = num;
39
+ var times = countDecimals(num);
40
+ var temp_num = num.toString().toUpperCase();
41
+ if (temp_num.split('E').length === 2) {
42
+ newNum = Math.round(num * Math.pow(10, times));
43
+ } else {
44
+ newNum = Number(temp_num.replace(".", ""));
45
+ }
46
+ return newNum;
47
+ };
48
+
49
+ var getCorrectResult = function (type, num1, num2, result) {
50
+ var temp_result = 0;
51
+ switch (type) {
52
+ case "add":
53
+ temp_result = num1 + num2;
54
+ break;
55
+ case "sub":
56
+ temp_result = num1 - num2;
57
+ break;
58
+ case "div":
59
+ temp_result = num1 / num2;
60
+ break;
61
+ case "mul":
62
+ temp_result = num1 * num2;
63
+ break;
64
+ }
65
+ if (Math.abs(result - temp_result) > 1) {
66
+ return temp_result;
67
+ }
68
+ return result;
69
+ };
70
+
71
+ let num = {
72
+ //加法
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
+ add(num1, num2) {
86
+ num1 = Number(num1);
87
+ num2 = Number(num2);
88
+ var dec1, dec2, times;
89
+ try { dec1 = countDecimals(num1) + 1; } catch (e) { dec1 = 0; }
90
+ try { dec2 = countDecimals(num2) + 1; } catch (e) { dec2 = 0; }
91
+ times = Math.pow(10, Math.max(dec1, dec2));
92
+ // var result = (num1 * times + num2 * times) / times;
93
+ var result = (this.mul(num1, times) + this.mul(num2, times)) / times;
94
+ // console.log(result,'---')
95
+ // result = result.toFixed(2)
96
+ return getCorrectResult("add", num1, num2, result);
97
+ // return result;
98
+ },
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
+ //减法
113
+ sub(num1, num2) {
114
+ num1 = Number(num1);
115
+ num2 = Number(num2);
116
+ var dec1, dec2, times;
117
+ try { dec1 = countDecimals(num1) + 1; } catch (e) { dec1 = 0; }
118
+ try { dec2 = countDecimals(num2) + 1; } catch (e) { dec2 = 0; }
119
+ times = Math.pow(10, Math.max(dec1, dec2));
120
+ // var result = Number(((num1 * times - num2 * times) / times);
121
+ var result = Number((this.mul(num1, times) - this.mul(num2, times)) / times);
122
+ return getCorrectResult("sub", num1, num2, result);
123
+ // return result;
124
+ },
125
+ //除法
126
+ div(num1, num2) {
127
+ num1 = Number(num1);
128
+ num2 = Number(num2);
129
+ var t1 = 0,
130
+ t2 = 0,
131
+ dec1, dec2;
132
+ try { t1 = countDecimals(num1); } catch (e) { }
133
+ try { t2 = countDecimals(num2); } catch (e) { }
134
+ dec1 = convertToInt(num1);
135
+ dec2 = convertToInt(num2);
136
+ var result = this.mul((dec1 / dec2), Math.pow(10, t2 - t1));
137
+ return getCorrectResult("div", num1, num2, result);
138
+ // return result;
139
+ },
140
+ //乘法
141
+ mul(num1, num2) {
142
+ num1 = Number(num1);
143
+ num2 = Number(num2);
144
+ var times = 0,
145
+ s1 = num1.toString(),
146
+ s2 = num2.toString();
147
+ try { times += countDecimals(s1); } catch (e) { }
148
+ try { times += countDecimals(s2); } catch (e) { }
149
+ var result = convertToInt(s1) * convertToInt(s2) / Math.pow(10, times);
150
+ return getCorrectResult("mul", num1, num2, result);
151
+ // return result;
152
+ }
153
+ }
154
+
155
+ export default num
@@ -0,0 +1,133 @@
1
+ // 验证码状态是否已经发送
2
+ var phoneCodeStatus = false
3
+ // 验证码计时器
4
+ var phoneCodeTimer = null
5
+ // 正则匹配
6
+ let reg = {
7
+ // 邮箱验证
8
+ Email(value, noValueMsg = "请输入邮箱", errValueMsg = "邮箱格式有误") {
9
+ let reg = /^([0-9A-Za-z\-_\.]+)@([0-9a-z]+\.[a-z]{2,3}(\.[a-z]{2})?)$/g;
10
+ if (value) {
11
+ if (reg.test(value)) {
12
+ return true;
13
+ } else {
14
+ return errValueMsg;
15
+ }
16
+ } else {
17
+ return noValueMsg;
18
+ }
19
+ },
20
+ // 身份证号码验证
21
+ IdCard(
22
+ value,
23
+ noValueMsg = "请输入身份证号码",
24
+ errValueMsg = "身份证号码格式有误"
25
+ ) {
26
+ let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
27
+ if (value) {
28
+ if (reg.test(value)) {
29
+ return true;
30
+ } else {
31
+ return errValueMsg;
32
+ }
33
+ } else {
34
+ return noValueMsg;
35
+ }
36
+ },
37
+ // 只能包含数字、字母以及下划线
38
+ Common(
39
+ value,
40
+ noValueMsg = "请输入包含数字、字母以及下划线的内容",
41
+ errValueMsg = "只能包含数字、字母以及下划线"
42
+ ) {
43
+ let reg = /^[a-zA-Z0-9_]+$/;
44
+ if (value) {
45
+ if (reg.test(value)) {
46
+ return true;
47
+ } else {
48
+ return errValueMsg;
49
+ }
50
+ } else {
51
+ return noValueMsg;
52
+ }
53
+ },
54
+ // QQ验证
55
+ QQ(
56
+ value,
57
+ noValueMsg = "请输入QQ号码",
58
+ errValueMsg = "QQ号码格式错误"
59
+ ) {
60
+ let reg = /^[1-9][0-9]{4,10}$/gim;
61
+ if (value) {
62
+ if (reg.test(value)) {
63
+ return true;
64
+ } else {
65
+ return errValueMsg;
66
+ }
67
+ } else {
68
+ return noValueMsg;
69
+ }
70
+ },
71
+ // 金额
72
+ Money(
73
+ value,
74
+ noValueMsg = "请输入金额(最多保留2位小数点)",
75
+ errValueMsg = "金额格式错误"
76
+ ) {
77
+ let reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
78
+ if (value) {
79
+ if (reg.test(value)) {
80
+ return true;
81
+ } else {
82
+ return errValueMsg;
83
+ }
84
+ } else {
85
+ return noValueMsg;
86
+ }
87
+ },
88
+ // 手机号验证
89
+ Phone(
90
+ value,
91
+ noValueMsg = "请输入手机号码",
92
+ errValueMsg = "手机号码格式有误"
93
+ ) {
94
+ let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/;
95
+ if (value) {
96
+ if (reg.test(value)) {
97
+ return true;
98
+ } else {
99
+ return errValueMsg;
100
+ }
101
+ } else {
102
+ return noValueMsg;
103
+ }
104
+ },
105
+ // 手机验证码
106
+ PhoneCode(e,ss=60,cc='后重新获取'){
107
+ const name = e.target.innerText
108
+ if (!phoneCodeStatus) {
109
+ phoneCodeStatus = true
110
+ e.target.innerText = `${ss-1}s${cc}`
111
+ let timer = ss-1
112
+ phoneCodeTimer = setInterval(()=>{
113
+ timer--
114
+ if (timer <= 0) {
115
+ // 时间归0后,设置按钮名称
116
+ e.target.innerText = name
117
+ phoneCodeStatus = false
118
+ clearInterval(phoneCodeTimer)
119
+ } else {
120
+ e.target.innerText = `${timer}s${cc}`
121
+ }
122
+ },1000)
123
+ }
124
+ },
125
+ // 清除手机验证码
126
+ PhoneCodeClear(){
127
+ clearInterval(phoneCodeTimer)
128
+ },
129
+ // 验证码状态是否已经发送
130
+ phoneCodeStatus: ()=> phoneCodeStatus
131
+ };
132
+
133
+ export default reg;
@@ -0,0 +1,40 @@
1
+ // 时间与时间戳的转化
2
+ let time = {
3
+ // 时间戳转日期
4
+ toDate(v, type) {
5
+ //时间戳为10位需*1000,时间戳为13位的话不需乘1000
6
+ var date = ''
7
+ if (String(v).length == 10) {
8
+ date = new Date(v * 1000)
9
+ } else {
10
+ date = new Date(v)
11
+ }
12
+ let Y = date.getFullYear();
13
+ let M = date.getMonth() + 1;
14
+ let D = date.getDate();
15
+ let h = date.getHours();
16
+ let m = date.getMinutes();
17
+ let s = date.getSeconds();
18
+ let tim = ''
19
+ if (type == 'yyyy-MM-dd') {
20
+ tim = `${Y}-${add0(M)}-${add0(D)}`;
21
+ } else if (type == 'yyyy-MM-dd HH:mm') {
22
+ tim = `${Y}-${add0(M)}-${add0(D)} ${add0(h)}:${add0(m)}`;
23
+ } else {
24
+ tim = `${Y}-${add0(M)}-${add0(D)} ${add0(h)}:${add0(m)}:${add0(s)}`;
25
+ }
26
+ return tim;
27
+ },
28
+ // 日期转时间戳 -- 默认当前时间,时间戳为10位
29
+ toStamp(v = new Date(), len = 10) {
30
+ var tmp = new Date(v.replace(/-/g, '/')).getTime().toString();
31
+ if (len == 10) {
32
+ tmp = tmp.substr(0, 10);
33
+ }
34
+ return parseInt(tmp);
35
+ }
36
+ }
37
+ // 补0
38
+ function add0(m) { return m < 10 ? '0' + m : m }
39
+
40
+ export default time