| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876 |
- const Constants = require('../utils/Constants.js')
- // 转换时间
- const getDate = (year, month, day, hour, minute) => {
- const newyear = year.substr(0, year.length - 1);
- const setmonth = month.substr(0, month.length - 1);
- const newmonth = setmonth < 10 ? '0' + setmonth : setmonth;
- const setday = day.substr(0, day.length - 1);
- const newday = setday < 10 ? '0' + setday : setday;
- // const sethour = hour.substr(0, hour.length - 1);
- const newhour = hour < 10 ? '0' + hour : hour;
- // const setminute = minute.substr(0, minute.length - 1);
- const newminute = minute < 10 ? '0' + minute : minute;
- return newyear + '-' + newmonth + '-' + newday + ' ' + newhour + ":" + newminute;
- }
- // 将时间戳转换为时间
- const getobjDate = (date) => {
- let now;
- if (date) {
- now = new Date(date)
- } else {
- now = new Date()
- }
- let y = now.getFullYear(),
- m = now.getMonth() + 1,
- d = now.getDate(),
- h = now.getHours(), //获取当前小时数(0-23)
- f = now.getMinutes(),
- n = (Math.ceil((now.getMinutes()) / 10)) * 10; //获取当前分钟数(0-59) 取整数
- return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d) + " " + (h < 10 ? "0" + h : h) + ":" + (f < 10 ? "0" + f : f);
- }
- // 将时间戳转换为日期
- const toDateStr = (date) => {
- let now;
- if (date) {
- now = new Date(date)
- } else {
- now = new Date()
- }
- let y = now.getFullYear(),
- m = now.getMonth() + 1,
- d = now.getDate()
- return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d);
- }
- const getobjDateApple = (date) => {
- let now;
- if (date) {
- now = new Date(date)
- } else {
- now = new Date()
- }
- let y = now.getFullYear(),
- m = now.getMonth() + 1,
- d = now.getDate(),
- h = now.getHours(), //获取当前小时数(0-23)
- f = now.getMinutes(),
- n = (Math.ceil((now.getMinutes()) / 10)) * 10; //获取当前分钟数(0-59) 取整数
- return y + "/" + (m < 10 ? "0" + m : m) + "/" + (d < 10 ? "0" + d : d) + " " + (h < 10 ? "0" + h : h) + ":" + (f < 10 ? "0" + f : f);
- }
- //根据年月 获取天数
- const mGetDate = (year, month) => {
- var d = new Date(year, month, 0);
- return d.getDate();
- }
- //根据时间2019-01-02 09:12 得到 ['2019','1','2','9','12']
- const getarrWithtime = (str) => {
- let arr = [];
- let arr1 = str.split(' ');
- let arr2 = (arr1[0]).split('-');
- let arr3 = arr1[1].split(':');
- arr = arr2.concat(arr3);
- arr[1] = arr[1].startsWith('0') ? arr[1].substr(1, arr[1].length) : arr[1];
- arr[2] = arr[2].startsWith('0') ? arr[2].substr(1, arr[2].length) : arr[2];
- arr[3] = arr[3].startsWith('0') ? arr[3].substr(1, arr[3].length) : arr[3];
- arr[4] = arr[4].startsWith('0') ? arr[4].substr(1, arr[4].length) : arr[4];
- return arr;
- }
- const getTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [hour, minute, second].map(formatNumber).join(':')
- }
- const formatTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- const formatDataTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- const transformTimestamp = timestamp => {
- let a = new Date(timestamp).getTime();
- const date = new Date(a);
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
- }
- const formatDayTime = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- return [year, month, day].map(formatNumber).join('-')
- }
- const formatDayTimeMoth = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = '01'
- return [year, month, day].map(formatNumber).join('-')
- }
- const formatDayTimeApple = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- return [year, month, day].map(formatNumber).join('/')
- }
- const formatDayYm = date => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- return year + '年' + month + '月'
- }
- const getGuid = function () {
- var s = [];
- var hexDigits = "0123456789abcdef";
- for (var i = 0; i < 36; i++) {
- s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
- }
- s[14] = "4";
- s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
- s[8] = s[13] = s[18] = s[23] = "-";
- var uuid = s.join("");
- return uuid;
- }
- function getSpecifiedYear(num) {
- var myDate = new Date();
- var year = myDate.getFullYear() + num;
- var beginDate = year + "-01-01";
- var endDate = year + "-12-31";
- return [beginDate, endDate]
- }
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : '0' + n
- }
- //浮点数加法运算解决精度问题
- function AddNumber(arg1, arg2) {
- arg1 = arg1.toString(), arg2 = arg2.toString();
- var arg1Arr = arg1.split("."), arg2Arr = arg2.split("."), d1 = arg1Arr.length == 2 ? arg1Arr[1] : "", d2 = arg2Arr.length == 2 ? arg2Arr[1] : "";
- var maxLen = Math.max(d1.length, d2.length);
- var m = Math.pow(10, maxLen);
- var result = Number(((arg1 * m + arg2 * m) / m).toFixed(maxLen));
- var d = arguments[2];
- return typeof d === "number" ? Number((result).toFixed(d)) : result;
- }
- // 两个浮点数相减
- function SubNumber(num1, num2) {
- var r1, r2, m;
- try {
- r1 = num1.toString().split('.')[1].length;
- } catch (e) {
- r1 = 0;
- }
- try {
- r2 = num2.toString().split(".")[1].length;
- } catch (e) {
- r2 = 0;
- }
- var m = Math.pow(10, Math.max(r1, r2));
- var n = (r1 >= r2) ? r1 : r2;
- return (Math.round(num1 * m - num2 * m) / m).toFixed(n);
- }
- function accMul(arg1, arg2) {
- var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
- try { m += s1.split(".")[1].length } catch (e) { }
- try { m += s2.split(".")[1].length } catch (e) { }
- return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
- }
- function except(arg1, arg2) {
- var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
- try { m += s1.split(".")[1].length } catch (e) { }
- try { m += s2.split(".")[1].length } catch (e) { }
- return Number(s1.replace(".", "")) / Number(s2.replace(".", "")) / Math.pow(10, m)
- }
- //获取当前时间 返回格式2021-12-14
- function getTodayTime() {
- var date = new Date();
- var time = (date.getFullYear() + 1) + "-" + (date.getMonth() + 1) + "-" + date.getDate()
- return time;
- }
- function fun_date(num) {
- var date1 = new Date();
- //今天时间
- var date2 = new Date(date1);
- date2.setDate(date1.getDate() + num);
- //num是正数表示之后的时间,num负数表示之前的时间,0表示今天
- var time2 = date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate();
- return time2;
- }
- function getCurrentMonth() {
- var firstDate = new Date();
- var startDate = firstDate.getFullYear() + "-" + ((firstDate.getMonth() + 1) < 10 ? "0" : "") + (firstDate.getMonth() + 1) + "-" + "01";
- var date = new Date();
- var currentMonth = date.getMonth();
- var nextMonth = ++currentMonth;
- var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
- var oneDay = 1000 * 60 * 60 * 24;
- var lastDate = new Date(nextMonthFirstDay - oneDay);
- var endDate = lastDate.getFullYear() + "-" + ((lastDate.getMonth() + 1) < 10 ? "0" : "") + (lastDate.getMonth() + 1) + "-" + (lastDate.getDate() < 10 ? "0" : "") + lastDate.getDate();
- return [startDate, endDate]
- }
- function getCurrentDateMonth(cdate) {
- var firstDate = new Date(cdate);
- var startDate = firstDate.getFullYear() + "-" + ((firstDate.getMonth() + 1) < 10 ? "0" : "") + (firstDate.getMonth() + 1) + "-" + "01";
- var date = new Date(cdate);
- var currentMonth = date.getMonth();
- var nextMonth = ++currentMonth;
- var nextMonthFirstDay = new Date(date.getFullYear(), nextMonth, 1);
- var oneDay = 1000 * 60 * 60 * 24;
- var lastDate = new Date(nextMonthFirstDay - oneDay);
- var endDate = lastDate.getFullYear() + "-" + ((lastDate.getMonth() + 1) < 10 ? "0" : "") + (lastDate.getMonth() + 1) + "-" + (lastDate.getDate() < 10 ? "0" : "") + lastDate.getDate();
- return [startDate, endDate]
- }
- function calc10000(arr, keySet) {
- arr.forEach(it => {
- keySet.forEach(kIt => {
- if (it[kIt]) {
- it[kIt] = parseFloat(it[kIt] / 10000).toFixed(2)
- }
- })
- })
- return arr
- }
- function parseFloatFixed2(num) {
- return parseFloat(num).toFixed(2)
- }
- function getCurrentWeek(n) {
- /***参数都是以周一为基准的***/
- //上周的开始时间
- // //上周的结束时间
- // //本周的开始时间
- // //本周的结束时间
- var now = new Date();
- var year = now.getFullYear();
- //因为月份是从0开始的,所以获取这个月的月份数要加1才行
- var month = now.getMonth() + 1;
- var date = now.getDate();
- var day = now.getDay();
- //判断是否为周日,如果不是的话,就让今天的day-1(例如星期二就是2-1)
- if (day !== 0) {
- n = n + (day - 1);
- } else {
- n = n + day;
- }
- if (day) {
- //这个判断是为了解决跨年的问题
- if (month > 1) {
- month = month;
- }
- //这个判断是为了解决跨年的问题,月份是从0开始的
- else {
- year = year - 1;
- month = 12;
- }
- }
- now.setDate(now.getDate() - n);
- return now;
- }
- function drawAndShareImage(param) {
- const ctx = wx.createCanvasContext('qrcode')
- ctx.beginPath()
- ctx.clearRect(0, 0, param.canvasWidth, param.canvasHeight)
- ctx.setFillStyle('#fff')
- ctx.fillRect(0, 0, param.canvasWidth, param.canvasHeight)
- /** 背景图 */
- ctx.beginPath()
- ctx.drawImage(param.background, 0, 0, param.canvasWidth, param.canvasHeight)
- ctx.save();
- /** 二维码 */
- ctx.beginPath()
- ctx.arc(param.qrX, param.qrY, 0, 0, 0)
- ctx.fill()
- ctx.clip()
- ctx.drawImage(
- param.qrcode,
- 0, 0, 375, 375
- )
- ctx.restore()
- ctx.save()
- ctx.draw(false, () => {
- wx.canvasToTempFilePath({
- x: 100,
- y: 200,
- width: 50,
- height: 50,
- destWidth: 100,
- destHeight: 100,
- canvasId: 'qrcode',
- complete(res) { }
- })
- })
- }
- //日期转换
- Date.prototype.format = function (format) {
- var o = {
- "M+": this.getMonth() + 1, //month
- "d+": this.getDate(), //day
- "h+": this.getHours(), //hour
- "m+": this.getMinutes(), //minute
- "s+": this.getSeconds(), //second
- "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
- "S": this.getMilliseconds() //millisecond
- }
- if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
- (this.getFullYear() + "").substr(4 - RegExp.$1.length));
- for (var k in o)
- if (new RegExp("(" + k + ")").test(format))
- format = format.replace(RegExp.$1,
- RegExp.$1.length == 1 ? o[k] :
- ("00" + o[k]).substr(("" + o[k]).length));
- return format;
- }
- Date.prototype.before = function (day) {
- var timestamp = Date.parse(this);
- var beforeTimestamp = timestamp - 86400000 * day;
- return new Date(beforeTimestamp);
- }
- Date.prototype.after = function (day) {
- var timestamp = Date.parse(this);
- var afterTimestamp = timestamp + 86400000 * day;
- return new Date(afterTimestamp);
- }
- //时间戳换成日期时间转
- function js_date_time(unixtime) {
- var date = new Date(unixtime);
- var y = date.getFullYear();
- var m = date.getMonth() + 1;
- m = m < 10 ? ('0' + m) : m;
- var d = date.getDate();
- d = d < 10 ? ('0' + d) : d;
- return y + '-' + m + '-' + d;
- }
- //时间戳换成日期时间转
- function js_month_time(unixtime) {
- var date = new Date(unixtime);
- var y = date.getFullYear();
- var m = date.getMonth() + 1;
- m = m < 10 ? ('0' + m) : m;
- var d = date.getDate();
- d = d < 10 ? ('0' + d) : d;
- let a = {
- first: y + '-' + m,
- second: y + m
- }
- return a;
- }
- function getYear(type, dates) {
- var dd = new Date();
- var n = dates || 0;
- var year = dd.getFullYear() + Number(n);
- var month = dd.getMonth() + Number(n);
- if (month != null && month != 11) {
- if (type == "s") {
- var day = year - 1 + "-11-30";
- };
- if (type == "e") {
- var day = year + "-12-01";
- };
- if (!type) {
- var day = year + "-01-01/" + year + "-12-31";
- };
- return day;
- } else if (month != null && month == 11) {
- if (type == "s") {
- var day = year + "-11-30";
- };
- if (type == "e") {
- var day = year + 1 + "-12-01";
- };
- if (!type) {
- var day = year + "-01-01/" + year + "-12-31";
- };
- return day;
- }
- }
- function timeForMat(count) {
- // 拼接时间
- const time1 = new Date()
- const time2 = new Date()
- if (count === 1) {
- time1.setTime(time1.getTime() - (24 * 60 * 60 * 1000))
- } else {
- if (count >= 0) {
- time1.setTime(time1.getTime())
- } else {
- if (count === -2) {
- time1.setTime(time1.getTime() + (24 * 60 * 60 * 1000) * 2)
- } else {
- time1.setTime(time1.getTime() + (24 * 60 * 60 * 1000))
- }
- }
- }
- const Y1 = time1.getFullYear()
- const M1 = ((time1.getMonth() + 1) > 9 ? (time1.getMonth() + 1) : '0' + (time1.getMonth() + 1))
- const D1 = (time1.getDate() > 9 ? time1.getDate() : '0' + time1.getDate())
- const timer1 = Y1 + '-' + M1 + '-' + D1 // 当前时间
- time2.setTime(time2.getTime() - (24 * 60 * 60 * 1000 * count))
- const Y2 = time2.getFullYear()
- const M2 = ((time2.getMonth() + 1) > 9 ? (time2.getMonth() + 1) : '0' + (time2.getMonth() + 1))
- const D2 = (time2.getDate() > 9 ? time2.getDate() : '0' + time2.getDate())
- const timer2 = Y2 + '-' + M2 + '-' + D2 // 以前的7天或者30天
- return [timer2, timer1]
- }
- /**
- * @desc : 复制
- * @date : 2022/7/29 16:49
- * @author : 周兴
- */
- function toCopy(value, label) {
- if (!value || !label) return;
- wx.setClipboardData({
- data: value,
- success: res => {
- wx.showToast({
- title: label + '已复制',
- duration: 1000,
- })
- }
- })
- }
- function numAdd(num1, num2) {
- var baseNum, baseNum1, baseNum2;
- try {
- baseNum1 = num1.toString().split(".")[1].length;
- } catch (e) {
- baseNum1 = 0;
- }
- try {
- baseNum2 = num2.toString().split(".")[1].length;
- } catch (e) {
- baseNum2 = 0;
- }
- baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
- return (num1 * baseNum + num2 * baseNum) / baseNum;
- }
- function numSub(num1, num2) {
- var baseNum, baseNum1, baseNum2;
- var precision;// 精度
- try {
- baseNum1 = num1.toString().split(".")[1].length;
- } catch (e) {
- baseNum1 = 0;
- }
- try {
- baseNum2 = num2.toString().split(".")[1].length;
- } catch (e) {
- baseNum2 = 0;
- }
- baseNum = Math.pow(10, Math.max(baseNum1, baseNum2));
- precision = (baseNum1 >= baseNum2) ? baseNum1 : baseNum2;
- return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision);
- }
- function jumpPageDate(type) {
- let date = []
- if (type == 1) {
- date = [formatTime(new Date()).substring(0, 10), formatTime(new Date()).substring(0, 10)]
- }
- else if (type == 2) {
- date = [formatTime(getCurrentWeek(0)).substring(0, 10), formatTime(getCurrentWeek(-6)).substring(0, 10)]
- }
- else if (type == 3) {
- date = getCurrentMonth();
- } else if (type == 4) {
- let startYear = getYear("s", 0)
- let endYear = getYear("e", 0)
- //本年
- date = [formatTime(new Date(startYear)).substring(0, 10),
- formatTime(new Date(endYear)).substring(0, 10)]
- }
- else if (type == 6) {
- //近7
- date = timeForMat(7)
- }
- else if (type == 5) {
- //近30天
- date = timeForMat(30)
- } else if (type == -1) {
- let dateEnd = formatTime(new Date()).substring(0, 10)
- let startYear = new Date().getFullYear() - 1;
- let startMonth = new Date().getMonth() + 1 > 9 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1);
- let startDay = new Date().getDate() > 9 ? new Date().getDate() : '0' + new Date().getDate();
- if (startMonth === 2 && startDay === 29) {
- startDay = 28
- }
- date = [startYear + '/' + startMonth + '/' + startDay, dateEnd]
- } else if (type == -2) {
- let dateEnd = formatTime(new Date()).substring(0, 10)
- let startYear = new Date().getFullYear() + 1;
- let startMonth = new Date().getMonth() + 1 > 9 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1);
- let startDay = new Date().getDate() > 9 ? new Date().getDate() : '0' + new Date().getDate();
- if (startMonth === 2 && startDay === 29) {
- startDay = 28
- }
- date = [dateEnd, startYear + '/' + startMonth + '/' + startDay]
- }
- return date;
- }
- /**
- * @desc : 判断手机号格式
- * @author : 于继渤
- * @date : 2022/8/19 10:16
- */
- function isPoneAvailable(poneInput) {
- var myreg = Constants.Mobile_Phone_Number_Regular_Expression
- if (!myreg.test(poneInput)) {
- return false;
- } else {
- return true;
- }
- }
- /**
- * @desc : 深度拷贝
- * @author : 于继渤
- * @date : 2022/8/19 10:16
- */
- function copyObj(obj) {
- var _obj = JSON.stringify(obj);
- var objClone = JSON.parse(_obj);
- return objClone;
- }
- /**
- * @desc : 直辖市更新
- * @author : 于继渤
- * @date : 2022/8/19 10:16
- */
- function updateProvince(location) {
- if (location.province && location.province != '' && typeof location.province == 'string') {
- let province = location.province
- if (province.indexOf('北京') != -1) {
- province = '北京'
- return location.province = province
- }
- if (province.indexOf('上海') != -1) {
- province = '上海'
- return location.province = province
- }
- if (province.indexOf('天津') != -1) {
- province = '天津'
- return location.province = province
- }
- if (province.indexOf('重庆') != -1) {
- province = '重庆'
- return location.province = province
- }
- } else {
- if (location.city) {
- let province = location.city.replace('市', '')
- return location.province = province
- }
- }
- }
- //判断数字是否为负数并转为负数
- function isNumberNegative(n) {
- if (!isNaN(n)) {
- let numberTemp = Number(0)
- if (n > 0) {
- numberTemp = (Number(0) - Number(n))
- return numberTemp
- } else if (n < 0) {
- return n
- } else {
- return n
- }
- } else {
- return Number(n)
- }
- }
- /**
- * @desc : 合并实体(供main.js)调用,其他地方,调用上面那个
- * @author : 周兴
- * @date : 2022/11/21 14:25
- */
- function objectMergeByMainJs(source, target) {
- if (typeof source !== 'object') {
- source = {};
- }
- if (Array.isArray(target)) {
- return source.slice();
- }
- if (!source['key']) {
- Object.keys(target).forEach((property) => {
- const targetProperty = target[property];
- if (typeof targetProperty === 'object') {
- source[property] = this.objectMergeByMainJs(source[property], targetProperty);
- } else {
- source[property] = targetProperty;
- }
- });
- }
- return source;
- }
- /**
- * @desc : id parentId扁平结构转变为children层级结构
- * @author : 周兴
- * @date : 2022/12/30 15:55
- */
- function convertToChildren(arr, pId = 'parentId', id = 'id', path = null) {
- if (!arr || arr.length === 0) return arr;
- let data = arr.filter(it => !it[pId]) // 获取最顶级
- if (data && data.length > 0) {
- data.forEach(it => {
- _convertToChildren(it, arr, it[id], pId, id);
- })
- }
- return data;
- }
- /**
- * @desc : 转成children格式数据(私有方法)
- * @author : 周兴
- * @date : 2022/12/30 17:06
- */
- function _convertToChildren(item, arr, idValue, pId, id, path = null) {
- // console.log('t1',item,idValue,)
- let filters = arr.filter(it => it[pId] === idValue);
- if (!filters || filters.length === 0) {
- return [];
- } else {
- item.children = filters;
- item.children.forEach(it => {
- _convertToChildren(it, arr, it[id], pId, id, path);
- })
- return item;
- }
- }
- /**
- * @desc : 根据枚举值获取相应的键名
- * @author : 周兴
- * @date : 2024/2/29 17:06
- */
- function getKeyByValue(enumObj, value) {
- for (let key in enumObj) {
- if (enumObj[key] === value) {
- return key;
- }
- }
- return null;
- }
- // 判断是否为空
- function isEmpty(obj) {
- if (typeof obj === 'undefined' || obj === null || obj === '') return true;
- return false
- }
- /**
- * @desc : 过滤掉数组中的空值行
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function filterArrayEmpty(table) {
- if (!table || table.length == 0) return table;
- let keys = Object.keys(table[0]);
- let returnTable = []
- table.forEach(row => {
- let flag = true
- keys.forEach(k => {
- if (k.indexOf('_errMsg') < 0 && !isEmpty(row[k])) {
- flag = false;
- }
- })
- if (!flag) {
- returnTable.push(row)
- }
- })
- return returnTable;
- }
- /**
- * @desc : 提示信息
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function showToast(info,duration = 2000) {
- if (info) {
- // 默认2s
- wx.showToast({
- title: info,
- icon: 'none',
- duration: duration
- })
- }
- }
- /**
- * @desc : 根据小数位数处理数据
- * @author : 周兴
- * @date : 2024/1/26 11:46
- */
- function handleQty(qty,decimalPlace = 2){
- // decimalPlace = decimalPlace?decimalPlace:0
- // return Number(Number(qty).toFixed(decimalPlace))
- return Math.round((Number(qty) * 100) ) / 100
- }
- /**
- * @desc : 防抖函数
- * @author : 于继渤
- * @date : 2024/6/28
- */
- function debounce(func, that, wait) {
- let timeout;
- if(!wait){
- wait = 400
- }
- return function() {
- const context = that;
- const args = arguments;
- clearTimeout(timeout);
- timeout = setTimeout(() => {
- func.apply(context, args);
- }, wait);
- };
- }
- /**
- * @desc : 设置查询提示值
- * @author : 周兴
- * @date : 2024/4/18 11:46
- */
- function setSearchPlaceholder(lang, cols) {
- var text = '';
- if (typeof cols == 'object') {
- cols.forEach(it=>{
- if(lang[it]){
- text += lang[it] + '/';
- }
- })
- text = text.substring(0, text.length - 1);
- } else {
- text = lang[cols];
- }
- return lang['search'] + ' ' + text;
- }
- module.exports = {
- debounce:debounce,
- handleQty:handleQty,
- setSearchPlaceholder:setSearchPlaceholder,
- showToast:showToast,
- filterArrayEmpty: filterArrayEmpty,
- getKeyByValue: getKeyByValue,
- convertToChildren: convertToChildren,
- objectMergeByMainJs: objectMergeByMainJs,
- updateProvince: updateProvince,
- isPoneAvailable: isPoneAvailable,
- formatTime: formatTime,
- drawAndShareImage,
- fun_date,
- getCurrentWeek,
- getCurrentMonth,
- getCurrentDateMonth,
- getTime,
- getGuid,
- js_date_time,
- js_month_time,
- getDate,
- toDateStr,
- getobjDate,
- mGetDate,
- getarrWithtime,
- getSpecifiedYear,
- getTodayTime,
- formatDataTime,
- formatDayTime,
- transformTimestamp,
- getYear,
- timeForMat,
- AddNumber,
- accMul,
- except,
- toCopy,
- numAdd,
- numSub, formatDayYm, jumpPageDate, calc10000, parseFloatFixed2,
- formatDayTimeApple, getobjDateApple,
- formatDayTimeMoth: formatDayTimeMoth,
- copyObj,
- SubNumber,
- isNumberNegative
- }
|