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.

106 lines
2.3 KiB

3 years ago
import {
host
} from './config'
3 years ago
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 formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
3 years ago
const http = (url, method, data, isLoading = true) => {
if (isLoading) {
wx.showLoading({
title: '加载中'
});
}
return new Promise(function (resolve, reject) {
3 years ago
if (url === '/user/login' || url === '/user/register') {
3 years ago
var header = {}
} else {
3 years ago
// wx.getStorage({
// key: 'token',
// success (res) {
// var token = res.data
// var header = {
// 'token': token
// }
// },
// fail(res) {
// if (res.errMsg === "getStorage:fail data not found"){
// wx.showToast({
// title: '未登录\r\n点击个人中心头像登录',
// icon: 'none',
// duration: 2000
// })
// }
// wx.hideLoading();
// },
// complete (res) {
// // console.log(res)
// }
// })
var header = {
'token': wx.getStorageSync('token')
}
3 years ago
}
3 years ago
console.log(url)
console.log(header)
3 years ago
wx.request({
url: host + url,
data: data,
method: method,
header,
success: res => {
if (isLoading) {
wx.hideLoading();
}
if (200 == res.data.code) {
resolve(res.data);
} else if (10008 === res.data.code && res.data.msg === "未注册!") {
resolve(res.data)
} else {
wx.showToast({
title: res.data.msg,
icon: 'none',
duration: 2000
})
}
},
fail: res => {
wx.hideLoading();
}
})
})
3 years ago
}
3 years ago
3 years ago
const lookup = (e) => {
// console.log(e)
if (e.type === 1) {
wx.navigateTo({
url: '/pages/lookup/loockvideo/video',
})
wx.setStorage({
key: 'video',
data: e
})
} else {
}
}
3 years ago
module.exports = {
formatTime,
3 years ago
http,
lookup
3 years ago
}