基础接口对接
This commit is contained in:
@@ -12,7 +12,7 @@ const toast = (title, duration = 1500, call, mask = false, icon = 'none') => {
|
||||
})
|
||||
setTimeout(() => {
|
||||
call && call()
|
||||
}, duration);
|
||||
}, duration)
|
||||
}
|
||||
/**
|
||||
* @description 格式化时间
|
||||
@@ -20,7 +20,7 @@ const toast = (title, duration = 1500, call, mask = false, icon = 'none') => {
|
||||
* @param cFormat
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function parseTime (time, cFormat) {
|
||||
function parseTime(time, cFormat) {
|
||||
if (arguments.length === 0) {
|
||||
return null
|
||||
}
|
||||
@@ -44,7 +44,7 @@ function parseTime (time, cFormat) {
|
||||
h: date.getHours(),
|
||||
i: date.getMinutes(),
|
||||
s: date.getSeconds(),
|
||||
a: date.getDay()
|
||||
a: date.getDay(),
|
||||
}
|
||||
return format.replace(/{([ymdhisa])+}/g, (result, key) => {
|
||||
let value = formatObj[key]
|
||||
@@ -58,14 +58,13 @@ function parseTime (time, cFormat) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description 格式化时间
|
||||
* @param time
|
||||
* @param option
|
||||
* @returns {string}
|
||||
*/
|
||||
function formatTime (time, option) {
|
||||
function formatTime(time, option) {
|
||||
if (('' + time).length === 10) {
|
||||
time = parseInt(time) * 1000
|
||||
} else {
|
||||
@@ -88,11 +87,7 @@ function formatTime (time, option) {
|
||||
return '1天前'
|
||||
}
|
||||
return (
|
||||
d.getMonth() +
|
||||
1 +
|
||||
'月' +
|
||||
d.getDate() +
|
||||
'日'
|
||||
d.getMonth() + 1 + '月' + d.getDate() + '日'
|
||||
// +
|
||||
// d.getHours() +
|
||||
// '时'
|
||||
@@ -122,24 +117,23 @@ const validatePhoneNumber = (phone) => {
|
||||
return testReg.test(phone)
|
||||
}
|
||||
|
||||
|
||||
const getUserLocation = (call) => {
|
||||
uni.getLocation({
|
||||
type: 'wgs84',
|
||||
success: function (address) {
|
||||
call(address)
|
||||
},
|
||||
fail: err => {
|
||||
fail: (err) => {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '定位失败,请打开定位权限',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
uni.openSetting({
|
||||
success: resSett => {
|
||||
success: (resSett) => {
|
||||
if (resSett.authSetting['scope.userLocation']) {
|
||||
uni.getLocation({
|
||||
success: address => {
|
||||
success: (address) => {
|
||||
call && call(address)
|
||||
},
|
||||
})
|
||||
@@ -147,7 +141,7 @@ const getUserLocation = (call) => {
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
@@ -156,7 +150,7 @@ const getUserLocation = (call) => {
|
||||
// 加载用户配置
|
||||
var globalConfigIsLoading = false,
|
||||
global_config = null,
|
||||
globalConfigCallbacks = [];
|
||||
globalConfigCallbacks = []
|
||||
/**
|
||||
* 加载用户配置
|
||||
* @param call 加载成功后的回调
|
||||
@@ -164,41 +158,44 @@ var globalConfigIsLoading = false,
|
||||
*/
|
||||
const loadConfig = (call, need_fresh = false) => {
|
||||
if (call && global_config && !need_fresh) {
|
||||
call(global_config);
|
||||
return;
|
||||
call(global_config)
|
||||
return
|
||||
}
|
||||
if (globalConfigIsLoading) {
|
||||
globalConfigCallbacks.push(call);
|
||||
return;
|
||||
globalConfigCallbacks.push(call)
|
||||
return
|
||||
}
|
||||
globalConfigIsLoading = true;
|
||||
globalConfigIsLoading = true
|
||||
request({
|
||||
url: '/org/userResource/userMsg',
|
||||
}).then(rs => {
|
||||
|
||||
globalConfigIsLoading = false;
|
||||
global_config = rs.data;
|
||||
uni.setStorage({
|
||||
key: 'userInfo',
|
||||
data: global_config,
|
||||
})
|
||||
if (call) {
|
||||
call(global_config);
|
||||
}
|
||||
for (var i = 0; i < globalConfigCallbacks.length; i++) {
|
||||
globalConfigCallbacks[i](global_config);
|
||||
}
|
||||
globalConfigCallbacks = [];
|
||||
}).catch(err => {
|
||||
globalConfigIsLoading = false;
|
||||
console.warn(err);
|
||||
// uni.reLaunch({ url: '/pages/user/login' })
|
||||
})
|
||||
.then((rs) => {
|
||||
globalConfigIsLoading = false
|
||||
global_config = rs.data
|
||||
uni.setStorage({
|
||||
key: 'userInfo',
|
||||
data: global_config,
|
||||
})
|
||||
if (call) {
|
||||
call(global_config)
|
||||
}
|
||||
for (var i = 0; i < globalConfigCallbacks.length; i++) {
|
||||
globalConfigCallbacks[i](global_config)
|
||||
}
|
||||
globalConfigCallbacks = []
|
||||
})
|
||||
.catch((err) => {
|
||||
globalConfigIsLoading = false
|
||||
console.warn(err)
|
||||
// uni.reLaunch({ url: '/pages/user/login' })
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
const prePage = () => {
|
||||
let pages = getCurrentPages()
|
||||
let prePage = pages[pages.length - 2]
|
||||
return prePage
|
||||
}
|
||||
|
||||
export default {
|
||||
validatePhoneNumber,
|
||||
@@ -208,4 +205,5 @@ export default {
|
||||
h5Helper,
|
||||
getUserLocation,
|
||||
loadConfig,
|
||||
prePage,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user