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.

94 lines
1.9 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(':')}`
3 years ago
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
3 years ago
const http = (url, method, data, isLoading = true) => {
3 years ago
if (false) {
3 years ago
wx.showLoading({
title: '加载中'
});
}
3 years ago
3 years ago
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
var header = {
'token': wx.getStorageSync('token')
}
3 years ago
}
wx.request({
url: host + url,
3 years ago
method: method,
3 years ago
data: data,
3 years ago
header: header,
3 years ago
success: res => {
wx.hideLoading();
3 years ago
console.log(res)
3 years ago
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
})
}
},
3 years ago
complete: res => {
wx.hideLoading();
console.log(res)
},
3 years ago
fail: res => {
3 years ago
console.log(res)
3 years ago
wx.hideLoading();
}
})
})
3 years ago
}
3 years ago
3 years ago
const lookup = (e) => {
3 years ago
console.log(e)
if (e.type === 1||e.teachRefeType === 1) {
3 years ago
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
})
3 years ago
}
}
3 years ago
module.exports = {
formatTime,
3 years ago
http,
3 years ago
lookup,
formatNumber
3 years ago
}