|
|
@@ -0,0 +1,450 @@
|
|
|
+
|
|
|
+let tools = {}
|
|
|
+/**
|
|
|
+ * 大小判断
|
|
|
+ * @param a
|
|
|
+ * @param b
|
|
|
+ * @returns {number}
|
|
|
+ */
|
|
|
+tools.sortNumber = function (a, b) {
|
|
|
+ return a - b;
|
|
|
+}
|
|
|
+
|
|
|
+tools.leftClick = function () {
|
|
|
+ let pages = getCurrentPages();
|
|
|
+ if(pages.length>1){
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ if(pages[pages.length -1].route.search("pages/finance") != -1){
|
|
|
+ uni.reLaunch({
|
|
|
+ url:"/pages/finance/index"
|
|
|
+ })
|
|
|
+ }else {
|
|
|
+ uni.switchTab({
|
|
|
+ url: '/pages/index/index'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+tools.formatDateAgo = (dateStr)=> {
|
|
|
+ const now = new Date();
|
|
|
+ const target = new Date(dateStr);
|
|
|
+ const diff = (now - target) / 1000 / 60; // 转换为分钟
|
|
|
+
|
|
|
+ if (diff < 1) {
|
|
|
+ return '刚刚';
|
|
|
+ } else if (diff < 60) {
|
|
|
+ return parseInt(diff) + '分钟前';
|
|
|
+ } else if (diff < 60 * 24) {
|
|
|
+ return parseInt(diff / 60) + '小时前';
|
|
|
+ } else if (diff < 60 * 24 * 30) {
|
|
|
+ return parseInt(diff / 60 / 24) + '天前';
|
|
|
+ } else if (diff < 60 * 24 * 30 * 12) {
|
|
|
+ return parseInt(diff / 60 / 24 / 30) + '个月前';
|
|
|
+ } else {
|
|
|
+ return parseInt(diff / 60 / 24 / 30 / 12) + '年前';
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+tools.getTimeY = function(data) {
|
|
|
+ return new Date(data).getFullYear();
|
|
|
+}
|
|
|
+tools.getTimeM = function(data) {
|
|
|
+ let m = new Date(data).getMonth() + 1;
|
|
|
+ m = m>10?m:'0'+m
|
|
|
+ return m
|
|
|
+}
|
|
|
+tools.setTimeYM = function() {
|
|
|
+ let YM
|
|
|
+ let data = new Date()
|
|
|
+ let y = tools.getTimeY(data)
|
|
|
+ let m = tools.getTimeM(data)
|
|
|
+ return YM = `${y}-${m}`
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 自定义 获取指定日期到当前日期的 所有年 or 年月
|
|
|
+ */
|
|
|
+tools.getCustomTimeList = (start,end,type)=>{
|
|
|
+ let timeList = [];
|
|
|
+ let s = start.split("-");
|
|
|
+ let e = end.split("-");
|
|
|
+ let min = new Date()
|
|
|
+ let max = new Date()
|
|
|
+ min.setFullYear(s[0], s[1]);
|
|
|
+ max.setFullYear(e[0], e[1]);
|
|
|
+ var curr = min;
|
|
|
+ var str = "";
|
|
|
+ while (curr <= max) {
|
|
|
+ var yers = curr.getFullYear();
|
|
|
+ var month = curr.getMonth();
|
|
|
+ if(type === 'y-m'){
|
|
|
+ if (month === 0) {
|
|
|
+ str = (yers - 1) + "-" + 12;
|
|
|
+ } else {
|
|
|
+ str = yers + "-" + (month < 10 ? ("0" + month) : month);
|
|
|
+ }
|
|
|
+ timeList.push(str);
|
|
|
+ curr.setMonth(month + 1);
|
|
|
+ }else if(type === 'y'){
|
|
|
+ if (month === 0) {
|
|
|
+ str = (yers - 1)
|
|
|
+ } else {
|
|
|
+ str = yers
|
|
|
+ }
|
|
|
+ timeList.push(str);
|
|
|
+ curr.setMonth(month + 1);
|
|
|
+ }else{}
|
|
|
+ }
|
|
|
+ if(type === 'y-m'){
|
|
|
+ return timeList.reverse()
|
|
|
+ }else{
|
|
|
+ let list = Array.from(new Set(timeList))
|
|
|
+ return list.reverse()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 获取 当前 年-月 配合 getCustomTimeList 使用 获取end
|
|
|
+
|
|
|
+tools.getDateYM = ()=>{
|
|
|
+ let DATE = new Date()
|
|
|
+ let Y = DATE.getFullYear()
|
|
|
+ let M = DATE.getMonth() + 1
|
|
|
+ return Y + '-' + (M<10?'0'+M:M)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 保留两位小数
|
|
|
+ * @param num
|
|
|
+ * @returns {string}
|
|
|
+ */
|
|
|
+tools.twoFloating = function (num) {
|
|
|
+ // 获取两位小数
|
|
|
+ let price = "";
|
|
|
+ price = num * 1;
|
|
|
+ price = String(price).split(".")[1];
|
|
|
+ if (price !== undefined && price.length === 1) {
|
|
|
+ price = `.${price}0`;
|
|
|
+ } else {
|
|
|
+ price === undefined ? (price = ".00") : (price = `.${price}`);
|
|
|
+ }
|
|
|
+ return price;
|
|
|
+}
|
|
|
+tools.formatDecimal = function (num, decimal) {
|
|
|
+ num = num.toString()
|
|
|
+ let index = num.indexOf('.')
|
|
|
+ if (index !== -1) {
|
|
|
+ num = num.substring(0, decimal + index + 1)
|
|
|
+ } else {
|
|
|
+ num = num.substring(0)
|
|
|
+ }
|
|
|
+ return parseFloat(num).toFixed(decimal)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 错误提示
|
|
|
+ * @param msg
|
|
|
+ */
|
|
|
+tools.error = function (msg) {
|
|
|
+ uni.showToast({
|
|
|
+ 'title': msg,
|
|
|
+ 'icon': 'error',
|
|
|
+ 'mask': true,
|
|
|
+ 'duration': 1500
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 成功提示
|
|
|
+ * @param msg
|
|
|
+ */
|
|
|
+tools.success = function (msg) {
|
|
|
+ uni.showToast({
|
|
|
+ 'title': msg,
|
|
|
+ 'icon': 'success',
|
|
|
+ 'mask': true,
|
|
|
+ 'duration': 1500
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 显示Loading
|
|
|
+ */
|
|
|
+tools.showLoading = function () {
|
|
|
+ uni.showLoading({
|
|
|
+ title: '加载中...',
|
|
|
+ mask: true
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 关闭Loading
|
|
|
+ */
|
|
|
+tools.hideLoading = function () {
|
|
|
+ uni.hideLoading();
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取时间戳(毫秒)
|
|
|
+ * @returns {number}
|
|
|
+ */
|
|
|
+tools.getTime = function () {
|
|
|
+ return new Date().getTime();
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+tools.updateVersion = function (sysVersion, appUrl) {
|
|
|
+ let app_version = plus.runtime.version;
|
|
|
+ if (app_version < sysVersion) {
|
|
|
+ uni.showLoading({
|
|
|
+ title: '更新中……'
|
|
|
+ })
|
|
|
+ uni.downloadFile({//执行下载
|
|
|
+ url: appUrl, //下载地址
|
|
|
+ success: (downloadResult) => {//下载成功
|
|
|
+ uni.hideLoading();
|
|
|
+ if (downloadResult.statusCode === 200) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '',
|
|
|
+ content: '更新成功,确定现在重启吗?',
|
|
|
+ confirmText: '重启',
|
|
|
+ confirmColor: '#EE8F57',
|
|
|
+ success: function (res) {
|
|
|
+ if (res.confirm === true) {
|
|
|
+ plus.runtime.install(//安装
|
|
|
+ downloadResult.tempFilePath, {
|
|
|
+ force: true
|
|
|
+ },
|
|
|
+ function (res) {
|
|
|
+ tools.success('更新成功,重启中')
|
|
|
+ plus.runtime.restart();
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // tools.success('你已是最新版本')
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * uniapp html图片显示控制
|
|
|
+ * @param str
|
|
|
+ * @returns {*}
|
|
|
+ */
|
|
|
+tools.imgDeal = function (str) {
|
|
|
+ console.log(str)
|
|
|
+ if(str===null || str===undefined){
|
|
|
+ return '';
|
|
|
+ }else {
|
|
|
+ return str.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;"');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取平台类型 1:微信,2:支付宝
|
|
|
+ * @returns {boolean|number}
|
|
|
+ */
|
|
|
+tools.platformType = function () {
|
|
|
+ let ua = window.navigator.userAgent.toLowerCase();
|
|
|
+ if (ua.indexOf('micromessenger') != -1) {
|
|
|
+ return 1;
|
|
|
+ } else if (ua.indexOf('alipay') != -1) {
|
|
|
+ return 2;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取开发平台
|
|
|
+ * @returns {string}
|
|
|
+ */
|
|
|
+tools.getPlatform = function () {
|
|
|
+ let platForm = undefined;
|
|
|
+ // #ifdef H5
|
|
|
+ platForm = 'H5';
|
|
|
+ //#endif
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ platForm = 'APP';
|
|
|
+ //#endif
|
|
|
+ // #ifdef APP-PLUS-NVUE
|
|
|
+ platForm = 'APP';
|
|
|
+ //#endif
|
|
|
+ // #ifdef APP-NVUE
|
|
|
+ platForm = 'APP';
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ platForm = 'MP-WEIXIN'; // 小程序
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-ALIPAY
|
|
|
+ platForm = 'MP-ALIPAY';
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-BAIDU
|
|
|
+ platForm = 'MP-BAIDU';
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-TOUTIAO
|
|
|
+ platForm = 'MP-TOUTIAO';
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-LARK
|
|
|
+ platForm = 'MP-LARK';
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-QQ
|
|
|
+ platForm = 'MP-QQ';
|
|
|
+ //#endif
|
|
|
+ // #ifdef MP-KUAISHOU
|
|
|
+ platForm = 'MP-KUAISHOU';
|
|
|
+ //#endif
|
|
|
+ // #ifdef QUICKAPP-WEBVIEW
|
|
|
+ platForm = 'QUICKAPP-WEBVIEW';
|
|
|
+ //#endif
|
|
|
+ return platForm;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 记录用户登录信息
|
|
|
+ * @param data
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+tools.setLoginData = function (data) {
|
|
|
+ uni.setStorageSync('m_id', data.m_id)
|
|
|
+ uni.setStorageSync('token', data.token)
|
|
|
+ tools.success('登陆成功')
|
|
|
+ setTimeout(() => {
|
|
|
+ uni.switchTab({
|
|
|
+ url: '/pages/index/index'
|
|
|
+ });
|
|
|
+ }, 1500)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 微信JSDK授权
|
|
|
+ * @param jsApiList
|
|
|
+ * @returns {Promise<*>}
|
|
|
+ */
|
|
|
+tools.wxInitialize = async function (jsApiList) {
|
|
|
+ // #ifdef H5
|
|
|
+ return await getJsConfig({ 'url': window.location.href,'type':3 }).then((ret) => {
|
|
|
+ if (ret.code === 1) {
|
|
|
+ wxJs.config({
|
|
|
+ beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
|
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
+ appId: ret.data.appId, // 必填,企业微信的corpID,必须是本企业的corpID,不允许跨企业使用
|
|
|
+ timestamp: ret.data.timestamp * 1, // 必填,生成签名的时间戳
|
|
|
+ nonceStr: ret.data.noncestr, // 必填,生成签名的随机串
|
|
|
+ signature: ret.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
|
|
|
+ jsApiList: jsApiList,// 必填,需要使用的JS接口列表
|
|
|
+ success: function(res) {
|
|
|
+ tools.success('成功')
|
|
|
+ },
|
|
|
+ fail: function(res) {}
|
|
|
+ });
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ //#endif
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+tools.weiXinPay = function (data) {
|
|
|
+ // #ifdef H5
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ wxJs.chooseWXPay({
|
|
|
+ appId: data.appId, // 必填,公众号的唯一标识
|
|
|
+ timestamp: data.timeStamp, // 支付签名时间戳,注意微信 jssdk 中的所有使用 timestamp 字段均为小写。但最新版的支付后台生成签名使用的 timeStamp 字段名需大写其中的 S 字符
|
|
|
+ nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
|
|
|
+ package: data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
|
|
|
+ signType: data.signType, // 微信支付V3的传入 RSA ,微信支付V2的传入格式与V2统一下单的签名格式保持一致
|
|
|
+ paySign: data.paySign, // 支付签名
|
|
|
+ success: function (res) {
|
|
|
+ resolve(true)
|
|
|
+ },
|
|
|
+ fail: function (res) {
|
|
|
+ resolve(false)
|
|
|
+ },
|
|
|
+ });
|
|
|
+ })
|
|
|
+ //#endif
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 判定当前浏览器是否为微信浏览器
|
|
|
+ */
|
|
|
+tools.isWx = function () {
|
|
|
+ //#ifdef H5
|
|
|
+ let ua = window.navigator.userAgent.toLowerCase();
|
|
|
+ if (ua.indexOf('micromessenger') !== -1) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //#endif
|
|
|
+ // #ifndef H5
|
|
|
+ return false;
|
|
|
+ // #endif
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+tools.wxLogin = function (urlPath) {
|
|
|
+ // #ifdef H5
|
|
|
+ // 微信浏览器
|
|
|
+ let url=window.location.href;
|
|
|
+ url = url.replace('&code=', '&code_a=1')
|
|
|
+ url = encodeURIComponent(url);
|
|
|
+
|
|
|
+ // let nodeEnv = process.env.NODE_ENV;
|
|
|
+ // let type = '';
|
|
|
+ // if(nodeEnv === 'development'){
|
|
|
+ // type = 2
|
|
|
+ // }else{
|
|
|
+ // type = 1
|
|
|
+ // }
|
|
|
+
|
|
|
+ window.location.href = `https://wx.jhcs888.com/#/?redirect_url=${Base64.encode(url)}&type=3`
|
|
|
+ //#endif
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+tools.setClipboardData=function (text){
|
|
|
+ uni.setClipboardData({
|
|
|
+ data: text,
|
|
|
+ success: function () {
|
|
|
+ tools.success('复制成功')
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+tools.download=function (url){
|
|
|
+ window.open(url)
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+tools.jyStart=function () {
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+export default tools
|