| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- var app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- is_login: 'false',
- nikename: '',
- avatar: '',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- var that = this
- if (wx.getStorageSync('user')) {
- that.setData({
- is_login: false,
- nikename: wx.getStorageSync('user').username,
- avatar: wx.getStorageSync('user').avatar
- })
- } else {
- that.setData({
- is_login: true
- })
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- },
- close_login: function() {
- this.setData({
- is_login: false
- })
- },
- userLogin: function(e) {
- this.setData({
- is_login: false
- })
- wx.showLoading({
- title: '登录中',
- })
- console.log(e.detail)
- var un = JSON.parse(e.detail.rawData)
- var that = this
- try {
- wx.login({
- success: function(res) {
- let code = res.code
- console.log(code)
- let tx = un.avatarUrl
- let nn = un.nickName
- app.request({
- url: 'https://t6.9026.com/api/furniture/service_login',
- method: 'POST',
- data: {
- code: code,
- avatar: tx,
- nickName: nn,
- store_id: app.globalData.store_id
- },
- success: function(res) {
- console.log(res.data)
- wx.setStorageSync("token", res.data.data.token)
- wx.setStorageSync('key', res.data.data.session_key)
- wx.setStorageSync("user", res.data.data.user);
- wx.setStorageSync('ma', 0)
- wx.setStorageSync('pa', 0)
- wx.setStorageSync('us', 0)
- wx.hideLoading();
- wx.showToast({
- title: '登录成功',
- icon: 'success',
- duration: 1000,
- success: () => {
- that.setData({
- nikename: wx.getStorageSync('user').username,
- avatar: wx.getStorageSync('user').avatar
- })
- }
- })
- }
- })
- }
- })
- } catch (e) {
- console.log(e.message)
- }
- },
- })
|