Commit 10b3f25b authored by liwei's avatar liwei

修改了登录

parent ec1a98ba
import {request} from '../../util/api'
//请求接口路径
const apis = {
getUserInfo: "/suituser/getInfo",
login: "/wxMiniApp/validLogin",
phoneLogin: "/wxMiniApp/phoneLogin",
};
export function getUserInfo(data){
return request({
url: apis.getUserInfo,
method: "get",
});
};
// 第一次登录接口
export function login(data){
return request({
url: apis.login,
method: "get",
needToken: false,
data,
});
};
// 手机号登录接口
export function phoneLogin(data){
return request({
method: "get",
url: '/wxMiniApp/phoneLogin?encryptedData='+data.encryptedData+'&iv='+data.iv+'&openId='+data.openId,
needToken: false,
});
}
// 根据字典类型查询字典数据信息
export function getDicts(params) {
return request({
url: '/system/dict/data/list',
params: params,
method: 'get'
})
}
//获取公共文化
export function getPublicActivity(query){
return request({
url: '/system/activity/getPublicActivity',
method: 'get'
})
}
// 获取个人信息
export function getInfo(id) {
return request({
url: '/sysUserManage/memberDetail/' + id,
method: 'get'
})
}
<template>
<view class="" style="background: #F4F5F9;">
<view class="home-page-container" style="min-height: 100vh;" @touchmove.stop.prevent="() => {}"
v-if="nologin==true">
<view class="home-page-container" style="min-height: 100vh;" @touchmove.stop.prevent="() => {}" v-if="nologin==true">
<image class="bgc-imga" src="../../static/images/bg-c.png" mode="aspectFill"></image>
<u-navbar leftText=" " title=" " :bgColor="bgColor" :fixed="false" :safeAreaInsetTop="true"
:placeholder="true">
......@@ -20,7 +19,7 @@
<view class="text"> 登录后才能查看我的哦 </view>
<view class="nobutton" @click="getUserInfo"> 点此登录 </view>
</view>
<view class="" v-if="nologin==false && flag == true">
<view class="" v-if="nologin == false && flag == true">
<image class="bgc-imga" src="../../static/images/my2.png" mode="aspectFill"></image>
<view class="logion">
......@@ -174,7 +173,7 @@
},
data() {
return {
flag: false,
flag: true,
dataflag: true,
nologin: '',
img: this.$BASE_URL,
......@@ -201,6 +200,7 @@
img: "../../static/images/myset.png",
}],
info: {
nickName:'11111',
userArticleViewResponse:{
articleImg:null,
articleContent:null
......@@ -209,26 +209,25 @@
numtwo: 0,
ownerId: null,
timeoutObj: null,
reConnect: true,
socketTask: null,
tipMsg: ""
};
},
onShow() {
if (uni.getStorageSync('token')) {
console.log('1111111')
this.ownerId = uni.getStorageSync('info') != null ? uni.getStorageSync('info').id : null;
}
if (uni.getStorageSync('info')) {
if (uni.getStorageSync('userInfo')) {
console.log('22222')
this.nologin = false
this.personalCenter()
// this.personalCenter()
} else {
this.nologin = true
}
},
onHide() {
this.reConnect = true;
this.closeSocket();
clearInterval(this.timeoutObj); //销毁定时器
},
methods: {
gotomation() {
......@@ -325,7 +324,6 @@
},
method: 'POST',
});
console.log(res, 'delshoucang');
var obj = {
code: code,
state: res.data.code,
......@@ -343,7 +341,7 @@
id: res.data.data.info.id,
nickName: res.data.data.info.nickName,
}
uni.setStorageSync('info', info);
uni.setStorageSync('userInfo', info);
uni.setStorageSync('token', res.data.data.token);
this.personalCenter()
this.getUnRead()
......
......@@ -196,7 +196,7 @@
'font-weight': '800',
'color': '#434343',
'border':'none',
}">
<image src="../../static/images/share.png" class="simg" mode="aspectFill"></image>
{{userData.gender!='MALE'?'她':'他'}}推荐给好友
......@@ -351,11 +351,9 @@
}
},
onLoad(options) {
debugger
this.id = options.id;
this.getUserInfo();
if (options.share != null) {
debugger
this.share = options.share;
}
this.menuButtonInfo = uni.getMenuButtonBoundingClientRect()
......@@ -494,7 +492,6 @@
this.canelLike(this.id);
},
async logion(id, type, url) {
debugger
this.animUrl = url;
const res = await this.$getId();
if (res == 11003) {
......@@ -642,7 +639,6 @@
}
},
backbar() {
debugger
if (this.share != null && this.share == "true") {
if (uni.getStorageSync('itemobj')) {
uni.switchTab({
......@@ -667,7 +663,7 @@
result='';
}
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; // 包含大小写字母和数字的所有字符集合
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * characters.length);
result += characters[randomIndex];
......@@ -1699,7 +1695,7 @@
.twoTemp{
&:after{
width: calc(33% - 10rpx);
content: '';
content: '';
}
image{
&:last-child{
......@@ -1731,4 +1727,4 @@
font-size: 28rpx;
color: #333333;
}
</style>
\ No newline at end of file
</style>
<template>
<view class="home-page-container" @touchmove.stop.prevent="() => {}">
<view class="" v-if="falg == true">
<view class="">
<image class="bgc-imga" src="../../static/images/bg-c.png" mode="widthFix"></image>
<image class="bgc-img" src="../static/images/home-bgc.png" mode="aspectFit"></image>
<image class="logo-img" src="../static/images/logo.png"></image>
<view class="start-btn" @click="handleShowTips">
<view>开始邂逅</view>
</view>
<u-popup u-popup :show="tipsShow" mode="center" round="12" :safeAreaInsetBottom="false">
<view class="popup-container">
<image class="pop-bgc" :src="img + '/img/home-pop-bg.png'"></image>
<view class="div-popo">
<view class="pop-title">温馨提示</view>
<view class="tips-content">
请您仔细阅读并充分理解相关条款, 点击同意即代表您已阅读并同意
<view class="agreement-btn">《用户协议》</view>
<view class="agreement-btn">《隐私政策》</view>
</view>
<view class="btn-c">
<view class="pop-btn agree" @click="handAgree">同意</view>
<view class="pop-btn" @click="handleNoAgree">不同意</view>
</view>
</view>
</view>
</u-popup>
<!-- <image class="logo-img" src="../static/images/logo.png"></image>-->
<!-- <view class="start-btn" @click="handleShowTips" >-->
<!-- <view>开始邂逅</view>-->
<!-- </view>-->
<view class="start-btn">
<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber($event)">开始邂逅</button>
</view>
<!-- <u-popup u-popup :show="tipsShow" mode="center" round="12" :safeAreaInsetBottom="false">-->
<!-- <view class="popup-container">-->
<!-- <image class="pop-bgc" :src="img + '/img/home-pop-bg.png'"></image>-->
<!-- <view class="div-popo">-->
<!-- <view class="pop-title">温馨提示</view>-->
<!-- <view class="tips-content">-->
<!-- 请您仔细阅读并充分理解相关条款, 点击同意即代表您已阅读并同意-->
<!-- <view class="agreement-btn">《用户协议》</view>-->
<!-- 、-->
<!-- <view class="agreement-btn">《隐私政策》</view>-->
<!-- </view>-->
<!-- <view class="btn-c">-->
<!-- <view class="pop-btn agree" @click="handAgree">同意</view>-->
<!-- <view class="pop-btn" @click="handleNoAgree">不同意</view>-->
<!-- </view>-->
<!-- </view>-->
<!-- </view>-->
<!-- </u-popup>-->
</view>
<ELM ref="elm" :msg="tipMsg" :isConfirm="isConfirm" @confirm="confirm"></ELM>
</view>
</template>
<script>
import ELM from '@/components/elm-toast/index.vue';
import {
login,
phoneLogin,
getUserInfo,
getPublicActivity,
getDicts,
getInfo
} from '../../api/login/index';
export default {
data() {
return {
//用户初始化登录 (可能用户类型传参错误)
initLoginError: false,
img: this.$BASE_URL,
tipsShow: false,
falg: false,
num: '',
tipMsg: '',
isConfirm: false
isConfirm: false,
token:'',
openId: '',
};
},
async created() {
// 获取openId
this.usersLogin().catch(res => {
console.log("登录错误信息", res)
//初始化登录错误
this.initLoginError = true
// 关闭加载
uni.hideLoading()
})
},
onShow() {
uni.switchTab({
url: '/pages/tab/index'
});
// if (uni.getStorageSync('itemobj')) {
// uni.switchTab({
// url: '/pages/tab/index'
// });
// // this.falg = false
// } else {
// console.log('[]');
// setTimeout(() => {
// this.falg = true;
// }, 1000);
// }
// uni.switchTab({
// url: '/pages/tab/index'
// });
},
components: {
ELM
},
methods: {
// 用户登录
usersLogin() {
return new Promise((resolve, reject) => {
//加载交互
uni.showLoading({
title: ''
});
uni.login({
provider: 'weixin',
success: res => {
let code = {
code: res.code,
}
console.log("code",code)
login(code).then(res => {
this.openId = res.data.openId
//证明不是第一次登录
if (res.data.token !== undefined && res.data.token !== null) {
this.token = res.data.token
this.openId = res.data.data.wxOpenid
this.userInfo = res.data.data
uni.setStorageSync('token', this.token)
uni.setStorageSync('userInfo', JSON.stringify(this.userInfo))
uni.reLaunch({
url: '/pages/tab/index'
})
//停止加载
uni.hideLoading()
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.setStorageSync("confirmLogin", true)
uni.reLaunch({
url: '/pages/tab/index'
})
return
}
//encodeURIComponent是为了解决后端接收不到+/等特殊字符
let code = {
encryptedData: encodeURIComponent(event.detail.encryptedData),
iv: encodeURIComponent(event.detail.iv),
openId: encodeURIComponent(this.openId)
}
// 第一次登录请求
await this.usersFirstLogin(code).catch(res => {
//结束加载交互
console.log("第一次登录错误信息", res);
//更改错误信息
if (res.message === '该员工账号不存在' || res.message === '您的手机号被占用,请联系客服') {
errMsg = res.message
}
})
// 判断是否获取到token
if (this.token) {
// 根据获取的手机号信息请求登录接口
//结束加载交互
uni.hideLoading();
//添加确认登录校验用于处理登录页面未进行登录而能直接从启动页面进入首页的情况
uni.setStorageSync("confirmLogin", true)
console.log("跳转2")
// this.$tab.reLaunch('/pages/index')
uni.reLaunch({
url: '/pages/tab/index'
})
return
} else {
//结束加载交互
uni.hideLoading()
uni.showToast({
title: errMsg,
icon: "none"
// icon: 'error'
})
}
},
/**
* 用户第一次使用手机号登录
* @param {Object} code 登录所需的信息
*/
usersFirstLogin(code) {
return phoneLogin(code).then((res) => {
this.token = res.data.token
// 存储token
// 存储用户信息
uni.setStorageSync('token', this.token)
uni.setStorageSync('userInfo', JSON.stringify(res.data.data))
})
},
/**
* 以下为原来的代码 暂时保留 后续没用了再删
*/
handleShowTips() {
this.getUserInfo();
// this.tipsShow = true
......@@ -170,8 +328,6 @@
},
// 生成指定长度的随机字符串
generateRandomString(length) {
debugger
let result = uni.getStorageSync('touristopenid');
if (result != null&&result!="") {
return result;
......
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