|
@@ -1,18 +1,18 @@
|
|
|
-const { $Message} = require('/component/iView/base/index');
|
|
|
+const { $Message} = require('/component/iView/base/index');
|
|
|
const md5 = require('./utils/md5.js');
|
|
|
-const secret= "117c0743819088468e590246464cc75e"
|
|
|
+const secret = "117c0743819088468e590246464cc75e"
|
|
|
+const {baseUrl} = require("./utils/util.js")
|
|
|
|
|
|
App({
|
|
|
globalData: {
|
|
|
- baseAPI: "https://edu.ndjsxh.cn:8443/weixin/",
|
|
|
- // baseAPI:"http://localhost:8000/weixin/",
|
|
|
pageSize: 10,
|
|
|
userInfo: {},
|
|
|
+ studyInfo: {},
|
|
|
},
|
|
|
- onLaunch: function() {
|
|
|
+ onLaunch: function () {
|
|
|
this.autoUpgrade()
|
|
|
},
|
|
|
- autoUpgrade: function(){
|
|
|
+ autoUpgrade: function () {
|
|
|
if (wx.canIUse('getUpdateManager')) {
|
|
|
const updateManager = wx.getUpdateManager()
|
|
|
updateManager.onCheckForUpdate(function (res) {
|
|
@@ -42,70 +42,90 @@ App({
|
|
|
})
|
|
|
}
|
|
|
},
|
|
|
- doLogin: function(cb){
|
|
|
+ gotoLogin: function(){
|
|
|
+ wx.navigateTo({
|
|
|
+ url: `/pages/user/identify/index`,
|
|
|
+ })
|
|
|
+ },
|
|
|
+ checkLogin: function (cb) {
|
|
|
let _this = this
|
|
|
- wx.login({
|
|
|
- success(wxres) {
|
|
|
- if (wxres.code) {
|
|
|
- _this.formPost('Auth.wxLogin', {
|
|
|
- "code": wxres.code
|
|
|
- }).then(res => {
|
|
|
- if (res.code == 200) {
|
|
|
- _this.setUserInfo( res.data )
|
|
|
- cb && cb( res.data );
|
|
|
- } else if (res.code == 401) {
|
|
|
- wx.reLaunch({
|
|
|
- url: '/pages/user/register/index',
|
|
|
- });
|
|
|
- } else {
|
|
|
- _this.message(res.message, 'error')
|
|
|
- }
|
|
|
- }).catch(e => {
|
|
|
- _this.message(e, 'error')
|
|
|
- })
|
|
|
- } else {
|
|
|
- _this.message(res.errMsg, 'error')
|
|
|
- }
|
|
|
+ let openid = wx.getStorageSync('@openid');
|
|
|
+ if( !openid ) {
|
|
|
+ cb&&cb({})
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let param = {"openid": openid};
|
|
|
+ _this.formPost('Auth.wxLogin', param).then( res =>{
|
|
|
+ if (res.code == 200) {
|
|
|
+ _this.setUserInfo(res.data);
|
|
|
}
|
|
|
+ cb && cb(res.data);
|
|
|
})
|
|
|
-
|
|
|
},
|
|
|
- message: function(content, type) {
|
|
|
+ message: function (content, type="info") {
|
|
|
$Message({
|
|
|
content: content,
|
|
|
type: type
|
|
|
});
|
|
|
},
|
|
|
- reLogin( cb ){
|
|
|
- this.globalData.userInfo = {};
|
|
|
- this.checkLogin( cb )
|
|
|
- },
|
|
|
- checkLogin: function(cb){
|
|
|
- let userInfo = this.globalData.userInfo;
|
|
|
- if (!userInfo || !userInfo.token) {
|
|
|
- this.doLogin( cb )
|
|
|
- }else{
|
|
|
- cb&&cb( userInfo )
|
|
|
- }
|
|
|
- },
|
|
|
- formPost: function(action, data) {
|
|
|
+ formPost: function (action, data) {
|
|
|
let _this = this
|
|
|
- const token = wx.getStorageSync('token')
|
|
|
- const user_id = wx.getStorageSync('userId')||""
|
|
|
- let timestamp = Date.now()
|
|
|
- action = action.toLowerCase()
|
|
|
- let signstr=`weixin_${token}_${action}_${timestamp}_${secret}`
|
|
|
- let signsure = md5.md5( signstr ).toLowerCase()
|
|
|
+ let userInfo = this.globalData.userInfo||{}
|
|
|
+ let user_id = userInfo.uid||0;
|
|
|
+ let token = userInfo.token||'';
|
|
|
+ console.log( userInfo );
|
|
|
+ let timestamp = Date.now()
|
|
|
+ action = action.toLowerCase()
|
|
|
+ let signstr = `weixin_${token}_${action}_${timestamp}_${secret}`
|
|
|
+ let signsure = md5.md5(signstr).toLowerCase()
|
|
|
let headers = {
|
|
|
'Content-Type': 'application/json',
|
|
|
'x-signsure': signsure,
|
|
|
'x-timestamp': timestamp,
|
|
|
'x-userId': user_id
|
|
|
}
|
|
|
- return new Promise(function(resolve, reject) {
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
wx.showNavigationBarLoading();
|
|
|
wx.request({
|
|
|
- url: _this.globalData.baseAPI + action,
|
|
|
+ url: `${baseUrl}weixin/${action}`,
|
|
|
+ header: headers,
|
|
|
+ method: 'POST',
|
|
|
+ data,
|
|
|
+ success(res) {
|
|
|
+ if (res.statusCode !== 200 || typeof res.data !== 'object') {
|
|
|
+ reject('网络出错')
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ resolve(res.data);
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ reject(res.msg)
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ complete(res) {
|
|
|
+ wx.hideNavigationBarLoading();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ studyPost: function (action, data) {
|
|
|
+ let {token, uid } = this.globalData.userInfo.studyUser;
|
|
|
+ let version = "1.0"
|
|
|
+ let _this = this
|
|
|
+ let mtime = parseInt(Date.now() / 1000)
|
|
|
+ action = action.toLowerCase()
|
|
|
+ let body = JSON.stringify(data);
|
|
|
+ let signstr = `hall_${version}${token}${body}${action}${mtime}${secret}`
|
|
|
+ let sign = md5.md5(signstr).toLowerCase()
|
|
|
+ let headers = {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ }
|
|
|
+ let studyUrl = `${baseUrl}rental/${method}?t=${mtime}&u=${uid}&v=${version}&s=${sign}`
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ wx.showNavigationBarLoading();
|
|
|
+ wx.request({
|
|
|
+ url: studyUrl,
|
|
|
header: headers,
|
|
|
method: 'POST',
|
|
|
data,
|
|
@@ -127,9 +147,43 @@ App({
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
- setUserInfo:function(userInfo){
|
|
|
+ getUserInfo: function ( cb ) {
|
|
|
+ let userInfo = this.globalData.userInfo
|
|
|
+ if( userInfo && userInfo.token ){
|
|
|
+ cb && cb( userInfo);
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let openid = wx.getStorageSync('@openid');
|
|
|
+ // let openid="oG3Fi5ait37qL-3edzAkzysH5apU"
|
|
|
+ if( !openid ) {
|
|
|
+ cb && cb({});
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let param = {"openid": openid};
|
|
|
+ this.formPost('Auth.wxLogin', param).then( res =>{
|
|
|
+ if (res.code == 200) {
|
|
|
+ this.setUserInfo(res.data);
|
|
|
+ }
|
|
|
+ cb && cb(res.data||{});
|
|
|
+ })
|
|
|
+ },
|
|
|
+ getStudyInfo: function () {
|
|
|
+ return this.globalData.studyInfo;
|
|
|
+ },
|
|
|
+ getSystemInfo( cb ){
|
|
|
+ wx.getSystemInfo({
|
|
|
+ success: function(res) {
|
|
|
+ cb &&cb( res.system )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ checkNavigateTo: function(url){
|
|
|
+ let openid = wx.getStorageSync('@openid');
|
|
|
+ if( !openid ) return this.gotoLogin()
|
|
|
+ wx.navigateTo({url})
|
|
|
+ },
|
|
|
+ setUserInfo: function (userInfo) {
|
|
|
this.globalData.userInfo = userInfo;
|
|
|
- wx.setStorageSync('token', userInfo.token )
|
|
|
- wx.setStorageSync('userId', userInfo.userId)
|
|
|
+ wx.setStorageSync('@openid', userInfo.openid)
|
|
|
}
|
|
|
})
|