微信登录修复: - 根因:manifest.json 的 mp-weixin.appid 为空 → 开发者工具用测试号,code 与服务端 appid 不匹配 - 修复:填入 wx40ca4b02d4d1cb58 - WxLogin 增加错误码语义映射(40029 appid 不一致 / 40125 secret 错 / 45011 频繁 / 40226 风控) - 登录页新增手机号登录兜底通道(微信不可用时业务不被卡住) 商家(企业账号): - 新表 fa_merchant / fa_merchant_order / fa_invoice(纯新增,DB 40→45 表) - Merchant 控制器:apply/info/update/bills/invoices/invoice/bindBatch 入驻含企业信息+营业执照+开票信息+结算方式(预付/月结) 账单按月汇总、开票额度按已付-已开票校验、批量下单按批次归属 - Auth::switchRole 支持 merchant(2001/2002/2003 语义码 + redirect) - Auth::profile 增加 is_merchant / merchant 前端: - 登录页角色扩为 业主/师傅/商家 三类 - pages/merchant/apply 企业入驻;workbench 商家工作台(经营数据+按月账单+近期订单+六宫格) - pages/merchant/batch 批量下单(多地址×多数量)→ 逐单建单支付 → 绑定批次 - pages/merchant/invoice 开票申请与记录 - pages/mine 增加商家入驻/切换商家端入口;角色徽章三态 验证:163 项断言全通过(page_flow 47 + e2e 65 + phase2 27 + phase3 24)
180 行
7.7 KiB
Vue
180 行
7.7 KiB
Vue
<template>
|
||
<view class="page">
|
||
<view class="top">
|
||
<view class="deco d1"></view>
|
||
<view class="deco d2"></view>
|
||
<view class="back" v-if="showBack" @tap="goBack"><text class="back-t">‹</text></view>
|
||
<text class="brand">优匠优服</text>
|
||
<text class="slogan">专业师傅 · 上门到家</text>
|
||
</view>
|
||
|
||
<view class="card">
|
||
<view class="role">
|
||
<view class="role-item" v-for="r in roles" :key="r.key" :class="{ on: role === r.key }" @tap="role = r.key">
|
||
<text class="role-name">{{ r.name }}</text>
|
||
<text class="role-desc">{{ r.desc }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="wx-btn" :class="{ disabled: loading }" @tap="wxLogin">
|
||
<view class="wx-icon"><text class="wx-icon-t">微</text></view>
|
||
<text class="wx-txt">{{ loading ? '微信授权中...' : '微信一键登录' }}</text>
|
||
</view>
|
||
|
||
<view class="fallback">
|
||
<view class="fb-toggle" @tap="showPhone = !showPhone">
|
||
<text class="fb-toggle-t">{{ showPhone ? '收起手机号登录' : '微信授权失败?改用手机号登录' }}</text>
|
||
</view>
|
||
<view class="fb-body" v-if="showPhone">
|
||
<input class="fb-input" v-model="mobile" type="number" maxlength="11" placeholder="请输入手机号" />
|
||
<input class="fb-input" v-model="code" type="number" maxlength="6" placeholder="验证码(联调固定 123456)" />
|
||
<view class="fb-btn" @tap="phoneLogin">手机号登录 / 注册</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="tip">授权仅用于账号识别,不会获取你的其他信息</view>
|
||
<view class="agree">登录即代表同意《用户服务协议》与《隐私政策》</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { ref } from 'vue';
|
||
import { onLoad } from '@dcloudio/uni-app';
|
||
import api from '@/utils/api.js';
|
||
import { setToken, setUser } from '@/utils/request.js';
|
||
import { setRole } from '@/utils/role.js';
|
||
|
||
const role = ref('user');
|
||
const loading = ref(false);
|
||
const showBack = ref(false);
|
||
const showPhone = ref(false);
|
||
const mobile = ref('');
|
||
const code = ref('');
|
||
|
||
const roles = [
|
||
{ key: 'user', name: '我是业主', desc: '下单找师傅' },
|
||
{ key: 'master', name: '我是师傅', desc: '接单赚收入' },
|
||
{ key: 'merchant', name: '我是商家', desc: '企业批量下单' }
|
||
];
|
||
|
||
function toast(t) { uni.showToast({ title: t, icon: 'none' }); }
|
||
|
||
/** 从「我的」进入时才显示返回键(作为启动页时不显示) */
|
||
onLoad(() => {
|
||
showBack.value = getCurrentPages().length > 1;
|
||
});
|
||
|
||
function goBack() { uni.navigateBack(); }
|
||
|
||
/** 微信授权登录:uni.login 取 code → 后端换 openid → 下发 token */
|
||
function wxLogin() {
|
||
if (loading.value) return;
|
||
loading.value = true;
|
||
uni.login({
|
||
provider: 'weixin',
|
||
success: async (res) => {
|
||
if (!res.code) {
|
||
loading.value = false;
|
||
toast('微信授权失败,请重试');
|
||
return;
|
||
}
|
||
try {
|
||
const data = await api.wxLogin({ code: res.code });
|
||
setToken(data.token);
|
||
setUser(data.userinfo);
|
||
setRole(role.value);
|
||
toast(data.is_new ? '登录成功,欢迎加入' : '登录成功');
|
||
setTimeout(() => routeAfterLogin(), 600);
|
||
} catch (e) {
|
||
toast(e.message || '登录失败');
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
},
|
||
fail: () => {
|
||
loading.value = false;
|
||
toast('未检测到微信环境,请在小程序内打开');
|
||
}
|
||
});
|
||
}
|
||
|
||
function phoneLogin() {
|
||
if (loading.value) return;
|
||
if (!/^1\d{10}$/.test(mobile.value)) { toast('请输入正确的手机号'); return; }
|
||
if (!code.value) { toast('请输入验证码'); return; }
|
||
loading.value = true;
|
||
api.login({ mobile: mobile.value, code: code.value }).then((data) => {
|
||
loading.value = false;
|
||
setToken(data.token);
|
||
setUser(data.userinfo);
|
||
setRole(role.value);
|
||
toast('登录成功');
|
||
setTimeout(() => routeAfterLogin(), 500);
|
||
}).catch((e) => {
|
||
loading.value = false;
|
||
toast(e.message || '登录失败');
|
||
});
|
||
}
|
||
|
||
function routeAfterLogin() {
|
||
if (role.value === 'user') {
|
||
uni.reLaunch({ url: '/YJYF/YJYF' });
|
||
return;
|
||
}
|
||
if (role.value === 'merchant') {
|
||
api.merchantInfo().then((res) => {
|
||
if (!res.applied || res.merchant.verify_status !== 'pass') {
|
||
uni.redirectTo({ url: '/pages/merchant/apply' });
|
||
} else {
|
||
uni.redirectTo({ url: '/pages/merchant/workbench' });
|
||
}
|
||
}).catch(() => uni.redirectTo({ url: '/pages/merchant/apply' }));
|
||
return;
|
||
}
|
||
api.masterInfo().then((res) => {
|
||
if (!res.applied || res.master.verify_status !== 'pass') {
|
||
uni.redirectTo({ url: '/pages/master/apply' });
|
||
} else {
|
||
uni.redirectTo({ url: '/pages/master/workbench' });
|
||
}
|
||
}).catch(() => {
|
||
uni.redirectTo({ url: '/pages/master/apply' });
|
||
});
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.page { min-height: 100vh; background: #F5F6F8; }
|
||
.top { position: relative; height: 420rpx; padding: 120rpx 0 0 48rpx; overflow: hidden;
|
||
background: linear-gradient(160deg, #FFB85C 0%, #F98D25 46%, #ED6F0E 100%); border-radius: 0 0 48rpx 48rpx; }
|
||
.deco { position: absolute; border-radius: 50%; }
|
||
.back { position: absolute; left: 26rpx; top: 92rpx; width: 64rpx; height: 64rpx; border-radius: 50%; background: rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center; }
|
||
.back-t { font-size: 44rpx; color: #fff; line-height: 44rpx; margin-top: -6rpx; }
|
||
.d1 { width: 360rpx; height: 360rpx; right: -120rpx; top: -160rpx; background: rgba(255,255,255,.14); }
|
||
.d2 { width: 220rpx; height: 220rpx; left: -90rpx; bottom: -80rpx; background: rgba(255,255,255,.10); }
|
||
.brand { position: relative; display: block; font-size: 52rpx; font-weight: 700; color: #fff; letter-spacing: 6rpx; text-shadow: 0 3rpx 12rpx rgba(180,80,10,.3); }
|
||
.slogan { position: relative; display: block; margin-top: 14rpx; font-size: 26rpx; color: rgba(255,255,255,.88); letter-spacing: 2rpx; }
|
||
.card { position: relative; margin: -140rpx 40rpx 0; padding: 40rpx 34rpx 34rpx; background: #fff; border-radius: 24rpx; box-shadow: 0 16rpx 40rpx rgba(226,120,26,.16); }
|
||
.role { display: flex; margin-bottom: 34rpx; }
|
||
.role-item { flex: 1; margin-right: 12rpx; padding: 18rpx 0; border-radius: 16rpx; background: #F7F7F7; display: flex; flex-direction: column; align-items: center; border: 2rpx solid transparent; }
|
||
.role-item:last-child { margin-right: 0; }
|
||
.role-item.on { background: linear-gradient(135deg, #FFF8EE 0%, #FFE9D2 100%); border-color: #F9A65B; }
|
||
.role-name { font-size: 26rpx; font-weight: 600; color: #333; }
|
||
.role-item.on .role-name { color: #C4580A; }
|
||
.role-desc { margin-top: 4rpx; font-size: 19rpx; color: #9A9A9A; }
|
||
.fallback { margin-top: 20rpx; }
|
||
.fb-toggle { text-align: center; padding: 12rpx 0; }
|
||
.fb-toggle-t { font-size: 22rpx; color: #9A9A9A; text-decoration: underline; }
|
||
.fb-body { margin-top: 10rpx; }
|
||
.fb-input { height: 88rpx; margin-bottom: 14rpx; padding: 0 24rpx; background: #F7F7F7; border-radius: 14rpx; font-size: 28rpx; color: #222; }
|
||
.fb-btn { height: 84rpx; display: flex; align-items: center; justify-content: center; border-radius: 42rpx; background: #FFF3E6; color: #E36B0C; font-size: 28rpx; font-weight: 600; }
|
||
.wx-btn { height: 96rpx; display: flex; align-items: center; justify-content: center; border-radius: 48rpx; background: linear-gradient(135deg, #4BC86A 0%, #2FA84F 100%); box-shadow: 0 10rpx 24rpx rgba(47,168,79,.28); }
|
||
.wx-btn.disabled { opacity: .7; }
|
||
.wx-icon { width: 44rpx; height: 44rpx; border-radius: 50%; background: #fff; display: flex; align-items: center; justify-content: center; margin-right: 14rpx; }
|
||
.wx-icon-t { font-size: 24rpx; font-weight: 700; color: #2FA84F; }
|
||
.wx-txt { font-size: 32rpx; font-weight: 600; color: #fff; letter-spacing: 1rpx; }
|
||
.tip { display: block; margin-top: 24rpx; text-align: center; font-size: 20rpx; color: #B5B5B5; }
|
||
.agree { display: block; margin-top: 12rpx; text-align: center; font-size: 20rpx; color: #C4C4C4; }
|
||
</style>
|