|
|
|
|
@ -1,48 +1,48 @@
|
|
|
|
|
import md5 from "./md5.min";
|
|
|
|
|
const HOSTARR = {
|
|
|
|
|
// 'development':'https://gb-test.ali251.langye.net',
|
|
|
|
|
// 'production': 'https://gb-test.ali251.langye.net',
|
|
|
|
|
'development':'https://gbyuyue.szgmbwg.org.cn',
|
|
|
|
|
'production': 'https://gbyuyue.szgmbwg.org.cn',
|
|
|
|
|
// 'production': 'https://gb-test.ali251.langye.net',
|
|
|
|
|
'development':'https://gbyuyue.szgmbwg.org.cn',
|
|
|
|
|
'production': 'https://gbyuyue.szgmbwg.org.cn',
|
|
|
|
|
// https://gbyuyue.szgmbwg.org.cn/
|
|
|
|
|
}; // 审核状态
|
|
|
|
|
|
|
|
|
|
const HOST = HOSTARR[process.env
|
|
|
|
|
.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const replaceImgUrl = (str,before,after)=>{
|
|
|
|
|
if(str.indexOf(before) != -1){
|
|
|
|
|
return str.replace(new RegExp(before, 'g'),after)
|
|
|
|
|
}else{
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const splitTime = (start,end)=> {
|
|
|
|
|
let arrStart = start.substring(0, 10).split("-")
|
|
|
|
|
let year = parseInt(arrStart[0])
|
|
|
|
|
let month = parseInt(arrStart[1]) < 10 ? parseInt(arrStart[1]) : parseInt(arrStart[1])
|
|
|
|
|
|
|
|
|
|
const replaceImgUrl = (str,before,after)=>{
|
|
|
|
|
if(str.indexOf(before) != -1){
|
|
|
|
|
return str.replace(new RegExp(before, 'g'),after)
|
|
|
|
|
}else{
|
|
|
|
|
return str
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const splitTime = (start,end)=> {
|
|
|
|
|
let arrStart = start.substring(0, 10).split("-")
|
|
|
|
|
let year = parseInt(arrStart[0])
|
|
|
|
|
let month = parseInt(arrStart[1]) < 10 ? parseInt(arrStart[1]) : parseInt(arrStart[1])
|
|
|
|
|
let day = parseInt(arrStart[2]) < 10 ? parseInt(arrStart[2]) : parseInt(arrStart[2])
|
|
|
|
|
if (end) {
|
|
|
|
|
// 判断end 是否为时间格式
|
|
|
|
|
if(isNaN(end)&&!isNaN(Date.parse(end))){
|
|
|
|
|
let arrEnd = end.substring(0, 10).split("-")
|
|
|
|
|
let yearEnd = parseInt(arrEnd[0])
|
|
|
|
|
let monthEnd = parseInt(arrEnd[1]) < 10 ? parseInt(arrEnd[1]) : parseInt(arrEnd[1])
|
|
|
|
|
let dayEnd = parseInt(arrEnd[2]) < 10 ? parseInt(arrEnd[2]) : parseInt(arrEnd[2])
|
|
|
|
|
if(year == yearEnd){
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '至' + monthEnd + '月' + dayEnd + '日'
|
|
|
|
|
}else{
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '至' + yearEnd + '年'+monthEnd + '月' + dayEnd + '日'
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '至' + end
|
|
|
|
|
if (end) {
|
|
|
|
|
// 判断end 是否为时间格式
|
|
|
|
|
if(isNaN(end)&&!isNaN(Date.parse(end))){
|
|
|
|
|
let arrEnd = end.substring(0, 10).split("-")
|
|
|
|
|
let yearEnd = parseInt(arrEnd[0])
|
|
|
|
|
let monthEnd = parseInt(arrEnd[1]) < 10 ? parseInt(arrEnd[1]) : parseInt(arrEnd[1])
|
|
|
|
|
let dayEnd = parseInt(arrEnd[2]) < 10 ? parseInt(arrEnd[2]) : parseInt(arrEnd[2])
|
|
|
|
|
if(year == yearEnd){
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '至' + monthEnd + '月' + dayEnd + '日'
|
|
|
|
|
}else{
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '至' + yearEnd + '年'+monthEnd + '月' + dayEnd + '日'
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '至' + end
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return year + '年' + month + '月' + day + '日' + '起'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const formatTime = date => {
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
@ -75,32 +75,95 @@ const getUserInfo = (cb, refresh) => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getOpenidInfo = (cb, refresh) => {
|
|
|
|
|
cb = cb || function() {}
|
|
|
|
|
refresh = refresh || false
|
|
|
|
|
if (!refresh) {
|
|
|
|
|
let user_info = uni.getStorageSync(user_info_key)
|
|
|
|
|
if (!isNull(user_info)) {
|
|
|
|
|
cb(user_info)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// cb = cb || function() {}
|
|
|
|
|
// refresh = refresh || false
|
|
|
|
|
// console.log("getOpenidInfo", refresh)
|
|
|
|
|
// if (!refresh) {
|
|
|
|
|
// let user_info = uni.getStorageSync(user_info_key)
|
|
|
|
|
// if (!isNull(user_info)) {
|
|
|
|
|
// cb(user_info)
|
|
|
|
|
// return
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
let user_info = uni.getStorageSync(user_info_key)
|
|
|
|
|
if (!isNull(user_info)) {
|
|
|
|
|
cb(user_info)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// 判断运行环境:H5还是小程序
|
|
|
|
|
const isH5 = typeof window !== 'undefined' && window.location
|
|
|
|
|
const isWeixinBrowser = isH5 && /MicroMessenger/i.test(navigator.userAgent)
|
|
|
|
|
|
|
|
|
|
if (isH5 && isWeixinBrowser) {
|
|
|
|
|
// H5环境下的微信授权登录
|
|
|
|
|
wxH5AuthLogin(cb)
|
|
|
|
|
} else {
|
|
|
|
|
// 小程序环境下的微信登录
|
|
|
|
|
uni.login({
|
|
|
|
|
provider: 'weixin',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
console.log(res.code);
|
|
|
|
|
let url = HOST + '/api/mobile/user/login?code=' + res.code;
|
|
|
|
|
uni.request({
|
|
|
|
|
url: url,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
success: result => {
|
|
|
|
|
let user_info = result.data
|
|
|
|
|
uni.setStorageSync(user_info_key, user_info)
|
|
|
|
|
cb(user_info)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uni.login({
|
|
|
|
|
provider: 'weixin',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
console.log(res.code);
|
|
|
|
|
let url = HOST + '/api/mobile/user/login?code=' + res.code;
|
|
|
|
|
uni.request({
|
|
|
|
|
url: url,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
success: result => {
|
|
|
|
|
let user_info = result.data
|
|
|
|
|
uni.setStorageSync(user_info_key, user_info)
|
|
|
|
|
cb(user_info)
|
|
|
|
|
// H5环境下的微信授权登录
|
|
|
|
|
const wxH5AuthLogin = (cb) => {
|
|
|
|
|
let link = window.location.href;
|
|
|
|
|
if (/code=/.test(link) || link.indexOf("code") > -1) {
|
|
|
|
|
// 已经获取到授权码,直接登录
|
|
|
|
|
let temp = decodeURIComponent((new RegExp('[?|&]' + 'code' + '=' + '([^&;]+?)(&|#|;|$)').exec(
|
|
|
|
|
link) || [, ''])[1].replace(/\+/g, '%20')) || null;
|
|
|
|
|
console.log("code", temp)
|
|
|
|
|
|
|
|
|
|
// 上传 code 到服务器获取 token
|
|
|
|
|
request({
|
|
|
|
|
api: `/api/mobile/user/wx-login?code=${temp}`,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
utilSuccess: (res) => {
|
|
|
|
|
if (res.token && res.token.trim() !== '') {
|
|
|
|
|
console.log('获取 token 成功:', res.token)
|
|
|
|
|
// 保持与小程序登录一致的存储方式
|
|
|
|
|
const userInfo = {
|
|
|
|
|
token: res.token,
|
|
|
|
|
// 可以根据需要添加其他字段,如 WeChatOpenID 等
|
|
|
|
|
}
|
|
|
|
|
uni.setStorageSync(user_info_key, userInfo)
|
|
|
|
|
cb(userInfo)
|
|
|
|
|
} else {
|
|
|
|
|
console.error('登录失败: token为空')
|
|
|
|
|
uni.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
utilFail: (err) => {
|
|
|
|
|
console.error('获取 token 失败:', err)
|
|
|
|
|
uni.showToast({ title: '登录失败,请重试', icon: 'none' })
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 未获取授权码,跳转到微信授权页面
|
|
|
|
|
const appId = 'wxbf4862e929ab85b0'
|
|
|
|
|
const currentUrl = window.location.href
|
|
|
|
|
const redirectUri = encodeURIComponent(currentUrl.replace(/#\//, ""));
|
|
|
|
|
const scope = 'snsapi_userinfo'
|
|
|
|
|
const state = 'STATE'
|
|
|
|
|
console.log(redirectUri)
|
|
|
|
|
const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`
|
|
|
|
|
|
|
|
|
|
// 重定向到微信授权页面
|
|
|
|
|
window.location.href = authUrl
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -108,13 +171,39 @@ const getOpenidInfo = (cb, refresh) => {
|
|
|
|
|
const getUserProfile = (cb) => {
|
|
|
|
|
cb = cb || function() {}
|
|
|
|
|
|
|
|
|
|
wx.getUserProfile({
|
|
|
|
|
desc: '用于完善会员资料',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
uni.setStorageSync('user_profile', res.userInfo)
|
|
|
|
|
cb(res.userInfo)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
// 判断运行环境:H5还是小程序
|
|
|
|
|
const isH5 = typeof window !== 'undefined' && window.location
|
|
|
|
|
const isWeixinBrowser = isH5 && /MicroMessenger/i.test(navigator.userAgent)
|
|
|
|
|
|
|
|
|
|
if (isH5 && isWeixinBrowser) {
|
|
|
|
|
// H5环境下,通过后端接口获取用户信息
|
|
|
|
|
// 微信公众号H5无法直接调用wx.getUserProfile
|
|
|
|
|
request({
|
|
|
|
|
api: '/api/mobile/user/profile',
|
|
|
|
|
method: 'GET',
|
|
|
|
|
utilSuccess: (res) => {
|
|
|
|
|
uni.setStorageSync('user_profile', res)
|
|
|
|
|
cb(res)
|
|
|
|
|
},
|
|
|
|
|
utilFail: (err) => {
|
|
|
|
|
console.error('获取用户信息失败:', err)
|
|
|
|
|
cb(null)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
// 小程序环境下,使用wx.getUserProfile
|
|
|
|
|
wx.getUserProfile({
|
|
|
|
|
desc: '用于完善会员资料',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
uni.setStorageSync('user_profile', res.userInfo)
|
|
|
|
|
cb(res.userInfo)
|
|
|
|
|
},
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
console.error('获取用户信息失败:', err)
|
|
|
|
|
cb(null)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -338,8 +427,8 @@ const isLogin = () => {
|
|
|
|
|
|
|
|
|
|
const isNull = p => {
|
|
|
|
|
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
|
|
|
|
|
}; // 正则
|
|
|
|
|
|
|
|
|
|
}; // 正则
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const phoneRegex = /^1[3456789]\d{9}$/;
|
|
|
|
|
@ -391,11 +480,11 @@ const isValidCardID = cardID => {
|
|
|
|
|
|
|
|
|
|
var last = parity[sum % 11];
|
|
|
|
|
return parity[sum % 11] == code[17];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const shareInfo = {
|
|
|
|
|
title:"",
|
|
|
|
|
imageUrl:"/static/share.jpg"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const shareInfo = {
|
|
|
|
|
title:"",
|
|
|
|
|
imageUrl:"/static/share.jpg"
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* UTF16和UTF8转换对照表
|
|
|
|
|
@ -580,6 +669,7 @@ module.exports = {
|
|
|
|
|
formatNumber: formatNumber,
|
|
|
|
|
alert: alert,
|
|
|
|
|
getOpenidInfo: getOpenidInfo,
|
|
|
|
|
wxH5AuthLogin: wxH5AuthLogin,
|
|
|
|
|
request: request,
|
|
|
|
|
payOrder: payOrder,
|
|
|
|
|
isLogin: isLogin,
|
|
|
|
|
@ -594,9 +684,9 @@ module.exports = {
|
|
|
|
|
auditStatusDic: auditStatusDic,
|
|
|
|
|
getUserProfile: getUserProfile,
|
|
|
|
|
getUserInfo: getUserInfo,
|
|
|
|
|
toast: toast,
|
|
|
|
|
isValidCardID:isValidCardID,
|
|
|
|
|
shareInfo:shareInfo,
|
|
|
|
|
replaceImgUrl:replaceImgUrl,
|
|
|
|
|
toast: toast,
|
|
|
|
|
isValidCardID:isValidCardID,
|
|
|
|
|
shareInfo:shareInfo,
|
|
|
|
|
replaceImgUrl:replaceImgUrl,
|
|
|
|
|
splitTime:splitTime
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|