diff --git a/.gitignore b/.gitignore index db222bf..58c129c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ -.hbuilderx/ -.history/ +.hbuilderx +.history +.idea env.js -node_moudel/ +node_moudel package-lock.json -unpackage/dist/build/.automator/ -unpackage/dist/dev -unpackage/cache +unpackage/ \ No newline at end of file diff --git a/common/utils/utils.js b/common/utils/utils.js index d75e33f..a964435 100644 --- a/common/utils/utils.js +++ b/common/utils/utils.js @@ -2,26 +2,18 @@ * @Author: ch * @Date: 2022-03-17 19:15:10 * @LastEditors: ch - * @LastEditTime: 2022-05-21 19:15:18 + * @LastEditTime: 2022-05-23 11:40:29 * @Description: 一些无法归类的公共方法容器 */ - /** - * 处理async await 标识结果处理 - * - * @param {*} promise promise对象 - * @param {*} isFromatResult 是否处理结果 - * @returns {error,result} error有错为错误对象,没错为null , result正确的返回结果 - * isFromatResult 为false时直接返回promise对象,不做任何处理 - * - */ -const ToAsyncAwait = (promise, isFromatResult = true) => { - if(!isFromatResult){ - return promise; - }else{ - return promise.then((res) => ({error:null,result:res})).catch((err) => ({error:err,result:null})); - } -} +import { + toAsyncAwait as ToAsyncAwait, + isPhone as IsPhone, + formatDate as FormatDate, + creatUuid as CreateUUID, + formatSearchJson as FormatSearchJson + +} from "js-util-all"; /** 防抖函数 * 首次运行时把定时器赋值给一个变量, 第二次执行时, @@ -42,136 +34,16 @@ const Debounce = (fn, 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 { // async await 标识结果处理 ToAsyncAwait, - // 防抖函数 - Debounce, // 判断是否为手机号 IsPhone, - // 判断是否为数字 - IsNumber, - // 判断是否为整数 - IsInteger, - // 判断是否double或float - IsDouble, // 时间格式化 FormatDate, + FormatSearchJson, CreateUUID, - ToSearchJson + // 防抖函数 + Debounce } \ No newline at end of file diff --git a/main.js b/main.js index ec83656..75683ce 100644 --- a/main.js +++ b/main.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2021-07-26 23:22:16 * @LastEditors: ch - * @LastEditTime: 2022-05-20 11:47:39 + * @LastEditTime: 2022-05-23 11:40:56 * @Description: file content */ import Vue from 'vue'; @@ -13,7 +13,7 @@ import uView from 'uview-ui'; import store from '@/common/store'; import Confirm from '@/components/mount/index'; 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 {Im, ImInit} from '@/common/utils'; import { ApiSktSysGetSession, ApiSktSysHeart } from './common/api/im'; @@ -34,7 +34,7 @@ if (store.state.token) { const ua = navigator ? navigator.userAgent.toLowerCase() : ''; if(ua.includes('micromessenger')) { if(!store.state.openId){ - let query = ToSearchJson(window.location.search) + let query = FormatSearchJson(window.location.search) if(query.code){ ApiGetOpenId({ code : query.code diff --git a/manifest.json b/manifest.json index 243053c..0999d66 100644 --- a/manifest.json +++ b/manifest.json @@ -132,6 +132,11 @@ "target" : "https://k8s-horse-gateway.mashibing.cn" } } + }, + "optimization" : { + "treeShaking" : { + "enable" : true + } } } } diff --git a/package.json b/package.json index a935eb2..3132fa9 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "author": "", "license": "ISC", "dependencies": { + "js-util-all": "^1.0.6", "mp-html": "^2.2.2", "uni-read-pages": "^1.0.5", "uni-simple-router": "^2.0.7",