WxApp/page/component/user/user.js

106 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-08-30 15:23:27 +08:00
const app = getApp()
const baseUrl = app.globalData.baseUrl
2024-08-29 14:36:16 +08:00
// page/component/new-pages/user/user.js
Page({
data: {
2024-08-30 15:23:27 +08:00
thumb: "",
nickname: "",
2024-08-29 14:36:16 +08:00
orders: [],
hasAddress: false,
2024-08-30 15:23:27 +08:00
address: {},
2024-08-29 14:36:16 +08:00
},
onLoad() {
2024-08-30 15:23:27 +08:00
var self = this
2024-08-29 14:36:16 +08:00
wx.getUserProfile({
2024-08-30 15:23:27 +08:00
desc: "用于完善会员资料", // 这里必须声明用途
2024-08-29 14:36:16 +08:00
success: function (res) {
self.setData({
thumb: res.userInfo.avatarUrl,
2024-08-30 15:23:27 +08:00
nickname: res.userInfo.nickName,
})
2024-08-29 14:36:16 +08:00
// 你可以将用户信息发送到后端或缓存到本地
},
fail: function (err) {
wx.showToast({
2024-08-30 15:23:27 +08:00
title: "用户拒绝了授权",
icon: "none",
})
},
})
2024-08-29 14:36:16 +08:00
/**
* 发起请求获取订单列表信息
*/
wx.request({
2024-08-30 15:23:27 +08:00
url: baseUrl + "/order/loadData",
method: "POST",
data: {
userId: 1,
},
2024-08-29 14:36:16 +08:00
success(res) {
self.setData({
2024-08-30 15:23:27 +08:00
orders: res.data,
2024-08-29 14:36:16 +08:00
})
2024-08-30 15:23:27 +08:00
},
2024-08-29 14:36:16 +08:00
})
},
/**
2024-08-30 15:23:27 +08:00
* 获取用户信息
*/
2024-08-29 14:36:16 +08:00
getUserProfile() {
2024-08-30 15:23:27 +08:00
var self = this
2024-08-29 14:36:16 +08:00
wx.getUserProfile({
2024-08-30 15:23:27 +08:00
desc: "用于完善会员资料", // 这里必须声明用途
2024-08-29 14:36:16 +08:00
success: function (res) {
self.setData({
thumb: res.userInfo.avatarUrl,
2024-08-30 15:23:27 +08:00
nickname: res.userInfo.nickName,
})
2024-08-29 14:36:16 +08:00
// 你可以将用户信息发送到后端或缓存到本地
},
fail: function (err) {
wx.showToast({
2024-08-30 15:23:27 +08:00
title: "用户拒绝了授权",
icon: "none",
})
},
})
2024-08-29 14:36:16 +08:00
},
onShow() {
2024-08-30 15:23:27 +08:00
var self = this
2024-08-29 14:36:16 +08:00
/**
* 获取本地缓存 地址信息
*/
wx.getStorage({
2024-08-30 15:23:27 +08:00
key: "address",
2024-08-29 14:36:16 +08:00
success: function (res) {
self.setData({
hasAddress: true,
2024-08-30 15:23:27 +08:00
address: res.data,
2024-08-29 14:36:16 +08:00
})
2024-08-30 15:23:27 +08:00
},
2024-08-29 14:36:16 +08:00
})
},
/**
* 发起支付请求
*/
payOrders() {
wx.requestPayment({
2024-08-30 15:23:27 +08:00
timeStamp: "String1",
nonceStr: "String2",
package: "String3",
signType: "MD5",
paySign: "String4",
2024-08-29 14:36:16 +08:00
success: function (res) {
console.log(res)
},
fail: function (res) {
wx.showModal({
2024-08-30 15:23:27 +08:00
title: "支付提示",
content: "<text>",
showCancel: false,
2024-08-29 14:36:16 +08:00
})
2024-08-30 15:23:27 +08:00
},
2024-08-29 14:36:16 +08:00
})
2024-08-30 15:23:27 +08:00
},
})