小小儁爺
2025-11-18 aab92bb255f1cbd758cb9d96a89bfc73133bfb4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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,
}