Commit a7ab804f authored by 罗林杰's avatar 罗林杰

Merge remote-tracking branch 'origin/master'

parents fc0b562e 729ee8ad
...@@ -166,8 +166,8 @@ ...@@ -166,8 +166,8 @@
//获取公告列表 //获取公告列表
getNoticeList() { getNoticeList() {
const query = { const query = {
page: this.queryParam.page, page: 1,
rows: this.queryParam.rows, rows: 1,
flag:'1' flag:'1'
} }
noticeList(query).then(res =>{ noticeList(query).then(res =>{
...@@ -217,7 +217,7 @@ ...@@ -217,7 +217,7 @@
this.tipMsg = '当前用户未实名,请先实名认证'; this.tipMsg = '当前用户未实名,请先实名认证';
this.isConfirm = true; this.isConfirm = true;
this.$refs.elm.showDialog(); this.$refs.elm.showDialog();
return return;
} }
uni.navigateTo({ uni.navigateTo({
url: '/pagesUser/userInfo?memberId='+item.businessId url: '/pagesUser/userInfo?memberId='+item.businessId
......
...@@ -16,7 +16,8 @@ ...@@ -16,7 +16,8 @@
<image :src="baseUrl+'/user/nologin.png'" style="width: 100%;height: 100%;" mode="aspectFill"/> <image :src="baseUrl+'/user/nologin.png'" style="width: 100%;height: 100%;" mode="aspectFill"/>
</view> </view>
<view class="noLogin-text"> 登录后才能查看我的哦 </view> <view class="noLogin-text"> 登录后才能查看我的哦 </view>
<view class="noLogin-button" @click="login"> 点此登录 </view> <!-- <view class="noLogin-button" @click="login"> 点此登录 </view>-->
<button class="noLogin-button" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber($event)">点此登录</button>
</view> </view>
...@@ -182,12 +183,14 @@ ...@@ -182,12 +183,14 @@
</view> </view>
</template> </template>
<script> <script>
import {setUserProfile} from '../../api/login/index' import {login, phoneLogin, setUserProfile} from '../../api/login/index'
import {getUserInfo, noReadMessageAllCount, userDetail} from "../../api/user"; import {getUserInfo, noReadMessageAllCount, userDetail} from "../../api/user";
import {articleList, getOssUrl, userArticleList} from "../../api/article"; import {articleList, getOssUrl, userArticleList} from "../../api/article";
export default { export default {
data() { data() {
return { return {
//用户初始化登录 (可能用户类型传参错误)
initLoginError: false,
//双重认证显示 2/2时 不显示 //双重认证显示 2/2时 不显示
authShow:true, authShow:true,
//动态图片 //动态图片
...@@ -242,11 +245,12 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article"; ...@@ -242,11 +245,12 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article";
} }
], ],
numtwo: 0, numtwo: 0,
tipMsg: "" tipMsg: "",
openId: '',
}; };
}, },
onShow(){ onShow(){
this.nologin = false this.nologin = true
this.userInfo = uni.getStorageSync('userInfo') this.userInfo = uni.getStorageSync('userInfo')
this.token = uni.getStorageSync('token') this.token = uni.getStorageSync('token')
if (this.token && this.token != null && this.token !== ''){ if (this.token && this.token != null && this.token !== ''){
...@@ -260,13 +264,167 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article"; ...@@ -260,13 +264,167 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article";
this.authorizeShow = true this.authorizeShow = true
} }
this.getUserInfoByToken() this.getUserInfoByToken()
this.nologin = false
} else { } else {
//token不存在,未登录,跳转到登录页面进行登录
this.nologin = true this.nologin = true
//token不存在,未登录,跳转到登录页面进行登录
// 获取openId
// this.usersLogin().catch(res => {
// console.log("登录错误信息", res)
// //初始化登录错误
// this.initLoginError = true
// // 关闭加载
// uni.hideLoading()
// })
} }
this.articleImg = [] this.articleImg = []
}, },
methods: { methods: {
/**
* 用户登录
*/
usersLogin() {
return new Promise((resolve, reject) => {
//加载交互
uni.showLoading({
title: ''
});
uni.login({
provider: 'weixin',
success: res => {
let code = {
code: res.code,
}
login(code).then(res => {
this.openId = res.data.openId
if (res.data.code == 1001){
//用户已被停用 提示报错信息 返回首页
uni.showToast({
title: res.data.message,
icon: 'none'
})
}
//证明不是第一次登录
if (res.data.token !== undefined && res.data.token !== null) {
this.token = res.data.token
this.openId = res.data.data.wxOpenid
uni.setStorageSync('token', this.token)
this.getUserInfoByToken()
// getUserInfo().then(res => {
// uni.setStorageSync('userInfo', res.data.data)
// })
//停止加载
uni.hideLoading()
this.nologin = false
resolve(null)
}
}).catch(res => {
reject(res)
})
},
fail: res => {
reject(res)
}
})
});
},
/**
* 用户点击手机号登录
*/
async getPhoneNumber(event) {
//加载交互
uni.showLoading({
title: '登录中'
});
console.log('登录信息',event)
if (event.detail.errMsg !== 'getPhoneNumber:ok') {
//结束加载交互
uni.hideLoading();
uni.showToast({
title: '获取手机号失败',
icon: 'error'
})
return;
}
//错误提示信息
let errMsg = '网络异常,请稍后重试'
//判断初始化登录是否错误
if (this.initLoginError) {
await this.usersLogin().catch(res => {
//登录错误,请联系管理员
console.log("登录错误,请联系管理员", res);
errMsg = res.message
})
}
//获取token则不继续请求
if (this.token) {
uni.hideLoading();
// uni.reLaunch({
// url: 'pages/tab/index'
// });
this.nologin = false
//判断授权
if (this.userInfo && this.userInfo.wxNickName !== '' && this.userInfo.wxNickName != null) {
//已授权过
this.authorizeShow = false
} else {
//没授权过,需要授权
this.authorizeShow = true
}
return
}
//encodeURIComponent是为了解决后端接收不到+/等特殊字符
let params = {
encryptedData: encodeURIComponent(event.detail.encryptedData),
iv: encodeURIComponent(event.detail.iv),
openId: encodeURIComponent(this.openId)
}
// 第一次登录请求
await phoneLogin(params).then((res) => {
this.token = res.data.token
// 存储token
// 存储用户信息
uni.setStorageSync('token', this.token)
this.getUserInfoByToken()
// getUserInfo().then(res => {
// uni.setStorageSync('userInfo', res.data.data)
// })
}).catch(res => {
//错误信息
if (res.message === '该员工账号不存在' || res.message === '您的手机号被占用,请联系客服') {
errMsg = res.message
}
})
// 判断是否获取到token
if (this.token) {
uni.hideLoading();
// uni.switchTab({
// url: '/pages/tab/index'
// });
if (this.userInfo && this.userInfo.wxNickName !== '' && this.userInfo.wxNickName != null) {
//已授权过
this.authorizeShow = false
} else {
//没授权过,需要授权
this.authorizeShow = true
}
this.nologin = false
return
} else {
//结束加载交互
uni.hideLoading()
uni.showToast({
title: errMsg,
icon: "none"
})
}
},
//获取用户信息 //获取用户信息
getUserInfoByToken(){ getUserInfoByToken(){
getUserInfo().then(res =>{ getUserInfo().then(res =>{
...@@ -359,14 +517,10 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article"; ...@@ -359,14 +517,10 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article";
uni.removeStorageSync('userInfo') uni.removeStorageSync('userInfo')
uni.removeStorageSync('token') uni.removeStorageSync('token')
//补充参数 //补充参数
this.userInfo.wxNickName = res.data.data.wxNickName
this.userInfo.wxHead = res.data.data.wxHead
this.userInfo.wxAddress = res.data.data.wxAddress
this.userInfo.wxSex = res.data.data.wxSex
this.token = res.data.token this.token = res.data.token
//重新设置存储信息token和userInfo //重新设置存储信息token和userInfo
uni.setStorageSync('userInfo', this.userInfo)
uni.setStorageSync('token', this.token) uni.setStorageSync('token', this.token)
this.getUserInfoByToken()
//停止加载 //停止加载
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
...@@ -391,7 +545,7 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article"; ...@@ -391,7 +545,7 @@ import {articleList, getOssUrl, userArticleList} from "../../api/article";
address: res.userInfo.country + res.userInfo.province + res.userInfo.city,//国家+省份+城市 address: res.userInfo.country + res.userInfo.province + res.userInfo.city,//国家+省份+城市
} }
setUserProfile(params).then(res => { setUserProfile(params).then(res => {
uni.setStorageSync('userInfo', res.data.data) this.getUserInfoByToken()
}).catch(err => { }).catch(err => {
console.log('err:',err) console.log('err:',err)
}) })
......
<template>
<view class="home-page-container" @touchmove.stop.prevent="() => {}">
<view class="">
<image class="bgc-imga" :src="baseUrl+'/login/bg-c.png'" mode="widthFix"></image>
<image class="bgc-img" :src="baseUrl+'/login/home-bgc.png'" mode="aspectFit"></image>
<!-- <image class="logo-img" src="static/images/logo.png"></image>-->
<view class="start-btn">
<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber($event)">开始邂逅</button>
</view>
</view>
</view>
</template>
<script>
import {
login,
phoneLogin
} from '../api/login/index';
import {getUserInfo} from "../api/user";
export default {
data() {
return {
baseUrl: this.$IMG_URL,
//用户初始化登录 (可能用户类型传参错误)
initLoginError: false,
tipMsg: '',
token:'',
openId: '',
};
},
created() {
// 获取openId
this.usersLogin().catch(res => {
console.log("登录错误信息", res)
//初始化登录错误
this.initLoginError = true
// 关闭加载
uni.hideLoading()
})
},
methods: {
/**
* 用户登录
*/
usersLogin() {
return new Promise((resolve, reject) => {
//加载交互
uni.showLoading({
title: ''
});
uni.login({
provider: 'weixin',
success: res => {
let code = {
code: res.code,
}
login(code).then(res => {
this.openId = res.data.openId
if (res.data.code == 1001){
//用户已被停用 提示报错信息 返回首页
uni.showToast({
title: res.data.message,
icon: 'none'
})
//间隔1秒 跳转到首页
setTimeout(() => {
uni.switchTab({
url: '/pages/tab/index'
});
}, 1500)
}
//证明不是第一次登录
if (res.data.token !== undefined && res.data.token !== null) {
this.token = res.data.token
this.openId = res.data.data.wxOpenid
uni.setStorageSync('token', this.token)
getUserInfo().then(res => {
uni.setStorageSync('userInfo', res.data.data)
})
//停止加载
uni.hideLoading()
uni.switchTab({
url: '/pages/tab/index'
});
resolve(null)
}
}).catch(res => {
reject(res)
})
},
fail: res => {
reject(res)
}
})
});
},
/**
* 用户点击手机号登录
*/
async getPhoneNumber(event) {
//加载交互
uni.showLoading({
title: '登录中'
});
console.log('登录信息',event)
if (event.detail.errMsg !== 'getPhoneNumber:ok') {
//结束加载交互
uni.hideLoading();
uni.showToast({
title: '获取手机号失败',
icon: 'error'
})
return;
}
//错误提示信息
let errMsg = '网络异常,请稍后重试'
//判断初始化登录是否错误
if (this.initLoginError) {
await this.usersLogin().catch(res => {
//登录错误,请联系管理员
console.log("登录错误,请联系管理员", res);
errMsg = res.message
})
}
//获取token则不继续请求
if (this.token) {
uni.hideLoading();
uni.reLaunch({
url: 'pages/tab/index'
});
return
}
//encodeURIComponent是为了解决后端接收不到+/等特殊字符
let params = {
encryptedData: encodeURIComponent(event.detail.encryptedData),
iv: encodeURIComponent(event.detail.iv),
openId: encodeURIComponent(this.openId)
}
// 第一次登录请求
await phoneLogin(params).then((res) => {
this.token = res.data.token
// 存储token
// 存储用户信息
uni.setStorageSync('token', this.token)
getUserInfo().then(res => {
uni.setStorageSync('userInfo', res.data.data)
})
}).catch(res => {
//错误信息
if (res.message === '该员工账号不存在' || res.message === '您的手机号被占用,请联系客服') {
errMsg = res.message
}
})
// 判断是否获取到token
if (this.token) {
uni.hideLoading();
uni.switchTab({
url: '/pages/tab/index'
});
return
} else {
//结束加载交互
uni.hideLoading()
uni.showToast({
title: errMsg,
icon: "none"
})
}
},
}
};
</script>
<style lang="scss" scoped>
page {
height: 100%;
}
.home-page-container {
position: relative;
text-align: center;
width: 100vw;
height: 100%;
.pop-bgc {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
// z-index: -1;
}
.popup-container {
height: 562rpx;
width: 544rpx;
overflow: hidden;
.div-popo {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
.pop-title {
color: rgba(45, 49, 50, 0.8);
font-weight: 400;
font-size: 40rpx;
margin-top: 78rpx;
font-family: 'PingFang SC-Heavy, PingFang SC';
}
.tips-content {
width: 448rpx;
margin: auto;
text-align: left;
margin-top: 50rpx;
line-height: 56rpx;
color: #666;
font-size: 28rpx;
font-family: 'PingFang SC-Regular, PingFang SC';
.agreement-btn {
display: inline-block;
color: #5b83e8;
font-family: 'PingFang SC-Bold, PingFang SC';
text-decoration: underline;
}
}
.btn-c {
display: flex;
margin: auto;
margin-top: 64rpx;
justify-content: space-between;
width: 428rpx;
}
}
.pop-btn {
width: 204rpx;
height: 76rpx;
border-radius: 38rpx;
text-align: center;
line-height: 76rpx;
border: 2rpx solid #446cd2;
color: #5b83e8;
font-family: 'PingFang SC-Regular, PingFang SC';
&.agree {
border: none;
background: linear-gradient(86deg, #c2d2f9 0%, #c5c2f3 100%);
}
}
}
.logo-img {
width: 168rpx;
height: 226rpx;
margin-top: 90vw;
}
.start-btn {
width: 536rpx;
height: 84rpx;
background: linear-gradient(86deg, #c2d2f9 0%, #c5c2f3 100%);
margin: auto;
border-radius: 42rpx 42rpx 42rpx 42rpx;
line-height: 84rpx;
color: rgba(65, 92, 158, 0.8);
font-weight: 400;
font-size: 28rpx;
position: fixed;
bottom: 15vh;
left: 112rpx;
font-family: 'PingFang SC-Bold, PingFang SC';
}
}
.bgc-img {
position: absolute;
top: -80rpx;
left: 40rpx;
width: 670rpx;
pointer-events: none;
height: 100%;
}
.bgc-imga {
position: absolute;
top: -100rpx;
left: 0rpx;
width: 100%;
pointer-events: none;
height: 100%;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment