From e6ec0514416315ff6b4470fcdd4a458f2489c6c6 Mon Sep 17 00:00:00 2001 From: lik Date: Tue, 10 Nov 2026 20:03:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(apply):=20=E6=89=8B=E6=9C=BA=E5=8F=B7?= =?UTF-8?q?=E5=86=B2=E7=AA=81=E8=B5=B0=E5=BE=AE=E4=BF=A1=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=B9=B6=E5=8F=B7=EF=BC=8C=E5=BE=85=E5=AE=A1=E6=A0=B8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 4 + pages/apply/index.js | 232 +++++++++++++++++++++++++++++++++++++++-- pages/apply/index.wxml | 30 ++++-- pages/apply/index.wxss | 79 +++++++++++++- pages/launch/index.js | 25 ++++- utils/api.js | 2 + utils/role.js | 12 ++- 7 files changed, 362 insertions(+), 22 deletions(-) diff --git a/app.js b/app.js index 306b00c..6e057a5 100644 --- a/app.js +++ b/app.js @@ -85,20 +85,24 @@ App({ API.user.wxSignin({ code: res.code }) .then((data) => { if (data.code == 0) { + console.info('[app] 静默登录成功', data.data.user && data.data.user.profile && data.data.user.profile.mobile) this.globalData.user = data.data.user; this.eventBus.emit('user-login', data.data.user); resolve(data.data.user); } else { + console.warn('[app] 静默登录被拒:', data.msg) this._loginPromise = null; reject(new Error(data.msg || '登录失败')); } }) .catch((err) => { + console.warn('[app] 静默登录请求异常:', err && err.message) this._loginPromise = null; reject(err); }); }, fail: (err) => { + console.warn('[app] wx.login 失败:', err && err.errMsg) this._loginPromise = null; reject(err); } diff --git a/pages/apply/index.js b/pages/apply/index.js index 14b4d72..c01c192 100644 --- a/pages/apply/index.js +++ b/pages/apply/index.js @@ -18,6 +18,8 @@ Page({ data: { loading: true, view: 'form', // form 填写 / pending 待审核 / approved 已通过但角色未刷新 + editing: false, // 待审核期间修改基本信息 + needPhoneAuth: false, // 手机号已有平台账号,需验证微信手机号后并入 submitting: false, rejectReason: '', application: null, @@ -45,7 +47,9 @@ Page({ * force=true:审批可能刚刚通过,必须绕过角色缓存 */ refresh() { - this.setData({ loading: true }) + // 修改资料时前后台切换不重置表单 + if (this.data.editing) return + this.setData({ loading: true, needPhoneAuth: false }) role .ensureRoleSafe(true) .then((detail) => { @@ -67,7 +71,12 @@ Page({ .getMine() .then((res) => { if (res.code !== 0) { - wx.showToast({ title: res.msg || '加载失败', icon: 'none' }) + // 未登录(新用户走到这里时还没有账号)不弹错误,直接展示表单 + if (res.code !== 401) { + wx.showToast({ title: res.msg || '加载失败', icon: 'none' }) + } else { + console.info('[apply] 未登录,展示申请表单') + } this.setData({ loading: false, accountName }) return } @@ -82,6 +91,7 @@ Page({ this.setData({ loading: false, view: 'pending', + editing: false, application, accountName, serviceAreaText: (application.applicant.serviceAreas || []).map(cityLabel).join('、'), @@ -145,6 +155,186 @@ Page({ this.setData({ cityIndex: Number(e.detail.value) || 0 }) }, + /** + * 提交前确保已登录: + * 老用户在启动页已完成静默登录;首次使用的新用户还没有账号, + * 用表单里的手机号+姓名走 wxSignin 注册(后端仅允许未验证手机号用于新建账号, + * 与健康档案手机号无关联)。 + */ + ensureLoginForApply() { + const app = getApp() + const current = app && app.globalData ? app.globalData.user : null + if (current && current.security && current.security.token) { + return Promise.resolve(current) + } + + return new Promise((resolve, reject) => { + wx.login({ + success: (res) => { + if (!res.code) { + reject(new Error('wx.login 未返回 code')) + return + } + API.user.wxSignin({ + code: res.code, + phoneNumber: this.data.form.mobile.trim(), + name: this.data.form.name.trim() + }) + .then((data) => { + if (data.code === 0) { + console.info('[apply] 注册/登录成功', + data.data.user && data.data.user.profile && data.data.user.profile.mobile) + app.globalData.user = data.data.user + app.eventBus.emit('user-login', data.data.user) + resolve(data.data.user) + return + } + console.warn('[apply] 注册/登录被拒:', data.msg) + reject(new Error(data.msg || '登录失败')) + }) + .catch(reject) + }, + fail: (err) => reject(new Error((err && err.errMsg) || 'wx.login 失败')) + }) + }) + }, + + /** + * 微信手机号快速验证后并入已有账号 + * + * phoneCode 是一次性凭证,只能交给 wxSignin 在服务端消费一次; + * 成功后账号已绑定当前微信,继续走正常提交 + */ + onPhoneAuth(e) { + const phoneCode = e.detail && e.detail.code ? e.detail.code : '' + if (!phoneCode) { + console.warn('[apply] 未获得手机号授权:', e.detail && e.detail.errMsg) + wx.showToast({ title: '需要授权手机号才能继续', icon: 'none' }) + return + } + if (this.data.submitting) return + this.setData({ submitting: true }) + + wx.login({ + success: (res) => { + if (!res.code) { + this.setData({ submitting: false }) + wx.showToast({ title: '登录失败,请重试', icon: 'none' }) + return + } + API.user + .wxSignin({ + phoneCode, + code: res.code, + name: this.data.form.name.trim() + }) + .then((data) => { + if (data.code !== 0) { + this.setData({ submitting: false }) + wx.showToast({ title: data.msg || '登录失败', icon: 'none' }) + return + } + // 账号已并入当前微信,先落全局用户,后续提交直接复用该身份 + const app = getApp() + app.globalData.user = data.data.user + app.eventBus.emit('user-login', data.data.user) + + // 验证回来的号码与填写不一致时,以微信验证的号码为准,避免把申请挂到别人的手机号上 + const verifiedMobile = + (data.data.user && data.data.user.profile && data.data.user.profile.mobile) || '' + const formMobile = this.data.form.mobile.trim() + if (verifiedMobile && formMobile && verifiedMobile !== formMobile) { + this.setData({ + submitting: false, + needPhoneAuth: false, + 'form.mobile': verifiedMobile + }) + wx.showModal({ + title: '手机号已更新', + content: `当前微信验证的手机号为 ${verifiedMobile},与填写的 ${formMobile} 不一致,已自动改用验证手机号,请确认后重新提交。`, + showCancel: false + }) + return + } + // submit 内部有 submitting 守卫,先复位再继续提交 + this.setData({ submitting: false, needPhoneAuth: false }) + this.submit() + }) + .catch((err) => { + console.warn('[apply] 手机号验证登录失败:', err) + this.setData({ submitting: false }) + wx.showToast({ title: '网络错误,请重试', icon: 'none' }) + }) + }, + fail: () => { + this.setData({ submitting: false }) + wx.showToast({ title: '登录失败,请重试', icon: 'none' }) + } + }) + }, + + cancelPhoneAuth() { + this.setData({ needPhoneAuth: false }) + }, + + /** + * 待审核 → 修改模式:回填已提交的基本信息 + */ + startEdit() { + const application = this.data.application + if (!application) return + const applicant = application.applicant || {} + const sexIndex = SEX_OPTIONS.findIndex((item) => item.value === applicant.sex) + this.setData({ + view: 'form', + editing: true, + rejectReason: '', + sexIndex: sexIndex > -1 ? sexIndex : 0, + cityIndex: cityIndex((applicant.serviceAreas || [])[0]), + form: { + name: applicant.name || '', + mobile: applicant.mobile || '', + sex: applicant.sex || '', + introduction: applicant.introduction || '' + } + }) + }, + + cancelEdit() { + // 放弃本次修改,回到待审核视图 + this.setData({ view: 'pending', editing: false }) + }, + + submitUpdate(payload) { + this.setData({ submitting: true }) + API.attendantApplication + .updateMine(payload) + .then((res) => { + if (res.code === 0) { + const application = res.data ? res.data.application : null + wx.showToast({ title: '已保存', icon: 'success' }) + this.setData({ + submitting: false, + view: 'pending', + editing: false, + application, + serviceAreaText: application + ? (application.applicant.serviceAreas || []).map(cityLabel).join('、') + : '', + submitTimeText: application ? this.formatTime(application.createtime) : '' + }) + return + } + this.setData({ submitting: false }) + wx.showToast({ title: res.msg || '保存失败', icon: 'none' }) + }) + .catch((err) => { + const msg = err && err.message ? err.message : '' + this.setData({ submitting: false }) + wx.showToast({ title: msg || '网络错误,请重试', icon: 'none' }) + }) + }, + submit() { if (this.data.submitting) return @@ -167,9 +357,15 @@ Page({ } } + // 待审核修改:只更新已有的申请单,不重新走提交逻辑 + if (this.data.editing) { + this.submitUpdate(payload) + return + } + this.setData({ submitting: true }) - API.attendantApplication - .create(payload) + this.ensureLoginForApply() + .then(() => API.attendantApplication.create(payload)) .then((res) => { if (res.code === 0) { const next = res.data ? res.data.application : null @@ -207,9 +403,33 @@ Page({ wx.showToast({ title: res.msg || '提交失败', icon: 'none' }) this.setData({ submitting: false }) }) - .catch(() => { - wx.showToast({ title: '网络错误,请重试', icon: 'none' }) + .catch((err) => { + const msg = err && err.message ? err.message : '' + console.warn('[apply] 提交失败:', msg) this.setData({ submitting: false }) + // 登录环节的业务拒绝(手机号已被注册/微信已绑定其他账号)需要弹窗说明 + if (/已注册/.test(msg)) { + // 手机号属于已有平台账号(如就诊人端注册过):手动填写的手机号不可信, + // 必须走微信手机号快速验证,由服务端确认号码归属后并入原账号 + wx.showModal({ + title: '手机号已有账号', + content: `${msg}。可点击「验证手机号」用当前微信绑定的手机号完成验证后继续。`, + confirmText: '验证手机号', + success: (res) => { + if (res.confirm) this.setData({ needPhoneAuth: true }) + } + }) + return + } + if (/已绑定|手机号/.test(msg)) { + wx.showModal({ + title: '无法提交', + content: msg, + showCancel: false + }) + return + } + wx.showToast({ title: msg || '网络错误,请重试', icon: 'none' }) }) }, diff --git a/pages/apply/index.wxml b/pages/apply/index.wxml index 7a820ae..fbf2f0e 100644 --- a/pages/apply/index.wxml +++ b/pages/apply/index.wxml @@ -6,10 +6,10 @@ - + 待审核 - 申请已提交 - 审核通过后成为实习陪诊师,可先查看订单;管理员转正后即可接单。期间无需重复提交。 + 申请已提交,请耐心等待 + 审核完成后会第一时间更新结果;期间无需重复提交,如需修改资料可点击下方「修改个人信息」。 @@ -35,6 +35,8 @@ + + 当前微信账号:{{accountName}} @@ -52,8 +54,8 @@ - 成为陪诊师 - 提交资料并通过审核后成为实习陪诊师,可先查看订单;管理员转正后即可接单。 + {{editing ? '修改个人信息' : '成为陪诊师'}} + {{editing ? '待审核期间可修改姓名、手机号等基本信息,保存后审核进度不受影响。' : '提交资料并通过审核后成为实习陪诊师,可先查看订单;管理员转正后即可接单。'}} @@ -135,10 +137,24 @@ - + + + + + 当前微信账号:{{accountName}}。如需更换账号,请在微信中切换后重新打开小程序。 diff --git a/pages/apply/index.wxss b/pages/apply/index.wxss index b9b7e50..610fc20 100644 --- a/pages/apply/index.wxss +++ b/pages/apply/index.wxss @@ -22,13 +22,26 @@ } .hero-badge { - display: inline-block; - padding: 6rpx 20rpx; - margin-bottom: 16rpx; + display: inline-flex; + align-items: center; + padding: 12rpx 36rpx; + margin-bottom: 20rpx; border-radius: 999rpx; background-color: #F7E4CE; color: #A8551F; - font-size: 24rpx; + font-size: 36rpx; + font-weight: 600; + letter-spacing: 2rpx; + box-shadow: 0 4rpx 16rpx rgba(168, 85, 31, 0.15); +} + +.hero-badge::before { + content: ''; + width: 14rpx; + height: 14rpx; + margin-right: 14rpx; + border-radius: 50%; + background-color: currentColor; } .hero-badge-ok { @@ -52,6 +65,35 @@ color: #8A8078; } +/* 待审核:状态置顶居中强化 */ +.hero-center { + display: flex; + flex-direction: column; + align-items: center; + padding: 56rpx 8rpx 40rpx; + text-align: center; +} + +.hero-center .hero-badge { + margin-bottom: 28rpx; + padding: 18rpx 60rpx; + font-size: 52rpx; + font-weight: 700; + letter-spacing: 4rpx; + box-shadow: 0 8rpx 28rpx rgba(168, 85, 31, 0.22); +} + +.hero-center .hero-badge::before { + width: 18rpx; + height: 18rpx; + margin-right: 16rpx; +} + +.hero-center .hero-title { + font-size: 34rpx; + line-height: 1.4; +} + /* 卡片 */ .card { margin-bottom: 24rpx; @@ -228,6 +270,35 @@ border: none; } +/* 待审核:进入修改模式 */ +.edit-btn { + height: 88rpx; + margin: 0 0 24rpx; + border: 1rpx solid #E7D6C3; + border-radius: 44rpx; + background-color: #fff; + color: #A8551F; + font-size: 30rpx; + line-height: 88rpx; +} + +.edit-btn::after { + border: none; +} + +/* 修改模式:取消返回待审核视图 */ +.cancel-btn { + margin: 0 0 24rpx; + background-color: transparent; + color: #8A8078; + font-size: 28rpx; + line-height: 88rpx; +} + +.cancel-btn::after { + border: none; +} + .foot-note { padding: 0 16rpx; text-align: center; diff --git a/pages/launch/index.js b/pages/launch/index.js index fb8ccf8..a75eedd 100644 --- a/pages/launch/index.js +++ b/pages/launch/index.js @@ -1,6 +1,9 @@ // pages/launch/index.js // 启动页:冷启动先解析身份再决定去首页还是入驻申请页, // 避免默认首页先渲染一帧再被全局守卫重定向。 +// +// 特殊分支:从未使用过的新用户没有账号,wxSignin 只带 code 会返回「缺少手机号」, +// 这不是网络故障——直接进申请页,由申请页用表单里的姓名+手机号完成注册。 const role = require('../../utils/role.js') Page({ @@ -14,9 +17,15 @@ Page({ enter() { this.setData({ error: '' }) - role - .ensureRoleSafe(true) + const app = getApp() + // 先单独走一次登录,才能拿到失败原因(ensureRoleSafe 会把错误吞成 ok:false) + app.ensureLogin() + .then((user) => { + console.info('[launch] 登录成功', user && user.profile && user.profile.mobile) + return role.ensureRoleSafe(true) + }) .then((detail) => { + console.info('[launch] 角色解析:', detail.ok ? detail.role : '解析失败') if (!detail.ok) { this.setData({ error: '网络异常,请重试' }) return @@ -27,7 +36,17 @@ Page({ } wx.switchTab({ url: '/pages/home/index' }) }) - .catch(() => this.setData({ error: '网络异常,请重试' })) + .catch((err) => { + const msg = err && err.message ? err.message : '' + console.warn('[launch] 进入失败:', msg) + // 新用户首次使用:后端返回「缺少手机号」,进申请页注册 + if (msg.indexOf('手机号') > -1) { + console.info('[launch] 新用户未注册,转入申请页') + wx.reLaunch({ url: '/pages/apply/index' }) + return + } + this.setData({ error: '网络异常,请重试' }) + }) }, onRetry() { diff --git a/utils/api.js b/utils/api.js index 7d954b4..1e6650b 100644 --- a/utils/api.js +++ b/utils/api.js @@ -54,6 +54,8 @@ const API = { attendantApplication: { create: (data) => request.post('/health/attendant-application', data), getMine: () => request.get('/health/attendant-application/mine'), + // 待审核期间修改基本信息(仅 pending 状态生效) + updateMine: (data) => request.put('/health/attendant-application/mine', data), // 证件材料后补:只覆盖本次提交的字段 updateMaterials: (data) => request.post('/health/attendant-application/mine/materials', data), list: (params) => request.get('/health/attendant-application', params), diff --git a/utils/role.js b/utils/role.js index 122a81c..9764cc4 100644 --- a/utils/role.js +++ b/utils/role.js @@ -102,10 +102,14 @@ async function resolveRoleDetail() { if (app && app.ensureLogin) user = await app.ensureLogin() else user = app && app.globalData ? app.globalData.user : null } catch (e) { + console.warn('[role] 登录失败:', e && e.message) return { ok: false, role: 'none' } } - if (!user) return { ok: false, role: 'none' } + if (!user) { + console.warn('[role] 无用户信息') + return { ok: false, role: 'none' } + } if (isAdminUser(user)) { cachedAttendant = null return { ok: true, role: 'admin' } @@ -113,7 +117,10 @@ async function resolveRoleDetail() { try { const res = await API.employee.getMe() - if (!res || res.code !== 0) return { ok: false, role: 'none' } + if (!res || res.code !== 0) { + console.warn('[role] employee/me 异常:', res && res.code, res && res.msg) + return { ok: false, role: 'none' } + } const employee = res.data ? res.data.employee : null // 实习与正式都算陪诊师:实习能进主页面,只是不能接单 if (employee && employee.status === 'active' && employee.role === 'attendant') { @@ -124,6 +131,7 @@ async function resolveRoleDetail() { return { ok: true, role: 'none' } } catch (e) { // 员工接口异常:解析失败,不据此判定为无身份 + console.warn('[role] employee/me 请求异常:', e && e.message) return { ok: false, role: 'none' } } }