You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

174 lines
4.9 KiB

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