|
@@ -3,7 +3,7 @@ import jWeixin from "wecomjsdk"
|
|
|
import {
|
|
import {
|
|
|
Base64
|
|
Base64
|
|
|
} from '@/js_sdk/js-base64/base64';
|
|
} from '@/js_sdk/js-base64/base64';
|
|
|
-import {getWxJsSign} from "@/api/weChat";
|
|
|
|
|
|
|
+import {getJsConfig} from "@/api/common.js";
|
|
|
|
|
|
|
|
let tools = {}
|
|
let tools = {}
|
|
|
/**
|
|
/**
|
|
@@ -16,6 +16,112 @@ tools.sortNumber = function (a, b) {
|
|
|
return 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.reLaunch({
|
|
|
|
|
+ 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)
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 保留两位小数
|
|
* 保留两位小数
|
|
@@ -45,6 +151,9 @@ tools.formatDecimal = function (num, decimal) {
|
|
|
return parseFloat(num).toFixed(decimal)
|
|
return parseFloat(num).toFixed(decimal)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 错误提示
|
|
* 错误提示
|
|
|
* @param msg
|
|
* @param msg
|
|
@@ -99,8 +208,6 @@ tools.getTime = function () {
|
|
|
|
|
|
|
|
tools.updateVersion = function (sysVersion, appUrl) {
|
|
tools.updateVersion = function (sysVersion, appUrl) {
|
|
|
let app_version = plus.runtime.version;
|
|
let app_version = plus.runtime.version;
|
|
|
- console.log('版本号信息对比------------------------------' + app_version + '---------' + sysVersion)
|
|
|
|
|
- console.log(app_version < sysVersion)
|
|
|
|
|
if (app_version < sysVersion) {
|
|
if (app_version < sysVersion) {
|
|
|
uni.showLoading({
|
|
uni.showLoading({
|
|
|
title: '更新中……'
|
|
title: '更新中……'
|
|
@@ -240,25 +347,21 @@ tools.setLoginData = function (data) {
|
|
|
*/
|
|
*/
|
|
|
tools.wxInitialize = async function (jsApiList) {
|
|
tools.wxInitialize = async function (jsApiList) {
|
|
|
|
|
|
|
|
- return await getWxJsSign({ 'url': window.location.href,'type':1 }).then((ret) => {
|
|
|
|
|
|
|
+ return await getJsConfig({ 'url': window.location.href,'type':1 }).then((ret) => {
|
|
|
if (ret.code === 1) {
|
|
if (ret.code === 1) {
|
|
|
wxJs.config({
|
|
wxJs.config({
|
|
|
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
|
|
|
- debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
|
|
|
|
+ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
|
|
|
appId: ret.data.appId, // 必填,企业微信的corpID,必须是本企业的corpID,不允许跨企业使用
|
|
appId: ret.data.appId, // 必填,企业微信的corpID,必须是本企业的corpID,不允许跨企业使用
|
|
|
timestamp: ret.data.timestamp * 1, // 必填,生成签名的时间戳
|
|
timestamp: ret.data.timestamp * 1, // 必填,生成签名的时间戳
|
|
|
nonceStr: ret.data.noncestr, // 必填,生成签名的随机串
|
|
nonceStr: ret.data.noncestr, // 必填,生成签名的随机串
|
|
|
signature: ret.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
|
|
signature: ret.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
|
|
|
jsApiList: jsApiList,// 必填,需要使用的JS接口列表
|
|
jsApiList: jsApiList,// 必填,需要使用的JS接口列表
|
|
|
success: function(res) {
|
|
success: function(res) {
|
|
|
- console.log(res)
|
|
|
|
|
- console.log('config:---------------OK')
|
|
|
|
|
|
|
+ console.log(res);
|
|
|
tools.success('成功')
|
|
tools.success('成功')
|
|
|
},
|
|
},
|
|
|
- fail: function(res) {
|
|
|
|
|
- console.log('config-error')
|
|
|
|
|
- console.log(res)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ fail: function(res) {}
|
|
|
});
|
|
});
|
|
|
return true;
|
|
return true;
|
|
|
} else {
|
|
} else {
|
|
@@ -267,49 +370,86 @@ tools.wxInitialize = async function (jsApiList) {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+tools.weiXinPay = function (data) {
|
|
|
|
|
+ console.log({
|
|
|
|
|
+ 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, // 支付签名
|
|
|
|
|
+ })
|
|
|
|
|
+ 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)
|
|
|
|
|
+ },
|
|
|
|
|
+ });
|
|
|
|
|
+ })
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
- * 企业微信信息授权
|
|
|
|
|
- * @param jsApiList
|
|
|
|
|
- * @returns {Promise<unknown>}
|
|
|
|
|
|
|
+ * 判定当前浏览器是否为微信浏览器
|
|
|
*/
|
|
*/
|
|
|
-tools.wxAgentInitialize=async function (jsApiList){
|
|
|
|
|
|
|
+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
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- return await getWxJsSign({ 'url': window.location.href ,'type':2}).then((ret) => {
|
|
|
|
|
- if (ret.code === 1) {
|
|
|
|
|
- jWeixin.agentConfig({
|
|
|
|
|
- corpid: ret.data.appId, // 必填,企业微信的corpID,必须是本企业的corpID,不允许跨企业使用
|
|
|
|
|
- agentid: ret.data.agentid, // 必填,企业微信的应用id (e.g. 1000247)
|
|
|
|
|
- timestamp: ret.data.timestamp * 1, // 必填,生成签名的时间戳
|
|
|
|
|
- nonceStr: ret.data.noncestr, // 必填,生成签名的随机串
|
|
|
|
|
- signature: ret.data.signature,// 必填,签名,见 附录-JS-SDK使用权限签名算法
|
|
|
|
|
- jsApiList: jsApiList,// 必填,需要使用的JS接口列表
|
|
|
|
|
- success: function(res) {
|
|
|
|
|
- console.log('agentConfig:---------------OK')
|
|
|
|
|
- console.log(res)
|
|
|
|
|
|
|
|
|
|
- },
|
|
|
|
|
- fail: function(res) {
|
|
|
|
|
- console.log('agentConfig-error')
|
|
|
|
|
- console.log(res)
|
|
|
|
|
- if(res.errMsg.indexOf('function not exist') > -1){
|
|
|
|
|
- alert('版本过低请升级')
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- });
|
|
|
|
|
|
|
+tools.wxLogin = function (urlPath) {
|
|
|
|
|
+ // 微信浏览器
|
|
|
|
|
+ let url=window.location.href;
|
|
|
|
|
+ url = url.replace('&code=', '&code_a=1')
|
|
|
|
|
+ url = encodeURIComponent(url);
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
|
- } else {
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ // 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=1`
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+tools.setClipboardData=function (text){
|
|
|
|
|
+ uni.setClipboardData({
|
|
|
|
|
+ data: text,
|
|
|
|
|
+ success: function () {
|
|
|
|
|
+ tools.success('复制成功')
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-tools.wxLogin = function () {
|
|
|
|
|
- console.log(Base64.encode('aaa'));
|
|
|
|
|
- // 微信浏览器
|
|
|
|
|
- let url = encodeURIComponent(window.location.href);
|
|
|
|
|
- window.location.href = `https://test-api.wealfavor.cn/api/weChat/wx?redirect_url=${Base64.encode(url)}`
|
|
|
|
|
|
|
+tools.download=function (url){
|
|
|
|
|
+ window.open(url)
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+tools.jyStart=function () {
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|