import {
|
AppTicketSelect,
|
} from '../../config/api.js';
|
import Vue from 'vue'
|
import axios from 'axios'
|
|
// 格式化地址栏参数 将对象自动拼接成地址栏传参形式
|
function formatData(data) {
|
let temp = ''
|
Object.keys(data).map((key, index) => {
|
temp += '&' + key + '=' + data[key]
|
})
|
let firstCharAt = temp.charAt(0)
|
temp = temp.replace(firstCharAt, '?')
|
return temp;
|
}
|
|
// 时间处理函数 年月日
|
function handleDatetime(value) {
|
const data = new Date(value)
|
const month = data.getMonth() < 9 ? '0' + (data.getMonth() + 1) : data.getMonth() + 1
|
const date = data.getDate() <= 9 ? '0' + data.getDate() : data.getDate()
|
return data.getFullYear() + '-' + month + '-' + date
|
}
|
|
// 获取当前时间
|
export function handleDatetime2(value) {
|
const dt = new Date(value)
|
const wk = dt.getDay()
|
const y = dt.getFullYear()
|
const m = (dt.getMonth() + 1 + '').padStart(2, '0')
|
const d = (dt.getDate() + '').padStart(2, '0')
|
|
const hh = (dt.getHours() + '').padStart(2, '0')
|
const mm = (dt.getMinutes() + '').padStart(2, '0')
|
const ss = (dt.getSeconds() + '').padStart(2, '0')
|
const weeks = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
|
const week = weeks[wk]
|
|
// return `${y}-${m}-${d} ${hh}:${mm}:${ss} ${week}`
|
return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
|
}
|
|
// 获取token 用于请求畅捷通接口
|
async function getTPlusToken() {
|
|
const r1 = await AppTicketSelect()
|
const r2 = r1.data[0]
|
Vue.prototype.$AppKey = r2.appKey
|
Vue.prototype.$AppSecret = r2.appSecret
|
const data = {
|
appTicket: r2.AppTicket,
|
certificate: r2.certificate
|
}
|
const headers = {
|
'appKey': Vue.prototype.$AppKey,
|
'appSecret': Vue.prototype.$AppSecret,
|
'Content-Type': 'application/json'
|
}
|
|
return await new Promise((resolve, reject) => {
|
uni.request({
|
url: Vue.prototype.$chanjetBaseUrl +
|
'/v1/common/auth/selfBuiltApp/generateToken',
|
data: data,
|
method: 'POST',
|
header: headers,
|
success: (res) => {
|
console.log(res.data.value)
|
resolve(res.data.value.accessToken)
|
},
|
fail: (err) => {
|
console.log('失败了')
|
// resolve('err')
|
}
|
});
|
})
|
|
}
|
|
|
module.exports = {
|
getTPlusToken,
|
formatData,
|
handleDatetime,
|
handleDatetime2,
|
}
|