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.

90 lines
1.8 KiB

import {
host
} from './config'
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}`
}
const http = (url, method, data, isLoading = true) => {
if (isLoading) {
wx.showLoading({
title: '加载中'
});
}
return new Promise(function (resolve, reject) {
if (url === '/user/login' || url === '/user/register') {
var header = {}
} else {
var header = {
'token': wx.getStorageSync('token')
}
}
// console.log(url)
// console.log(method)
wx.request({
url: host + url,
method: 'POST',
data: data,
header: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();
}
})
})
}
const lookup = (e) => {
console.log(e.type)
if (e.type === 1) {
wx.navigateTo({
url: '/pages/lookup/loockvideo/video',
})
wx.setStorage({
key: 'video',
data: e
})
} else {
wx.navigateTo({
url: '/pages/lookup/lookimg/img',
})
wx.setStorage({
key: 'article',
data: e
})
}
}
module.exports = {
formatTime,
http,
lookup
}