|
|
// index.js
|
|
|
// 获取应用实例
|
|
|
const app = getApp()
|
|
|
import {
|
|
|
httpUtil,
|
|
|
http
|
|
|
} from '../../../utils/util'
|
|
|
Page({
|
|
|
data: {
|
|
|
statusBarHeight: getApp().globalData.statusBarHeight,
|
|
|
login_pop: false,
|
|
|
hasUserInfo: false,
|
|
|
show: false,
|
|
|
cross_bar: [{
|
|
|
name: "我的订单",
|
|
|
icon: "/images/ui/order.png",
|
|
|
url: '/pages/user/my_order/my_order'
|
|
|
}, {
|
|
|
name: '我的钱包',
|
|
|
icon: "/images/ui/wallet.png",
|
|
|
url: '/pages/user/wallet/wallet/wallet'
|
|
|
}],
|
|
|
vertical_bar: [{
|
|
|
name: '我的优惠券',
|
|
|
icon: "/images/ui/ticket.png",
|
|
|
url: '/pages/user/discount/discount/discount'
|
|
|
}, {
|
|
|
name: '想看的演出',
|
|
|
icon: "/images/ui/wanted.png",
|
|
|
url: '/pages/user/my_show/wanted_show/wanted_show'
|
|
|
}, {
|
|
|
name: '看过的演出',
|
|
|
icon: "/images/ui/finished.png",
|
|
|
url: '/pages/user/my_show/finished_show/finished_show'
|
|
|
}, {
|
|
|
name: '我的发票',
|
|
|
icon: "/images/ui/invoice.png",
|
|
|
url: '/pages/user/invoice/invoice_index/invoice_index'
|
|
|
}, {
|
|
|
name: '观演人信息',
|
|
|
icon: "/images/ui/viewer.png",
|
|
|
url: '/pages/user/viewer_list/viewer_list'
|
|
|
}]
|
|
|
},
|
|
|
sss() {
|
|
|
wx.showToast({
|
|
|
title: '暂未开放',
|
|
|
icon: 'error',
|
|
|
duration: 500
|
|
|
})
|
|
|
},
|
|
|
_exit() {
|
|
|
var that = this
|
|
|
wx.showModal({
|
|
|
content: '您正在退出登录',
|
|
|
success(res) {
|
|
|
if (res.confirm) {
|
|
|
http("/api/v1/logout", "get").then(res => {
|
|
|
console.log(res)
|
|
|
})
|
|
|
wx.removeStorageSync("userInfo");
|
|
|
app.globalData.token = null
|
|
|
app.globalData.uid = null
|
|
|
app.globalData.userInfo = null
|
|
|
that.setData({
|
|
|
hasUserInfo: false,nickName:null,avatarUrl:null,
|
|
|
userInfo: []
|
|
|
})
|
|
|
console.log('用户点击确定')
|
|
|
} else if (res.cancel) {
|
|
|
console.log('用户点击取消')
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
getUserProfile(e) {
|
|
|
wx.showLoading({
|
|
|
title: "加载...",
|
|
|
mask: true
|
|
|
});
|
|
|
var that = this
|
|
|
// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
|
|
|
wx.getUserProfile({
|
|
|
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
|
|
|
success: (res) => {
|
|
|
wx.login({
|
|
|
success: res1 => {
|
|
|
app.globalData.code = res1.code
|
|
|
that.userInfo=res.userInfo
|
|
|
that.setData({
|
|
|
show: true
|
|
|
})
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
complete: (res) => {
|
|
|
wx.hideLoading()
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
onClose() {
|
|
|
this.setData({
|
|
|
show: false
|
|
|
});
|
|
|
},
|
|
|
getPhoneNumber(e) {
|
|
|
if (e.detail.encryptedData || e.detail.iv) {
|
|
|
let code = getApp().globalData.code
|
|
|
if (code) {
|
|
|
httpUtil("/api/v1/get-token", "get", {
|
|
|
code
|
|
|
}).then(res => {
|
|
|
if (res.token) {
|
|
|
app.globalData.code = null
|
|
|
let data = {
|
|
|
token: res.token,
|
|
|
encryptedData: e.detail.encryptedData,
|
|
|
iv: e.detail.iv
|
|
|
}
|
|
|
httpUtil("/api/v1/login", "post", data).then(res1 => {
|
|
|
let userInfo = this.userInfo
|
|
|
wx.setStorageSync('userInfo', Object.assign(res1, userInfo))
|
|
|
app.globalData.token = res1.token
|
|
|
app.globalData.uid = res1.uid
|
|
|
app.globalData.nickName=userInfo.nickName
|
|
|
app.globalData.avatarUrl=userInfo.avatarUrl
|
|
|
app.globalData.userInfo=userInfo
|
|
|
|
|
|
this.setData({
|
|
|
hasUserInfo: true,nickName:userInfo.nickName,avatarUrl:userInfo.avatarUrl.replace("/132", "/0")
|
|
|
})
|
|
|
console.log("登录成功!")
|
|
|
})
|
|
|
} else {
|
|
|
console.log("token获取异常!")
|
|
|
}
|
|
|
})
|
|
|
} else {
|
|
|
console.log("调用wx.login出错或者code失效")
|
|
|
}
|
|
|
} else {
|
|
|
console.log("获取用户手机号被拒!")
|
|
|
}
|
|
|
},
|
|
|
onClose() {
|
|
|
this.setData({
|
|
|
login_pop: false
|
|
|
});
|
|
|
},
|
|
|
onLoad() {
|
|
|
console.log("测试!!!")
|
|
|
console.log("user页面onload获取globalData:", app.globalData)
|
|
|
|
|
|
},
|
|
|
onShow() {
|
|
|
console.log("测试!!!")
|
|
|
console.log("user页面onshow获取globalData:", app.globalData)
|
|
|
if (app.globalData.userInfo || (app.globalData.nickName && app.globalData.avatarUrl)) {
|
|
|
let userInfo = app.globalData.userInfo
|
|
|
let nickName = app.globalData.nickName
|
|
|
let avatarUrl = app.globalData.avatarUrl.replace("/132", "/0")
|
|
|
this.setData({
|
|
|
userInfo,nickName,avatarUrl,
|
|
|
hasUserInfo: true
|
|
|
})
|
|
|
}
|
|
|
// if (getApp().globalData.gologin) {
|
|
|
// getApp().globalData.gologin = false
|
|
|
// this.setData({
|
|
|
// login_pop: true
|
|
|
// })
|
|
|
// }
|
|
|
}
|
|
|
}) |