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.
200 lines
5.7 KiB
200 lines
5.7 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 time = se => {
|
|
// console.log(se)
|
|
if (se === null) {
|
|
return ''
|
|
}
|
|
var minutes = parseInt(se / (1000 * 60));
|
|
if (minutes < 10) {
|
|
minutes = '0' + minutes
|
|
}
|
|
var seconds = parseInt((se % (1000 * 60)) / 1000);
|
|
if (seconds < 10) {
|
|
seconds = '0' + seconds
|
|
}
|
|
// console.log(minutes + " 分钟 " + seconds + " 秒 ")
|
|
return minutes + ':' + seconds
|
|
}
|
|
|
|
const formatNumber = n => {
|
|
n = n.toString()
|
|
return n[1] ? n : `0${n}`
|
|
}
|
|
|
|
const http = (url, method, data, isLoading = true) => {
|
|
if (false) {
|
|
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')
|
|
}
|
|
}
|
|
wx.request({
|
|
url: host + url,
|
|
method: method,
|
|
data: data,
|
|
header: header,
|
|
success: res => {
|
|
wx.hideLoading();
|
|
if (200 == res.data.code) {
|
|
resolve(res.data);
|
|
} else if (10008 === res.data.code && res.data.msg === "未注册!") {
|
|
resolve(res.data)
|
|
} else if (10010 === res.data.code) {
|
|
wx.login({
|
|
success: res => {
|
|
http("/user/login", "post", {
|
|
code: res.code
|
|
}).then(res => {
|
|
if (res.msg === "未注册!") {
|
|
wx.getSystemInfo({
|
|
success(res) {
|
|
if (res.environment) {
|
|
// 企业微信环境
|
|
this.getUserProfile()
|
|
} else {
|
|
// 微信·环境
|
|
wx.showToast({
|
|
title: '初次打开请在企业微信中',
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
getApp().globalData.token = res.data.token
|
|
wx.setStorage({
|
|
key: 'user',
|
|
data: res.data.user
|
|
})
|
|
wx.setStorage({
|
|
key: 'token',
|
|
data: res.data.token
|
|
})
|
|
if (res.data.user.departmentName === '' || res.data.user.departmentName === null) {
|
|
wx.getSystemInfo({
|
|
success(res) {
|
|
if (res.environment) {
|
|
// 企业微信环境
|
|
wx.qy.login({
|
|
success: function (res) {
|
|
http("/qywx/userDepartmentRefresh", "post", {
|
|
code: res.code
|
|
}).then(res => {
|
|
console.log(res)
|
|
if (res.success) {
|
|
wx.showToast({
|
|
title: '刷新成功',
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
this.userlogin()
|
|
} else {}
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
// 微信·环境
|
|
wx.showToast({
|
|
title: '请在企业微信中打开\r\n以获取企业架构',
|
|
icon: 'none',
|
|
duration: 3000
|
|
})
|
|
}
|
|
}
|
|
})
|
|
} else {
|
|
wx.getSystemInfo({
|
|
success(res) {
|
|
if (res.environment) {
|
|
// 企业微信环境
|
|
wx.qy.login({
|
|
success: function (res) {
|
|
http("/qywx/userDepartmentRefresh", "post", {
|
|
code: res.code
|
|
}).then(res => {
|
|
console.log(res)
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
// 微信·环境
|
|
}
|
|
}
|
|
})
|
|
}
|
|
}
|
|
http(url, method, data, isLoading = true).then(res => {
|
|
console.log(res)
|
|
})
|
|
})
|
|
}
|
|
})
|
|
} else {
|
|
wx.showToast({
|
|
title: res.data.msg,
|
|
icon: 'none',
|
|
duration: 2000
|
|
})
|
|
resolve(res.data)
|
|
}
|
|
},
|
|
complete: res => {
|
|
wx.hideLoading();
|
|
},
|
|
fail: res => {
|
|
wx.hideLoading();
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
const lookup = (e) => {
|
|
console.log(e)
|
|
if (e.type === 1 || e.teachRefeType === 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,
|
|
formatNumber,
|
|
time
|
|
} |