Files
szjs/pages/my/my.js

185 lines
3.3 KiB
JavaScript
Raw Normal View History

2025-03-07 22:27:18 +08:00
var Token = require('../../utils/util.js');
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
2025-03-09 23:19:35 +08:00
// 用户信息相关
userInfo: null,
hasUserInfo: false,
2025-03-07 22:27:18 +08:00
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'),
2025-03-09 23:19:35 +08:00
// 登录状态相关
2025-03-07 22:27:18 +08:00
phone: wx.getStorageSync('uid'),
uidFlag: wx.getStorageSync('uidFlag'),
code: '',
2025-03-09 23:19:35 +08:00
// 界面布局相关
statusBarHeight: 0,
height: 0,
2025-03-07 22:27:18 +08:00
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
2025-03-09 23:19:35 +08:00
this.initStatusBarHeight()
2025-03-07 22:27:18 +08:00
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getLogin()
},
2025-03-09 23:19:35 +08:00
// 初始化状态栏高度
initStatusBarHeight() {
const statusBarHeight = wx.getSystemInfoSync().statusBarHeight
this.setData({
statusBarHeight,
height: 46 + statusBarHeight
})
},
// 登录相关方法
2025-03-07 22:27:18 +08:00
getLogin() {
wx.login({
success: res => {
app.globalData.code = res.code
2025-03-09 23:19:35 +08:00
this.setData({ code: res.code })
this.getUserInfo()
2025-03-07 22:27:18 +08:00
}
})
},
2025-03-09 23:19:35 +08:00
getUserInfo() {
wx.getUserInfo({
success: (data) => {
const { encryptedData, iv } = data
app.globalData.encryptedData = encryptedData
app.globalData.iv = iv
}
})
},
// 获取手机号并登录
getPhoneNumber() {
2025-03-07 22:27:18 +08:00
wx.request({
url: app.globalData.url + 'app/Ghdwechat/wechatLogin',
2025-03-09 23:19:35 +08:00
method: 'POST',
header: { 'content-type': 'application/x-www-form-urlencoded' },
2025-03-07 22:27:18 +08:00
data: {
code: app.globalData.code,
encryptedData: app.globalData.encryptedData,
iv: app.globalData.iv
},
2025-03-09 23:19:35 +08:00
success: this.handleLoginResponse.bind(this)
2025-03-07 22:27:18 +08:00
})
},
2025-03-09 23:19:35 +08:00
handleLoginResponse(res) {
if (res.data.erro === 0) {
this.saveUserData(res.data)
this.navigateToHome()
}
wx.showToast({
title: res.data.msg,
icon: 'none'
2025-03-07 22:27:18 +08:00
})
},
2025-03-09 23:19:35 +08:00
saveUserData(data) {
const { uid } = data
wx.setStorageSync('phone', uid)
wx.setStorageSync('uid', uid)
wx.setStorageSync('token', uid)
wx.setStorageSync('uidFlag', true)
this.setData({
uidFlag: true,
phone: uid
})
app.globalData.uid = uid
},
navigateToHome() {
wx.switchTab({
url: '/pages/home/home'
})
},
// 页面导航方法
shoucang() {
wx.navigateTo({
url: '/pages/myshoucang/myshoucang_index?type=1'
})
},
pintuan() {
wx.navigateTo({
url: '/pages/order/order'
})
},
qianbao() {
wx.navigateTo({
url: '/pages/wodeqianbao/qianbao'
})
},
guanyu() {
wx.navigateTo({
url: '/pages/guanyu/guanyu'
})
2025-03-07 22:27:18 +08:00
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
})