diff --git a/app.js b/app.js index 25c6969..d53c374 100644 --- a/app.js +++ b/app.js @@ -1,16 +1,22 @@ let config = require("./config/config.js"); const Http = require("./utils/HttpBasics"); +const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {} App({ data: {}, onLaunch: function (options) { - console.log("onUnload ") var that = this; + console.log("onLuanch") that.globalData.sceneAddress = options.scene; - + /** + * 用户登录 + */ + that.userLogin(options.scene); + /** + * 小程序版本更新 + */ if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager() updateManager.onCheckForUpdate(function (res) { - console.log('onCheckForUpdate====', res) // 请求完新版本信息的回调 if (res.hasUpdate) { console.log('res.hasUpdate====') @@ -39,11 +45,65 @@ App({ }) } }, + /** + * 用户登录 + */ + userLogin: function (sceneAddress) { + let that = this; + // 登录 + wx.login({ + success: ({ + code + }) => { + let usrdata = { + appId: config.weapp.AppId, + code: code, + sceneAddress: sceneAddress + } + Http.post({ + url: config.api.login, + data: usrdata + }) + .then(res => { + if (res.data && res.data.score) { + if (res.data.score != 0) { + that.globalData.score = res.data.score; + } + } + Http.setToken(res.data.token); + that.globalData.token = res.data.token; + console.log(that.globalData.token) + + if (that.tokenCallback) { + that.tokenCallback(res.data.token); + } + }) + .catch(err => { + console.log(err) + wx.showModal({ + title: '提示', + showCancel: false, + content: '登录失败,请重新尝试', + success: function (res) { + if (res.cancel) { + //点击取消,默认隐藏弹框 + } else { + //点击确定 + wx.reLaunch({ + url: '/pages/index/index', + }) + } + } + }) + }) + } + }) + }, /** * 获取地址位置信息 */ getLocation: function () { - var that = this + var that = this; wx.getLocation({ type: "wgs84", success: function (res) { diff --git a/pages/coupon/detail/index.js b/pages/coupon/detail/index.js index ba6e945..b3ce745 100644 --- a/pages/coupon/detail/index.js +++ b/pages/coupon/detail/index.js @@ -266,6 +266,9 @@ Page({ }, gotopay: function(e) { let that = this; + wx.showLoading({ + title: '', + }) if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50){ wx.navigateTo({ url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId, @@ -285,7 +288,7 @@ Page({ } }) .then(res => { - console.log(res); + wx.hideLoading(); if (res.data == undefined) { that.orderFunc(discount); that.setData({ @@ -307,6 +310,7 @@ Page({ } }) .catch(err => { + wx.hideLoading(); wx.showToast({ title: err.message, icon: 'none', @@ -651,7 +655,7 @@ Page({ }); }) .catch(err => { - console.log(err); + wx.hideLoading() that.setData({ showbutton: false, showbutton1: false @@ -806,6 +810,7 @@ Page({ } }, fail: res => { + wx.hideLoading(); /** * 支付失败,需要更新订单的状态 */ @@ -820,6 +825,7 @@ Page({ /// End payment -------- }) .catch(err => { + wx.hideLoading(); wx.showToast({ title: err.message, icon: 'none', diff --git a/pages/discountCardList/discountCardList.js b/pages/discountCardList/discountCardList.js index 795cb79..f23d531 100644 --- a/pages/discountCardList/discountCardList.js +++ b/pages/discountCardList/discountCardList.js @@ -46,11 +46,11 @@ Page({ this.setData({ paramData:options },function(){ - this.userLogin() + // this.userLogin() }) } }, - //点击跳转到券详情页面 + //点击跳转到卡详情页面 gotouse: function (e) { console.log(e.currentTarget.dataset.couponid) wx.navigateTo({ @@ -156,70 +156,70 @@ Page({ /** * 用户登录 */ - userLogin: function () { - var that = this; - // 登录 - wx.login({ - success: ({ - code - }) => { - wx.getSystemInfo({ - success: function (res) { - that.setData({ - systemInfo: JSON.stringify(res) - }) - } - }) - var usrdata = { - appId: config.weapp.AppId, - code: code, - sceneAddress: app.globalData.sceneAddress, - scene: that.data.scene, - systemInfo: that.data.systemInfo - }; - if (app.globalData.locationInfo) { - usrdata = { - appId: config.weapp.AppId, - code: code, - sceneAddress: app.globalData.sceneAddress, - latitude: "" + app.globalData.locationInfo.latitude, - longitude: "" + app.globalData.locationInfo.longitude, - scene: that.data.scene, - systemInfo: that.data.systemInfo - }; - } - Http.post({ - url: config.api.login, - data: usrdata - }) - .then(res => { - that.setData({ - showPages: true - }) - app.globalData.token = res.data.token; - Http.setToken(res.data.token); - that.checkuerstatus(); - }) - .catch(err => { - wx.showModal({ - title: '提示', - showCancel: false, - content: '登录失败,请重新尝试', - success: function (res) { - if (res.cancel) { - //点击取消,默认隐藏弹框 - } else { - //点击确定 - wx.reLaunch({ - url: '/pages/index/index', - }) - } - } - }) - }); - } - }); - }, + // userLogin: function () { + // var that = this; + // // 登录 + // wx.login({ + // success: ({ + // code + // }) => { + // wx.getSystemInfo({ + // success: function (res) { + // that.setData({ + // systemInfo: JSON.stringify(res) + // }) + // } + // }) + // var usrdata = { + // appId: config.weapp.AppId, + // code: code, + // sceneAddress: app.globalData.sceneAddress, + // scene: that.data.scene, + // systemInfo: that.data.systemInfo + // }; + // if (app.globalData.locationInfo) { + // usrdata = { + // appId: config.weapp.AppId, + // code: code, + // sceneAddress: app.globalData.sceneAddress, + // latitude: "" + app.globalData.locationInfo.latitude, + // longitude: "" + app.globalData.locationInfo.longitude, + // scene: that.data.scene, + // systemInfo: that.data.systemInfo + // }; + // } + // Http.post({ + // url: config.api.login, + // data: usrdata + // }) + // .then(res => { + // that.setData({ + // showPages: true + // }) + // app.globalData.token = res.data.token; + // Http.setToken(res.data.token); + // that.checkuerstatus(); + // }) + // .catch(err => { + // wx.showModal({ + // title: '提示', + // showCancel: false, + // content: '登录失败,请重新尝试', + // success: function (res) { + // if (res.cancel) { + // //点击取消,默认隐藏弹框 + // } else { + // //点击确定 + // wx.reLaunch({ + // url: '/pages/index/index', + // }) + // } + // } + // }) + // }); + // } + // }); + // }, checkuerstatus(){ Http.get({ url: config.api.checkPhoneStatus, diff --git a/pages/index/index.js b/pages/index/index.js index 9001909..8e5a6c7 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -11,8 +11,13 @@ Page({ /** * 生命周期函数--监听页面加载 */ - onLoad: function (options) { + onLoad: function(options) { let that = this; + wx.showToast({ + title: '加载中', + icon: "loading", + duration: 2000 + }) /** * 根据接收到的参数的值,判断跳转到哪个页面 */ @@ -22,7 +27,7 @@ Page({ if (decodeURIComponent(options.scene) == "undefined") { that.setData({ scene: 0 - }); + }) } else { that.setData({ scene: decodeURIComponent(options.scene) @@ -30,7 +35,6 @@ Page({ that.setData({ newArr: this.data.scene.split(':') }) - console.log(this.data.newArr) //// 大屏-二维码-start if (this.data.newArr[0] == 'JC') { // 跳转券详情 @@ -39,12 +43,11 @@ Page({ // 跳转拼团详情 options.couponChannelId = this.data.newArr[1]; options.path = 'daping' - } - else if (this.data.newArr[0] == 't') { + } else if (this.data.newArr[0] == 't') { // 普通二维码 options.type = this.data.newArr[1]; app.globalData.type = options.type; - if(options.type == 'cd') { + if (options.type == 'cd') { options.couponChannelId = this.data.newArr[2]; } else if (options.type == 'bd') { options.bt = this.data.newArr[2]; @@ -59,28 +62,49 @@ Page({ } } } - wx.showToast({ - title: '加载中', - icon: "loading", - duration: 2000 - }) + wx.setStorageSync('options', JSON.stringify(options)) wx.setStorageSync('imgurl', imgurl) - app.getLocation(); - if (options.couponChannelId || options.orderId || options.id) { - that.userLogin(options); + + // app.getLocation(); + if (app.globalData.token) { + if (options.couponChannelId || options.orderId || options.id) { + that.userStatus(options); + } else { + that.userStatus(); + } + } else { + // 由于 token 是网络请求,可能会在 Page.onLoad 之后才返回 + // 所以此处加入 callback 以防止这种情况 + app.tokenCallback = token => { + if (options.couponChannelId || options.orderId || options.id) { + that.userStatus(options); + } else { + that.userStatus(); + } + } } }, - onShow(){ - let that = this; - that.userLogin(); - console.log("onshow-----------------------------------login") + + /** + * 检查用户的状态 + */ + userStatus: function(options) { + var that = this; + if (options && (options.couponChannelId || options.orderId || options.id)) { + that.checkuserstatus(options); + } else { + that.checkuserstatus(); + } }, + checkuserstatus(options) { - let that = this; - Http.get({ + let that = this; + Http.get({ url: config.api.checkUserStatus, - data: {} + data: { + token:app.globalData.token + } }) .then(res => { //参与拼团 @@ -88,7 +112,6 @@ Page({ wx.redirectTo({ url: `/pages/joinFrDpell/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}` }) - return; } //来自大屏的跳转拼团券详情 else if (options && options.couponChannelId && options.path == 'daping') { @@ -105,33 +128,30 @@ Page({ wx.redirectTo({ url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}&couponId=${data.couponId}` }) - }); - return; - } - - else if (options && options.couponChannelId && !options.spellGroup) { - // 转赠判断 - if (options.cuserId){ + }) + } else if (options && options.couponChannelId && !options.spellGroup) { + // 转赠判断 + if (options.cuserId) { wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}`, }) - }else{ + } else { // 跳转普通券/消费卡/限时秒杀/砍价详情 wx.redirectTo({ url: `/pages/coupon/detail/index?couponChannelId=${options.couponChannelId}`, }) } - } + } // 拼团详情页(只有通过扫码进入才可能进入拼团详情页面,只有这一个入口) else if (options && options.couponChannelId && app.globalData.type == 'sd' || options && options.couponChannelId && options.spellGroup) { wx.redirectTo({ url: `/pages/spellGroup/mySpellGroup/index?couponChannelId=${options.couponChannelId}`, }) - } + } // 游戏页面 else if (options && options.id && app.globalData.type == 'gm') { that.getGameOne(app.globalData.token, options.id) - } + } // 宣传页详情 else if (options && options.bt && options.id && app.globalData.type == 'bd') { if (options.bt == '2') { @@ -145,13 +165,13 @@ Page({ url: `/pages/bannerdetail/index?id=${options.id}`, }) } - } + } // 专题 - else if (options && options.id && app.globalData.type == 'td'){ + else if (options && options.id && app.globalData.type == 'td') { wx.redirectTo({ url: `/pages/topicDetail/index?id=${options.id}` }); - } + } // 参与砍价 else if (options && options.orderId) { wx.redirectTo({ @@ -163,117 +183,117 @@ Page({ wx.switchTab({ url: '/pages/user/index' }); - } + } // 积分 else if (app.globalData.type == 'jf') { wx.redirectTo({ url: '/pages/integralmall/index' }); - } + } // 首页 else if (app.globalData.type == 'in') { wx.switchTab({ url: '/pages/main/index' }); - } + } // 停车 else if (app.globalData.type == 'pc') { // 停车 wx.switchTab({ url: '/pages/passCar/passCar' }); - } + } // 我的券包 else if (app.globalData.type == 'mc') { // 我的券包 wx.redirectTo({ url: '/pages/couponorder/index/index' }); - } + } // 我的订单 else if (app.globalData.type == 'mo') { // 我的订单 wx.redirectTo({ url: '/pages/order/index/index?id=all' }); - } + } // 我的卡包 else if (app.globalData.type == 'ca') { // 我的卡包 wx.redirectTo({ url: '/pages/cardorder/index/index' }); - } + } // 特享礼遇 else if (app.globalData.type == 'sc') { // 特享礼遇 wx.redirectTo({ url: '/pages/specialcourtesy/specialcourtesy' }); - } + } // 限时秒杀 else if (app.globalData.type == 'rb') { // 限时秒杀 wx.redirectTo({ url: '/pages/rushToBuy/index' - }); - } + }) + } // 砍价专场 else if (app.globalData.type == 'bl') { // 砍价专场 wx.redirectTo({ url: '/pages/bargain/bargain' - }); - } + }) + } // 我的砍价 else if (app.globalData.type == 'mb') { // 我的砍价 wx.redirectTo({ url: '/pages/bargain/bargain?from=myhtml' - }); - } + }) + } // 拼团专场 else if (app.globalData.type == 'sl') { // 拼团专场 wx.redirectTo({ url: '/pages/spellGroup/spellGroup' - }); - } + }) + } // 我的拼团 else if (app.globalData.type == 'ms') { // 我的拼团 wx.redirectTo({ url: '/pages/spellGroup/spellGroup?from=myhtml' - }); - } + }) + } // 消费卡 else if (app.globalData.type == 'dc') { // 消费卡 wx.redirectTo({ url: '/pages/discountCardList/discountCardList' - }); - } + }) + } // 门店 else if (app.globalData.type == 'ml') { // 门店 wx.switchTab({ url: '/pages/index/searchbar/index' - }); + }) } else { // 主页 wx.switchTab({ url: '/pages/main/index' - }); + }) } }) .catch(err => { + console.log(err) if (err.code == 11004) { // 用户昵称未授权 if (options && options.orderGroupId) { wx.redirectTo({ url: `/pages/getuserinfo/index?couponId=${options.couponId}&orderGroupId=${options.orderGroupId}&couponChannelId=${options.couponChannelId}&orderId=${options.orderId}&avatarUrl=${options.avatarUrl}&nickName=${options.nickName}` }) - return; } /** * spellGroup @@ -283,22 +303,22 @@ Page({ if (options && options.couponChannelId && !options.cuserId && !options.spellGroup) { wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}` - }); + }) } else if (options && options.couponChannelId && !options.cuserId && options.spellGroup) { wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&spellGroup=${options.spellGroup}` - }); + }) } else if (options && options.couponChannelId && options.cuserId) { /** * 转赠判断 */ wx.redirectTo({ url: `/pages/getuserinfo/index?couponChannelId=${options.couponChannelId}&cuserId=${options.cuserId}&coverImg=${options.coverImg}&userName=${options.userName}&avatarUrl=${options.avatarUrl}&couponOrderId=${options.couponOrderId}&updateDate=${options.updateDate}` - }); + }) } else if (options && options.orderId) { wx.redirectTo({ url: `/pages/getuserinfo/index?orderId=${options.orderId}&from='${"discount"}` - }); + }) } else { wx.redirectTo({ url: `/pages/getuserinfo/index` @@ -307,124 +327,34 @@ Page({ } }); }, - /** - * 用户登录 - */ - userLogin: function (options) { - var that = this; - // 登录 - wx.login({ - success: ({ - code - }) => { - wx.getSystemInfo({ - success: function (res) { - that.setData({ - systemInfo: JSON.stringify(res) - }) - } - }) - var usrdata = { - appId: config.weapp.AppId, - code: code, - sceneAddress: app.globalData.sceneAddress, - scene: that.data.scene, - systemInfo: that.data.systemInfo - }; - if (app.globalData.locationInfo) { - usrdata = { - appId: config.weapp.AppId, - code: code, - sceneAddress: app.globalData.sceneAddress, - latitude: "" + app.globalData.locationInfo.latitude, - longitude: "" + app.globalData.locationInfo.longitude, - scene: that.data.scene, - systemInfo: that.data.systemInfo - }; + getGameOne: function(token, id) { + let _this = this; + Http.get({ + url: config.api.getOneGame, + data: { + token: token, + id: id } - Http.post({ - url: config.api.login, - data: usrdata + }).then(res => { + wx.redirectTo({ + url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId, }) - .then(res => { - that.setData({ - showPages: true - }) - app.globalData.token = res.data.token; - app.globalData.openId = res.data.openId; - // 初始化websocket - if (extConfig.attr.ifHaveWebSocket == 1) { - app.initSocket(); - // 回调发送给自己的消息 - app.globalData.socketReceiver = function (e) { - let msgList = that.data.msgList - msgList.push(e) - that.setData({ - msgList: msgList + }) + .catch(err => { + wx.showModal({ + title: '提示', + content: err.message, + showCancel: false, + success: function(res) { + // 如果游戏下架或者找不到,重启首页 + if (res.confirm) { + wx.reLaunch({ + url: '/pages/index/index', }) } } - - if (res.data && res.data.score) { - if (res.data.score != 0) { - app.globalData.score = res.data.score; - } - } - Http.setToken(res.data.token); - if (options && (options.couponChannelId || options.orderId || options.id)) { - that.checkuserstatus(options); - } else { - that.checkuserstatus(); - } }) - .catch(err => { - wx.showModal({ - title: '提示', - showCancel: false, - content: '登录失败,请重新尝试', - success: function (res) { - if (res.cancel) { - //点击取消,默认隐藏弹框 - } else { - //点击确定 - wx.reLaunch({ - url: '/pages/index/index', - }) - } - } - }) - }); - } - }); - }, - getGameOne: function (token, id) { - let _this = this; - Http.get({ - url: config.api.getOneGame, - data: { - token: token, - id: id - } - }).then(res => { - wx.redirectTo({ - url: '/pages/game/index?url=' + res.data.url + "&id=" + res.data.id + "&gameId=" + res.data.gameId, + this.alphaClick(); }) - }) - .catch(err => { - wx.showModal({ - title: '提示', - content: err.message, - showCancel: false, - success:function(res){ - // 如果游戏下架或者找不到,重启首页 - if (res.confirm){ - wx.reLaunch({ - url: '/pages/index/index', - }) - } - } - }) - this.alphaClick(); - }) }, }) \ No newline at end of file diff --git a/pages/main/index.js b/pages/main/index.js index f1cc507..c4a32ab 100644 --- a/pages/main/index.js +++ b/pages/main/index.js @@ -216,9 +216,9 @@ Page({ that.setData({ optionsData: optionss }) - that.userLogin(optionss.couponChannelId, optionss.orderId); + that.getWeapNote(optionss.couponChannelId, optionss.orderId); } else { - that.userLogin() + that.getWeapNote() } //获取条形码 // util.barcode("barcode", optionss.quancode, 510, 100); @@ -255,10 +255,9 @@ Page({ that.alphaClick(); }, 8000) }, - // 会员码获取 getmemberId: function(token) { - let that = this; - Http.get({ + let that = this; + Http.get({ url: config.api.getScore, data: { token: token @@ -271,6 +270,13 @@ Page({ credit: res.data.credit ? res.data.credit : 0, score: res.data.score }) + + if (res.data && res.data.score) { + if (res.data.score != 0) { + app.globalData.score = res.data.score; + } + } + if (res.data.nickName) { that.setData({ ismember: true, @@ -310,13 +316,10 @@ Page({ onBargain: function(e) { console.log(e) }, - /** - * 用户登录 - */ - userLogin: function(couponChannelId, couponId, orderId) { + getWeapNote: function(couponChannelId, couponId, orderId) { var that = this; + // 登录 that.getmemberId(app.globalData.token); - that.getUserInfo(); that.getBannerlist(); that.topicShow(); that.getMallInfo(app.globalData.token); @@ -529,21 +532,21 @@ Page({ /** * 获取用户信息 */ - getUserInfo: function() { - // 获取用户信息 - wx.getSetting({ - success: res => { - if (res.authSetting["scope.userInfo"]) { - // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 - wx.getUserInfo({ - success: res => { - // 可以将 res 发送给后台解码出 unionId - } - }); - } - } - }); - }, + // getUserInfo: function() { + // // 获取用户信息 + // wx.getSetting({ + // success: res => { + // if (res.authSetting["scope.userInfo"]) { + // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + // wx.getUserInfo({ + // success: res => { + // // 可以将 res 发送给后台解码出 unionId + // } + // }); + // } + // } + // }); + // }, gotoBargain: function() { wx.navigateTo({ url: '/pages/bargain/bargain' @@ -554,14 +557,14 @@ Page({ */ onPullDownRefresh: function(e) { let that = this; - that.userLogin(); + that.getWeapNote(); that.setData({ page: 1 }) if (this.data.optionsData != null && (this.data.optionsData.couponChannelId || this.data.optionsData.orderId)) { - this.userLogin(this.data.optionsData.couponChannelId, this.data.optionsData.orderId); + this.getWeapNote(this.data.optionsData.couponChannelId, this.data.optionsData.orderId); } else { - this.userLogin() + this.getWeapNote() } if (that.data.code == 0 || that.data.code == undefined) { that.selectComponent("#lists").getList(0, 1, "refresh"); @@ -598,6 +601,7 @@ Page({ return { title: this.data.weappShareTitle, imageUrl: this.data.weappShareCoverImg, + // desc: this.data.desc, success: function(res) { wx.showToast({ title: "分享成功", diff --git a/pages/passCar/passCar.js b/pages/passCar/passCar.js index f10cf5b..278c88c 100644 --- a/pages/passCar/passCar.js +++ b/pages/passCar/passCar.js @@ -208,7 +208,7 @@ Page({ app.globalData.token = res.data.token; Http.setToken(res.data.token); that.checkUserCarStatus(); - that.getUserInfo(); + // that.getUserInfo(); that.getList(); that.init(); that.initUsrCarList(); @@ -259,21 +259,21 @@ Page({ /** * 获取用户信息 */ - getUserInfo: function () { - // 获取用户信息 - wx.getSetting({ - success: res => { - if (res.authSetting["scope.userInfo"]) { - // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 - wx.getUserInfo({ - success: res => { - // 可以将 res 发送给后台解码出 unionId - } - }); - } - } - }) - }, + // getUserInfo: function () { + // // 获取用户信息 + // wx.getSetting({ + // success: res => { + // if (res.authSetting["scope.userInfo"]) { + // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框 + // wx.getUserInfo({ + // success: res => { + // // 可以将 res 发送给后台解码出 unionId + // } + // }); + // } + // } + // }) + // }, jumpToAdd: function () { wx.navigateTo({ url: `/pages/addPark/addPark?flags=managepalte`