刘翔宇-旅管家 3 years ago
parent 73c1ac919e
commit 70ec63f416

@ -650,21 +650,31 @@
} }
}, },
utilFail: res => { utilFail: res => {
console.log(res)
uni.showToast({ uni.showToast({
title: res, title: res,
duration: 5000 duration: 5000
}) })
console.log(res);
} }
}) })
} }
}, },
utilFail: r => { utilFail: r => {
uni.showToast({ uni.showModal({
title: r, title: '',
duration: 5000 content: r,
}) showCancel: false,
console.log(r); success() {
if (r == "重复购买") {
uni.redirectTo({
url: "../../../packageOrder/pages/myOrder/myOrder"
})
}
}
});
} }
}) })

@ -13,40 +13,41 @@ const formatTime = date => {
const month = date.getMonth() + 1; const month = date.getMonth() + 1;
const day = date.getDate(); const day = date.getDate();
return [year, month, day].map(formatNumber).join('-'); return [year, month, day].map(formatNumber).join('-');
}; };
// 其他更多是格式化有如下: // 其他更多是格式化有如下:
// yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合 // yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合
function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') {try { function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') {
try {
// 如果为null,则格式化当前时间
if (!dateTime) dateTime = Number(new Date()); // 如果为null,则格式化当前时间
// 如果dateTime长度为10或者13则为秒和毫秒的时间戳如果超过13位则为其他的时间格式 if (!dateTime) dateTime = Number(new Date());
if (dateTime.toString().length == 10) dateTime *= 1000; // 如果dateTime长度为10或者13则为秒和毫秒的时间戳如果超过13位则为其他的时间格式
if (dateTime.toString().indexOf("-")>-1) dateTime= dateTime.replace(/-/g,'/') if (dateTime.toString().length == 10) dateTime *= 1000;
let date = new Date(dateTime); if (dateTime.toString().indexOf("-") > -1) dateTime = dateTime.replace(/-/g, '/')
let date = new Date(dateTime);
let ret;
let opt = { let ret;
"y+": date.getFullYear().toString(), // 年 let opt = {
"m+": (date.getMonth() + 1).toString(), // 月 "y+": date.getFullYear().toString(), // 年
"d+": date.getDate().toString(), // 日 "m+": (date.getMonth() + 1).toString(), // 月
"h+": date.getHours().toString(), // 时 "d+": date.getDate().toString(), // 日
"M+": date.getMinutes().toString(), // 分 "h+": date.getHours().toString(), // 时
"s+": date.getSeconds().toString() // 秒 "M+": date.getMinutes().toString(), // 分
// 有其他格式化字符需求可以继续添加,必须转化成字符串 "s+": date.getSeconds().toString() // 秒
}; // 有其他格式化字符需求可以继续添加,必须转化成字符串
for (let k in opt) { };
ret = new RegExp("(" + k + ")").exec(fmt); for (let k in opt) {
if (ret) { ret = new RegExp("(" + k + ")").exec(fmt);
fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) if (ret) {
}; fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0")))
}; };
return fmt; };
}catch(e){ return fmt;
console.log(e) } catch (e) {
console.log(e)
} }
} }
@ -97,8 +98,8 @@ const auditStatusDic = {
}; // 请求封装 }; // 请求封装
const request = options => { const request = options => {
if (!options.customLoading) { if (!options.customLoading) {
//if(false){ //if(false){
uni.showLoading({ uni.showLoading({
title: '正在加载' title: '正在加载'
}); });
@ -135,6 +136,7 @@ const request = options => {
uni.request({ uni.request({
...options, ...options,
success: function(res) { success: function(res) {
uni.hideLoading();
if (res.statusCode != 200) { if (res.statusCode != 200) {
if (options.utilFail != undefined) { if (options.utilFail != undefined) {
if (res.statusCode == 401) { if (res.statusCode == 401) {
@ -160,16 +162,19 @@ const request = options => {
} }
} }
}, },
fail: options.utilFail, fail: function(res) {
uni.hideLoading();
options.utilFail(res);
},
complete: function(res) { complete: function(res) {
if (!options.customLoading) { if (!options.customLoading) {
uni.hideNavigationBarLoading(); uni.hideNavigationBarLoading();
uni.hideLoading();
} else { } else {
// 当前页面请求数量-1 // 当前页面请求数量-1
if (options.bindThis) { if (options.bindThis) {
//options.bindThis.setData({ //options.bindThis.setData({
//loadingCount: options.bindThis.data.loadingCount - 1 //loadingCount: options.bindThis.data.loadingCount - 1
//}); //});
} }
} }
@ -264,14 +269,14 @@ const payOrder = (orderID, orderType, success, fail) => {
const getRegions = () => { const getRegions = () => {
request({ request({
api: 'api/get-regions', api: 'api/get-regions',
customLoading:true, customLoading: true,
utilSuccess: function(res) { utilSuccess: function(res) {
var r = res[0]; var r = res[0];
r.latitude = 31.53908730560652; //res.latitude;31.536744,120.40841 r.latitude = 31.53908730560652; //res.latitude;31.536744,120.40841
r.longitude = 120.41435442003421; // res.longitude; r.longitude = 120.41435442003421; // res.longitude;
uni.setStorageSync("region", r); uni.setStorageSync("region", r);
}, },
utilFail: function(res) { utilFail: function(res) {
console.log(res) console.log(res)
@ -354,65 +359,65 @@ const getfile = (id, success, fail) => {
// } // }
// }); // });
}; };
const openid_info_key = "openid_info" const openid_info_key = "openid_info"
const user_info_key = 'user_info_key' const user_info_key = 'user_info_key'
const solgn="无锡新吴欢迎您"; const solgn = "无锡新吴欢迎您";
const shareInfo=(type)=>{ const shareInfo = (type) => {
return { return {
title:solgn title: solgn
} }
} }
const getOpenidInfo= (cb, refresh) => { const getOpenidInfo = (cb, refresh) => {
cb = cb || function() {} cb = cb || function() {}
refresh = refresh || false refresh = refresh || false
if (!refresh) { if (!refresh) {
let user_info = uni.getStorageSync(user_info_key) let user_info = uni.getStorageSync(user_info_key)
if (user_info && user_info.openid && user_info.session_key) { if (user_info && user_info.openid && user_info.session_key) {
cb(user_info) cb(user_info)
return return
}
} }
}
uni.login({
provider: 'weixin',
success: (res) => {
uni.request({
url: HOST + 'api/member/login-by-code',
method: 'POST',
data: {
code: res.code
},
success: result => {
const user_info1 = result.data.data.user_info
user_info1.openid = user_info1.wechat_openid
uni.setStorageSync(user_info_key, user_info1)
cb(user_info1)
}
});
}
});
}
const getUserProfile = (cb) => {
cb = cb || function() {}
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
uni.setStorageSync('user_profile', res.userInfo)
cb(res.userInfo)
}
})
}
const getUserInfoCache = () => {
return uni.getStorageSync(user_info_key)
}
uni.login({
provider: 'weixin',
success: (res) => {
uni.request({
url: HOST + 'api/member/login-by-code',
method: 'POST',
data: {
code: res.code
},
success: result => {
const user_info1 = result.data.data.user_info
user_info1.openid = user_info1.wechat_openid
uni.setStorageSync(user_info_key, user_info1)
cb(user_info1)
}
});
}
});
}
const getUserProfile=(cb) => {
cb = cb || function() {}
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
uni.setStorageSync('user_profile', res.userInfo)
cb(res.userInfo)
}
})
}
const getUserInfoCache= () => {
return uni.getStorageSync(user_info_key)
}
//获取订单详情 //获取订单详情
const getOrderInfo = (id, success, fail) => { const getOrderInfo = (id, success, fail) => {
@ -752,11 +757,11 @@ var Base64 = {
} }
return this.UTF8ToUTF16(res.join('')); return this.UTF8ToUTF16(res.join(''));
}, },
}; };
@ -791,10 +796,10 @@ module.exports = {
getOrderInfo: getOrderInfo, getOrderInfo: getOrderInfo,
getOrderItemInfo: getOrderItemInfo, getOrderItemInfo: getOrderItemInfo,
stateArr: stateArr, stateArr: stateArr,
getRegions: getRegions, getRegions: getRegions,
getOpenidInfo:getOpenidInfo, getOpenidInfo: getOpenidInfo,
getUserProfile:getUserProfile, getUserProfile: getUserProfile,
getUserInfoCache:getUserInfoCache, getUserInfoCache: getUserInfoCache,
timeFormat:timeFormat, timeFormat: timeFormat,
shareInfo:shareInfo shareInfo: shareInfo
}; };

Loading…
Cancel
Save