登录和绑定微信的完善,我的页面需要登录验证
This commit is contained in:
+23
-6
@@ -1,25 +1,42 @@
|
||||
export function wxBind(callback){
|
||||
// 获取openid进行手机号和微信的绑定
|
||||
let count = 1
|
||||
wx.login({
|
||||
success (res) {
|
||||
if (res.code) {
|
||||
//发起网络请求
|
||||
if (res.code && count === 1) {
|
||||
wx.request({
|
||||
url: 'https://api.weixin.qq.com/sns/jscode2session',
|
||||
data: {
|
||||
appid: 'wx24914e866df035fb',
|
||||
secret: '0d2830f26f57722716249f2b2236f409',
|
||||
appid: 'wx322b63d1e6ff4765',
|
||||
secret: '7d3dd94092bb50981d0a8ded849601a0',
|
||||
js_code: res.code,
|
||||
grant_type: 'authorization_code'
|
||||
},
|
||||
success (res) { // 成功拿到openId
|
||||
// 微信和该账号绑定
|
||||
callback(res)
|
||||
if(count === 1){ // 回调会莫名回调两次,未知原因
|
||||
callback(res)
|
||||
}
|
||||
count++
|
||||
}
|
||||
})
|
||||
} else {
|
||||
console.log('授权失败!' + res.errMsg)
|
||||
console.log('授权失败!' + res.message)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
// 检验是否登录
|
||||
export function isLogin(callback){
|
||||
wx.getStorage({
|
||||
key: 'X-Access-Token',
|
||||
success(res){
|
||||
callback()
|
||||
},
|
||||
fail(){
|
||||
wx.navigateTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -22,7 +22,6 @@ const http = (method, url, data, header= headerDefault) => {
|
||||
header: header,
|
||||
data: data,
|
||||
success: res => {
|
||||
console.log(res)
|
||||
wx.hideLoading();
|
||||
if (res.statusCode === 200) {
|
||||
// 接口请求错误的时候提示
|
||||
@@ -37,15 +36,14 @@ const http = (method, url, data, header= headerDefault) => {
|
||||
// 200: 服务端业务处理正常结束
|
||||
resolve(res.data)
|
||||
} else {
|
||||
console.error(res.data);
|
||||
reject(res.data);
|
||||
wx.hideLoading();
|
||||
wx.showToast({
|
||||
title: "登录失效,请重新登录",
|
||||
icon: "none",
|
||||
duration: 1500,
|
||||
mask: true
|
||||
});
|
||||
// wx.showToast({
|
||||
// title: "登录失效,请重新登录",
|
||||
// icon: "none",
|
||||
// duration: 1500,
|
||||
// mask: true
|
||||
// });
|
||||
// wx.navigateTo({
|
||||
// url: '/pages/login/login',
|
||||
// })
|
||||
|
||||
+4
-4
@@ -17,10 +17,10 @@ Page({
|
||||
{ path: '../../assets/images/ziliao.png', text: '资料网员' },
|
||||
],
|
||||
titleList: [
|
||||
'会议提醒',
|
||||
'文件提醒',
|
||||
'邮寄提醒',
|
||||
'催款提醒',
|
||||
'会议通知',
|
||||
'文件通知',
|
||||
'邮寄通知',
|
||||
'催款通知',
|
||||
],
|
||||
index: 0,
|
||||
list: [], // 消息列表
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
<view class="sign-list">
|
||||
<view class="select-list">
|
||||
<view class="select-item">
|
||||
<picker bindchange="bindTitleChange" value="{{searchParams.titile}}" range="{{titleList}}">
|
||||
<picker bindchange="bindTitleChange" range="{{titleList}}">
|
||||
<view class="picker">
|
||||
<text wx:if="{{!searchParams.titile}}">类型</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 3}}">会议提醒</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 6}}">文件提醒</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 7}}">邮寄提醒</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 8}}">催款提醒</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 3}}">会议通知</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 6}}">文件通知</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 7}}">邮寄通知</text>
|
||||
<text wx:if="{{searchParams.titile}}" wx:if="{{searchParams.titile == 8}}">催款通知</text>
|
||||
</view>
|
||||
</picker>
|
||||
</view>
|
||||
|
||||
+11
-9
@@ -80,10 +80,11 @@ Page({
|
||||
},
|
||||
// 微信登录
|
||||
wxLogin(){
|
||||
const that = this
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
rsaPublicKey: this.data.rsaPublicKey
|
||||
rsaPublicKey: that.data.rsaPublicKey
|
||||
}
|
||||
UserApi.wxLogin(params).then(res=>{
|
||||
if(res.success) {// 已经用手机号登录过,此时用微信快捷登录时,把微信的个人信息存进缓存(微信信息在缓存的userInfoTemp)
|
||||
@@ -96,11 +97,7 @@ Page({
|
||||
url: '../home/home',
|
||||
})
|
||||
}else{ // 首次登录不能直接用微信快捷登录
|
||||
wx.showToast({
|
||||
title: '暂未授权手机号',
|
||||
duration: 2000,
|
||||
icon: "none",
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -120,6 +117,7 @@ Page({
|
||||
key: 'userInfo',
|
||||
data: res.result.userInfo
|
||||
})
|
||||
// 第一次登录系统,需要设置密码
|
||||
if(res.message === "updatePassword") {
|
||||
// 存临时token
|
||||
wx.setStorage({
|
||||
@@ -136,8 +134,11 @@ Page({
|
||||
key: 'X-Access-Token',
|
||||
data: res.result.token
|
||||
})
|
||||
// 绑定微信
|
||||
this.wxBind()
|
||||
// 如果绑定过微信就不再进行绑定
|
||||
if(!res.result.userInfo.openId){
|
||||
// 绑定微信
|
||||
this.wxBindPhone()
|
||||
}
|
||||
// 跳转首页
|
||||
wx.switchTab({
|
||||
url: '../home/home',
|
||||
@@ -167,7 +168,8 @@ Page({
|
||||
})
|
||||
},
|
||||
// 绑定微信
|
||||
wxBind(){
|
||||
wxBindPhone(){
|
||||
const that = this
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
openId: res.data.openid,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<view class="btn-area">
|
||||
<button type="primary" formType="submit">登录</button>
|
||||
</view>
|
||||
<view bindtap="forget" class="forget">
|
||||
<view class="forget">
|
||||
<text bindtap="phonePassword">手机密码登录</text>
|
||||
<text bindtap="updateInfo">忘记密码?</text>
|
||||
</view>
|
||||
|
||||
+90
-88
@@ -1,6 +1,8 @@
|
||||
// pages/mine/mine.js
|
||||
import UserApi from '../../assets/js/http/userApi'
|
||||
import http from '../../assets/js/http/http'
|
||||
import {
|
||||
isLogin
|
||||
} from '../../assets/js/common'
|
||||
Page({
|
||||
|
||||
/**
|
||||
@@ -13,121 +15,121 @@ Page({
|
||||
rsaPublicKey: '',
|
||||
},
|
||||
// 个人信息
|
||||
mineInfo(){
|
||||
wx.navigateTo({
|
||||
url: '../mineInfo/mineInfo',
|
||||
mineInfo() {
|
||||
isLogin(() => {
|
||||
wx.navigateTo({
|
||||
url: '../mineInfo/mineInfo',
|
||||
})
|
||||
})
|
||||
},
|
||||
// 修改密码
|
||||
upDateInfo(){
|
||||
wx.navigateTo({
|
||||
url: '../upDateInfo/upDateInfo',
|
||||
upDateInfo() {
|
||||
isLogin(() => {
|
||||
wx.navigateTo({
|
||||
url: '../upDateInfo/upDateInfo',
|
||||
})
|
||||
})
|
||||
},
|
||||
// 解除绑定
|
||||
unBind(){
|
||||
wx.showModal({
|
||||
cancelColor: '取消',
|
||||
content: '确定解绑并退出登录?',
|
||||
confirmColor: '#069F99',
|
||||
success (res) {
|
||||
if (res.confirm) {
|
||||
UserApi.wxUnbind().then(res=>{
|
||||
if(res.success){
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
}else{
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if (res.cancel) {}
|
||||
}
|
||||
unBind() {
|
||||
isLogin(() => {
|
||||
wx.showModal({
|
||||
cancelColor: '取消',
|
||||
content: '确定解绑并退出登录?',
|
||||
confirmColor: '#069F99',
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
UserApi.wxUnbind().then(res => {
|
||||
if (res.success) {
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
} else {
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
}
|
||||
})
|
||||
} else if (res.cancel) {}
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// 扫码签到
|
||||
scanCode(){
|
||||
// wx.scanCode({
|
||||
// onlyFromCamera: false,
|
||||
// scanType: [],
|
||||
// success: (result) => {
|
||||
// console.log(result)
|
||||
// },
|
||||
// fail: (res) => {
|
||||
// console.log(result)
|
||||
// },
|
||||
// complete: (res) => {
|
||||
// console.log(result)
|
||||
// },
|
||||
scanCode() {
|
||||
// isLogin(() => {
|
||||
// wx.scanCode({
|
||||
// onlyFromCamera: false,
|
||||
// scanType: [],
|
||||
// success: (result) => {
|
||||
// console.log(result)
|
||||
// },
|
||||
// fail: (res) => {
|
||||
// console.log(result)
|
||||
// },
|
||||
// complete: (res) => {
|
||||
// console.log(result)
|
||||
// },
|
||||
// })
|
||||
// 成功扫码的回调 1448213074467938306,1448107789464113154
|
||||
UserApi.scanCode({
|
||||
meetingId: '1448213074467938306'
|
||||
}).then(res => {
|
||||
if (res.success) {
|
||||
let result = JSON.stringify(res.result)
|
||||
wx.navigateTo({
|
||||
url: `../scanSign/scanSign?signed=1&meeting=${result}`,
|
||||
})
|
||||
} else {
|
||||
let result = JSON.stringify(res.result)
|
||||
// 未查到报名信息
|
||||
wx.navigateTo({
|
||||
url: `../scanSign/scanSign?signed=0&meeting=${result}`,
|
||||
})
|
||||
}
|
||||
})
|
||||
// })
|
||||
// 成功扫码的回调 1448213074467938306,1448107789464113154
|
||||
UserApi.scanCode({meetingId: '1448213074467938306'}).then(res=>{
|
||||
if(res.success){
|
||||
let result = JSON.stringify(res.result)
|
||||
wx.navigateTo({
|
||||
url: `../scanSign/scanSign?signed=1&meeting=${result}`,
|
||||
})
|
||||
}else{
|
||||
let result = JSON.stringify(res.result)
|
||||
// 未查到报名信息
|
||||
wx.navigateTo({
|
||||
url: `../scanSign/scanSign?signed=0&meeting=${result}`,
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
// 我的资料
|
||||
mineData(){
|
||||
wx.navigateTo({
|
||||
url: '../mineData/mineData',
|
||||
mineData() {
|
||||
isLogin(()=>{
|
||||
wx.navigateTo({
|
||||
url: '../mineData/mineData',
|
||||
})
|
||||
})
|
||||
},
|
||||
// 我的合同
|
||||
mineContract(){
|
||||
wx.navigateTo({
|
||||
url: '../mineContract/mineContract',
|
||||
mineContract() {
|
||||
isLogin(()=>{
|
||||
wx.navigateTo({
|
||||
url: '../mineContract/mineContract',
|
||||
})
|
||||
})
|
||||
},
|
||||
// 去登录
|
||||
goLogin(){
|
||||
goLogin() {
|
||||
wx.navigateTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
},
|
||||
// 退出登录
|
||||
logout(){
|
||||
logout() {
|
||||
wx.showModal({
|
||||
cancelColor: '取消',
|
||||
content: '确定退出登录?',
|
||||
confirmColor: '#069F99',
|
||||
success (res) {
|
||||
success(res) {
|
||||
if (res.confirm) {
|
||||
UserApi.logout().then(res=>{
|
||||
if(res.success){
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
}else{
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
}
|
||||
UserApi.logout().then(res => {
|
||||
wx.clearStorage()
|
||||
wx.redirectTo({
|
||||
url: '../login/login',
|
||||
})
|
||||
})
|
||||
} else if (res.cancel) {}
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
onLoad: function (options) {
|
||||
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
@@ -138,11 +140,11 @@ Page({
|
||||
this.setData({
|
||||
token
|
||||
})
|
||||
if(userInfo){
|
||||
if (userInfo) {
|
||||
this.setData({
|
||||
name: userInfo.name,
|
||||
phone: userInfo.phone.substr(0, 3) + '-' + userInfo.phone.substr(3, 4) + '-' + userInfo.phone.substr(7, 4)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -13,9 +13,9 @@ Page({
|
||||
form: {
|
||||
currdatetime: '',
|
||||
requestCodeSuccess: true,
|
||||
randCodeImage: '', // 验证码
|
||||
rsaPublicKey: '', // 公钥
|
||||
randCodeImage: '' // 验证码
|
||||
},
|
||||
rsaPublicKey: '', // 公钥
|
||||
flag: false
|
||||
},
|
||||
|
||||
@@ -108,8 +108,11 @@ Page({
|
||||
if(this.data.flag){
|
||||
UserApi.passWordLogin(params).then(res => {
|
||||
if(res.success){
|
||||
// 微信绑定
|
||||
this.wxBind()
|
||||
// 如果绑定过微信就不再进行绑定
|
||||
if(!res.result.userInfo.openId){
|
||||
// 绑定微信
|
||||
this.wxBindPhone()
|
||||
}
|
||||
// 存token和userInfo
|
||||
wx.setStorage({
|
||||
key: 'X-Access-Token',
|
||||
@@ -137,7 +140,8 @@ Page({
|
||||
},
|
||||
|
||||
// 绑定微信
|
||||
wxBind(){
|
||||
wxBindPhone(){
|
||||
const that = this
|
||||
// 获取openid进行手机号和微信的绑定
|
||||
wxBind((res)=>{
|
||||
let params = {
|
||||
|
||||
@@ -101,6 +101,7 @@ Page({
|
||||
},
|
||||
// 绑定微信
|
||||
wxBind(){
|
||||
const that = this
|
||||
wxBind((res)=>{
|
||||
// 微信和该账号绑定
|
||||
let params = {
|
||||
@@ -130,7 +131,6 @@ Page({
|
||||
that.setData({
|
||||
password: res.data
|
||||
})
|
||||
console.log(that.data.password)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user