You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
3.6 KiB
155 lines
3.6 KiB
|
5 years ago
|
var app = getApp()
|
||
|
|
const formatTime = date => {
|
||
|
|
const year = date.getFullYear()
|
||
|
|
const month = date.getMonth() + 1
|
||
|
|
const day = date.getDate()
|
||
|
|
const hour = date.getHours()
|
||
|
|
const minute = date.getMinutes()
|
||
|
|
const second = date.getSeconds()
|
||
|
|
|
||
|
|
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
|
||
|
|
}
|
||
|
|
const formatDate = date => {
|
||
|
|
const year = date.getFullYear()
|
||
|
|
const month = date.getMonth() + 1
|
||
|
|
const day = date.getDate()
|
||
|
|
return [year, month, day].map(formatNumber).join('-');
|
||
|
|
}
|
||
|
|
|
||
|
|
const formatNumber = n => {
|
||
|
|
n = n.toString()
|
||
|
|
return n[1] ? n : '0' + n
|
||
|
|
}
|
||
|
|
const isTel = tel => {
|
||
|
|
if (!(/^1\d{10}$/.test(tel))) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const setTitleBarColor = color => {
|
||
|
|
if(color==1){
|
||
|
|
wx.setNavigationBarColor({
|
||
|
|
frontColor: '#ffffff',
|
||
|
|
backgroundColor: '#ffffff'
|
||
|
|
})
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
wx.setNavigationBarColor({
|
||
|
|
frontColor: '#000000',
|
||
|
|
backgroundColor: '#000000'
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
const FILE_BASE_NAME = 'tmp_base64src'; //自定义文件名
|
||
|
|
|
||
|
|
function base64src(base64data, cb) {
|
||
|
|
const [, format, bodyData] = /data:image\/(\w+);base64,(.*)/.exec(base64data) || [];
|
||
|
|
if (!format) {
|
||
|
|
return (new Error('ERROR_BASE64SRC_PARSE'));
|
||
|
|
}
|
||
|
|
const filePath = `${wx.env.USER_DATA_PATH}/${FILE_BASE_NAME}.${format}`;
|
||
|
|
const buffer = wx.base64ToArrayBuffer(bodyData);
|
||
|
|
fsm.writeFile({
|
||
|
|
filePath,
|
||
|
|
data: buffer,
|
||
|
|
encoding: 'binary',
|
||
|
|
success() {
|
||
|
|
cb(filePath);
|
||
|
|
},
|
||
|
|
fail() {
|
||
|
|
return (new Error('ERROR_BASE64SRC_WRITE'));
|
||
|
|
},
|
||
|
|
});
|
||
|
|
};
|
||
|
|
const back = function(){
|
||
|
|
let pages = getCurrentPages();
|
||
|
|
if (pages.length>1){
|
||
|
|
wx.navigateBack({
|
||
|
|
delta: 1
|
||
|
|
})
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
wx.switchTab({
|
||
|
|
url: app.globalData.menuRoute
|
||
|
|
})
|
||
|
|
}
|
||
|
|
// if(pages<=1){
|
||
|
|
// wx.switchTab({
|
||
|
|
// url: app.globalData.menuRoute
|
||
|
|
// })
|
||
|
|
// }
|
||
|
|
// else {
|
||
|
|
// wx.navigateBack({
|
||
|
|
// delta: 1
|
||
|
|
// })
|
||
|
|
// }
|
||
|
|
}
|
||
|
|
const checkLocation = function(){
|
||
|
|
return new Promise((resolve,reject)=>{
|
||
|
|
wx.getSetting({
|
||
|
|
success: (res) => {
|
||
|
|
var statu = res.authSetting;
|
||
|
|
if (!statu['scope.userLocation']) { //没授权
|
||
|
|
wx.showModal({
|
||
|
|
title: '提示',
|
||
|
|
content: '需要获取您的地理位置,请确认授权',
|
||
|
|
confirmColor: '#f16765',
|
||
|
|
success: res => {
|
||
|
|
if (res.confirm) {
|
||
|
|
wx.openSetting({
|
||
|
|
success: data => {
|
||
|
|
if (data.authSetting["scope.userLocation"]) {
|
||
|
|
wx.getLocation({
|
||
|
|
type: 'gcj02',
|
||
|
|
success: function (res) {
|
||
|
|
resolve(res)
|
||
|
|
},
|
||
|
|
fail(){
|
||
|
|
reject()
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
reject()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
reject()
|
||
|
|
}
|
||
|
|
},
|
||
|
|
fail(){
|
||
|
|
reject()
|
||
|
|
}
|
||
|
|
})
|
||
|
|
} else { //已授权
|
||
|
|
//做一些事情...
|
||
|
|
console.log(res)
|
||
|
|
wx.getLocation({
|
||
|
|
type: 'gcj02',
|
||
|
|
success: function (res) {
|
||
|
|
resolve(res)
|
||
|
|
},
|
||
|
|
fail(){
|
||
|
|
reject()
|
||
|
|
}
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
})
|
||
|
|
}
|
||
|
|
module.exports = {
|
||
|
|
formatTime: formatTime,
|
||
|
|
formatNumber: formatNumber,
|
||
|
|
isTel: isTel,
|
||
|
|
setTitleBarColor: setTitleBarColor,
|
||
|
|
base64src: base64src,
|
||
|
|
back: back,
|
||
|
|
formatDate:formatDate,
|
||
|
|
checkLocation:checkLocation
|
||
|
|
}
|