zhangjinli 3 years ago
parent 0e7cc39195
commit 0fcd9dac30

@ -96,54 +96,20 @@ Page({
}) })
} }
}, },
fresh() {
wx.getSystemInfo({
success(res) {
if (res.environment) {
// 企业微信环境
wx.qy.login({
success: function (res) {
http("/qywx/userDepartmentRefresh", "post", {
code: res.code
}).then(res => {
console.log(res)
if(res.success){
wx.showToast({
title: '刷新成功',
icon: 'none',
duration: 3000
})
this.userlogin()
} else {
}
})
}
})
} else {
// 微信·环境
wx.showToast({
title: '请在企业微信中打开\r\n以获取企业架构',
icon: 'none',
duration: 3000
})
}
}
})
},
userlogin() { userlogin() {
let that = this
wx.login({ wx.login({
success: res => { success: res => {
this.setData({ that.setData({
code: res.code code: res.code
}) })
http("/user/login", "post", { http("/user/login", "post", {
code: res.code code: res.code
}).then(res => { }).then(loginRes => {
if (res.msg === "未注册!") { if (loginRes.code === 10008) {
let that = this
wx.getSystemInfo({ wx.getSystemInfo({
success(res) { success(sysRes) {
if (res.environment) { if (sysRes.environment) {
console.log('企业微信环境') console.log('企业微信环境')
// 企业微信环境 // 企业微信环境
that.getUserProfile() that.getUserProfile()
@ -160,34 +126,7 @@ Page({
} }
}) })
} else { } else {
getApp().globalData.token = res.data.token that.setUserInfo(loginRes.data)
this.setData({
user_avatar: res.data.user.avatar,
user_name: res.data.user.name,
user_tip: '欢迎来到星途~',
userInfo: res.data.user
})
wx.setStorage({
key: 'user',
data: res.data.user
})
wx.setStorage({
key: 'token',
data: res.data.token
})
if (this.data.userInfo.departmentName===''||this.data.userInfo.departmentName===null) {
this.fresh()
} else {
wx.qy.login({
success: function (res) {
http("/qywx/userDepartmentRefresh", "post", {
code: res.code
}).then(res => {
console.log(res)
})
}
})
}
} }
}) })
} }
@ -225,14 +164,14 @@ Page({
let that = this let that = this
let param = { let param = {
userinfo: { userinfo: {
iv: this.data.iv, iv: that.data.iv,
encryptedData: this.data.encryptedData encryptedData: that.data.encryptedData
}, },
phone: { phone: {
iv: e.detail.iv, iv: e.detail.iv,
encryptedData: e.detail.encryptedData encryptedData: e.detail.encryptedData
}, },
code: this.data.code code: that.data.code
} }
http("/user/register", "post", param).then(res => { http("/user/register", "post", param).then(res => {
// wx.showToast({ // wx.showToast({
@ -240,7 +179,55 @@ Page({
// icon: 'none', // icon: 'none',
// duration: 2000 // duration: 2000
// }) // })
this.userlogin() console.log("注册============",res)
that.setUserInfo(res.data)
})
},
// 将用户信息嵌入页面、全局和缓存
setUserInfo(userInfo){
let that = this
getApp().globalData.token = userInfo.token
that.setData({
user_avatar: userInfo.avatar,
user_name: userInfo.name,
user_tip: '欢迎来到星途~',
userInfo: userInfo
})
wx.setStorageSync('user', userInfo)
wx.setStorageSync('token', userInfo.token)
if ( userInfo.main_department===null) {
that.dpRefresh()
}
},
dpRefresh() {
let that = this
wx.getSystemInfo({
success(sysRes) {
if (sysRes.environment) {
// 企业微信环境
wx.qy.login({
success: function (qyRes) {
http("/qywx/userDepartmentRefresh", "post", {
code: qyRes.code
}).then(res => {
if(res.success){
that.setData({
userInfo: res.data
})
wx.setStorageSync('user', res.data)
}
})
}
})
} else {
// 微信·环境
wx.showToast({
title: '请在企业微信中打开\r\n以获取企业架构',
icon: 'none',
duration: 3000
})
}
}
}) })
}, },
colse() { colse() {

Loading…
Cancel
Save