市北党建引领小程序初始化
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.

163 lines
4.5 KiB

2 years ago
// pages/redGrider/redGrider.js
var api = require('../../utils/api.js')
2 years ago
const app = getApp()
2 years ago
Page({
/**
* 页面的初始数据
*/
data: {
2 years ago
statusHeight: app.globalData.deviceInfo.statusHeight, // 自定义头部状态栏高度
navigationHeight: app.globalData.deviceInfo.navigationHeight,
userName: {},
faceImg: '',
userInfo: {},
2 years ago
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// this.getUserProfile()
2 years ago
},
getUserProfile(e) {
let than = this
wx.getUserInfo({
success: function (res) {
var userInfo = res.userInfo;
var avatarUrl = userInfo.avatarUrl; // 用户头像链接
// 其他操作...
than.setData({
faceImg: avatarUrl
})
},
fail: function (res) {
// 用户拒绝授权,处理授权失败的情况
}
});
},
2 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
let savedUserInfoString = wx.getStorageSync("userInfo");
if (savedUserInfoString) {
let savedUserInfo = JSON.parse(savedUserInfoString);
console.log(savedUserInfo.faceImg);
this.setData({
userName: savedUserInfo.realName,
faceImg: savedUserInfo.faceImg
})
} else {
this.setData({
userName: '请先注册',
faceImg: '../../images/head.png'
})
}
2 years ago
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
2 years ago
},
back() {
console.log("dddddddddd")
//返回上一级,关闭当前页面
wx.navigateBack({
delta: 1
})
},
tapchangeImg() {
const _this = this;
wx.chooseMedia({
count: 1,
mediaType: ['image'],
sourceType: ['album', 'camera'],
camera: 'back',
success(res) {
const url = res.tempFiles[0].tempFilePath;
if (url) {
_this.setData({
faceImg: url
});
wx.login({
success: (res) => {
let para = {}
let obj = JSON.parse(wx.getStorageSync('userInfo') || {})
para.identityNo = obj.identityNo;
para.mobile = obj.mobile;
para.partyFlag = obj.partyFlag;
para.realName = obj.realName;
para.shibei = obj.shibei;
para.villageName = obj.villageName;
para.workIndustry = obj.workIndustry;
para.workType = obj.workType;
para.workUnit = obj.workUnit;
para.allDeptIds = obj.allDeptIds.split(",");
para.couplingCommunity = obj.couplingCommunity.split(",");
para.userId = wx.getStorageSync('userId')
para.wxCode = res.code
para.faceImg = url || ""
if (res.code) {
api.userInfoUpdate(para).then(res => {
if (res.code == 0) {
_this.getUserInfo()
}
}).catch(err => {
console.log(err);
})
}
},
})
}
}
})
},
getUserInfo() {
api.getUserInfo().then(res => {
let userInfoString = JSON.stringify(res.data);
wx.setStorageSync('userInfo', userInfoString);
}).catch(err => {
console.log(err)
})
}
2 years ago
})