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.

143 lines
3.2 KiB

2 years ago
// pages/set/set.js
var app = getApp()
var WXAPI = require('../../utils/server.js');
2 years ago
Page({
data: {
},
onLoad: function (options) {
2 years ago
},
onReady: function () {
},
agreeGetUser: function (e) {
let that = this;
wx.getSetting({
success: function (res) {
if (res.authSetting['scope.userInfo']) {
wx.getUserInfo({
success: function (res) {
console.log(res.userInfo)
console.log('用户已经授权过');
}
})
} else {
wx.openSetting({
success: (res) => {
2 years ago
}
})
}
}
})
if (e.detail.errMsg == 'getUserInfo:ok') {
//获取成功设置状态
//设置用户信息本地存储
console.log(e.detail.userInfo)
wx.setStorageSync('userInfo', e.detail.userInfo);
var userInfo = e.detail.userInfo;
var nickName = userInfo.nickName;
var avatarUrl = userInfo.avatarUrl;
var gender = userInfo.gender; //性别 0:未知、1:男、2:女
wx.request({
url: app.d.ceshiUrl + '&action=user&m=material',
method: 'post',
data: {
openid: app.globalData.userInfo.openid,
nickName: nickName,
avatarUrl: avatarUrl,
gender: gender
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
wx.showToast({
title: res.data.info,
success: 2000
});
}
})
}
},
logout: function() {
2 years ago
WXAPI.logout({
accessId: app.globalData.accessId,
storeId: 239,
storeType: 1,
}).then(res => {
wx.clearStorage({
success: (res) => {
wx.clearStorageSync('isLogin');
wx.clearStorageSync('accessId');
wx.navigateBack()
},
})
2 years ago
});
},
2 years ago
onShow: function () {
},
onHide: function () {
},
clearStorage: function () {
wx.clearStorageSync();
wx.clearStorage();
wx.showToast({
title: '清理成功!',
duration: 2000
});
},
onPullDownRefresh: function () {
},
onReachBottom: function () {
},
changePwd: function () {
wx.navigateTo({
url: '/pages/set/password'
})
},
2 years ago
update: function () {
wx.getUserInfo({
success: function (res) {
console.log(res)
var userInfo = res.userInfo;
var nickName = userInfo.nickName;
var avatarUrl = userInfo.avatarUrl;
var gender = userInfo.gender; //性别 0:未知、1:男、2:女
wx.request({
url: app.d.ceshiUrl + '&action=user&m=material',
method: 'post',
data: {
openid: app.globalData.userInfo.openid,
nickName: nickName,
avatarUrl: avatarUrl,
gender: gender
},
header: {
'Content-Type': 'application/x-www-form-urlencoded'
},
success: function (res) {
console.log(nickName)
wx.showToast({
title: res.data.info,
success: 2000
});
}
})
}
})
}
})