优化退出登录

This commit is contained in:
gyq
2025-07-23 09:19:53 +08:00
parent 4dad65e0e0
commit c98eb7406a
2 changed files with 239 additions and 233 deletions

View File

@@ -7,9 +7,8 @@
uni.login({ uni.login({
provider: 'weixin', provider: 'weixin',
success: async (data) => { success: async (data) => {
uni.cache.set('weixincode', data.code);
let res = await Api.getminiuserinfo({ let res = await Api.getminiuserinfo({
code: uni.cache.get('weixincode') //临时登录凭证 code: data.code
}) })
uni.cache.set('open_id', res.data.openid) uni.cache.set('open_id', res.data.openid)
this.$isResolve() this.$isResolve()

View File

@@ -1,18 +1,14 @@
<template> <template>
<view class="content"> <view class="content">
<view class="contentnav"> <view class="contentnav">欢迎您登录开票系统</view>
欢迎您登录开票系统
</view>
<view class="top_box"> <view class="top_box">
<view class="top_box_one"> <view class="top_box_one">
<text class="top_box_one_text">手机号码</text> <text class="top_box_one_text">手机号码</text>
<input type="number" v-model="form.account" :adjust-position="false" placeholder="请输入手机号码" maxlength="-1" <input type="number" v-model="form.account" :adjust-position="false" placeholder="请输入手机号码" maxlength="-1" data-key="mobile" />
data-key="mobile" />
</view> </view>
<view class="top_box_one"> <view class="top_box_one">
<text class="top_box_one_text">密码</text> <text class="top_box_one_text">密码</text>
<input type="mobile" v-model="form.password" :adjust-position="false" placeholder="请输入密码" <input type="mobile" v-model="form.password" :adjust-position="false" placeholder="请输入密码" maxlength="16" :password="!showPassword" />
maxlength="16" :password="!showPassword" />
<view class="repeat" @click="display"> <view class="repeat" @click="display">
<u-icon name="eye" v-if="showPassword"></u-icon> <u-icon name="eye" v-if="showPassword"></u-icon>
<u-icon v-else name="eye-off"></u-icon> <u-icon v-else name="eye-off"></u-icon>
@@ -40,20 +36,17 @@
<view class="agreement-Item" @click="Privacy(2)">隐私政策</view> <view class="agreement-Item" @click="Privacy(2)">隐私政策</view>
</view>--> </view>-->
<view class="agreement" @click="clickpassword"> <view class="agreement" @click="clickpassword">忘记密码</view>
忘记密码
</view> </view>
</view> <view style="margin-top: 80rpx; text-align: center; color: #3088fd; position: fixed; bottom: 40rpx; left: 50%; transform: translate(-50%, -50%)" @click="quyonghu">
<view
style="margin-top:80rpx;text-align: center;color:#3088fd;position: fixed; bottom:40rpx;left: 50%;transform: translate(-50%,-50%);"
@click="quyonghu">
我是用户 我是用户
</view> </view>
</view> </view>
</template> </template>
<script> <script>
export default { import Api from '@/common/js/api.js';
export default {
data() { data() {
return { return {
showPassword: false, //是否显示密码 showPassword: false, //是否显示密码
@@ -65,30 +58,44 @@
// 注册定时器 初始值 // 注册定时器 初始值
second: 60, second: 60,
showText: true, showText: true,
Recapture: '发送验证码', Recapture: '发送验证码'
} };
}, },
async onLoad(e) { async onLoad(e) {
uni.login({
provider: 'weixin',
success: async (data) => {
let openid = uni.cache.get('open_id');
if (!openid) {
let res = await Api.getminiuserinfo({
code: data.code
});
uni.cache.set('open_id', res.data.openid);
}
await this.$onLaunched; await this.$onLaunched;
if (e.userId) { if (e.userId) {
uni.showLoading({ uni.showLoading({
title: '加载中', title: '加载中',
mask: true mask: true
}) });
// this.onLoaduserId = e.userId // this.onLoaduserId = e.userId
uni.cache.set('Type', e.type); uni.cache.set('Type', e.type);
uni.cache.set('userId', e.userId); uni.cache.set('userId', e.userId);
let token = await this.api.h5encryption({ let token = await this.api.h5encryption({
store_id: uni.cache.get('userId') store_id: uni.cache.get('userId')
}) });
if (token.code == 1) { if (token.code == 1) {
uni.cache.set('token', token.data.token); uni.cache.set('token', token.data.token);
uni.cache.set('store_status', 1); uni.cache.set('store_status', 1);
uni.navigateTo({ uni.navigateTo({
url: '/pages/index/index?restype=' + 1 url: '/pages/index/index?restype=' + 1
}) });
} }
} }
}
});
}, },
methods: { methods: {
async CodeRegister() { async CodeRegister() {
@@ -100,7 +107,8 @@
}); });
return false; return false;
} }
const res = await this.api.smssend({ // post 手机验证码 const res = await this.api.smssend({
// post 手机验证码
mobile: this.form.account, mobile: this.form.account,
event: 'mobilelogin' event: 'mobilelogin'
}); });
@@ -137,8 +145,8 @@
}, },
clickpassword() { clickpassword() {
uni.navigateTo({ uni.navigateTo({
url:'/pages/login/password' url: '/pages/login/password'
}) });
}, },
async userlogin() { async userlogin() {
if (this.form.account == null || this.form.account == '') { if (this.form.account == null || this.form.account == '') {
@@ -165,8 +173,8 @@
let res = await this.api.userlogin({ let res = await this.api.userlogin({
account: this.form.account, account: this.form.account,
password: this.form.password, password: this.form.password,
open_id: uni.cache.get('open_id'), open_id: uni.cache.get('open_id')
}) });
uni.cache.set('userId', res.data.userinfo.store_id); uni.cache.set('userId', res.data.userinfo.store_id);
uni.cache.set('logintoken', res.data.userinfo.token); uni.cache.set('logintoken', res.data.userinfo.token);
uni.cache.set('store_status', res.data.store_status); uni.cache.set('store_status', res.data.store_status);
@@ -176,20 +184,19 @@
if (res.data.set_pwd == 1) { if (res.data.set_pwd == 1) {
uni.navigateTo({ uni.navigateTo({
url: '/pages/login/repairpassword' url: '/pages/login/repairpassword'
}) });
} else { } else {
uni.reLaunch({ uni.reLaunch({
url: '/pages/index/index?restype=' + 1 url: '/pages/index/index?restype=' + 1
}); });
} }
}
} }
} }
};
</script> </script>
<style lang="scss"> <style lang="scss">
.content { .content {
.contentnav { .contentnav {
padding-left: 48rpx; padding-left: 48rpx;
padding-top: 200rpx; padding-top: 200rpx;
@@ -289,5 +296,5 @@
} }
} }
} }
} }
</style> </style>