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.

238 lines
5.4 KiB

3 years ago
// pages/user/user.js
3 years ago
import {
http
} from '../../utils/util'
3 years ago
Page({
/**
* 页面的初始数据
*/
data: {
3 years ago
user_avatar: '/images/img_tx_ydl@2x.png',
3 years ago
user_name: '点击头像登录',
3 years ago
user_tip: '登录获得更多信息',
balance: 0,
user_data: [{
name: '我的收藏夹',
img: '/images/ic_scscj@3x.png',
3 years ago
url: '/pages/user/subpage/newest/newest'
3 years ago
}, {
name: '我的任务',
img: '/images/ic_wdrw@3x.png',
url: '/pages/user/subpage/quest/quest'
}, {
name: '通用教程',
img: '/images/ic_tyjc@3x.png',
3 years ago
url: '/pages/user/subpage/tutorial/tutorial'
3 years ago
}],
skills: [{
name: "账号关联",
image: '/images/ic_zhgl@3x.png',
url: '/pages/user/subpage/relation/relation'
}, {
name: "系统消息",
image: '/images/ic_xtxx@3x.png',
url: '/pages/user/subpage/system/system'
}, {
name: "线索收集",
image: '/images/ic_xxsj@3x.png',
url: '/pages/user/subpage/colllection/colllection'
}, {
name: "设置",
image: '/images/ic_sz@3x.png',
url: '/pages/user/subpage/setup/setup'
}, ],
userInfo: {},
canIUse: wx.canIUse('button.open-type.getUserInfo'),
canIUseGetUserProfile: false,
canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName'),
3 years ago
phone: false,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '',
success: function (res) {}
})
if (wx.getUserProfile) {
this.setData({
canIUseGetUserProfile: true
})
}
let that = this
wx.getStorage({
key: 'user',
success(res) {
// console.log('res')
// console.log(res)
that.setData({
user_avatar: res.data.avatar,
user_name: res.data.name,
user_tip: '欢迎来到星途~'
})
}
})
http("/userPoints/detail", "post",{}).then(res=>{
this.setData({
balance: res.data.points
})
})
3 years ago
},
3 years ago
to(e) {
3 years ago
wx.navigateTo({
url: e.currentTarget.dataset.url,
})
},
3 years ago
userlogin() {
wx.login({
success: res => {
this.setData({
code: res.code
})
http("/user/login", "post", {
code: res.code
}).then(res => {
if (res.msg === "未注册!") {
this.getUserProfile()
} else {
3 years ago
getApp().globalData.token = res.data.token
3 years ago
this.setData({
3 years ago
user_avatar: res.data.user.avatar,
user_name: res.data.user.name,
user_tip: '欢迎来到星途~'
3 years ago
})
wx.setStorage({
key: 'user',
data: res.data.user
})
wx.setStorage({
key: 'token',
data: res.data.token
})
3 years ago
// wx.getStorage({
// key: 'token',
// success (res) {
// }
// })
3 years ago
wx.qy.login({
success: function (res) {
http("/qywx/userDepartmentRefresh", "post", {
code: res.code
}).then(res => {
console.log(res)
})
}
})
3 years ago
}
})
}
})
},
getUserProfile(e) {
let that = this
// 推荐使用wx.getUserProfile获取用户信息开发者每次通过该接口获取用户个人信息均需用户确认开发者妥善保管用户快速填写的头像昵称避免重复弹窗
wx.login({
success: loginRes => {
wx.showModal({
title: '温馨提示',
content: '进一步获取用户信息',
success() {
wx.getUserProfile({
desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
success: (userRes) => {
that.setData({
iv: userRes.iv,
encryptedData: userRes.encryptedData,
code: loginRes.code,
phone: true
})
}
})
}
})
}
})
},
getPhoneNumber(e) {
this.setData({
phone: false
})
let that = this
let param = {
userinfo: {
iv: this.data.iv,
encryptedData: this.data.encryptedData
},
phone: {
iv: e.detail.iv,
encryptedData: e.detail.encryptedData
},
code: this.data.code
}
http("/user/register", "post", param).then(res => {
3 years ago
// wx.showToast({
// title: '注册成功,请再次点击头像登录',
// icon: 'none',
// duration: 2000
// })
this.userlogin()
3 years ago
})
},
3 years ago
colse() {
3 years ago
this.data({
phone: false
})
},
3 years ago
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})