perf:增加js-util-all库引用

fix/0523-ch
ch 3 years ago
parent 3f3b164c64
commit 567ee059a1

11
.gitignore vendored

@ -1,8 +1,7 @@
.hbuilderx/ .hbuilderx
.history/ .history
.idea
env.js env.js
node_moudel/ node_moudel
package-lock.json package-lock.json
unpackage/dist/build/.automator/ unpackage/
unpackage/dist/dev
unpackage/cache

@ -2,26 +2,18 @@
* @Author: ch * @Author: ch
* @Date: 2022-03-17 19:15:10 * @Date: 2022-03-17 19:15:10
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-21 19:15:18 * @LastEditTime: 2022-05-23 11:40:29
* @Description: 一些无法归类的公共方法容器 * @Description: 一些无法归类的公共方法容器
*/ */
/** import {
* 处理async await 标识结果处理 toAsyncAwait as ToAsyncAwait,
* isPhone as IsPhone,
* @param {*} promise promise对象 formatDate as FormatDate,
* @param {*} isFromatResult 是否处理结果 creatUuid as CreateUUID,
* @returns {error,result} error有错为错误对象没错为null result正确的返回结果 formatSearchJson as FormatSearchJson
* isFromatResult 为false时直接返回promise对象不做任何处理
* } from "js-util-all";
*/
const ToAsyncAwait = (promise, isFromatResult = true) => {
if(!isFromatResult){
return promise;
}else{
return promise.then((res) => ({error:null,result:res})).catch((err) => ({error:err,result:null}));
}
}
/** /**
* 首次运行时把定时器赋值给一个变量 第二次执行时 * 首次运行时把定时器赋值给一个变量 第二次执行时
@ -42,136 +34,16 @@ const Debounce = (fn, delay) => {
}, delay) }, delay)
} }
} }
/**
* 匹配phone
*/
const IsPhone = (str) => /^(1[3-9]\d{9})$/.test(str);
/**
* 判断数值类型包括整数和浮点数
*/
const IsNumber = (str) => (isDouble(str) || isInteger(str)) ? true : false;
/**
* 匹配integer
*/
const IsInteger = (str) => {
if (str == null || str == "") return false
var result = str.match(/^[-\+]?\d+$/)
if (result == null) return false
return true
}
/**
* 匹配double或float
*/
const IsDouble = (str) => {
if (str == null || str == "") return false
var result = str.match(/^[-\+]?\d+(\.\d+)?$/)
if (result == null) return false
return true
}
/**
*
* 时间格式化
* @param {number|string|Date} d 时间参数能被new Date识别的数字字符串日期
* @param {string} fmt 时间格式参数 字符串类型 默认'yyyy/mm/dd'
*/
const FormatDate = (date = new Date(), fmt = 'yyyy/mm/dd') => {
// 处理不识别的时间表示字符串如2020年01月01日00时00分00秒
if(date.constructor === String){
date = date.replace(/\D+/ig,'/');
let arr = date.split('/');
// 长度大于3说明带了时分秒信息 特殊时间处理格式
if(arr.length > 3){
let time = ` ${arr[3]}:${arr[4]}:${arr[5]}`
arr.length = 3;
date = arr.join('/') + time;
}
};
try{
date = date ? date.constructor === Date ? date : new Date(date) : new Date();
} catch(e){
throw new Error('不能识别的时间格式');
}
const o = {
'm+': date.getMonth() + 1, //月份
'd+': date.getDate(), //日
'h+': date.getHours(), //小时
'i+': date.getMinutes(), //分
's+': date.getSeconds(), //秒ji“
'q+': Math.floor((date.getMonth() + 3) / 3), //季度
'l+': date.getMilliseconds() //毫秒
};
if (/(y+)/i.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear().toString()).substr(4 - RegExp.$1.length));
}
for (let k in o) {
if (new RegExp(`(${k})`, 'i').test(fmt)) {
const str = o[k].toString();
fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : (`0${str}`).substr(str.length-1));
}
}
return fmt;
}
const CreateUUID = (len,radix) => {
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
let uuid = [],
i=0;
radix = radix || chars.length;
if(len){
for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
}else{
let r = 0;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4';
for (i = 0; i < 36; i++) {
if (!uuid[i]) {
r = 0 | Math.random()*16;
uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
}
const ToSearchJson = (search)=>{
search = search.replace(/\?/g,'&');
let searchArr = search.split('&'),
obj = {};
searchArr.forEach(i =>{
const me = i.split('=');
if(me[0]){
obj[me[0]] = decodeURIComponent(me[1]);
}
});
return obj;
}
const getPlatform = ()=>{
}
// 工具类的文件需要把文件提供的工具类统一放最下方做一个统一输出 // 工具类的文件需要把文件提供的工具类统一放最下方做一个统一输出
export { export {
// async await 标识结果处理 // async await 标识结果处理
ToAsyncAwait, ToAsyncAwait,
// 防抖函数
Debounce,
// 判断是否为手机号 // 判断是否为手机号
IsPhone, IsPhone,
// 判断是否为数字
IsNumber,
// 判断是否为整数
IsInteger,
// 判断是否double或float
IsDouble,
// 时间格式化 // 时间格式化
FormatDate, FormatDate,
FormatSearchJson,
CreateUUID, CreateUUID,
ToSearchJson // 防抖函数
Debounce
} }

@ -2,7 +2,7 @@
* @Author: ch * @Author: ch
* @Date: 2021-07-26 23:22:16 * @Date: 2021-07-26 23:22:16
* @LastEditors: ch * @LastEditors: ch
* @LastEditTime: 2022-05-20 11:47:39 * @LastEditTime: 2022-05-23 11:40:56
* @Description: file content * @Description: file content
*/ */
import Vue from 'vue'; import Vue from 'vue';
@ -13,7 +13,7 @@ import uView from 'uview-ui';
import store from '@/common/store'; import store from '@/common/store';
import Confirm from '@/components/mount/index'; import Confirm from '@/components/mount/index';
import route from 'uview-ui/libs/util/route'; import route from 'uview-ui/libs/util/route';
import {ToSearchJson} from '@/common/utils'; import {FormatSearchJson} from '@/common/utils';
import {ApiGetOpenId, ApiGetAuthUrl} from '@/common/api/wx'; import {ApiGetOpenId, ApiGetAuthUrl} from '@/common/api/wx';
import {Im, ImInit} from '@/common/utils'; import {Im, ImInit} from '@/common/utils';
import { ApiSktSysGetSession, ApiSktSysHeart } from './common/api/im'; import { ApiSktSysGetSession, ApiSktSysHeart } from './common/api/im';
@ -34,7 +34,7 @@ if (store.state.token) {
const ua = navigator ? navigator.userAgent.toLowerCase() : ''; const ua = navigator ? navigator.userAgent.toLowerCase() : '';
if(ua.includes('micromessenger')) { if(ua.includes('micromessenger')) {
if(!store.state.openId){ if(!store.state.openId){
let query = ToSearchJson(window.location.search) let query = FormatSearchJson(window.location.search)
if(query.code){ if(query.code){
ApiGetOpenId({ ApiGetOpenId({
code : query.code code : query.code

@ -132,6 +132,11 @@
"target" : "https://k8s-horse-gateway.mashibing.cn" "target" : "https://k8s-horse-gateway.mashibing.cn"
} }
} }
},
"optimization" : {
"treeShaking" : {
"enable" : true
}
} }
} }
} }

@ -14,6 +14,7 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"js-util-all": "^1.0.6",
"mp-html": "^2.2.2", "mp-html": "^2.2.2",
"uni-read-pages": "^1.0.5", "uni-read-pages": "^1.0.5",
"uni-simple-router": "^2.0.7", "uni-simple-router": "^2.0.7",

Loading…
Cancel
Save