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.
93 lines
2.3 KiB
93 lines
2.3 KiB
import { WX_API, H5_API, httpPrefix } from './site.config.js';
|
|
var _url = H5_API+ WX_API + httpPrefix
|
|
|
|
import store from '@/store/index.js'
|
|
|
|
export function checkToken(vm) {
|
|
let expiresTime = vm.$store.state.user.vuex_loginInfo.expiresTime
|
|
let nowTime = new Date() * 1
|
|
// console.log('超时了')
|
|
// console.log(expiresTime)
|
|
if (nowTime > expiresTime * 1) {
|
|
vm.$store.commit('goLogin')
|
|
// 如果小于20分钟就刷新一下token &&
|
|
} else if ((expiresTime * 1 - nowTime) / 60000 <5) {
|
|
vm.$store.dispatch('refreshToken')
|
|
}
|
|
}
|
|
|
|
function dateRangeFn(dateRange) {
|
|
let tmp = []
|
|
let dateArr = []
|
|
dateRange.forEach((date) => {
|
|
let dateStr = date.toISOString().split('T')[0]
|
|
let dd = dateStr.split('-')[2]
|
|
const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
|
|
const dayOfWeek = date.getDay();
|
|
const weekName = daysOfWeek[dayOfWeek];
|
|
// console.log(dateStr)
|
|
// console.log(weekName)
|
|
if (tmp.length == 0) {
|
|
dateArr.push(tmp)
|
|
}
|
|
let obj = {
|
|
week: weekName,
|
|
num: dd,
|
|
date: dateStr
|
|
}
|
|
tmp.push(obj)
|
|
if (tmp.length == 5) {
|
|
tmp = []
|
|
}
|
|
});
|
|
// console.log(dateArr)
|
|
return dateArr
|
|
}
|
|
|
|
export function getDates(startDate, endDate) {
|
|
const dates = [];
|
|
let currentDate = new Date(startDate);
|
|
|
|
while (currentDate <= endDate) {
|
|
dates.push(new Date(currentDate));
|
|
currentDate.setDate(currentDate.getDate() + 1);
|
|
}
|
|
return dateRangeFn(dates)
|
|
}
|
|
|
|
export function uploadImgApi(filePath, imgName, imgLink='image') {
|
|
console.log(filePath)
|
|
let token = 'Bearer '+ store.state.user.vuex_loginInfo.accessToken
|
|
let timer = new Date() * 1
|
|
return new Promise((reslove, reject)=>{
|
|
// 上传图片到服务器
|
|
uni.uploadFile({
|
|
url: _url + 'infra/file/upload',//接口
|
|
filePath: filePath,//要上传的图片的本地路径
|
|
name: 'file',
|
|
// complain
|
|
formData: {
|
|
path: imgLink+'/'+ uni.$u.date(timer, 'yyyy-mm-dd')+'/'+timer + '-'+ imgName,
|
|
type: 1,
|
|
fileSuffix: "png"
|
|
},
|
|
header: {
|
|
Authorization: token,
|
|
// 'tenant-id': '1704459882232553474'
|
|
},
|
|
success(res) {
|
|
console.log('上传成功??')
|
|
console.log(res)
|
|
let res2 = JSON.parse(res.data)
|
|
reslove(res2.data)
|
|
|
|
},
|
|
fail() {
|
|
reject(0)
|
|
},
|
|
complete: (err)=> {
|
|
uni.hideLoading();
|
|
}
|
|
})
|
|
})
|
|
}
|