文件
yjyf/yjyf-master-app/pages/login/login.vue
MiAn 734bc03a26 feat(master): 完善师傅实名认证拦截及提示逻辑
- 移除登录时的草稿状态跳转逻辑
- 新增API接口未登录时返回401错误处理
- 新增实名认证状态判断及提示弹窗
- 优化师傅工作台信息加载逻辑
- 完善接单、报价等操作的实名认证拦截
2026-11-24 09:31:01 +08:00

629 行
15 KiB
Vue

<template>
<view class="page">
<view class="hero-bg-wrapper">
<image class="hero-bg-img" src="/static/login-bg.jpg" mode="aspectFill" />
<view class="hero-bg-mask"></view>
</view>
<YjyfNavBar theme="transparent" title="" :placeholder="false" :customBack="true" @back="handleBackOrHome">
<template #left>
<view class="login-nav-back clickable-hover" @tap="handleBackOrHome">
<image
class="login-nav-back-ico"
:src="showBack ? '/static/icons/back-white.svg' : '/static/icons/home-white.svg'"
mode="aspectFit"
/>
</view>
</template>
</YjyfNavBar>
<view class="main-content">
<view class="brand-hero">
<text class="brand-title">优匠优服师傅端</text>
<text class="brand-slogan">实名认证 · 海量同城好单</text>
</view>
<view class="action-block">
<!-- #ifdef MP-WEIXIN -->
<button
class="btn-wx-primary clickable-hover"
:class="{ disabled: loading, 'btn-shake': needShake }"
:open-type="agreePolicy ? 'getPhoneNumber' : ''"
@getphonenumber="onGetPhoneNumber"
@tap="handleTapButton"
>
<view class="wx-icon-wrap">
<image class="wx-svg-icon" src="/static/icons/wechat.svg" mode="aspectFit" />
</view>
<text class="btn-text">{{ loading ? '安全授权中...' : '微信手机号一键登录' }}</text>
</button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<view class="account-login-card">
<view class="input-row">
<view class="input-icon-box">
<image class="field-icon" src="/static/icons/login-phone.svg" mode="aspectFit" />
</view>
<input
class="field-input"
type="number"
maxlength="11"
v-model="account"
placeholder="请输入师傅账号手机号"
placeholder-class="field-placeholder"
/>
<view class="input-clear-btn clickable-hover" v-if="account" @tap="account = ''">
<image class="clear-icon" src="/static/icons/input-clear.svg" mode="aspectFit" />
</view>
</view>
<view class="input-row">
<view class="input-icon-box">
<image class="field-icon" src="/static/icons/login-lock.svg" mode="aspectFit" />
</view>
<input
class="field-input"
:password="!showPassword"
v-model="password"
placeholder="请输入登录密码"
placeholder-class="field-placeholder"
/>
<view class="input-eye-btn clickable-hover" @tap="showPassword = !showPassword">
<image
class="eye-icon"
:src="showPassword ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'"
mode="aspectFit"
/>
</view>
</view>
<button
class="btn-account-primary clickable-hover"
:class="{ disabled: loading, 'btn-shake': needShake }"
@tap="handleAccountLogin"
>
<text class="btn-text">{{ loading ? '安全登录中...' : '立即登录' }}</text>
</button>
</view>
<!-- #endif -->
<view class="skip-btn clickable-hover" @tap="handleSkip">
<text class="skip-text">暂不登录,先去逛逛</text>
</view>
</view>
</view>
<view class="footer-legal">
<view
class="agreement-container clickable-hover"
:class="{ 'shake-alert': needShake }"
@tap="toggleAgree"
>
<view class="checkbox-ui" :class="{ 'is-checked': agreePolicy }">
<view class="check-tick" v-if="agreePolicy"></view>
</view>
<view class="agreement-labels">
<text class="label-normal">我已阅读并同意</text>
<text class="label-link" @tap.stop="openAgreement('master')">《师傅服务协议》</text>
<text class="label-normal">与</text>
<text class="label-link" @tap.stop="openAgreement('privacy')">《隐私保护指引》</text>
</view>
</view>
</view>
<YjyfPrivacyPopup />
</view>
</template>
<script setup>
import { ref } from 'vue';
import { onLoad, onUnload } from '@dcloudio/uni-app';
import api from '@/utils/api.js';
import { setToken, setUser } from '@/utils/request.js';
import { getWxCode } from '@/utils/wxlogin.js';
import { getWindowInfoSafe } from '@/utils/system.js';
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
const LOGIN_AGREEMENT_EVENT = 'master_login_agreement_confirm';
const loading = ref(false);
const showBack = ref(false);
const agreePolicy = ref(false);
const needShake = ref(false);
const account = ref('');
const password = ref('');
const showPassword = ref(false);
let redirectUrl = '';
const statusBarHeight = ref(20);
function handleAgreementConfirm() {
agreePolicy.value = true;
}
function toast(title) {
uni.showToast({ title, icon: 'none', duration: 2000 });
}
function formatWxPhoneError(errMsg) {
const msg = String(errMsg || '').toLowerCase();
if (msg) {
console.warn('[master-login] getPhoneNumber fail:', errMsg);
}
if (msg.includes('deny') || msg.includes('cancel')) {
return '您取消了手机号授权,登录需授权手机号';
}
if (msg.includes('privacy') || msg.includes('not declared')) {
return '隐私保护指引尚未生效,请稍后重试或联系客服';
}
if (msg.includes('no permission') || msg.includes('unauthorized')) {
return '当前暂不支持微信手机号快捷登录,请联系客服';
}
if (msg.includes('quota') || msg.includes('limit')) {
return '手机号验证次数已达上限,请稍后再试';
}
return '获取微信手机号失败,请重试';
}
function formatLoginError(err, fallback) {
const msg = err && err.message ? String(err.message).trim() : '';
if (!msg || !/[\u4e00-\u9fa5]/.test(msg)) {
if (msg) console.warn('[master-login] request fail:', msg);
return fallback;
}
return msg;
}
onLoad((options) => {
uni.$on(LOGIN_AGREEMENT_EVENT, handleAgreementConfirm);
const sys = getWindowInfoSafe();
if (sys && sys.statusBarHeight) {
statusBarHeight.value = sys.statusBarHeight;
}
if (options && options.redirect) {
let decoded = decodeURIComponent(options.redirect);
if (decoded.startsWith('%2F') || decoded.startsWith('%2f')) {
try {
decoded = decodeURIComponent(decoded);
} catch (e) {}
}
redirectUrl = decoded;
}
const pages = getCurrentPages();
showBack.value = pages.length > 1;
});
onUnload(() => {
uni.$off(LOGIN_AGREEMENT_EVENT, handleAgreementConfirm);
});
function handleBackOrHome() {
if (getCurrentPages().length > 1) {
uni.navigateBack({
fail: () => uni.reLaunch({ url: '/pages/master/hall' })
});
} else {
uni.reLaunch({ url: '/pages/master/hall' });
}
}
function handleSkip() {
uni.reLaunch({ url: '/pages/master/hall' });
}
function safeVibrate() {
// #ifdef MP-WEIXIN
try {
if (uni.vibrateShort) {
uni.vibrateShort({ type: 'light' });
}
} catch (e) {}
// #endif
}
function toggleAgree() {
agreePolicy.value = !agreePolicy.value;
safeVibrate();
}
function handleTapButton() {
if (!agreePolicy.value) {
safeVibrate();
triggerShake();
toast('请先阅读并勾选师傅服务协议与隐私指引');
}
}
function triggerShake() {
needShake.value = true;
setTimeout(() => {
needShake.value = false;
}, 500);
}
async function handleAccountLogin() {
if (!agreePolicy.value) {
safeVibrate();
triggerShake();
toast('请先阅读并勾选师傅服务协议与隐私指引');
return;
}
const loginAccount = account.value.trim();
if (!loginAccount) {
toast('请输入手机号');
return;
}
if (!/^1\d{10}$/.test(loginAccount)) {
toast('手机号格式不正确');
return;
}
if (!password.value) {
toast('请输入登录密码');
return;
}
if (loading.value) return;
loading.value = true;
try {
const res = await api.login({
mobile: loginAccount,
account: loginAccount,
password: password.value
});
const info = res.masterinfo || res.userinfo || {};
setToken(res.token);
setUser(info);
toast('登录成功');
setTimeout(() => {
loading.value = false;
finishLogin(info);
}, 500);
} catch (err) {
loading.value = false;
toast(formatLoginError(err, '登录失败,请检查手机号或密码'));
}
}
async function onGetPhoneNumber(e) {
if (!agreePolicy.value) {
toast('请先阅读并勾选师傅服务协议与隐私指引');
return;
}
const detail = e.detail || {};
if (!detail.code) {
toast(formatWxPhoneError(detail.errMsg));
return;
}
if (loading.value) return;
loading.value = true;
try {
let loginCode = '';
try {
loginCode = await getWxCode();
} catch (err) {
loginCode = '';
}
const res = await api.wxPhoneLogin({
phone_code: detail.code,
login_code: loginCode
});
const info = res.masterinfo || res.userinfo || {};
setToken(res.token);
setUser(info);
toast(res.is_new ? '欢迎加入优匠优服师傅端' : '登录成功');
setTimeout(() => {
loading.value = false;
finishLogin(info);
}, 500);
} catch (err) {
loading.value = false;
toast(formatLoginError(err, '微信手机号登录失败,请重试'));
}
}
function finishLogin(info) {
if (redirectUrl && (redirectUrl.startsWith('/pages/master/') || redirectUrl.startsWith('/pages/message/'))) {
if (
redirectUrl.startsWith('/pages/master/hall') ||
redirectUrl.startsWith('/pages/master/orders') ||
redirectUrl.startsWith('/pages/master/workbench') ||
redirectUrl.startsWith('/pages/message/message')
) {
uni.reLaunch({ url: redirectUrl });
} else {
uni.redirectTo({
url: redirectUrl,
fail: () => uni.reLaunch({ url: '/pages/master/hall' })
});
}
return;
}
uni.reLaunch({ url: '/pages/master/hall' });
}
function openAgreement(type) {
const apiType = type === 'master' ? 'master' : 'privacy';
const title = type === 'master' ? '师傅入驻与履约服务协议' : '优匠优服隐私保护指引';
uni.navigateTo({
url: `/pages/agreement/detail?type=${encodeURIComponent(apiType)}&title=${encodeURIComponent(title)}&confirmEvent=${encodeURIComponent(LOGIN_AGREEMENT_EVENT)}`
});
}
</script>
<style scoped>
.page {
min-height: 100vh;
background: #FFFFFF;
display: flex;
flex-direction: column;
justify-content: space-between;
position: relative;
box-sizing: border-box;
overflow-x: hidden;
}
.hero-bg-wrapper {
position: absolute;
top: 0;
left: 0;
right: 0;
height: 580rpx;
overflow: hidden;
pointer-events: none;
z-index: 0;
}
.hero-bg-img {
width: 100%;
height: 100%;
opacity: 0.95;
}
.hero-bg-mask {
position: absolute;
inset: 0;
background: linear-gradient(
180deg,
rgba(15, 23, 42, 0.32) 0%,
rgba(255, 255, 255, 0.15) 28%,
rgba(255, 255, 255, 0.88) 78%,
#FFFFFF 100%
);
}
.login-nav-back {
width: 68rpx;
height: 68rpx;
margin-left: 8rpx;
border-radius: 34rpx;
background: rgba(15, 23, 42, 0.44);
border: 1rpx solid rgba(255, 255, 255, 0.28);
box-shadow: 0 4rpx 14rpx rgba(0, 0, 0, 0.16);
display: flex;
align-items: center;
justify-content: center;
backdrop-filter: blur(8px);
}
.login-nav-back-ico {
width: 36rpx;
height: 36rpx;
}
.main-content {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 0 52rpx;
position: relative;
z-index: 5;
margin-top: 20rpx;
}
.brand-hero {
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 80rpx;
}
.brand-title {
font-size: 52rpx;
font-weight: 700;
color: #1D2129;
letter-spacing: 4rpx;
line-height: 64rpx;
}
.brand-slogan {
font-size: 30rpx;
font-weight: 500;
color: #4E5969;
letter-spacing: 2rpx;
margin-top: 14rpx;
line-height: 42rpx;
}
.action-block {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
}
.account-login-card {
width: 100%;
display: flex;
flex-direction: column;
box-sizing: border-box;
}
.input-row {
width: 100%;
height: 96rpx;
background: #F7F8FA;
border-radius: 48rpx;
display: flex;
align-items: center;
padding: 0 32rpx;
margin-bottom: 24rpx;
box-sizing: border-box;
border: 1.5rpx solid #E5E6EB;
}
.input-row:focus-within {
background: #FFFFFF;
border-color: #F0710D;
box-shadow: 0 0 0 4rpx rgba(240, 113, 13, 0.12);
}
.input-icon-box {
width: 44rpx;
height: 44rpx;
display: flex;
align-items: center;
justify-content: center;
margin-right: 16rpx;
flex-shrink: 0;
}
.field-icon {
width: 38rpx;
height: 38rpx;
}
.field-input {
flex: 1;
height: 100%;
font-size: 28rpx;
color: #1D2129;
}
.field-placeholder {
font-size: 28rpx;
color: #86909C;
}
.input-clear-btn,
.input-eye-btn {
width: 44rpx;
height: 44rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
padding: 4rpx;
}
.clear-icon {
width: 32rpx;
height: 32rpx;
}
.eye-icon {
width: 36rpx;
height: 36rpx;
}
.btn-account-primary {
width: 100%;
height: 96rpx;
border-radius: 48rpx;
background: linear-gradient(135deg, #FFA93F 0%, #F0710D 100%);
box-shadow: 0 12rpx 28rpx rgba(240, 113, 13, 0.28);
display: flex;
align-items: center;
justify-content: center;
border: none;
margin: 8rpx 0 0 0;
}
.btn-account-primary::after { border: none; }
.btn-account-primary.disabled { opacity: 0.65; }
.btn-wx-primary {
width: 100%;
height: 100rpx;
border-radius: 50rpx;
background: linear-gradient(135deg, #07C160 0%, #05A351 100%);
box-shadow: 0 12rpx 28rpx rgba(7, 193, 96, 0.28);
display: flex;
align-items: center;
justify-content: center;
border: none;
}
.btn-wx-primary::after { border: none; }
.btn-wx-primary.disabled { opacity: 0.65; }
.wx-icon-wrap {
width: 50rpx;
height: 50rpx;
border-radius: 50%;
background: #FFFFFF;
display: flex;
align-items: center;
justify-content: center;
margin-right: 18rpx;
}
.wx-svg-icon { width: 34rpx; height: 34rpx; }
.btn-text {
font-size: 32rpx;
font-weight: 600;
color: #FFFFFF;
}
.skip-btn {
margin-top: 26rpx;
height: 76rpx;
padding: 0 36rpx;
display: flex;
align-items: center;
justify-content: center;
}
.skip-text { font-size: 28rpx; color: #4E5969; }
.footer-legal {
padding: 24rpx 24rpx calc(48rpx + env(safe-area-inset-bottom));
display: flex;
align-items: center;
justify-content: center;
position: relative;
z-index: 50;
}
.agreement-container {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 16rpx 12rpx;
white-space: nowrap;
}
.checkbox-ui {
width: 36rpx;
height: 36rpx;
border-radius: 50%;
border: 2rpx solid #C9CDD4;
display: flex;
align-items: center;
justify-content: center;
background: #FFFFFF;
margin-right: 12rpx;
flex-shrink: 0;
}
.checkbox-ui.is-checked {
background: #F0710D;
border-color: #F0710D;
}
.check-tick {
width: 12rpx;
height: 20rpx;
border-right: 4rpx solid #FFFFFF;
border-bottom: 4rpx solid #FFFFFF;
transform: rotate(45deg) translate(-2rpx, -4rpx);
}
.agreement-labels {
font-size: 24rpx;
color: #6B7280;
display: inline-flex;
align-items: center;
white-space: nowrap;
}
.label-normal { color: #6B7280; }
.label-link { color: #F0710D; font-weight: 600; padding: 0 2rpx; }
.btn-shake, .shake-alert { animation: shake-h 0.4s ease-in-out; }
@keyframes shake-h {
0%, 100% { transform: translateX(0); }
20%, 60% { transform: translateX(-8rpx); }
40%, 80% { transform: translateX(8rpx); }
}
</style>