|
|
//app.js
|
|
|
App({
|
|
|
onLaunch: function () {
|
|
|
onLaunch: function() {
|
|
|
// 展示本地存储能力
|
|
|
var logs = wx.getStorageSync('logs') || []
|
|
|
logs.unshift(Date.now())
|
...
|
...
|
@@ -8,18 +8,32 @@ App({ |
|
|
// 获取用户信息
|
|
|
console.log(111)
|
|
|
|
|
|
// 添加显示条数
|
|
|
|
|
|
// wx.setTabBarItem({
|
|
|
// index: 4,
|
|
|
// text: '1',
|
|
|
// // iconPath: 'images/index1.png',
|
|
|
// // selectedIconPath: 'images/index1.png'
|
|
|
// })
|
|
|
},
|
|
|
changeToken() {
|
|
|
let url = '/api/user/codeToToken', t = this;
|
|
|
let url = '/api/user/codeToToken',
|
|
|
t = this;
|
|
|
wx.login({
|
|
|
success: function (res) {
|
|
|
t.post(url, { code: res.code }).then((r) => {
|
|
|
success: function(res) {
|
|
|
t.post(url, {
|
|
|
code: res.code
|
|
|
}).then((r) => {
|
|
|
wx.setStorageSync('token', r.userInfo.token)
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
post: function (url, data, showLoad) {
|
|
|
|
|
|
|
|
|
post: function(url, data, showLoad) {
|
|
|
let app = this;
|
|
|
/**
|
|
|
* 自定义post函数,返回Promise
|
|
|
* +-------------------
|
...
|
...
|
@@ -28,54 +42,62 @@ App({ |
|
|
* +-------------------
|
|
|
* @return {Promise} promise 返回promise供后续操作
|
|
|
*/
|
|
|
(showLoad == undefined || showLoad)?
|
|
|
(showLoad == undefined || showLoad) ?
|
|
|
wx.showLoading({
|
|
|
title: '加载中',
|
|
|
})
|
|
|
:''
|
|
|
}): ''
|
|
|
wx.showNavigationBarLoading()
|
|
|
var promise = new Promise((resolve, reject) => {
|
|
|
//init
|
|
|
let that = this,token=wx.getStorageSync('token'),header={
|
|
|
let that = this,
|
|
|
token = wx.getStorageSync('token'),
|
|
|
header = {
|
|
|
'content-type': 'application/x-www-form-urlencoded',
|
|
|
'token': token||''
|
|
|
},postData;
|
|
|
data.header ? (token ? (header['token'] = token, delete data.header):setTimeout(()=>{
|
|
|
'token': token || ''
|
|
|
},
|
|
|
postData;
|
|
|
data.header ? (token ? (header['token'] = token, delete data.header) : setTimeout(() => {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/register/register',
|
|
|
})
|
|
|
},1100)):""
|
|
|
}, 1100)) : ""
|
|
|
//网络请求
|
|
|
wx.request({
|
|
|
url: this.globalData.baseUrl + url,
|
|
|
data: data,
|
|
|
method: 'POST',
|
|
|
header: header,
|
|
|
success: function (res) {//返回取得的数据
|
|
|
success: function(res) { //返回取得的数据
|
|
|
if (res.data.code == '1') {
|
|
|
resolve(res.data.data);
|
|
|
} else if (res.data.code == '201') {
|
|
|
resolve(res.data);
|
|
|
}else {
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
title: res.data.msg,
|
|
|
icon:'none',
|
|
|
icon: 'none',
|
|
|
})
|
|
|
reject(res.data)
|
|
|
if (res.data.code == '401'){
|
|
|
setTimeout(()=>{
|
|
|
if (res.data.code == '401') {
|
|
|
console.log(app.globalData.register)
|
|
|
if (!app.globalData.register){
|
|
|
setTimeout(() => {
|
|
|
wx.navigateTo({
|
|
|
url: '/pages/register/register',
|
|
|
})
|
|
|
},1200)
|
|
|
}, 1200)
|
|
|
app.globalData.register = 1
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
(showLoad || showLoad == undefined) ? wx.hideLoading() : "";
|
|
|
(showLoad || showLoad == undefined) ? wx.hideLoading(): "";
|
|
|
wx.hideNavigationBarLoading()
|
|
|
},
|
|
|
fail: function (e) {
|
|
|
fail: function(e) {
|
|
|
reject('网络出错');
|
|
|
(showLoad || showLoad == undefined) ? wx.hideLoading() : "";
|
|
|
(showLoad || showLoad == undefined) ? wx.hideLoading(): "";
|
|
|
wx.hideNavigationBarLoading()
|
|
|
}
|
|
|
})
|
...
|
...
|
@@ -85,7 +107,7 @@ App({ |
|
|
timeFormate(timestamp, timeType) {
|
|
|
if (timestamp) {
|
|
|
var timeStamp = timestamp.length == 13 ? timestamp : timestamp * 1000
|
|
|
var date = new Date(timeStamp);//时间戳为10位需*1000,时间戳为13位的话不需乘1000
|
|
|
var date = new Date(timeStamp); //时间戳为10位需*1000,时间戳为13位的话不需乘1000
|
|
|
var Y = date.getFullYear() + '-';
|
|
|
var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
|
|
|
var D = date.getDate() + ' ';
|
...
|
...
|
@@ -103,6 +125,6 @@ App({ |
|
|
},
|
|
|
globalData: {
|
|
|
userInfo: null,
|
|
|
baseUrl:'https://txgyy.jjjtech.cn/'
|
|
|
baseUrl: 'https://txgyy.jjjtech.cn',
|
|
|
}
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|