feat(master): 后台增加师傅密码重置功能并优化师傅端账号安全页面
- 后端后台管理:在师傅管理模块新增 resetpwd 功能,支持重置登录密码、支付密码或全部重置,并联动清理锁定状态与在线令牌 - 视图与脚本:新增 resetpwd.html 弹窗视图并在 master.js 与 index.html 中注册操作按钮与表单联动逻辑 - 师傅端接口:MasterAuth::setPaymentPassword 简化流程,依托已有登录态直接设置6位数字支付密码,并在修改登录密码时自动重置锁定状态 - 师傅端小程序:security.vue 全面升级账号安全中心界面视觉与交互,展示账号信息、认证状态并提供标准弹窗;清理 wxlogin.js 中冗余代码
这个提交包含在:
@@ -2,50 +2,166 @@
|
||||
<view class="page">
|
||||
<YjyfNavBar theme="white" :title="setupFromPayment ? '设置支付密码' : '账号安全'" :border="true" :showBack="setupFromPayment ? true : null" :customBack="setupFromPayment" @back="handleBack" />
|
||||
<template v-if="!setupFromPayment">
|
||||
<view v-if="loaded" class="card">
|
||||
<view class="row clickable-hover" @tap="openPassword('login')">
|
||||
<text>登录密码</text>
|
||||
<view class="value">{{ status.has_login_password ? '已设置' : '未设置' }}<image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" /></view>
|
||||
<view v-if="loaded" class="security-body">
|
||||
<!-- 安全状态概览 -->
|
||||
<view class="hero-card">
|
||||
<image class="hero-ico" :src="isAccountSafe ? '/static/icons/shield-green.svg' : '/static/icons/info-orange.svg'" mode="aspectFit" />
|
||||
<view class="hero-info">
|
||||
<text class="hero-title">{{ isAccountSafe ? '账号安全保护中' : '建议完善安全设置' }}</text>
|
||||
<text class="hero-sub">登录账号:{{ status.mobile || '-' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="row clickable-hover" @tap="openPassword('payment')">
|
||||
<text>支付密码(用于提现验证)</text>
|
||||
<view class="value">{{ status.has_payment_password ? '已设置' : '未设置' }}<image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" /></view>
|
||||
|
||||
<!-- 账号基础信息 -->
|
||||
<view class="card">
|
||||
<view class="card-head">
|
||||
<text class="card-title">账号信息</text>
|
||||
</view>
|
||||
<view class="row">
|
||||
<text class="row-label">绑定手机号</text>
|
||||
<view class="row-right">
|
||||
<text class="row-val">{{ status.mobile || '-' }}</text>
|
||||
<text v-if="status.mobile" class="tag tag-success">已绑定</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="row clickable-hover" @tap="goVerifyStatus">
|
||||
<text class="row-label">实名认证</text>
|
||||
<view class="row-right">
|
||||
<text class="tag" :class="verifyTagClass">{{ verifyStatusText }}</text>
|
||||
<image v-if="status.verify_status !== 'pass'" class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 安全凭证管理 -->
|
||||
<view class="card">
|
||||
<view class="card-head">
|
||||
<text class="card-title">安全凭证</text>
|
||||
</view>
|
||||
<view class="row clickable-hover" @tap="openPassword('login')">
|
||||
<view class="row-left">
|
||||
<text class="row-label">登录密码</text>
|
||||
<text class="row-desc">用于 H5 网页端手机号密码登录</text>
|
||||
</view>
|
||||
<view class="row-right">
|
||||
<text class="row-val" :class="{ unset: !status.has_login_password }">{{ status.has_login_password ? '已设置' : '未设置' }}</text>
|
||||
<image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="row clickable-hover" @tap="openPassword('payment')">
|
||||
<view class="row-left">
|
||||
<text class="row-label">支付密码</text>
|
||||
<text class="row-desc">用于余额提现安全确认</text>
|
||||
</view>
|
||||
<view class="row-right">
|
||||
<text class="row-val" :class="{ unset: !status.has_payment_password }">{{ status.has_payment_password ? '已设置' : '未设置' }}</text>
|
||||
<image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="logout clickable-hover" @tap="logout">
|
||||
<text>退出登录</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="loaded" class="logout clickable-hover" @tap="logout">退出登录</view>
|
||||
</template>
|
||||
|
||||
<view v-if="mode" class="mask">
|
||||
<view class="sheet">
|
||||
<view class="sheet-head"><text class="title">{{ sheetTitle }}</text><text class="close" @tap="cancelSheet">取消</text></view>
|
||||
<!-- 密码设置 / 修改底部弹窗 -->
|
||||
<view v-if="mode" class="mask" @tap="cancelSheet">
|
||||
<view class="sheet" @tap.stop>
|
||||
<view class="sheet-head">
|
||||
<text class="title">{{ sheetTitle }}</text>
|
||||
<text class="close" @tap="cancelSheet">取消</text>
|
||||
</view>
|
||||
|
||||
<!-- 登录密码表单 -->
|
||||
<template v-if="mode === 'login'">
|
||||
<input v-if="status.has_login_password" v-model="oldPassword" class="input" password placeholder="请输入原登录密码" />
|
||||
<input v-model="newPassword" class="input" password maxlength="30" placeholder="新登录密码(6至30位)" />
|
||||
<input v-model="confirmPassword" class="input" password maxlength="30" placeholder="再次输入新登录密码" />
|
||||
<text v-if="!status.has_login_password" class="hint">请使用绑定的微信手机号验证身份。</text>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button v-if="!status.has_login_password" class="primary" open-type="getPhoneNumber" :disabled="busy" @getphonenumber="onPhoneVerifyLogin">验证手机号并设置</button>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<text v-if="!status.has_login_password" class="hint">请在微信小程序中完成手机号验证后设置。</text>
|
||||
<!-- #endif -->
|
||||
<button v-if="status.has_login_password" class="primary" :disabled="busy" @tap="savePassword">确认修改</button>
|
||||
<view v-if="status.has_login_password" class="input-box">
|
||||
<input
|
||||
v-model="oldPassword"
|
||||
class="input-field"
|
||||
:password="!showOldPwd"
|
||||
placeholder="请输入原登录密码"
|
||||
/>
|
||||
<view class="eye-btn" @tap="showOldPwd = !showOldPwd">
|
||||
<image class="eye-ico" :src="showOldPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="input-box">
|
||||
<input
|
||||
v-model="newPassword"
|
||||
class="input-field"
|
||||
:password="!showNewPwd"
|
||||
maxlength="30"
|
||||
placeholder="新登录密码(6至30位非空字符)"
|
||||
/>
|
||||
<view class="eye-btn" @tap="showNewPwd = !showNewPwd">
|
||||
<image class="eye-ico" :src="showNewPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="input-box">
|
||||
<input
|
||||
v-model="confirmPassword"
|
||||
class="input-field"
|
||||
:password="!showConfirmPwd"
|
||||
maxlength="30"
|
||||
placeholder="再次输入新登录密码"
|
||||
/>
|
||||
<view class="eye-btn" @tap="showConfirmPwd = !showConfirmPwd">
|
||||
<image class="eye-ico" :src="showConfirmPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<button class="primary" :disabled="busy" @tap="savePassword">
|
||||
{{ status.has_login_password ? '确认修改' : '确认设置' }}
|
||||
</button>
|
||||
<text v-if="status.has_login_password" class="hint center-hint">如忘记原密码,请联系平台管理员在后台重置</text>
|
||||
</template>
|
||||
|
||||
<!-- 支付密码表单 -->
|
||||
<template v-else-if="mode === 'payment'">
|
||||
<input v-if="status.has_payment_password" v-model="oldPassword" class="input" type="number" password maxlength="6" placeholder="请输入原支付密码" />
|
||||
<input v-else-if="status.has_login_password" v-model="oldPassword" class="input" password placeholder="请输入登录密码以验证身份" />
|
||||
<input v-model="newPassword" class="input" type="number" password maxlength="6" placeholder="设置6位数字支付密码" />
|
||||
<input v-model="confirmPassword" class="input" type="number" password maxlength="6" placeholder="再次输入支付密码" />
|
||||
<template v-if="!status.has_payment_password && !status.has_login_password">
|
||||
<text class="hint">当前尚未设置登录密码,请通过绑定微信手机号验证后设置支付密码。</text>
|
||||
<!-- #ifdef MP-WEIXIN -->
|
||||
<button class="primary" open-type="getPhoneNumber" :disabled="busy" @getphonenumber="onPhoneVerifyPayment">验证手机号并设置</button>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef MP-WEIXIN -->
|
||||
<text class="hint">请在微信小程序内完成手机号验证,或先设置登录密码。</text>
|
||||
<!-- #endif -->
|
||||
</template>
|
||||
<button v-else class="primary" :disabled="busy" @tap="savePassword">确认</button>
|
||||
<view v-if="status.has_payment_password" class="input-box">
|
||||
<input
|
||||
v-model="oldPassword"
|
||||
class="input-field"
|
||||
type="number"
|
||||
:password="!showOldPwd"
|
||||
maxlength="6"
|
||||
placeholder="请输入原6位数字支付密码"
|
||||
/>
|
||||
<view class="eye-btn" @tap="showOldPwd = !showOldPwd">
|
||||
<image class="eye-ico" :src="showOldPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="input-box">
|
||||
<input
|
||||
v-model="newPassword"
|
||||
class="input-field"
|
||||
type="number"
|
||||
:password="!showNewPwd"
|
||||
maxlength="6"
|
||||
placeholder="请输入6位数字支付密码"
|
||||
/>
|
||||
<view class="eye-btn" @tap="showNewPwd = !showNewPwd">
|
||||
<image class="eye-ico" :src="showNewPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="input-box">
|
||||
<input
|
||||
v-model="confirmPassword"
|
||||
class="input-field"
|
||||
type="number"
|
||||
:password="!showConfirmPwd"
|
||||
maxlength="6"
|
||||
placeholder="再次输入6位数字支付密码"
|
||||
/>
|
||||
<view class="eye-btn" @tap="showConfirmPwd = !showConfirmPwd">
|
||||
<image class="eye-ico" :src="showConfirmPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||||
</view>
|
||||
</view>
|
||||
<button class="primary" :disabled="busy" @tap="savePassword">
|
||||
{{ status.has_payment_password ? '确认修改' : '确认设置' }}
|
||||
</button>
|
||||
<text v-if="status.has_payment_password" class="hint center-hint">如忘记原支付密码,请联系平台管理员在后台重置</text>
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
@@ -70,8 +186,31 @@
|
||||
const oldPassword = ref('');
|
||||
const newPassword = ref('');
|
||||
const confirmPassword = ref('');
|
||||
const showOldPwd = ref(false);
|
||||
const showNewPwd = ref(false);
|
||||
const showConfirmPwd = ref(false);
|
||||
|
||||
const sheetTitle = computed(() => mode.value === 'login' ? '登录密码' : '支付密码');
|
||||
const isAccountSafe = computed(() => !!(status.value.mobile && status.value.has_payment_password));
|
||||
|
||||
const verifyStatusText = computed(() => {
|
||||
const map = { pass: '已认证', pending: '审核中', reject: '未通过', draft: '未认证' };
|
||||
return map[status.value.verify_status] || '未认证';
|
||||
});
|
||||
|
||||
const verifyTagClass = computed(() => {
|
||||
const st = status.value.verify_status;
|
||||
if (st === 'pass') return 'tag-success';
|
||||
if (st === 'pending') return 'tag-warning';
|
||||
if (st === 'reject') return 'tag-danger';
|
||||
return 'tag-muted';
|
||||
});
|
||||
|
||||
const sheetTitle = computed(() => {
|
||||
if (mode.value === 'login') {
|
||||
return status.value.has_login_password ? '修改登录密码' : '设置登录密码';
|
||||
}
|
||||
return status.value.has_payment_password ? '修改支付密码' : '设置支付密码';
|
||||
});
|
||||
|
||||
async function load() {
|
||||
if (!isLogin()) {
|
||||
@@ -84,64 +223,86 @@
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (busy.value) return;
|
||||
mode.value = '';
|
||||
function resetFormFields() {
|
||||
oldPassword.value = '';
|
||||
newPassword.value = '';
|
||||
confirmPassword.value = '';
|
||||
showOldPwd.value = false;
|
||||
showNewPwd.value = false;
|
||||
showConfirmPwd.value = false;
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (busy.value) return;
|
||||
mode.value = '';
|
||||
resetFormFields();
|
||||
}
|
||||
|
||||
function openPassword(which) {
|
||||
resetFormFields();
|
||||
mode.value = which;
|
||||
}
|
||||
|
||||
function goVerifyStatus() {
|
||||
if (status.value.verify_status === 'pass') return;
|
||||
uni.navigateTo({ url: '/pages/master/apply' });
|
||||
}
|
||||
|
||||
function validPassword() {
|
||||
const valid = mode.value === 'payment' ? /^\d{6}$/.test(newPassword.value) : /^\S{6,30}$/.test(newPassword.value);
|
||||
if (!valid || newPassword.value !== confirmPassword.value) {
|
||||
uni.showToast({ title: '请检查两次输入的密码', icon: 'none' });
|
||||
const isPayment = mode.value === 'payment';
|
||||
const needOld = isPayment ? status.value.has_payment_password : status.value.has_login_password;
|
||||
if (needOld && !oldPassword.value) {
|
||||
uni.showToast({ title: '请输入原密码', icon: 'none' });
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isPayment) {
|
||||
if (!/^\d{6}$/.test(newPassword.value)) {
|
||||
uni.showToast({ title: '支付密码须为6位数字', icon: 'none' });
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (!/^\S{6,30}$/.test(newPassword.value)) {
|
||||
uni.showToast({ title: '登录密码须为6至30位非空字符', icon: 'none' });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (newPassword.value !== confirmPassword.value) {
|
||||
uni.showToast({ title: '两次输入的新密码不一致', icon: 'none' });
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
async function onPhoneVerifyLogin(event) {
|
||||
const code = event.detail && event.detail.code;
|
||||
if (!code) { uni.showToast({ title: '未完成手机号验证', icon: 'none' }); return; }
|
||||
await savePassword(code);
|
||||
}
|
||||
|
||||
async function onPhoneVerifyPayment(event) {
|
||||
const code = event.detail && event.detail.code;
|
||||
if (!code) { uni.showToast({ title: '未完成手机号验证', icon: 'none' }); return; }
|
||||
await savePassword(code);
|
||||
}
|
||||
|
||||
async function savePassword(phoneCode = '') {
|
||||
if (typeof phoneCode !== 'string') phoneCode = '';
|
||||
async function savePassword() {
|
||||
if (busy.value || !validPassword()) return;
|
||||
busy.value = true;
|
||||
try {
|
||||
if (mode.value === 'login') {
|
||||
await api.changeLoginPassword({ old_password: oldPassword.value, new_password: newPassword.value, phone_code: phoneCode });
|
||||
await api.changeLoginPassword({
|
||||
old_password: oldPassword.value,
|
||||
new_password: newPassword.value
|
||||
});
|
||||
clearAuth();
|
||||
uni.showToast({ title: '请重新登录', icon: 'none' });
|
||||
setTimeout(() => uni.reLaunch({ url: '/pages/login/login' }), 700);
|
||||
uni.showToast({ title: '密码已更新,请重新登录', icon: 'none' });
|
||||
setTimeout(() => uni.reLaunch({ url: '/pages/login/login' }), 800);
|
||||
return;
|
||||
}
|
||||
|
||||
const firstSetup = !status.value.has_payment_password;
|
||||
if (!firstSetup) {
|
||||
await api.changePaymentPassword({ old_password: oldPassword.value, new_password: newPassword.value });
|
||||
if (firstSetup) {
|
||||
await api.setPaymentPassword({ new_password: newPassword.value });
|
||||
} else {
|
||||
await api.setPaymentPassword({
|
||||
login_password: oldPassword.value,
|
||||
phone_code: phoneCode,
|
||||
await api.changePaymentPassword({
|
||||
old_password: oldPassword.value,
|
||||
new_password: newPassword.value
|
||||
});
|
||||
}
|
||||
|
||||
busy.value = false;
|
||||
close();
|
||||
uni.showToast({ title: '保存成功' });
|
||||
uni.showToast({ title: firstSetup ? '设置成功' : '修改成功', icon: 'success' });
|
||||
if (setupFromPayment.value && firstSetup) {
|
||||
try { await finishPaymentSetup(uni); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
|
||||
} else {
|
||||
@@ -168,8 +329,9 @@
|
||||
title: '退出登录',
|
||||
content: '确认退出当前师傅账号?',
|
||||
confirmColor: '#F0710D',
|
||||
success: (result) => {
|
||||
success: async (result) => {
|
||||
if (result.confirm) {
|
||||
try { await api.logout(); } catch (e) {}
|
||||
clearAuth();
|
||||
uni.reLaunch({ url: '/pages/login/login' });
|
||||
}
|
||||
@@ -202,20 +364,116 @@
|
||||
|
||||
<style lang="scss" scoped>
|
||||
@import '@/uni.scss';
|
||||
.page { min-height: 100vh; background: $yjyf-bg-page; }
|
||||
.card { margin: 24rpx; padding: 0 28rpx; background: $yjyf-bg-card; border-radius: 20rpx; }
|
||||
.row { display: flex; align-items: center; justify-content: space-between; min-height: 104rpx; border-bottom: 1rpx solid $yjyf-border-color; font-size: 28rpx; color: $yjyf-text-main; }
|
||||
.row:last-child { border-bottom: 0; }
|
||||
.value { display: flex; align-items: center; gap: 12rpx; color: $yjyf-text-secondary; font-size: 26rpx; }
|
||||
.arrow { width: 28rpx; height: 28rpx; }
|
||||
.logout { margin: 40rpx 24rpx; height: 92rpx; line-height: 92rpx; text-align: center; border-radius: 16rpx; background: $yjyf-bg-card; color: $yjyf-danger; font-size: 28rpx; font-weight: 600; }
|
||||
.mask { position: fixed; inset: 0; z-index: 999; display: flex; align-items: flex-end; background: rgba(0,0,0,.45); }
|
||||
.sheet { width: 100%; padding: 32rpx 28rpx 48rpx; border-radius: 24rpx 24rpx 0 0; background: $yjyf-bg-card; display: flex; flex-direction: column; gap: 20rpx; }
|
||||
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8rpx; }
|
||||
.title { font-size: 32rpx; font-weight: 700; color: $yjyf-text-main; }
|
||||
.close { font-size: 26rpx; color: $yjyf-text-secondary; }
|
||||
.input { height: 88rpx; padding: 0 24rpx; border-radius: 12rpx; background: $yjyf-bg-page; font-size: 28rpx; color: $yjyf-text-main; }
|
||||
.hint { font-size: 24rpx; color: $yjyf-text-secondary; line-height: 1.5; }
|
||||
.primary { width: 100%; height: 90rpx; line-height: 90rpx; border-radius: 45rpx; background: $yjyf-gradient-primary; color: #fff; font-size: 30rpx; font-weight: 600; border: none; }
|
||||
.page { min-height: 100vh; background: $yjyf-bg-page; padding-bottom: calc(48rpx + env(safe-area-inset-bottom)); }
|
||||
.security-body { padding-top: 20rpx; }
|
||||
|
||||
.hero-card {
|
||||
margin: 0 $yjyf-space-md 20rpx;
|
||||
padding: 28rpx 32rpx;
|
||||
background: $yjyf-bg-card;
|
||||
border-radius: $yjyf-radius-md;
|
||||
box-shadow: $yjyf-shadow-card;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 20rpx;
|
||||
}
|
||||
.hero-ico { width: 52rpx; height: 52rpx; flex-shrink: 0; }
|
||||
.hero-info { display: flex; flex-direction: column; gap: 6rpx; min-width: 0; }
|
||||
.hero-title { font-size: $yjyf-font-title; font-weight: 700; color: $yjyf-text-main; }
|
||||
.hero-sub { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; }
|
||||
|
||||
.card {
|
||||
margin: 0 $yjyf-space-md 20rpx;
|
||||
padding: 0 32rpx;
|
||||
background: $yjyf-bg-card;
|
||||
border-radius: $yjyf-radius-md;
|
||||
box-shadow: $yjyf-shadow-card;
|
||||
}
|
||||
.card-head { padding: 26rpx 0 12rpx; }
|
||||
.card-title { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; font-weight: 600; }
|
||||
|
||||
.row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16rpx;
|
||||
min-height: 108rpx;
|
||||
border-top: 1rpx solid $yjyf-border-color;
|
||||
}
|
||||
.row-left { display: flex; flex-direction: column; gap: 4rpx; }
|
||||
.row-label { font-size: $yjyf-font-body; color: $yjyf-text-main; }
|
||||
.row-desc { font-size: $yjyf-font-micro; color: $yjyf-text-muted; }
|
||||
.row-right { display: flex; align-items: center; gap: 12rpx; flex-shrink: 0; }
|
||||
.row-val { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; }
|
||||
.row-val.unset { color: $yjyf-warning; font-weight: 500; }
|
||||
.arrow { width: 24rpx; height: 24rpx; }
|
||||
|
||||
.tag {
|
||||
padding: 6rpx 16rpx;
|
||||
border-radius: $yjyf-radius-pill;
|
||||
font-size: $yjyf-font-micro;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
}
|
||||
.tag-success { background: rgba(47, 168, 79, 0.1); color: $yjyf-success; }
|
||||
.tag-warning { background: rgba(249, 141, 37, 0.12); color: $yjyf-warning; }
|
||||
.tag-danger { background: rgba(232, 51, 27, 0.1); color: $yjyf-danger; }
|
||||
.tag-muted { background: $yjyf-bg-page; color: $yjyf-text-secondary; }
|
||||
|
||||
.logout {
|
||||
margin: 40rpx $yjyf-space-md 0;
|
||||
height: 92rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-radius: $yjyf-radius-pill;
|
||||
background: $yjyf-bg-card;
|
||||
box-shadow: $yjyf-shadow-card;
|
||||
color: $yjyf-danger;
|
||||
font-size: $yjyf-font-body;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.mask { position: fixed; inset: 0; z-index: 999; display: flex; align-items: flex-end; background: rgba(0, 0, 0, 0.45); }
|
||||
.sheet {
|
||||
width: 100%;
|
||||
padding: 32rpx 32rpx calc(40rpx + env(safe-area-inset-bottom));
|
||||
border-radius: $yjyf-radius-lg $yjyf-radius-lg 0 0;
|
||||
background: $yjyf-bg-card;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20rpx;
|
||||
}
|
||||
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4rpx; }
|
||||
.title { font-size: $yjyf-font-title; font-weight: 700; color: $yjyf-text-main; }
|
||||
.close { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; padding: 8rpx 0 8rpx 16rpx; }
|
||||
|
||||
.input-box {
|
||||
height: 92rpx;
|
||||
padding: 0 20rpx 0 24rpx;
|
||||
border-radius: $yjyf-radius-sm;
|
||||
background: $yjyf-bg-page;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
}
|
||||
.input-field { flex: 1; min-width: 0; height: 92rpx; font-size: $yjyf-font-body; color: $yjyf-text-main; }
|
||||
.eye-btn { width: 56rpx; height: 56rpx; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
|
||||
.eye-ico { width: 34rpx; height: 34rpx; }
|
||||
|
||||
.hint { font-size: $yjyf-font-micro; color: $yjyf-text-muted; line-height: 1.5; }
|
||||
.center-hint { text-align: center; }
|
||||
.primary {
|
||||
width: 100%;
|
||||
height: 90rpx;
|
||||
line-height: 90rpx;
|
||||
border-radius: $yjyf-radius-pill;
|
||||
background: $yjyf-gradient-primary;
|
||||
box-shadow: $yjyf-shadow-button;
|
||||
color: $yjyf-text-inverse;
|
||||
font-size: $yjyf-font-body;
|
||||
font-weight: 700;
|
||||
border: none;
|
||||
}
|
||||
.primary::after { border: none; }
|
||||
</style>
|
||||
|
||||
@@ -16,7 +16,6 @@ export default {
|
||||
|
||||
/* ---------- 师傅端独立鉴权与安全 ---------- */
|
||||
login: (data) => post('/master_auth/login', data, { silent: true }),
|
||||
wxLogin: (data) => post('/master_auth/wxlogin', data, { silent: true }),
|
||||
wxPhoneLogin: (data) => post('/master_auth/wxPhoneLogin', data, { silent: true }),
|
||||
logout: () => post('/master_auth/logout', {}, { silent: true }),
|
||||
profile: () => get('/master_auth/profile'),
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
/**
|
||||
* 微信登录统一入口
|
||||
* 解决两个线上问题:
|
||||
* 1) code 一次性(5 分钟、单次有效)——静默登录与手动登录若同时发起会互相抢 code
|
||||
* → 用「单飞(in-flight)」保证同一时刻只有一个换取流程
|
||||
* 2) 40029(invalid code)——可能来自 code 已被消费/过期
|
||||
* → 自动用全新 code 重试一次
|
||||
* 微信登录辅助工具
|
||||
* 师傅端统一使用「获取微信手机号」登录,不做 OpenID 静默登录。
|
||||
* 此处仅提供 getWxCode() 用于在手机号授权时同步换取 OpenID 完成绑定。
|
||||
*/
|
||||
import api from './api.js';
|
||||
import { setToken, setUser } from './request.js';
|
||||
|
||||
let inflight = null;
|
||||
|
||||
/** 取微信一次性 code */
|
||||
export function getWxCode() {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
@@ -21,45 +12,3 @@ export function getWxCode() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isCodeInvalid(err) {
|
||||
const code = err && err.data ? Number(err.data.wx_errcode) : 0;
|
||||
if (code === 40029 || code === 40163) return true;
|
||||
return /invalid code|code been used|40029/i.test((err && err.message) || '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用 code 换 token;遇到 code 失效自动换新 code 重试一次
|
||||
*/
|
||||
async function exchange(payload, retry) {
|
||||
const code = await getWxCode();
|
||||
try {
|
||||
const data = await api.wxLogin(Object.assign({}, payload, { code: code }));
|
||||
setToken(data.token);
|
||||
setUser(data.masterinfo || data.userinfo);
|
||||
return data;
|
||||
} catch (err) {
|
||||
if (retry && isCodeInvalid(err)) {
|
||||
return exchange(payload, false);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动授权登录(点击「微信一键登录」)
|
||||
*/
|
||||
export function wxAuthorizeLogin(payload) {
|
||||
if (inflight) {
|
||||
// 复用在途结果,避免抢同一个 code
|
||||
return inflight.then((data) => {
|
||||
if (data) return data;
|
||||
return exchange(payload || {}, true);
|
||||
});
|
||||
}
|
||||
inflight = exchange(payload || {}, true).then(
|
||||
(data) => { inflight = null; return data; },
|
||||
(err) => { inflight = null; throw err; }
|
||||
);
|
||||
return inflight;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户