货无忧
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.
 
 
 
 
 

181 lines
3.6 KiB

import {
checkIDCard_province,
checkIDCard_birthday,
checkParity
} from './IDCardVerification.js';
// import qq from '@/utils/qqmap-wx-jssdk.min.js'
// import QQMapWX from './qqmap-wx-jssdk.min.js';
// import QQMapWX from './qqmap-wx-jssdk.min.js';
// const QQMapWX=require('./qqmap-wx-jssdk.min.js')
// import * as QQMapwx from '@/utils/qqmap-wx-jssdk.min.js'
// var qqmapsdk;
import base64 from '@/utils/base64.js';
import { imghost,host,APPKEY } from '@/config/host.js'
const api = {
loginModalState: true,
getloctiontime(){
uni.request({
url:'https://restapi.amap.com/v5/direction/driving',
method:'POST',
data:{
key:'高德地图KEY',
origin:'', //起点经纬度
destination:'', //终点经纬度
waypoints:'',//途经点
show_fields:'cost',
},
success(res) {
console.log(res);
}
})
},
urlToObj:(url)=>{
let obj = {}
let str = url.slice(url.indexOf('?') + 1)
let arr = str.split('&')
for (let j = arr.length, i = 0; i < j; i++) {
let arr_temp = arr[i].split('=')
obj[arr_temp[0]] = arr_temp[1]
}
return obj
},
upfile:(file)=>{
console.log(file);
return new Promise((relove, reject) => {
uni.showLoading({
title:'上传中'
})
let header={}
let token=uni.getStorageSync('access_token')
header['Blade-Auth']=`bearer ${token}`
header.Authorization=`Basic ${base64.encode(APPKEY)}`
uni.uploadFile({
url: `${host}blade-resource/oss/endpoint/put-file`,
filePath:file,
name: 'file',
header,
success: (uploadFileRes) => {
uni.hideLoading()
relove(JSON.parse(uploadFileRes.data).data)
// console.log(JSON.parse(uploadFileRes.data).data);
}
});
})
},
imgurl:(url)=>{
if(url){
if(url.indexOf('http')==-1){
return imghost+url
}else{
return url
}
}else{
return ''
}
},
/**
* 失败
*/
error: (msg) => {
return new Promise((relove, reject) => {
uni.showToast({
title: msg,
icon: "none",
duration:2000
})
setTimeout(() => {
relove();
}, 2000)
})
},
/**
* 成功提示
*/
success: (msg) => {
return new Promise((relove, reject) => {
uni.showToast({
title: msg,
icon: "success",
duration:2000
})
setTimeout(() => {
relove();
}, 2000)
})
},
/**
* 确认对话框
* @param {Object} contents
* @param {Object} callback
*/
confirm: (contents) => {
return new Promise((relove, reject) => {
uni.showModal({
title: '提示',
content: contents,
success: function(res) {
if (res.confirm) {
relove();
}
}
});
})
},
payment: (param) => {
return new Promise((relove, reject) => {
uni.requestPayment({
provider: 'wxpay',
timeStamp: param.timeStamp,
nonceStr: param.nonceStr,
package: param.package,
signType: param.signType,
paySign: param.paySign,
success: function(res) {
relove(res);
},
fail: function(err) {
console.log(err);
// relove(err);
api.error("支付失败");
}
});
})
},
checkFormat_IDCardNumber: (idCardNumber) => {
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (idCardNumber == "") {
return false;
} //校验长度,类型
else if (reg.test(idCardNumber) === false) {
console.log("错误1");
return false;
} else if (checkIDCard_province(idCardNumber) === false) {
console.log("错误2");
//校验省份
return false;
} else if (checkIDCard_birthday(idCardNumber) === false) {
console.log("错误3");
//校验生日
return false;
} else if (checkParity(idCardNumber) === false) {
console.log("错误4");
//检验位的检测
return false;
}
return true;
}
}
export default api;