Compare commits
5
Commits
e6ec051441
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6da802cff9 | ||
|
|
8e508d6934 | ||
|
|
b200d0a1ab | ||
|
|
1d8af0cb26 | ||
|
|
3bca677f30 |
@@ -2,6 +2,8 @@
|
||||
import config from './config';
|
||||
import createBus from './utils/eventBus';
|
||||
const API = require('./utils/api.js');
|
||||
const request = require('./utils/request.js');
|
||||
const AIChatSocket = require('./utils/chatmsg.js');
|
||||
const role = require('./utils/role.js');
|
||||
|
||||
// ==================== 全局页面守卫 ====================
|
||||
@@ -44,6 +46,9 @@ Page = function (options = {}) {
|
||||
|
||||
App({
|
||||
onLaunch() {
|
||||
// 接口层遇到 code 401(token 已失效)时静默重登并自动重试原请求
|
||||
request.setUnauthorizedHandler(() => this.silentSignin());
|
||||
|
||||
const updateManager = wx.getUpdateManager();
|
||||
|
||||
updateManager.onCheckForUpdate((res) => {
|
||||
@@ -73,12 +78,17 @@ App({
|
||||
|
||||
/** 执行登录,返回可复用的 Promise(避免页面请求早于登录完成的竞态) */
|
||||
signin() {
|
||||
// 已登录或登录在飞都复用同一个 Promise:每次回前台都重签会轮换 token,
|
||||
// 让在飞请求拿着旧 token 收到 401;token 真失效时由 silentSignin 主动重登
|
||||
if (this._loginPromise) return this._loginPromise;
|
||||
|
||||
this._loginPending = true;
|
||||
const finish = () => { this._loginPending = false };
|
||||
this._loginPromise = new Promise((resolve, reject) => {
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
if (!res.code) {
|
||||
finish();
|
||||
this._loginPromise = null;
|
||||
return reject(new Error('wx.login 未返回 code'));
|
||||
}
|
||||
@@ -88,21 +98,25 @@ App({
|
||||
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);
|
||||
finish();
|
||||
resolve(data.data.user);
|
||||
} else {
|
||||
console.warn('[app] 静默登录被拒:', data.msg)
|
||||
finish();
|
||||
this._loginPromise = null;
|
||||
reject(new Error(data.msg || '登录失败'));
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('[app] 静默登录请求异常:', err && err.message)
|
||||
finish();
|
||||
this._loginPromise = null;
|
||||
reject(err);
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.warn('[app] wx.login 失败:', err && err.errMsg)
|
||||
finish();
|
||||
this._loginPromise = null;
|
||||
reject(err);
|
||||
}
|
||||
@@ -118,6 +132,34 @@ App({
|
||||
return this.signin();
|
||||
},
|
||||
|
||||
/** AI 页发送前的登录等待:返回是否已拿到可用用户 */
|
||||
waitForAuth() {
|
||||
return this.ensureLogin()
|
||||
.then(() => !!this.globalData.user?._id)
|
||||
.catch(() => false);
|
||||
},
|
||||
|
||||
/** 静默重登:服务端已作废本地 token 时重新走一次 wx.login 换新 token */
|
||||
silentSignin() {
|
||||
// 已有登录在飞时先等它落定,避免并发换 token 造成 token 互相覆盖
|
||||
if (this._loginPending && this._loginPromise) {
|
||||
return this._loginPromise
|
||||
.then(() => !!this.globalData.user?.security?.token)
|
||||
.catch(() => false);
|
||||
}
|
||||
this._loginPromise = null;
|
||||
return this.signin()
|
||||
.then(() => !!this.globalData.user?.security?.token)
|
||||
.catch(() => false);
|
||||
},
|
||||
|
||||
/** AI 聊天 WebSocket 懒创建:语音分片与聊天共用同一条连接 */
|
||||
initChatSocket() {
|
||||
if (this.globalData.chatSocket) return this.globalData.chatSocket;
|
||||
this.globalData.chatSocket = new AIChatSocket();
|
||||
return this.globalData.chatSocket;
|
||||
},
|
||||
|
||||
/** 全局事件总线 */
|
||||
eventBus: createBus(),
|
||||
|
||||
@@ -146,5 +188,6 @@ App({
|
||||
user: null,
|
||||
unreadNum: 0, // 未读消息数量
|
||||
socket: null, // SocketTask 对象
|
||||
chatSocket: null, // AI 聊天 / 语音识别 WebSocket
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
/**app.wxss**/
|
||||
page {
|
||||
background-color: #FAF6F1;
|
||||
/* 统一全局基础字号:正文主字号 28rpx */
|
||||
font-size: 28rpx;
|
||||
color: #2A211B;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
|
||||
.page {
|
||||
|
||||
@@ -85,13 +85,13 @@
|
||||
|
||||
.os-label {
|
||||
margin-top: 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #8A8078;
|
||||
}
|
||||
|
||||
.os-fee {
|
||||
margin-top: 10rpx;
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 600;
|
||||
color: #2A211B;
|
||||
padding: 4rpx 16rpx;
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
}
|
||||
|
||||
.pi-sex {
|
||||
font-size: 20rpx;
|
||||
font-size: 22rpx;
|
||||
padding: 2rpx 12rpx;
|
||||
border-radius: 8rpx;
|
||||
font-weight: 500;
|
||||
@@ -71,19 +71,19 @@
|
||||
}
|
||||
|
||||
.pi-mobile {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #8A8078;
|
||||
}
|
||||
|
||||
.pi-call {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #C26A2E;
|
||||
font-weight: 500;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
.pi-extra {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #8A8078;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
+1434
-170
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -1,9 +1,11 @@
|
||||
{
|
||||
"navigationBarTitleText": "AI助手",
|
||||
"navigationBarBackgroundColor": "#ffffff",
|
||||
"navigationBarBackgroundColor": "#FAF6F1",
|
||||
"navigationBarTextStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"backgroundColor": "#FAF6F1",
|
||||
"disableScroll": true,
|
||||
"usingComponents": {
|
||||
"t-icon": "tdesign-miniprogram/icon/icon",
|
||||
"t-chat-markdown": "tdesign-miniprogram/chat-markdown/chat-markdown"
|
||||
}
|
||||
}
|
||||
|
||||
+198
-56
@@ -1,75 +1,217 @@
|
||||
<view class="chat-container">
|
||||
<scroll-view class="message-list" scroll-y scroll-into-view="{{scrollToMessage}}" scroll-with-animation>
|
||||
<view class="quick-questions" wx:if="{{messages.length === 0}}">
|
||||
<view class="welcome-text">您好,我是您的AI助手,有什么可以帮您?</view>
|
||||
<view class="quick-list">
|
||||
<view class="quick-item" wx:for="{{quickQuestions}}" wx:key="*this" data-question="{{item}}" bindtap="onQuickQuestionTap">
|
||||
{{item}}
|
||||
<!-- 消息列表区域:页面唯一滚动容器 -->
|
||||
<scroll-view
|
||||
class="message-list"
|
||||
scroll-y
|
||||
scroll-into-view="{{scrollToMessage}}"
|
||||
enhanced
|
||||
show-scrollbar="{{false}}"
|
||||
scroll-with-animation
|
||||
>
|
||||
<!-- 欢迎区:空会话时的落点 -->
|
||||
<view class="welcome-area" wx:if="{{messages.length === 0}}">
|
||||
<text class="welcome-title">陪诊助手</text>
|
||||
<view class="question-heading"><text>您可以这样问</text><text class="question-heading-sub">点选即发送</text></view>
|
||||
<view class="question-list">
|
||||
<view
|
||||
class="quick-item"
|
||||
wx:for="{{quickQuestions}}"
|
||||
wx:key="id"
|
||||
bindtap="onQuickQuestionTap"
|
||||
data-question="{{item.text}}"
|
||||
hover-class="question-hover"
|
||||
aria-role="button"
|
||||
aria-label="{{item.text}}"
|
||||
>
|
||||
<view class="question-mark" aria-hidden="true">?</view>
|
||||
<text>{{item.text}}</text>
|
||||
<t-icon name="chevron-right" size="26rpx" color="#A8551F" />
|
||||
</view>
|
||||
</view>
|
||||
<text class="welcome-note">AI 生成内容仅供参考,请以系统实际数据为准。</text>
|
||||
</view>
|
||||
|
||||
<view class="message-item {{item.type}}" wx:for="{{messages}}" wx:key="id" id="msg-{{item.id}}">
|
||||
<view class="avatar {{item.type}}-avatar">
|
||||
<text class="avatar-text">{{item.type === 'user' ? '我' : 'AI'}}</text>
|
||||
<!-- 消息:头像在上、气泡在下,时间紧跟头像右侧;用户消息整条靠右 -->
|
||||
<view
|
||||
class="message-item {{item.type}}"
|
||||
wx:for="{{messages}}"
|
||||
wx:key="id"
|
||||
id="msg-{{item.id}}"
|
||||
>
|
||||
<!-- 连接或服务错误是系统状态,不使用头像 -->
|
||||
<view wx:if="{{item.type === 'system'}}" class="system-message">
|
||||
<text>{{item.content}}</text>
|
||||
</view>
|
||||
<block wx:else>
|
||||
<view class="message-head">
|
||||
<!-- AI:品牌线稿标记;用户:人像图标,身份只由图形区分 -->
|
||||
<view wx:if="{{item.type === 'ai'}}" class="avatar">
|
||||
<image class="avatar-img" src="/images/ai-ink.png" mode="aspectFit" />
|
||||
</view>
|
||||
<view wx:else class="avatar">
|
||||
<t-icon name="user" size="30rpx" color="#6F655C" />
|
||||
</view>
|
||||
<text class="message-author">{{item.type === 'ai' ? 'AI助手' : '我'}}</text>
|
||||
<text class="message-time" wx:if="{{item.showTime}}">{{item.time}}</text>
|
||||
</view>
|
||||
|
||||
<view class="message-content">
|
||||
<view class="message-bubble" wx:if="{{item.contentType !== 'questions'}}">
|
||||
<t-chat-markdown
|
||||
wx:if="{{item.type === 'ai' && item.contentType === 'text'}}"
|
||||
class="message-markdown"
|
||||
content="{{item.content}}"
|
||||
/>
|
||||
<text wx:elif="{{item.contentType === 'text'}}" class="message-text" user-select>{{item.content}}</text>
|
||||
<image
|
||||
wx:if="{{item.contentType === 'image' && item.content}}"
|
||||
class="message-image"
|
||||
src="{{item.content}}"
|
||||
mode="widthFix"
|
||||
bindtap="previewImage"
|
||||
data-src="{{item.content}}"
|
||||
/>
|
||||
<!-- 历史里的图片不存临时路径(重启即失效),退化成一行占位 -->
|
||||
<text wx:elif="{{item.contentType === 'image'}}" class="message-image-placeholder">[图片]</text>
|
||||
</view>
|
||||
<!-- 常见问题:把问题清单直接铺进会话流里,点一下即发送 -->
|
||||
<view wx:else class="question-list">
|
||||
<view
|
||||
class="quick-item"
|
||||
wx:for="{{item.content}}"
|
||||
wx:for-item="question"
|
||||
wx:key="id"
|
||||
bindtap="onQuickQuestionTap"
|
||||
data-question="{{question.text}}"
|
||||
hover-class="question-hover"
|
||||
aria-role="button"
|
||||
aria-label="{{question.text}}"
|
||||
>
|
||||
<text>{{question.text}}</text>
|
||||
<t-icon name="chevron-right" size="26rpx" color="#A8551F" />
|
||||
</view>
|
||||
</view>
|
||||
<!-- AI 声明:本地问题清单和系统错误均不展示 -->
|
||||
<text
|
||||
wx:if="{{item.type === 'ai' && item.contentType !== 'questions'}}"
|
||||
class="message-note"
|
||||
>AI 生成,仅供参考</text>
|
||||
<text
|
||||
wx:if="{{item.type === 'user' && item.status === 'failed'}}"
|
||||
class="message-retry"
|
||||
bindtap="onRetryMessage"
|
||||
data-id="{{item.id}}"
|
||||
>发送失败,点击重试</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
|
||||
<!-- AI 正在输入:图片/语音识别期间也用它作为等待态 -->
|
||||
<view class="message-item ai" wx:if="{{isTyping}}" id="msg-typing">
|
||||
<view class="message-head">
|
||||
<view class="avatar">
|
||||
<image class="avatar-img" src="/images/ai-ink.png" mode="aspectFit" />
|
||||
</view>
|
||||
<text class="message-author">AI助手</text>
|
||||
</view>
|
||||
<view class="message-content">
|
||||
<view class="message-bubble {{item.type}}-bubble">
|
||||
<!-- subagent 消息:引用卡片样式,默认折叠 -->
|
||||
<block wx:if="{{item.source === 'subagent'}}">
|
||||
<view class="subagent-header" data-id="{{item.id}}" bindtap="toggleSubagent">
|
||||
<text class="subagent-label">思考中...</text>
|
||||
<text class="subagent-arrow {{expandedIds[item.id] ? 'expanded' : ''}}">▸</text>
|
||||
</view>
|
||||
<view class="subagent-body" wx:if="{{expandedIds[item.id]}}">
|
||||
<t-chat-markdown class="message-markdown" content="{{item.content}}" />
|
||||
</view>
|
||||
</block>
|
||||
<t-chat-markdown
|
||||
wx:elif="{{item.contentType === 'text' && item.type === 'ai'}}"
|
||||
class="message-markdown"
|
||||
content="{{item.content}}"
|
||||
/>
|
||||
<text class="message-text" wx:elif="{{item.contentType === 'text'}}">{{item.content}}</text>
|
||||
<view class="message-bubble typing-bubble">
|
||||
<view class="typing-lines">
|
||||
<text class="typing-text">{{isRecognizing ? '正在识别,请稍候' : '正在处理...' + processingSeconds + '秒'}}</text>
|
||||
<!-- 后台进度:工具/子代理有动作时这行会变化,避免只剩一个计时器 -->
|
||||
<text
|
||||
class="typing-progress"
|
||||
wx:if="{{!isRecognizing && progressLabel}}"
|
||||
>{{progressLabel}}{{progressStep ? ' · 已完成 ' + progressStep + ' 步' : ''}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<text class="message-time" wx:if="{{item.time}}">{{item.time}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="typing-indicator" wx:if="{{isTyping}}">
|
||||
<view class="avatar ai-avatar">
|
||||
<text class="avatar-text">AI</text>
|
||||
</view>
|
||||
<view class="typing-bubble">
|
||||
<view class="dot"></view>
|
||||
<view class="dot"></view>
|
||||
<view class="dot"></view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 底部留白,确保最新消息可见 -->
|
||||
<view style="height: 40rpx;"></view>
|
||||
</scroll-view>
|
||||
|
||||
<view class="chat-footer">
|
||||
<view class="chat-toolbar" wx:if="{{messages.length > 0}}">
|
||||
<view class="chat-toolbar-action" bindtap="clearChat">
|
||||
<text>清空记录</text>
|
||||
<!-- 语音状态:只在录音阶段显示,紧贴输入区上方 -->
|
||||
<view class="voice-status" wx:if="{{recording}}">
|
||||
<view class="voice-dot recording"></view>
|
||||
<view class="voice-status-main">
|
||||
<text class="voice-status-text">正在录音 {{recordTime}}</text>
|
||||
<text class="voice-status-sub">{{voiceRealtimeOff ? '结束后整段转写' : '点麦克风或发送键发出'}}</text>
|
||||
</view>
|
||||
<view
|
||||
class="voice-cancel"
|
||||
bindtap="onCancelVoiceTap"
|
||||
aria-role="button"
|
||||
aria-label="取消语音输入"
|
||||
>
|
||||
<t-icon name="close" size="24rpx" color="#A8551F" />
|
||||
<text>取消</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 输入面板:上方文字,下方输入方式与发送 -->
|
||||
<view class="composer">
|
||||
<view class="input-area">
|
||||
<textarea
|
||||
class="message-input {{recording || isRecognizing ? 'is-readonly' : ''}}"
|
||||
value="{{inputValue}}"
|
||||
placeholder="说说您的问题或需要…"
|
||||
placeholder-class="input-placeholder"
|
||||
auto-height
|
||||
maxlength="-1"
|
||||
cursor-spacing="24"
|
||||
confirm-type="send"
|
||||
disabled="{{recording || isRecognizing}}"
|
||||
adjust-position="{{true}}"
|
||||
hold-keyboard="{{true}}"
|
||||
bindinput="onInputChange"
|
||||
bindconfirm="sendMessage"
|
||||
focus="{{inputFocus}}"
|
||||
/>
|
||||
</view>
|
||||
<view class="composer-actions">
|
||||
<view class="input-tools">
|
||||
<view class="input-tool {{recording ? 'is-recording' : ''}}" bindtap="onMicTap" aria-role="button" aria-label="{{recording ? '结束并发送语音' : '语音输入'}}">
|
||||
<t-icon name="microphone" size="34rpx" color="{{recording ? '#A8551F' : '#6F655C'}}" />
|
||||
<text>{{recording ? '结束' : '语音'}}</text>
|
||||
</view>
|
||||
<view class="input-tool" bindtap="onImageTap" aria-role="button" aria-label="拍照或选择图片">
|
||||
<t-icon name="image" size="34rpx" color="#6F655C" />
|
||||
<text>图片</text>
|
||||
</view>
|
||||
<view class="input-tool {{showMoreMenu ? 'is-open' : ''}}" bindtap="toggleMoreMenu" aria-role="button" aria-label="更多功能" aria-expanded="{{showMoreMenu}}">
|
||||
<view class="more-dots" aria-hidden="true">
|
||||
<view class="more-dot"></view>
|
||||
<view class="more-dot"></view>
|
||||
<view class="more-dot"></view>
|
||||
</view>
|
||||
<text>更多</text>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
class="send-btn {{inputValue && !isRecognizing ? 'active' : ''}}"
|
||||
bindtap="sendMessage"
|
||||
aria-role="button"
|
||||
aria-label="发送消息"
|
||||
aria-disabled="{{!inputValue || isRecognizing}}"
|
||||
>
|
||||
<text>发送</text>
|
||||
<t-icon name="chevron-right" size="30rpx" color="{{inputValue && !isRecognizing ? '#FFFFFF' : '#6F655C'}}" />
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="input-area">
|
||||
<input
|
||||
class="chat-input"
|
||||
type="text"
|
||||
placeholder="请输入您的问题..."
|
||||
value="{{inputValue}}"
|
||||
bindinput="onInputChange"
|
||||
confirm-type="send"
|
||||
bindconfirm="sendMessage"
|
||||
adjust-position="{{true}}"
|
||||
cursor-spacing="20"
|
||||
hold-keyboard="{{true}}"
|
||||
/>
|
||||
<view class="send-btn {{canSend ? 'active' : ''}}" bindtap="sendMessage">
|
||||
<text class="send-text">发送</text>
|
||||
<!-- 更多菜单:向上展开,点遮罩关闭;清空仍走二次确认 -->
|
||||
<view class="more-mask" wx:if="{{showMoreMenu}}" bindtap="onCloseMoreMenu" aria-hidden="true"></view>
|
||||
<view class="more-menu" wx:if="{{showMoreMenu}}" aria-role="menu">
|
||||
<view class="more-item" bindtap="onMoreQuickQuestions" aria-role="menuitem">
|
||||
<t-icon name="help-circle" size="30rpx" color="#6F655C" />
|
||||
<text class="more-item-text">常见问题</text>
|
||||
</view>
|
||||
<view class="more-divider" wx:if="{{messages.length}}"></view>
|
||||
<view class="more-item more-item-muted" wx:if="{{messages.length}}" bindtap="onMoreClearChat" aria-role="menuitem">
|
||||
<t-icon name="delete" size="30rpx" color="#6F655C" />
|
||||
<text class="more-item-text">清空聊天记录</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
+125
-375
@@ -1,6 +1,25 @@
|
||||
/* 与就诊人端 AI 页同源:暖白纸面、清晰左基线、克制的暖橙强调。
|
||||
页面不滚动,唯一滚动容器是消息区;颜色令牌取自本项目 TDesign 主题色阶。 */
|
||||
page {
|
||||
background-color: #FAF6F1;
|
||||
color: #2A211B;
|
||||
--brand-strong: #C26A2E;
|
||||
--brand-soft: #FCF3E9;
|
||||
--brand-line: #EFCAA6;
|
||||
--brand-ink: #A8551F;
|
||||
--ink: #2A211B;
|
||||
--ink-2: #4A4038;
|
||||
--muted: #6F655C;
|
||||
--line: #EAE1D6;
|
||||
--paper: #FAF6F1;
|
||||
--white: #FFFFFF;
|
||||
--fs-24: 24rpx;
|
||||
--fs-26: 26rpx;
|
||||
--fs-28: 28rpx;
|
||||
--fs-30: 30rpx;
|
||||
--shadow-card: 0 2rpx 10rpx rgba(63, 43, 25, 0.07);
|
||||
|
||||
background-color: var(--paper);
|
||||
color: var(--ink);
|
||||
font-size: var(--fs-28);
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
||||
}
|
||||
|
||||
@@ -8,389 +27,120 @@ page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100vh;
|
||||
background-color: #FAF6F1;
|
||||
}
|
||||
|
||||
.chat-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 88rpx;
|
||||
padding: 0 24rpx;
|
||||
background-color: #ffffff;
|
||||
border-bottom: 1rpx solid #EAE1D6;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.chat-header-title {
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #2A211B;
|
||||
}
|
||||
|
||||
.message-list {
|
||||
flex: 1;
|
||||
padding: 20rpx;
|
||||
padding-bottom: 200rpx;
|
||||
box-sizing: border-box;
|
||||
overflow: hidden;
|
||||
background: var(--paper);
|
||||
}
|
||||
|
||||
.quick-questions {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 40rpx 20rpx;
|
||||
}
|
||||
.message-list { flex: 1; height: 0; min-height: 0; box-sizing: border-box; }
|
||||
.welcome-area { padding: 32rpx 32rpx 24rpx; }
|
||||
.welcome-title { display: block; color: var(--ink); font-size: 44rpx; font-weight: 600; line-height: 1.45; }
|
||||
.question-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12rpx; margin: 32rpx 0 16rpx; color: var(--ink); font-size: var(--fs-28); font-weight: 500; }
|
||||
.question-heading-sub { color: var(--muted); font-size: var(--fs-24); font-weight: 400; }
|
||||
.question-list { display: flex; flex-direction: column; gap: 12rpx; width: 100%; box-sizing: border-box; }
|
||||
.quick-item { display: flex; align-items: center; justify-content: space-between; gap: 16rpx; min-height: 96rpx; box-sizing: border-box; padding: 20rpx; border: 2rpx solid var(--line); border-radius: 20rpx; background: var(--white); color: var(--ink-2); font-size: var(--fs-28); line-height: 1.6; }
|
||||
.quick-item > text { flex: 1; min-width: 0; word-break: break-all; }
|
||||
.question-mark { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 40rpx; height: 40rpx; border-radius: 12rpx; background: var(--paper); color: var(--brand-ink); font-size: var(--fs-26); }
|
||||
.quick-item.question-hover, .quick-item:active { background: var(--brand-soft); border-color: var(--brand-line); }
|
||||
.welcome-note { display: block; margin-top: 20rpx; color: var(--muted); font-size: var(--fs-24); line-height: 1.7; }
|
||||
|
||||
.welcome-text {
|
||||
font-size: 32rpx;
|
||||
color: #2A211B;
|
||||
margin-bottom: 40rpx;
|
||||
text-align: center;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.quick-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
gap: 20rpx;
|
||||
}
|
||||
|
||||
.quick-item {
|
||||
background-color: #ffffff;
|
||||
border-radius: 24rpx;
|
||||
padding: 24rpx 32rpx;
|
||||
font-size: 28rpx;
|
||||
color: #C26A2E;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
text-align: center;
|
||||
border: 1rpx solid #EAE1D6;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.quick-item:active {
|
||||
transform: scale(0.98);
|
||||
background-color: rgba(194, 106, 46, 0.05);
|
||||
}
|
||||
|
||||
.message-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.message-item.ai {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.message-item.user {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.message-time {
|
||||
font-size: 22rpx;
|
||||
color: #A3988B;
|
||||
margin-top: 8rpx;
|
||||
padding: 0 4rpx;
|
||||
}
|
||||
|
||||
.message-item.ai .message-time {
|
||||
text-align: left;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.message-item.user .message-time {
|
||||
text-align: right;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
width: 64rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
margin-bottom: 12rpx;
|
||||
}
|
||||
|
||||
.user-avatar {
|
||||
background: #C26A2E;
|
||||
box-shadow: 0 4rpx 12rpx rgba(180, 85, 42, 0.25);
|
||||
}
|
||||
|
||||
.ai-avatar {
|
||||
background: #B4552A;
|
||||
box-shadow: 0 4rpx 12rpx rgba(217, 134, 52, 0.25);
|
||||
}
|
||||
|
||||
.avatar-text {
|
||||
color: #fff;
|
||||
font-size: 26rpx;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.message-content {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
max-width: 95%;
|
||||
}
|
||||
|
||||
.message-item.user .message-content {
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.message-item.ai .message-content {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.message-bubble {
|
||||
padding: 20rpx 24rpx;
|
||||
border-radius: 16rpx;
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
word-break: break-word;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.user-bubble {
|
||||
background: #C26A2E;
|
||||
color: #fff;
|
||||
border-bottom-right-radius: 4rpx;
|
||||
box-shadow: 0 4rpx 12rpx rgba(180, 85, 42, 0.2);
|
||||
margin-right: 4rpx;
|
||||
}
|
||||
|
||||
.ai-bubble {
|
||||
background-color: #ffffff;
|
||||
color: #2A211B;
|
||||
border-bottom-left-radius: 4rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
border: 1rpx solid #EAE1D6;
|
||||
margin-left: 4rpx;
|
||||
}
|
||||
|
||||
/* Markdown 渲染区域 */
|
||||
/* 对话正文占据主要宽度,避免头像左右分栏挤压长回答和报告表格 */
|
||||
.message-item { display: flex; flex-direction: column; padding: 20rpx 32rpx; }
|
||||
.message-item.user { align-items: flex-end; }
|
||||
.message-head { display: flex; align-items: center; gap: 10rpx; margin-bottom: 12rpx; }
|
||||
.message-item.user .message-head { flex-direction: row-reverse; }
|
||||
.avatar { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 44rpx; height: 44rpx; border-radius: 14rpx; background: var(--white); border: 2rpx solid var(--line); }
|
||||
.avatar-img { width: 30rpx; height: 30rpx; }
|
||||
.message-item.user .avatar { background: transparent; border-color: transparent; }
|
||||
.message-author { color: var(--ink-2); font-size: var(--fs-24); font-weight: 500; }
|
||||
.message-time { color: var(--muted); font-size: var(--fs-24); margin: 0 6rpx; }
|
||||
.message-content { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 100%; }
|
||||
.message-item.ai .message-content { width: 100%; }
|
||||
.message-item.user .message-content { align-items: flex-end; max-width: 90%; }
|
||||
.message-bubble { box-sizing: border-box; min-width: 0; max-width: 100%; padding: 24rpx; border-radius: 24rpx; word-wrap: break-word; word-break: break-word; }
|
||||
.message-item.ai .message-bubble { width: 100%; border: 2rpx solid var(--line); border-top-left-radius: 8rpx; background: var(--white); }
|
||||
.message-item.user .message-bubble { border: 2rpx solid var(--brand-line); border-top-right-radius: 8rpx; background: var(--brand-soft); }
|
||||
.message-text { font-size: var(--fs-30); line-height: 1.75; white-space: pre-wrap; color: var(--ink-2); word-break: break-word; }
|
||||
.message-item.user .message-text { color: var(--brand-ink); }
|
||||
.message-image { display: block; width: 400rpx; max-width: 100%; border-radius: 16rpx; }
|
||||
.message-image-placeholder { font-size: var(--fs-28); color: var(--muted); line-height: 1.6; }
|
||||
.message-note { margin-top: 10rpx; color: var(--muted); font-size: var(--fs-24); line-height: 1.6; }
|
||||
.message-retry { display: flex; align-items: center; min-height: 88rpx; color: var(--brand-ink); font-size: var(--fs-26); }
|
||||
.message-item.system { align-items: center; }
|
||||
.system-message { max-width: 100%; padding: 8rpx 16rpx; color: var(--muted); font-size: var(--fs-26); line-height: 1.7; text-align: center; }
|
||||
.message-markdown {
|
||||
display: block;
|
||||
width: 100%;
|
||||
font-size: 28rpx;
|
||||
color: #2A211B;
|
||||
line-height: 1.6;
|
||||
min-width: 0;
|
||||
font-size: var(--fs-30);
|
||||
line-height: 1.75;
|
||||
color: var(--ink-2);
|
||||
/* 组件内的色彩通过实际消费的 TDesign 变量传入,不依赖跨组件选择器 */
|
||||
--td-text-color-primary: var(--ink-2);
|
||||
--td-bg-color-component: var(--brand-soft);
|
||||
--td-bg-color-page: var(--paper);
|
||||
--td-bg-color-secondarycontainer: var(--paper);
|
||||
--td-component-border: var(--line);
|
||||
}
|
||||
|
||||
/* 表格样式覆盖(防止过宽) */
|
||||
.message-markdown .t-chat-markdown-table {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
border: 1rpx solid #EAE1D6;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.message-markdown .t-chat-markdown-table__container {
|
||||
display: table;
|
||||
min-width: 100%;
|
||||
max-width: max-content;
|
||||
border-collapse: collapse;
|
||||
white-space: normal;
|
||||
table-layout: fixed;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
.message-markdown .t-chat-markdown-table { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 2rpx solid var(--line); border-radius: 12rpx; }
|
||||
.message-markdown .t-chat-markdown-table__container { display: table; min-width: 100%; border-collapse: collapse; }
|
||||
.message-markdown .t-chat-markdown-table__container-th,
|
||||
.message-markdown .t-chat-markdown-table__container-td { padding: 12rpx; font-size: var(--fs-26); line-height: 1.6; word-break: break-word; }
|
||||
.message-markdown .t-chat-markdown-table__container-th { background: var(--brand-soft); color: var(--ink); }
|
||||
.message-markdown .t-chat-markdown-table__container-tr:nth-child(2n) { background: var(--paper); }
|
||||
/* 兼容表格子组件的另一套类名 */
|
||||
.message-markdown .t-chat-markdown-table__th,
|
||||
.message-markdown .t-chat-markdown-table__td {
|
||||
padding: 8rpx 12rpx;
|
||||
font-size: 24rpx;
|
||||
line-height: 1.4;
|
||||
white-space: normal;
|
||||
word-break: break-word;
|
||||
word-wrap: break-word;
|
||||
overflow-wrap: break-word;
|
||||
max-width: 320rpx;
|
||||
}
|
||||
.message-markdown .t-chat-markdown-table__td { padding: 12rpx; font-size: var(--fs-26); line-height: 1.6; white-space: normal; word-break: break-word; }
|
||||
.message-markdown .t-chat-markdown-table__th { background: var(--brand-soft); color: var(--ink); }
|
||||
.message-markdown .t-chat-markdown-table__tr:nth-child(2n) { background: var(--paper); }
|
||||
.message-markdown .t-chat-markdown-code, .message-markdown .t-chat-markdown-codespan { font-size: var(--fs-26); word-break: break-all; }
|
||||
.message-item.ai .typing-bubble { display: flex; align-items: center; width: auto; min-height: 88rpx; }
|
||||
.typing-lines { display: flex; flex-direction: column; gap: 2rpx; }
|
||||
.typing-text { font-size: var(--fs-26); color: var(--muted); line-height: 1.6; }
|
||||
.typing-progress { font-size: 22rpx; color: var(--muted); line-height: 1.5; opacity: 0.85; }
|
||||
|
||||
.message-markdown .t-chat-markdown-table__th {
|
||||
background-color: #FAF6F1;
|
||||
font-weight: 600;
|
||||
color: #2A211B;
|
||||
}
|
||||
/* 统一白色输入面板:文字在上,更多与发送在下,所有操作横向展开。
|
||||
position: relative 供「更多」菜单定位(菜单从按钮上方展开) */
|
||||
.composer { position: relative; flex-shrink: 0; margin: 12rpx 24rpx 8rpx; padding: 20rpx 20rpx 12rpx; border: 2rpx solid var(--line); border-radius: 28rpx; background: var(--white); box-shadow: var(--shadow-card); }
|
||||
.input-area { padding: 0 4rpx; }
|
||||
.message-input { display: block; box-sizing: border-box; width: 100%; min-height: 76rpx; max-height: 180rpx; padding: 4rpx 0 12rpx; color: var(--ink); font-size: var(--fs-30); line-height: 1.6; background: transparent; }
|
||||
.message-input.is-readonly { color: var(--muted); }
|
||||
.input-placeholder { color: var(--muted); font-size: var(--fs-28); }
|
||||
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 16rpx; }
|
||||
.input-tools { display: flex; align-items: center; gap: 8rpx; }
|
||||
.input-tool { display: flex; align-items: center; justify-content: center; gap: 8rpx; box-sizing: border-box; min-width: 104rpx; min-height: 88rpx; padding: 12rpx; border-radius: 16rpx; color: var(--muted); font-size: var(--fs-24); }
|
||||
.input-tool.is-open { color: var(--brand-ink); background: var(--brand-soft); }
|
||||
.input-tool.is-recording { color: var(--brand-ink); background: var(--brand-soft); }
|
||||
.input-tool:active { background: var(--paper); }
|
||||
/* 三个点用 CSS 画,不依赖图标名;与文字同一条基线 */
|
||||
.more-dots { display: flex; align-items: center; justify-content: center; gap: 5rpx; width: 34rpx; height: 34rpx; }
|
||||
.more-dot { width: 8rpx; height: 8rpx; border-radius: 50%; background: var(--muted); }
|
||||
.input-tool.is-open .more-dot { background: var(--brand-ink); }
|
||||
.send-btn { display: flex; align-items: center; justify-content: center; flex-shrink: 0; gap: 10rpx; box-sizing: border-box; min-width: 136rpx; min-height: 88rpx; padding: 16rpx 20rpx; border-radius: 20rpx; background: var(--paper); color: var(--muted); font-size: var(--fs-28); font-weight: 500; }
|
||||
.send-btn.active { background: var(--brand-strong); color: var(--white); }
|
||||
.send-btn.active:active { background: var(--brand-ink); }
|
||||
|
||||
.message-markdown .t-chat-markdown-table__tr:nth-child(2n) {
|
||||
background-color: #FCFAF7;
|
||||
}
|
||||
/* ===== 「更多」菜单 =====
|
||||
透明遮罩负责点外部关闭;菜单锚在输入面板上方左侧,向上展开 */
|
||||
.more-mask { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 120; background: transparent; }
|
||||
.more-menu { position: absolute; left: 20rpx; bottom: calc(100% + 8rpx); z-index: 121; box-sizing: border-box; min-width: 320rpx; padding: 8rpx 0; border: 2rpx solid var(--line); border-radius: 20rpx; background: var(--white); box-shadow: var(--shadow-card); animation: more-menu-in 0.16s ease-out; }
|
||||
@keyframes more-menu-in { from { opacity: 0; transform: translateY(8rpx); } to { opacity: 1; transform: translateY(0); } }
|
||||
.more-item { display: flex; align-items: center; gap: 14rpx; box-sizing: border-box; min-height: 88rpx; padding: 0 24rpx; color: var(--ink-2); font-size: var(--fs-28); line-height: 1.4; }
|
||||
.more-item:active { background: var(--brand-soft); }
|
||||
.more-item-muted { color: var(--muted); }
|
||||
.more-divider { height: 2rpx; margin: 0 20rpx; background: var(--line); }
|
||||
|
||||
/* 代码块样式覆盖 */
|
||||
.message-markdown .t-chat-markdown-codespan,
|
||||
.message-markdown .t-chat-markdown-code {
|
||||
font-size: 24rpx;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* subagent 引用卡片(默认折叠) */
|
||||
.subagent-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 4rpx 0;
|
||||
}
|
||||
|
||||
.subagent-label {
|
||||
font-size: 24rpx;
|
||||
color: #6F655C;
|
||||
}
|
||||
|
||||
.subagent-arrow {
|
||||
font-size: 24rpx;
|
||||
color: #A3988B;
|
||||
transition: transform 0.2s ease;
|
||||
}
|
||||
|
||||
.subagent-arrow.expanded {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.subagent-body {
|
||||
margin-top: 12rpx;
|
||||
padding-top: 12rpx;
|
||||
border-top: 1rpx solid #EAE1D6;
|
||||
}
|
||||
|
||||
.typing-indicator {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
margin-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.typing-bubble {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12rpx;
|
||||
background-color: #ffffff;
|
||||
padding: 24rpx 32rpx;
|
||||
border-radius: 16rpx;
|
||||
border-bottom-left-radius: 4rpx;
|
||||
box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
|
||||
border: 1rpx solid #EAE1D6;
|
||||
}
|
||||
|
||||
.dot {
|
||||
width: 16rpx;
|
||||
height: 16rpx;
|
||||
background-color: #A3988B;
|
||||
border-radius: 50%;
|
||||
animation: bounce 1.4s infinite ease-in-out both;
|
||||
}
|
||||
|
||||
.dot:nth-child(1) {
|
||||
animation-delay: -0.32s;
|
||||
}
|
||||
|
||||
.dot:nth-child(2) {
|
||||
animation-delay: -0.16s;
|
||||
}
|
||||
|
||||
@keyframes bounce {
|
||||
0%, 80%, 100% {
|
||||
transform: scale(0.6);
|
||||
}
|
||||
40% {
|
||||
transform: scale(1);
|
||||
}
|
||||
}
|
||||
|
||||
.input-area {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 20rpx 24rpx;
|
||||
background-color: #ffffff;
|
||||
gap: 16rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.chat-footer {
|
||||
position: fixed;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 10;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
.chat-toolbar {
|
||||
display: flex;
|
||||
align-items: right;
|
||||
justify-content: right;
|
||||
padding: 12rpx 24rpx;
|
||||
background-color: #FAF6F1;
|
||||
border-top: 1rpx solid #EAE1D6;
|
||||
border-bottom: 1rpx solid #EAE1D6;
|
||||
}
|
||||
|
||||
.chat-toolbar-action {
|
||||
display: flex;
|
||||
align-items: right;
|
||||
justify-content: right;
|
||||
padding: 6rpx 24rpx;
|
||||
border-radius: 24rpx;
|
||||
background-color: #ffffff;
|
||||
border: 1rpx solid #EAE1D6;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.chat-toolbar-action:active {
|
||||
transform: scale(0.96);
|
||||
background-color: rgba(194, 106, 46, 0.08);
|
||||
border-color: #C26A2E;
|
||||
}
|
||||
|
||||
.chat-toolbar-action text {
|
||||
font-size: 24rpx;
|
||||
color: #6F655C;
|
||||
}
|
||||
|
||||
.chat-input {
|
||||
flex: 1;
|
||||
height: 72rpx;
|
||||
background-color: #FAF6F1;
|
||||
border-radius: 36rpx;
|
||||
padding: 0 28rpx;
|
||||
font-size: 28rpx;
|
||||
color: #2A211B;
|
||||
border: 1rpx solid #EAE1D6;
|
||||
}
|
||||
|
||||
.chat-input::placeholder {
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
.send-btn {
|
||||
width: 120rpx;
|
||||
height: 72rpx;
|
||||
background-color: #EAE1D6;
|
||||
border-radius: 36rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.send-btn.active {
|
||||
background: #C26A2E;
|
||||
box-shadow: 0 4rpx 12rpx rgba(180, 85, 42, 0.25);
|
||||
}
|
||||
|
||||
.send-text {
|
||||
color: #A3988B;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
transition: color 0.2s ease;
|
||||
}
|
||||
|
||||
.send-btn.active .send-text {
|
||||
color: #FFFFFF;
|
||||
/* 语音状态条:只在录音阶段显示,紧贴输入区上方 */
|
||||
.voice-status { display: flex; align-items: center; flex-shrink: 0; gap: 16rpx; margin: 8rpx 24rpx 0; padding: 8rpx 16rpx; border: 2rpx solid var(--brand-line); border-radius: 20rpx; background: var(--brand-soft); }
|
||||
.voice-dot { flex-shrink: 0; width: 12rpx; height: 12rpx; border-radius: 50%; background: var(--brand-strong); }
|
||||
.voice-dot.recording { animation: record-pulse 1.2s infinite ease-in-out; }
|
||||
.voice-status-main { display: flex; flex: 1; flex-direction: column; gap: 4rpx; min-width: 0; }
|
||||
.voice-status-text { font-size: var(--fs-26); font-weight: 500; color: var(--ink-2); line-height: 1.5; }
|
||||
.voice-status-sub { font-size: var(--fs-24); color: var(--muted); line-height: 1.5; }
|
||||
.voice-cancel { display: flex; align-items: center; justify-content: center; flex-shrink: 0; gap: 8rpx; min-width: 88rpx; min-height: 88rpx; padding: 0 8rpx; color: var(--brand-ink); font-size: var(--fs-26); }
|
||||
@keyframes record-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
|
||||
@media (prefers-reduced-motion: reduce) { .voice-dot.recording, .more-menu { animation: none; transition: none; } }
|
||||
@media (max-width: 340px) {
|
||||
.input-tool { min-width: 88rpx; padding: 8rpx; }
|
||||
.composer-actions { gap: 8rpx; }
|
||||
}
|
||||
|
||||
+114
-76
@@ -13,13 +13,16 @@ const SEX_OPTIONS = [
|
||||
]
|
||||
const SEX_LABELS = SEX_OPTIONS.map((item) => item.label)
|
||||
const MOBILE_REGEX = /^1[3-9]\d{9}$/
|
||||
// 待审核期间的轮询间隔:后台审核通过后本页自动刷新角色并跳转首页
|
||||
const PENDING_POLL_INTERVAL = 10 * 1000
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: true,
|
||||
view: 'form', // form 填写 / pending 待审核 / approved 已通过但角色未刷新
|
||||
editing: false, // 待审核期间修改基本信息
|
||||
needPhoneAuth: false, // 手机号已有平台账号,需验证微信手机号后并入
|
||||
loggedIn: false, // 是否已完成微信登录
|
||||
loggingIn: false, // 微信登录请求中
|
||||
submitting: false,
|
||||
rejectReason: '',
|
||||
application: null,
|
||||
@@ -40,6 +43,55 @@ Page({
|
||||
|
||||
onShow() {
|
||||
this.refresh()
|
||||
this.startPolling()
|
||||
},
|
||||
|
||||
onHide() {
|
||||
this.stopPolling()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
this.stopPolling()
|
||||
},
|
||||
|
||||
startPolling() {
|
||||
this.stopPolling()
|
||||
this._pollTimer = setInterval(() => this.pollApproval(), PENDING_POLL_INTERVAL)
|
||||
},
|
||||
|
||||
stopPolling() {
|
||||
if (this._pollTimer) {
|
||||
clearInterval(this._pollTimer)
|
||||
this._pollTimer = null
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 待审核轮询:后台审核通过后员工档案生效,角色解析为 attendant,
|
||||
* 这里直接跳首页,无需用户手动重进
|
||||
*/
|
||||
pollApproval() {
|
||||
// 只在待审核/已通过待同步时轮询;加载、提交、修改资料期间跳过
|
||||
if (this.data.loading || this.data.submitting || this.data.editing) return
|
||||
if (this.data.view !== 'pending' && this.data.view !== 'approved') return
|
||||
if (this._polling) return
|
||||
this._polling = true
|
||||
|
||||
role
|
||||
.ensureRoleSafe(true)
|
||||
.then((detail) => {
|
||||
if (detail.ok && detail.role !== 'none') {
|
||||
this.stopPolling()
|
||||
wx.switchTab({ url: '/pages/home/index' })
|
||||
return
|
||||
}
|
||||
// 角色未变(或解析失败):静默刷新申请单,驳回等状态变化也能及时反映
|
||||
return this.loadApplication(true)
|
||||
})
|
||||
.catch(() => {})
|
||||
.then(() => {
|
||||
this._polling = false
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -49,11 +101,12 @@ Page({
|
||||
refresh() {
|
||||
// 修改资料时前后台切换不重置表单
|
||||
if (this.data.editing) return
|
||||
this.setData({ loading: true, needPhoneAuth: false })
|
||||
this.setData({ loading: true })
|
||||
role
|
||||
.ensureRoleSafe(true)
|
||||
.then((detail) => {
|
||||
if (detail.ok && detail.role !== 'none') {
|
||||
this.stopPolling()
|
||||
wx.switchTab({ url: '/pages/home/index' })
|
||||
return
|
||||
}
|
||||
@@ -62,28 +115,41 @@ Page({
|
||||
.catch(() => this.loadApplication())
|
||||
},
|
||||
|
||||
loadApplication() {
|
||||
/**
|
||||
* @param {boolean} [silent] 轮询静默刷新:不弹错误提示,不切换 loading
|
||||
*/
|
||||
loadApplication(silent) {
|
||||
const app = getApp()
|
||||
const user = app && app.globalData ? app.globalData.user : null
|
||||
const accountName = user && user.profile && user.profile.name ? user.profile.name : '微信用户'
|
||||
const loggedIn = !!(user && user.security && user.security.token)
|
||||
|
||||
API.attendantApplication
|
||||
.getMine()
|
||||
.then((res) => {
|
||||
if (res.code !== 0) {
|
||||
// 未登录(新用户走到这里时还没有账号)不弹错误,直接展示表单
|
||||
if (res.code !== 401) {
|
||||
// 未登录(新用户走到这里时还没有账号)不弹错误,直接展示登录入口
|
||||
if (silent) {
|
||||
console.info('[apply] 轮询刷新未拿到申请单:', res.code, res.msg)
|
||||
} else if (res.code !== 401) {
|
||||
wx.showToast({ title: res.msg || '加载失败', icon: 'none' })
|
||||
} else {
|
||||
console.info('[apply] 未登录,展示申请表单')
|
||||
console.info('[apply] 未登录,展示登录入口')
|
||||
}
|
||||
this.setData({ loading: false, accountName })
|
||||
this.setData({ loading: false, accountName, loggedIn })
|
||||
return
|
||||
}
|
||||
|
||||
const application = res.data ? res.data.application : null
|
||||
if (!application) {
|
||||
this.setData({ loading: false, view: 'form', accountName })
|
||||
// 新账号的手机号/姓名来自微信登录,表单为空时自动带出
|
||||
const profile = (user && user.profile) || {}
|
||||
const patch = { loading: false, view: 'form', accountName, loggedIn }
|
||||
if (!this.data.form.mobile.trim() && profile.mobile) patch['form.mobile'] = profile.mobile
|
||||
if (!this.data.form.name.trim() && profile.name && profile.name !== profile.mobile) {
|
||||
patch['form.name'] = profile.name
|
||||
}
|
||||
this.setData(patch)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -92,6 +158,7 @@ Page({
|
||||
loading: false,
|
||||
view: 'pending',
|
||||
editing: false,
|
||||
loggedIn: true,
|
||||
application,
|
||||
accountName,
|
||||
serviceAreaText: (application.applicant.serviceAreas || []).map(cityLabel).join('、'),
|
||||
@@ -102,7 +169,7 @@ Page({
|
||||
|
||||
if (application.status === 'approved') {
|
||||
// 走到这里说明员工档案还没查到(接口抖动或数据延迟),给一个手动重试入口
|
||||
this.setData({ loading: false, view: 'approved', application, accountName })
|
||||
this.setData({ loading: false, view: 'approved', loggedIn: true, application, accountName })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -112,6 +179,7 @@ Page({
|
||||
this.setData({
|
||||
loading: false,
|
||||
view: 'form',
|
||||
loggedIn: true,
|
||||
application,
|
||||
accountName,
|
||||
rejectReason: application.rejectReason || '',
|
||||
@@ -126,8 +194,8 @@ Page({
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
this.setData({ loading: false, accountName })
|
||||
wx.showToast({ title: '网络错误,请重试', icon: 'none' })
|
||||
this.setData({ loading: false, accountName, loggedIn })
|
||||
if (!silent) wx.showToast({ title: '网络错误,请重试', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
@@ -200,83 +268,66 @@ Page({
|
||||
},
|
||||
|
||||
/**
|
||||
* 微信手机号快速验证后并入已有账号
|
||||
* 第一步:手机号登录
|
||||
*
|
||||
* 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 })
|
||||
onLogin() {
|
||||
const name = this.data.form.name.trim()
|
||||
const mobile = this.data.form.mobile.trim()
|
||||
if (!name) return this.toast('请填写姓名')
|
||||
if (!MOBILE_REGEX.test(mobile)) return this.toast('请填写正确的手机号')
|
||||
if (this.data.loggingIn) return
|
||||
this.setData({ loggingIn: true })
|
||||
|
||||
wx.login({
|
||||
success: (res) => {
|
||||
if (!res.code) {
|
||||
this.setData({ submitting: false })
|
||||
this.setData({ loggingIn: false })
|
||||
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
||||
return
|
||||
}
|
||||
API.user
|
||||
.wxSignin({
|
||||
phoneCode,
|
||||
code: res.code,
|
||||
name: this.data.form.name.trim()
|
||||
})
|
||||
.wxSignin({ code: res.code, phoneNumber: mobile, name })
|
||||
.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
|
||||
})
|
||||
this.setData({ loggingIn: false })
|
||||
wx.showModal({
|
||||
title: '手机号已更新',
|
||||
content: `当前微信验证的手机号为 ${verifiedMobile},与填写的 ${formMobile} 不一致,已自动改用验证手机号,请确认后重新提交。`,
|
||||
title: '登录失败',
|
||||
content: data.msg || '请重试',
|
||||
showCancel: false
|
||||
})
|
||||
return
|
||||
}
|
||||
// submit 内部有 submitting 守卫,先复位再继续提交
|
||||
this.setData({ submitting: false, needPhoneAuth: false })
|
||||
this.submit()
|
||||
const app = getApp()
|
||||
app.globalData.user = data.data.user
|
||||
app.eventBus.emit('user-login', data.data.user)
|
||||
// 清掉登录失败时缓存的角色结果,登录成功后重新解析
|
||||
role.resetRole()
|
||||
|
||||
// 并入已有账号时,姓名与手机号以账号里的为准
|
||||
const profile = (data.data.user && data.data.user.profile) || {}
|
||||
const form = { ...this.data.form }
|
||||
if (profile.mobile) form.mobile = profile.mobile
|
||||
if (profile.name && profile.name !== profile.mobile) form.name = profile.name
|
||||
this.setData({ loggingIn: false, loggedIn: true, form })
|
||||
wx.showToast({ title: '登录成功', icon: 'success' })
|
||||
this.loadApplication()
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('[apply] 手机号验证登录失败:', err)
|
||||
this.setData({ submitting: false })
|
||||
wx.showToast({ title: '网络错误,请重试', icon: 'none' })
|
||||
console.warn('[apply] 登录失败:', err)
|
||||
this.setData({ loggingIn: false })
|
||||
wx.showToast({ title: (err && err.message) || '网络错误,请重试', icon: 'none' })
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
this.setData({ submitting: false })
|
||||
this.setData({ loggingIn: false })
|
||||
wx.showToast({ title: '登录失败,请重试', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
cancelPhoneAuth() {
|
||||
this.setData({ needPhoneAuth: false })
|
||||
},
|
||||
|
||||
/**
|
||||
* 待审核 → 修改模式:回填已提交的基本信息
|
||||
*/
|
||||
@@ -407,21 +458,8 @@ Page({
|
||||
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)) {
|
||||
// 登录环节的业务拒绝(手机号已注册且姓名不一致/微信已绑定其他账号)需要弹窗说明
|
||||
if (/已注册|已绑定|手机号/.test(msg)) {
|
||||
wx.showModal({
|
||||
title: '无法提交',
|
||||
content: msg,
|
||||
|
||||
+40
-15
@@ -58,13 +58,48 @@
|
||||
<text class="hero-desc">{{editing ? '待审核期间可修改姓名、手机号等基本信息,保存后审核进度不受影响。' : '提交资料并通过审核后成为实习陪诊师,可先查看订单;管理员转正后即可接单。'}}</text>
|
||||
</view>
|
||||
|
||||
<view class="reject-box" wx:if="{{rejectReason}}">
|
||||
<!-- 第一步:未登录先完成手机号登录 -->
|
||||
<view class="card login-card" wx:if="{{!loggedIn}}">
|
||||
<text class="card-title">第一步 · 登录</text>
|
||||
<text class="card-tip">填写姓名与手机号完成登录;该手机号已有账号时会自动并入,无需重复注册。</text>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">姓名</text>
|
||||
<input
|
||||
class="field-input"
|
||||
value="{{form.name}}"
|
||||
data-key="name"
|
||||
maxlength="20"
|
||||
placeholder="请输入真实姓名"
|
||||
bindinput="onInput"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<view class="field">
|
||||
<text class="field-label">手机号</text>
|
||||
<input
|
||||
class="field-input"
|
||||
type="number"
|
||||
value="{{form.mobile}}"
|
||||
data-key="mobile"
|
||||
maxlength="11"
|
||||
placeholder="请输入手机号"
|
||||
bindinput="onInput"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<button class="submit-btn" loading="{{loggingIn}}" disabled="{{loggingIn}}" bindtap="onLogin">
|
||||
登录
|
||||
</button>
|
||||
</view>
|
||||
|
||||
<view class="reject-box" wx:if="{{loggedIn && rejectReason}}">
|
||||
<text class="reject-title">上次申请未通过</text>
|
||||
<text class="reject-text">原因:{{rejectReason}}</text>
|
||||
<text class="reject-hint">修改后可重新提交。</text>
|
||||
</view>
|
||||
|
||||
<view class="card">
|
||||
<view class="card" wx:if="{{loggedIn}}">
|
||||
<text class="card-title">基本信息</text>
|
||||
|
||||
<view class="field">
|
||||
@@ -137,23 +172,13 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<button
|
||||
wx:if="{{needPhoneAuth}}"
|
||||
class="submit-btn"
|
||||
open-type="getPhoneNumber"
|
||||
bindgetphonenumber="onPhoneAuth"
|
||||
loading="{{submitting}}"
|
||||
disabled="{{submitting}}"
|
||||
>
|
||||
验证手机号并继续
|
||||
</button>
|
||||
|
||||
<button wx:else class="submit-btn" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">
|
||||
<block wx:if="{{loggedIn}}">
|
||||
<button class="submit-btn" loading="{{submitting}}" disabled="{{submitting}}" bindtap="submit">
|
||||
{{editing ? '保存修改' : '提交申请'}}
|
||||
</button>
|
||||
|
||||
<button wx:if="{{needPhoneAuth}}" class="cancel-btn" bindtap="cancelPhoneAuth">返回修改手机号</button>
|
||||
<button wx:if="{{editing}}" class="cancel-btn" bindtap="cancelEdit">取消</button>
|
||||
</block>
|
||||
|
||||
<view class="foot-note">
|
||||
当前微信账号:{{accountName}}。如需更换账号,请在微信中切换后重新打开小程序。
|
||||
|
||||
+17
-8
@@ -12,7 +12,7 @@
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
.hero-desc {
|
||||
display: block;
|
||||
margin-top: 12rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
color: #8A8078;
|
||||
}
|
||||
@@ -106,7 +106,7 @@
|
||||
.card-title {
|
||||
display: block;
|
||||
padding: 24rpx 0 8rpx;
|
||||
font-size: 28rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
color: #2A211B;
|
||||
}
|
||||
@@ -114,7 +114,7 @@
|
||||
.card-tip {
|
||||
display: block;
|
||||
padding-bottom: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #9C9188;
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@
|
||||
|
||||
.upload-tip {
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@
|
||||
.reject-text {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
color: #9E443A;
|
||||
}
|
||||
@@ -251,7 +251,7 @@
|
||||
.reject-hint {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #C0564A;
|
||||
}
|
||||
|
||||
@@ -270,6 +270,15 @@
|
||||
border: none;
|
||||
}
|
||||
|
||||
/* 登录卡片 */
|
||||
.login-card {
|
||||
padding-bottom: 32rpx;
|
||||
}
|
||||
|
||||
.login-card .field:last-of-type {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
/* 待审核:进入修改模式 */
|
||||
.edit-btn {
|
||||
height: 88rpx;
|
||||
@@ -302,7 +311,7 @@
|
||||
.foot-note {
|
||||
padding: 0 16rpx;
|
||||
text-align: center;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.6;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ page {
|
||||
padding: 16rpx 28rpx;
|
||||
background: @accent-primary;
|
||||
color: #ffffff;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
border-radius: 32rpx;
|
||||
white-space: nowrap;
|
||||
@@ -121,7 +121,7 @@ page {
|
||||
}
|
||||
|
||||
.stats-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @text-secondary;
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ page {
|
||||
|
||||
.loading-text {
|
||||
color: @text-secondary !important;
|
||||
font-size: 26rpx !important;
|
||||
font-size: 28rpx !important;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
@@ -257,7 +257,7 @@ page {
|
||||
align-items: center;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 10rpx;
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
font-weight: 500;
|
||||
|
||||
&.male {
|
||||
@@ -272,18 +272,18 @@ page {
|
||||
}
|
||||
|
||||
.customer-date {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
color: @text-muted;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.customer-phone {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: @text-secondary;
|
||||
}
|
||||
|
||||
.customer-location {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @text-muted;
|
||||
}
|
||||
|
||||
@@ -321,6 +321,6 @@ page {
|
||||
}
|
||||
|
||||
.no-more {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @text-muted;
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ page {
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ page {
|
||||
}
|
||||
|
||||
.stat-unit {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ page {
|
||||
|
||||
.section-title {
|
||||
display: block;
|
||||
font-size: 32rpx;
|
||||
font-size: 30rpx;
|
||||
font-weight: 700;
|
||||
color: #2A211B;
|
||||
margin-left: 8rpx;
|
||||
@@ -110,7 +110,7 @@ page {
|
||||
}
|
||||
|
||||
.quick-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #3A322B;
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ page {
|
||||
}
|
||||
|
||||
.order-service {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
color: #C26A2E;
|
||||
flex: 1;
|
||||
@@ -124,7 +124,7 @@ page {
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
padding: 6rpx 20rpx;
|
||||
border-radius: 30rpx;
|
||||
font-weight: 500;
|
||||
@@ -169,7 +169,7 @@ page {
|
||||
}
|
||||
|
||||
.order-hospital {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #8A8078;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
@@ -179,7 +179,7 @@ page {
|
||||
}
|
||||
|
||||
.order-time {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -192,7 +192,7 @@ page {
|
||||
text-align: center;
|
||||
|
||||
text {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #C0B7AC;
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -10,22 +10,22 @@ function resolveDisplayStatus(order) {
|
||||
return order?.status || 'pending'
|
||||
}
|
||||
|
||||
// 快捷入口:type=quick 为快捷操作(琥珀浅色系),type=function 为功能入口(暖铜主色系),分行显示。
|
||||
// 快捷入口:琥珀浅色系为快捷操作,暖铜主色系为功能入口,统一在一行内展示。
|
||||
// 管理员与陪诊员共用同一套入口配置,但陪诊员不展示档案/客户等管理员能力
|
||||
const ADMIN_ENTRIES = [
|
||||
{ type: 'quick', icon: 'add-circle', name: '增加预约', url: '/pages/order/orderEdit', color: '#E8A96B' },
|
||||
{ type: 'quick', icon: 'file-add', name: '增加档案', url: '/pages/healthprofile/profileInfo', color: '#E8A96B' },
|
||||
{ type: 'quick', icon: 'lightbulb-circle-filled', name: 'AI办公', url: '/pages/ai/index', isTab: true, color: '#E8A96B' },
|
||||
{ type: 'function', icon: 'bill', name: '预约订单', url: '/pages/order/index', isTab: true, color: '#C26A2E' },
|
||||
{ type: 'function', icon: 'heart', name: '健康档案', url: '/pages/healthprofile/index', color: '#C26A2E' },
|
||||
{ type: 'function', icon: 'user', name: '注册用户', url: '/pages/customer/index', color: '#C26A2E' },
|
||||
{ type: 'function', icon: 'user-circle', name: '个人信息', url: '/pages/me/index', color: '#C26A2E' }
|
||||
{ icon: 'add-circle', name: '增加预约', url: '/pages/order/orderEdit', color: '#E8A96B' },
|
||||
{ icon: 'file-add', name: '增加档案', url: '/pages/healthprofile/profileInfo', color: '#E8A96B' },
|
||||
{ icon: 'lightbulb-circle-filled', name: 'AI办公', url: '/pages/ai/index', isTab: true, color: '#E8A96B' },
|
||||
{ icon: 'bill', name: '预约订单', url: '/pages/order/index', isTab: true, color: '#C26A2E' },
|
||||
{ icon: 'heart', name: '健康档案', url: '/pages/healthprofile/index', color: '#C26A2E' },
|
||||
{ icon: 'user', name: '注册用户', url: '/pages/customer/index', color: '#C26A2E' },
|
||||
{ icon: 'user-circle', name: '个人信息', url: '/pages/me/index', color: '#C26A2E' }
|
||||
]
|
||||
|
||||
const ATTENDANT_ENTRIES = [
|
||||
{ type: 'quick', icon: 'lightbulb-circle-filled', name: 'AI办公', url: '/pages/ai/index', isTab: true, color: '#E8A96B' },
|
||||
{ type: 'function', icon: 'bill', name: '预约订单', url: '/pages/order/index', isTab: true, color: '#C26A2E' },
|
||||
{ type: 'function', icon: 'user-circle', name: '个人信息', url: '/pages/me/index', color: '#C26A2E' }
|
||||
{ icon: 'lightbulb-circle-filled', name: 'AI办公', url: '/pages/ai/index', isTab: true, color: '#E8A96B' },
|
||||
{ icon: 'bill', name: '预约订单', url: '/pages/order/index', isTab: true, color: '#C26A2E' },
|
||||
{ icon: 'user-circle', name: '个人信息', url: '/pages/me/index', color: '#C26A2E' }
|
||||
]
|
||||
|
||||
Page({
|
||||
|
||||
+4
-14
@@ -55,21 +55,11 @@
|
||||
<view class="section">
|
||||
<text class="section-title">快捷入口</text>
|
||||
<view class="quick-grid card">
|
||||
<view class="quick-row">
|
||||
<view class="quick-item" wx:for="{{quickEntries}}" wx:key="name" wx:if="{{item.type === 'quick'}}" bindtap="onEntryTap" data-index="{{index}}">
|
||||
<view class="quick-icon" style="background-color: {{item.color}}1a;">
|
||||
<t-icon name="{{item.icon}}" size="40rpx" color="{{item.color}}" />
|
||||
</view>
|
||||
<text class="quick-label">{{item.name}}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="quick-row">
|
||||
<view class="quick-item" wx:for="{{quickEntries}}" wx:key="name" wx:if="{{item.type === 'function'}}" bindtap="onEntryTap" data-index="{{index}}">
|
||||
<view class="quick-icon" style="background-color: {{item.color}}1a;">
|
||||
<t-icon name="{{item.icon}}" size="40rpx" color="{{item.color}}" />
|
||||
</view>
|
||||
<text class="quick-label">{{item.name}}</text>
|
||||
<view class="quick-item" wx:for="{{quickEntries}}" wx:key="name" bindtap="onEntryTap" data-index="{{index}}">
|
||||
<view class="quick-icon" style="background-color: {{item.color}}1a;">
|
||||
<t-icon name="{{item.icon}}" size="36rpx" color="{{item.color}}" />
|
||||
</view>
|
||||
<text class="quick-label">{{item.name}}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
+22
-26
@@ -107,14 +107,14 @@ page {
|
||||
}
|
||||
|
||||
.level-text {
|
||||
font-size: 20rpx;
|
||||
font-size: 22rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.greeting {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ page {
|
||||
|
||||
.intern-tip-text {
|
||||
margin-left: 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.5;
|
||||
color: #8A5A32;
|
||||
}
|
||||
@@ -146,7 +146,7 @@ page {
|
||||
}
|
||||
|
||||
.switch-text {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
margin-right: 10rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ page {
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ page {
|
||||
}
|
||||
|
||||
.stat-unit {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
margin-right: 4rpx;
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ page {
|
||||
.view-all {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -274,22 +274,17 @@ page {
|
||||
|
||||
.quick-grid {
|
||||
margin-top: 16rpx;
|
||||
padding: 32rpx 8rpx 8rpx;
|
||||
padding: 32rpx 0;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.quick-row {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-wrap: nowrap;
|
||||
}
|
||||
|
||||
.quick-item {
|
||||
width: 25%;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-bottom: 32rpx;
|
||||
transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.3s cubic-bezier(0.32, 0.72, 0, 1);
|
||||
}
|
||||
|
||||
@@ -299,19 +294,20 @@ page {
|
||||
}
|
||||
|
||||
.quick-icon {
|
||||
width: 88rpx;
|
||||
height: 88rpx;
|
||||
border-radius: 26rpx;
|
||||
width: 72rpx;
|
||||
height: 72rpx;
|
||||
border-radius: 22rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-bottom: 14rpx;
|
||||
margin-bottom: 12rpx;
|
||||
box-shadow: inset 0 2rpx 4rpx rgba(255, 255, 255, 0.8), 0 4rpx 10rpx rgba(90, 62, 42, 0.06);
|
||||
}
|
||||
|
||||
.quick-label {
|
||||
font-size: 26rpx;
|
||||
font-size: 24rpx;
|
||||
color: #5C5044;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* === 订单列表 === */
|
||||
@@ -348,7 +344,7 @@ page {
|
||||
}
|
||||
|
||||
.order-service {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
color: #C26A2E;
|
||||
flex: 1;
|
||||
@@ -358,7 +354,7 @@ page {
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
padding: 6rpx 20rpx;
|
||||
border-radius: 30rpx;
|
||||
font-weight: 500;
|
||||
@@ -403,7 +399,7 @@ page {
|
||||
}
|
||||
|
||||
.order-hospital {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #8A8078;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
@@ -413,7 +409,7 @@ page {
|
||||
}
|
||||
|
||||
.order-time {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
@@ -432,6 +428,6 @@ page {
|
||||
|
||||
.empty-text {
|
||||
margin-top: 16rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #C7BDB2;
|
||||
}
|
||||
|
||||
@@ -26,19 +26,19 @@ page {
|
||||
|
||||
.launch-sub {
|
||||
margin-top: 12rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #9C9188;
|
||||
}
|
||||
|
||||
.launch-tip {
|
||||
margin-top: 48rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #B5AAA0;
|
||||
}
|
||||
|
||||
.launch-error {
|
||||
margin-top: 48rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #C26A2E;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ page {
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #9C9188;
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ page {
|
||||
.hero-desc {
|
||||
display: block;
|
||||
margin-top: 12rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
line-height: 1.6;
|
||||
color: #8A8078;
|
||||
}
|
||||
@@ -65,7 +65,7 @@ page {
|
||||
.empty-desc {
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #8A8078;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ page {
|
||||
.status-desc {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #8A8078;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ page {
|
||||
|
||||
.upload-tip {
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #9C9188;
|
||||
}
|
||||
|
||||
|
||||
+150
-2
@@ -16,7 +16,25 @@ Page({
|
||||
isAttendant: false,
|
||||
serviceAreaLabels: CITY_LABELS,
|
||||
serviceAreaIndex: 0,
|
||||
serviceAreaText: ''
|
||||
serviceAreaText: '',
|
||||
// 个人信息编辑态:只开放后端支持自助修改的字段(姓名/性别/生日/地区)
|
||||
editing: false,
|
||||
saving: false,
|
||||
today: '',
|
||||
form: {
|
||||
name: '',
|
||||
sex: '',
|
||||
birth: '',
|
||||
province: '',
|
||||
city: '',
|
||||
district: '',
|
||||
regionText: ''
|
||||
}
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.rawUser = null
|
||||
this.setData({ today: this.formatDate(new Date()) })
|
||||
},
|
||||
|
||||
onShow() {
|
||||
@@ -98,6 +116,129 @@ Page({
|
||||
wx.navigateTo({ url: '/pages/materials/index' })
|
||||
},
|
||||
|
||||
/**
|
||||
* 用当前用户数据构建编辑表单
|
||||
*/
|
||||
buildForm(user) {
|
||||
const profile = (user && user.profile) || {}
|
||||
const location = (user && user.location) || {}
|
||||
const province = location.province || ''
|
||||
const city = location.city || ''
|
||||
const district = location.district || ''
|
||||
return {
|
||||
name: profile.name || '',
|
||||
sex: profile.sex || 'male',
|
||||
birth: this.formatDate(profile.birth),
|
||||
province,
|
||||
city,
|
||||
district,
|
||||
regionText: [province, city, district].filter(Boolean).join(' ')
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 进入/退出编辑态:退出时不保存,直接丢弃未提交的修改
|
||||
*/
|
||||
onToggleEdit() {
|
||||
if (this.data.saving) return
|
||||
if (this.data.editing) {
|
||||
this.setData({ editing: false, form: this.buildForm(this.rawUser) })
|
||||
return
|
||||
}
|
||||
this.setData({ editing: true, form: this.buildForm(this.rawUser) })
|
||||
},
|
||||
|
||||
onFormInput(e) {
|
||||
this.setData({ [`form.${e.currentTarget.dataset.field}`]: e.detail.value })
|
||||
},
|
||||
|
||||
onSelectSex(e) {
|
||||
this.setData({ 'form.sex': e.currentTarget.dataset.sex })
|
||||
},
|
||||
|
||||
onBirthChange(e) {
|
||||
this.setData({ 'form.birth': e.detail.value })
|
||||
},
|
||||
|
||||
onRegionChange(e) {
|
||||
const region = e.detail.value || []
|
||||
const province = region[0] || ''
|
||||
const city = region[1] || ''
|
||||
const district = region[2] || ''
|
||||
this.setData({
|
||||
'form.province': province,
|
||||
'form.city': city,
|
||||
'form.district': district,
|
||||
'form.regionText': [province, city, district].filter(Boolean).join(' ')
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 保存个人信息:/user/update 只接受姓名、性别、生日、手机号与地区,这里提交可自助修改的字段
|
||||
*/
|
||||
onSaveProfile() {
|
||||
if (this.data.saving) return
|
||||
|
||||
const form = this.data.form
|
||||
const name = (form.name || '').trim()
|
||||
if (!name) {
|
||||
wx.showToast({ title: '请输入姓名', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!form.sex) {
|
||||
wx.showToast({ title: '请选择性别', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const app = getApp()
|
||||
if (!app.globalData.user) {
|
||||
wx.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
this.setData({ saving: true })
|
||||
wx.showLoading({ title: '保存中...' })
|
||||
|
||||
API.user
|
||||
.update({
|
||||
profile: {
|
||||
name,
|
||||
sex: form.sex,
|
||||
birth: form.birth || ''
|
||||
},
|
||||
location: {
|
||||
province: form.province,
|
||||
city: form.city,
|
||||
district: form.district
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
wx.hideLoading()
|
||||
this.setData({ saving: false })
|
||||
if (!res || res.code !== 0) {
|
||||
wx.showToast({ title: (res && res.msg) || '保存失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
// 回写全局用户:响应是脱敏用户(不含本机 token),需保留本地 security
|
||||
const prev = app.globalData.user || {}
|
||||
const updated = {
|
||||
...prev,
|
||||
...((res.data && res.data.user) || {}),
|
||||
security: prev.security || {}
|
||||
}
|
||||
app.globalData.user = updated
|
||||
this.rawUser = updated
|
||||
this.setData({ editing: false })
|
||||
this.setUser(updated)
|
||||
wx.showToast({ title: '保存成功', icon: 'success' })
|
||||
})
|
||||
.catch((err) => {
|
||||
wx.hideLoading()
|
||||
this.setData({ saving: false })
|
||||
wx.showToast({ title: (err && err.message) || '网络错误,请重试', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* 加载当前登录用户信息
|
||||
*/
|
||||
@@ -117,6 +258,7 @@ Page({
|
||||
*/
|
||||
setUser(user) {
|
||||
if (!user) return
|
||||
this.rawUser = user
|
||||
const profile = user.profile || {}
|
||||
const location = user.location || {}
|
||||
const meta = user.meta || {}
|
||||
@@ -139,6 +281,11 @@ Page({
|
||||
createText: this.formatDate(meta.createtime)
|
||||
}
|
||||
})
|
||||
|
||||
// 编辑中不覆盖用户正在填写的表单
|
||||
if (!this.data.editing) {
|
||||
this.setData({ form: this.buildForm(user) })
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -147,7 +294,8 @@ Page({
|
||||
formatDate(dateStr) {
|
||||
if (!dateStr) return ''
|
||||
const date = new Date(dateStr)
|
||||
if (isNaN(date.getTime())) return ''
|
||||
// birth 默认值是 0(1970-01-01),视为未填写
|
||||
if (isNaN(date.getTime()) || date.getTime() <= 0) return ''
|
||||
const pad = (n) => String(n).padStart(2, '0')
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
|
||||
},
|
||||
|
||||
+79
-1
@@ -51,6 +51,8 @@ page {
|
||||
margin-left: 28rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
@@ -60,10 +62,26 @@ page {
|
||||
|
||||
.user-mobile {
|
||||
margin-top: 10rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
/* === 编辑入口 === */
|
||||
.edit-entry {
|
||||
flex-shrink: 0;
|
||||
margin-left: 16rpx;
|
||||
padding: 10rpx 24rpx;
|
||||
border-radius: 28rpx;
|
||||
background-color: rgba(255, 255, 255, 0.16);
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.4);
|
||||
font-size: 26rpx;
|
||||
color: #ffffff;
|
||||
|
||||
&:active {
|
||||
background-color: rgba(255, 255, 255, 0.28);
|
||||
}
|
||||
}
|
||||
|
||||
/* === 详细信息卡 === */
|
||||
.info-card {
|
||||
margin-top: 24rpx;
|
||||
@@ -117,3 +135,63 @@ page {
|
||||
font-size: 32rpx;
|
||||
color: #C9BFB5;
|
||||
}
|
||||
|
||||
/* === 编辑态表单 === */
|
||||
.edit-input {
|
||||
flex: 1;
|
||||
height: 48rpx;
|
||||
min-height: 48rpx;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.edit-placeholder {
|
||||
color: #C7BDB2;
|
||||
}
|
||||
|
||||
.sex-edit {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
}
|
||||
|
||||
.sex-chip {
|
||||
padding: 6rpx 32rpx;
|
||||
border-radius: 24rpx;
|
||||
background-color: #F4EFE9;
|
||||
border: 1rpx solid transparent;
|
||||
font-size: 26rpx;
|
||||
color: #6F655C;
|
||||
transition: all 0.2s ease;
|
||||
|
||||
&.active {
|
||||
background-color: rgba(194, 106, 46, 0.1);
|
||||
border-color: #C26A2E;
|
||||
color: #C26A2E;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
/* === 保存按钮 === */
|
||||
.save-bar {
|
||||
margin-top: 32rpx;
|
||||
}
|
||||
|
||||
.save-btn {
|
||||
height: 96rpx;
|
||||
line-height: 96rpx;
|
||||
text-align: center;
|
||||
border-radius: 48rpx;
|
||||
background-color: #C26A2E;
|
||||
color: #ffffff;
|
||||
font-size: 30rpx;
|
||||
font-weight: 600;
|
||||
box-shadow: 0 8rpx 24rpx rgba(180, 85, 42, 0.25);
|
||||
|
||||
&::after {
|
||||
border: none;
|
||||
}
|
||||
|
||||
&:active {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
|
||||
+70
-3
@@ -10,10 +10,32 @@
|
||||
<text class="user-name">{{user.name}}</text>
|
||||
<text class="user-mobile">{{user.mobile || '暂未绑定手机号'}}</text>
|
||||
</view>
|
||||
<view class="edit-entry {{editing ? 'active' : ''}}" bindtap="onToggleEdit">
|
||||
<text>{{editing ? '取消' : '编辑'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 详细信息 -->
|
||||
<view class="info-card">
|
||||
<!-- 姓名 -->
|
||||
<view class="info-item">
|
||||
<view class="info-left">
|
||||
<t-icon name="user-circle" size="36rpx" color="#C26A2E" />
|
||||
<text class="info-label">姓名</text>
|
||||
</view>
|
||||
<input
|
||||
wx:if="{{editing}}"
|
||||
class="info-value edit-input"
|
||||
value="{{form.name}}"
|
||||
maxlength="20"
|
||||
placeholder="请输入姓名"
|
||||
placeholder-class="edit-placeholder"
|
||||
bindinput="onFormInput"
|
||||
data-field="name"
|
||||
/>
|
||||
<text wx:else class="info-value">{{user.name}}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-item" wx:if="{{identityText}}">
|
||||
<view class="info-left">
|
||||
<t-icon name="award" size="36rpx" color="#C26A2E" />
|
||||
@@ -21,20 +43,46 @@
|
||||
</view>
|
||||
<text class="info-value">{{identityText}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 性别 -->
|
||||
<view class="info-item">
|
||||
<view class="info-left">
|
||||
<t-icon name="user" size="36rpx" color="#C26A2E" />
|
||||
<text class="info-label">性别</text>
|
||||
</view>
|
||||
<text class="info-value">{{user.sexLabel}}</text>
|
||||
<view class="sex-edit" wx:if="{{editing}}">
|
||||
<view class="sex-chip {{form.sex === 'male' ? 'active' : ''}}" bindtap="onSelectSex" data-sex="male">
|
||||
<text>男</text>
|
||||
</view>
|
||||
<view class="sex-chip {{form.sex === 'female' ? 'active' : ''}}" bindtap="onSelectSex" data-sex="female">
|
||||
<text>女</text>
|
||||
</view>
|
||||
</view>
|
||||
<text wx:else class="info-value">{{user.sexLabel}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 出生日期 -->
|
||||
<view class="info-item">
|
||||
<view class="info-left">
|
||||
<t-icon name="calendar" size="36rpx" color="#C26A2E" />
|
||||
<text class="info-label">出生日期</text>
|
||||
</view>
|
||||
<text class="info-value">{{user.birthText || '未填写'}}</text>
|
||||
<picker
|
||||
wx:if="{{editing}}"
|
||||
mode="date"
|
||||
value="{{form.birth || today}}"
|
||||
start="1930-01-01"
|
||||
end="{{today}}"
|
||||
bindchange="onBirthChange"
|
||||
>
|
||||
<view class="info-value picker-value">
|
||||
{{form.birth || '请选择'}}
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
<text wx:else class="info-value">{{user.birthText || '未填写'}}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-item">
|
||||
<view class="info-left">
|
||||
<t-icon name="mail" size="36rpx" color="#C26A2E" />
|
||||
@@ -49,13 +97,27 @@
|
||||
</view>
|
||||
<text class="info-value">{{user.idnumber || '未填写'}}</text>
|
||||
</view>
|
||||
|
||||
<!-- 所在地区 -->
|
||||
<view class="info-item">
|
||||
<view class="info-left">
|
||||
<t-icon name="location" size="36rpx" color="#C26A2E" />
|
||||
<text class="info-label">所在地区</text>
|
||||
</view>
|
||||
<text class="info-value">{{user.locationText || '未填写'}}</text>
|
||||
<picker
|
||||
wx:if="{{editing}}"
|
||||
mode="region"
|
||||
value="{{[form.province, form.city, form.district]}}"
|
||||
bindchange="onRegionChange"
|
||||
>
|
||||
<view class="info-value picker-value">
|
||||
{{form.regionText || '请选择'}}
|
||||
<text class="arrow">›</text>
|
||||
</view>
|
||||
</picker>
|
||||
<text wx:else class="info-value">{{user.locationText || '未填写'}}</text>
|
||||
</view>
|
||||
|
||||
<view class="info-item" wx:if="{{isAttendant}}">
|
||||
<view class="info-left">
|
||||
<t-icon name="location" size="36rpx" color="#C26A2E" />
|
||||
@@ -91,4 +153,9 @@
|
||||
<text class="info-value">{{user.createText || '未知'}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 编辑态保存 -->
|
||||
<view class="save-bar" wx:if="{{editing}}">
|
||||
<button class="save-btn" loading="{{saving}}" bindtap="onSaveProfile">保存</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
+18
-18
@@ -74,7 +74,7 @@ page {
|
||||
|
||||
.header-sub {
|
||||
display: block;
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
font-weight: 300;
|
||||
letter-spacing: 1rpx;
|
||||
@@ -85,7 +85,7 @@ page {
|
||||
z-index: 1;
|
||||
flex-shrink: 0;
|
||||
padding: 16rpx 28rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #fff;
|
||||
background: rgba(255, 255, 255, 0.18);
|
||||
border: 1rpx solid rgba(255, 255, 255, 0.4);
|
||||
@@ -109,7 +109,7 @@ page {
|
||||
padding: 16rpx 0;
|
||||
text-align: center;
|
||||
border-radius: 26rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: @muted;
|
||||
transition: all 0.25s;
|
||||
|
||||
@@ -130,7 +130,7 @@ page {
|
||||
}
|
||||
|
||||
.filter-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @muted;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ page {
|
||||
padding: 12rpx 24rpx;
|
||||
background: @card;
|
||||
border-radius: 28rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @text;
|
||||
border: 1rpx solid rgba(90, 62, 42, 0.06);
|
||||
box-shadow: 0 4rpx 12rpx rgba(90, 62, 42, 0.05);
|
||||
@@ -178,7 +178,7 @@ page {
|
||||
|
||||
.loading-text {
|
||||
color: @muted !important;
|
||||
font-size: 26rpx !important;
|
||||
font-size: 28rpx !important;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
@@ -191,7 +191,7 @@ page {
|
||||
padding: 14rpx 48rpx;
|
||||
background: @accent;
|
||||
color: #fff;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
border-radius: 28rpx;
|
||||
display: inline-block;
|
||||
}
|
||||
@@ -231,7 +231,7 @@ page {
|
||||
}
|
||||
|
||||
.order-tag {
|
||||
font-size: 20rpx;
|
||||
font-size: 22rpx;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 20rpx;
|
||||
font-weight: 500;
|
||||
@@ -248,14 +248,14 @@ page {
|
||||
}
|
||||
|
||||
.order-no {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @muted;
|
||||
font-weight: 500;
|
||||
font-family: 'DIN Alternate', 'Helvetica Neue', monospace;
|
||||
}
|
||||
|
||||
.status-badge {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
padding: 6rpx 20rpx;
|
||||
border-radius: 30rpx;
|
||||
font-weight: 500;
|
||||
@@ -338,7 +338,7 @@ page {
|
||||
}
|
||||
|
||||
.patient-sex {
|
||||
font-size: 20rpx;
|
||||
font-size: 22rpx;
|
||||
padding: 2rpx 10rpx;
|
||||
border-radius: 8rpx;
|
||||
font-weight: 500;
|
||||
@@ -355,12 +355,12 @@ page {
|
||||
}
|
||||
|
||||
.patient-age {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
color: @muted;
|
||||
}
|
||||
|
||||
.patient-phone {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @muted;
|
||||
}
|
||||
|
||||
@@ -377,14 +377,14 @@ page {
|
||||
}
|
||||
|
||||
.line-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @muted;
|
||||
width: 64rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.line-value {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: @text;
|
||||
flex: 1;
|
||||
}
|
||||
@@ -406,7 +406,7 @@ page {
|
||||
}
|
||||
|
||||
.fee-label {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @muted;
|
||||
}
|
||||
|
||||
@@ -425,7 +425,7 @@ page {
|
||||
.action-btn {
|
||||
padding: 14rpx 32rpx;
|
||||
border-radius: 24rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
font-weight: 500;
|
||||
transition: all 0.2s;
|
||||
|
||||
@@ -455,6 +455,6 @@ page {
|
||||
}
|
||||
|
||||
.no-more {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: @muted;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ page {
|
||||
|
||||
.status-desc {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: rgba(255, 255, 255, 0.7);
|
||||
font-weight: 300;
|
||||
}
|
||||
@@ -151,7 +151,7 @@ page {
|
||||
}
|
||||
|
||||
.patient-sex {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
padding: 4rpx 12rpx;
|
||||
border-radius: 10rpx;
|
||||
font-weight: 500;
|
||||
@@ -168,12 +168,12 @@ page {
|
||||
}
|
||||
|
||||
.patient-age {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
.patient-phone {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ page {
|
||||
}
|
||||
|
||||
.attendant-phone {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ page {
|
||||
}
|
||||
|
||||
.note-label {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
width: 140rpx;
|
||||
flex-shrink: 0;
|
||||
@@ -258,7 +258,7 @@ page {
|
||||
}
|
||||
|
||||
.note-content {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #5C5044;
|
||||
line-height: 1.6;
|
||||
flex: 1;
|
||||
@@ -314,7 +314,7 @@ page {
|
||||
}
|
||||
|
||||
.order-tag {
|
||||
font-size: 20rpx;
|
||||
font-size: 22rpx;
|
||||
padding: 4rpx 14rpx;
|
||||
border-radius: 20rpx;
|
||||
font-weight: 500;
|
||||
@@ -336,7 +336,7 @@ page {
|
||||
border-radius: 20rpx;
|
||||
background: #FBF0DC;
|
||||
color: #A97712;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@@ -377,7 +377,7 @@ page {
|
||||
}
|
||||
|
||||
.share-close {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -399,7 +399,7 @@ page {
|
||||
border-radius: 50%;
|
||||
border: 2rpx solid #D9CFC3;
|
||||
margin-right: 24rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 40rpx;
|
||||
text-align: center;
|
||||
color: #fff;
|
||||
@@ -422,7 +422,7 @@ page {
|
||||
}
|
||||
|
||||
.share-stage {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
color: #A3988B;
|
||||
margin-top: 6rpx;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ page {
|
||||
.share-empty {
|
||||
padding: 60rpx 0;
|
||||
text-align: center;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ page {
|
||||
}
|
||||
|
||||
.brief-tag {
|
||||
font-size: 22rpx;
|
||||
font-size: 24rpx;
|
||||
background-color: rgba(194, 106, 46, 0.1);
|
||||
color: #C26A2E;
|
||||
border-radius: 16rpx;
|
||||
@@ -44,7 +44,7 @@ page {
|
||||
.brief-remark {
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #8A8078;
|
||||
line-height: 1.5;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ page {
|
||||
|
||||
.profile-empty-sub {
|
||||
margin-top: 6rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #8A8078;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ page {
|
||||
border-radius: 40rpx;
|
||||
background-color: rgba(194, 106, 46, 0.1);
|
||||
color: #C26A2E;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
@@ -188,14 +188,14 @@ page {
|
||||
|
||||
.picker-item-sub {
|
||||
margin-left: 12rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #9A9087;
|
||||
}
|
||||
|
||||
.picker-item-mobile {
|
||||
display: block;
|
||||
margin-top: 4rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #9A9087;
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ page {
|
||||
.picker-empty {
|
||||
padding: 60rpx 0;
|
||||
text-align: center;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #9A9087;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ page {
|
||||
|
||||
.switch-label {
|
||||
margin-right: 16rpx;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
|
||||
&.paid {
|
||||
color: #C26A2E;
|
||||
@@ -326,7 +326,7 @@ page {
|
||||
.field-tip {
|
||||
display: block;
|
||||
margin-top: 8rpx;
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #D98E04;
|
||||
}
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ page {
|
||||
}
|
||||
|
||||
.level-text {
|
||||
font-size: 20rpx;
|
||||
font-size: 22rpx;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ page {
|
||||
}
|
||||
|
||||
.login-desc {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: rgba(255, 255, 255, 0.65);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ page {
|
||||
}
|
||||
|
||||
.login-btn-text {
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #C26A2E;
|
||||
font-weight: 600;
|
||||
}
|
||||
@@ -210,7 +210,7 @@ page {
|
||||
}
|
||||
|
||||
.version-text {
|
||||
font-size: 24rpx;
|
||||
font-size: 26rpx;
|
||||
color: #A3988B;
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ page {
|
||||
|
||||
.form-label {
|
||||
display: block;
|
||||
font-size: 26rpx;
|
||||
font-size: 28rpx;
|
||||
color: #6F655C;
|
||||
margin-bottom: 12rpx;
|
||||
font-weight: 500;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
const request = require('./request.js')
|
||||
|
||||
// 语音 / 图片识别链路最长可到 60s,单独放宽超时,避免网络稍慢就整单失败
|
||||
const AI_MEDIA_TIMEOUT = 90000
|
||||
|
||||
const API = {
|
||||
user: {
|
||||
wxGetPhoneNumber: (data) => request.post('https://api.huashengtec.com/user/wxgetphonenumber', data),
|
||||
@@ -74,6 +77,10 @@ const API = {
|
||||
|
||||
ai: {
|
||||
chat: (data) => request.post('/ai/chat', data),
|
||||
// 语音 / 图片识别:语音优先走 /chat 的实时分片链路,整段接口用于兜底;
|
||||
// 识别链路最长可到 60s,单独放宽超时
|
||||
asr: (data) => request.post('/health/ai/asr', data, { timeout: AI_MEDIA_TIMEOUT }),
|
||||
ocr: (data) => request.post('/health/ai/ocr', data, { timeout: AI_MEDIA_TIMEOUT }),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
+94
-112
@@ -1,22 +1,26 @@
|
||||
// AI 聊天 / 语音识别 WebSocket(与 health 服务同域)
|
||||
const WS_BASE_URL = 'wss://api.huashengtec.com/health-ws'
|
||||
//const WS_BASE_URL = 'ws://127.0.0.1:9005'
|
||||
|
||||
const WS_HEARTBEAT_INTERVAL = 30000
|
||||
const WS_MAX_RECONNECT_ATTEMPTS = 3
|
||||
const WS_RECONNECT_DELAY = 3000
|
||||
|
||||
class AIChatSocket {
|
||||
constructor(url = `${WS_BASE_URL}/chat`, options = {}) {
|
||||
this.url = url
|
||||
this.options = {
|
||||
timeout: 10000,
|
||||
heartbeatInterval: 30000,
|
||||
heartbeatInterval: WS_HEARTBEAT_INTERVAL,
|
||||
autoReconnect: true,
|
||||
maxReconnectAttempts: 3,
|
||||
reconnectDelay: 3000,
|
||||
maxReconnectAttempts: WS_MAX_RECONNECT_ATTEMPTS,
|
||||
reconnectDelay: WS_RECONNECT_DELAY,
|
||||
...options
|
||||
}
|
||||
|
||||
this.socketTask = null
|
||||
this.isConnected = false
|
||||
this.isConnecting = false
|
||||
this.messageQueue = []
|
||||
this.connectPromise = null
|
||||
this.reconnectAttempts = 0
|
||||
|
||||
this._openCallback = null
|
||||
@@ -26,136 +30,125 @@ class AIChatSocket {
|
||||
this._heartbeatTimer = null
|
||||
}
|
||||
|
||||
// 连接 Promise 单飞:调用方必须 await 成功后再发送,避免断线后的首条消息竞态
|
||||
connect() {
|
||||
if (this.isConnected || this.isConnecting) {
|
||||
console.log('[AIChatSocket] Already connected or connecting')
|
||||
return Promise.resolve()
|
||||
}
|
||||
if (this.isConnected) return Promise.resolve()
|
||||
if (this.connectPromise) return this.connectPromise
|
||||
|
||||
this.isConnecting = true
|
||||
this.connectPromise = new Promise((resolve, reject) => {
|
||||
let settled = false
|
||||
const succeed = () => {
|
||||
if (settled) return
|
||||
settled = true
|
||||
this.isConnecting = false
|
||||
this.connectPromise = null
|
||||
resolve()
|
||||
}
|
||||
const fail = (err) => {
|
||||
if (settled) return
|
||||
settled = true
|
||||
this.isConnecting = false
|
||||
this.connectPromise = null
|
||||
reject(err instanceof Error ? err : new Error('WebSocket 连接失败'))
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
this.socketTask = wx.connectSocket({
|
||||
url: this.url,
|
||||
header: {
|
||||
'content-type': 'application/json',
|
||||
...this.options.header
|
||||
},
|
||||
protocols: this.options.protocols || [],
|
||||
success: () => {
|
||||
console.log('[AIChatSocket] WebSocket connecting...')
|
||||
},
|
||||
fail: (err) => {
|
||||
this.isConnecting = false
|
||||
console.error('[AIChatSocket] Connect failed:', err)
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
try {
|
||||
this.socketTask = wx.connectSocket({
|
||||
url: this.url,
|
||||
header: {
|
||||
'content-type': 'application/json',
|
||||
...this.options.header
|
||||
},
|
||||
protocols: this.options.protocols || [],
|
||||
fail
|
||||
})
|
||||
} catch (err) {
|
||||
fail(err)
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.socketTask) {
|
||||
this.isConnecting = false
|
||||
reject(new Error('SocketTask creation failed'))
|
||||
fail(new Error('SocketTask creation failed'))
|
||||
return
|
||||
}
|
||||
|
||||
this.socketTask.onOpen(() => {
|
||||
console.log('[AIChatSocket] Connection opened')
|
||||
this.isConnected = true
|
||||
this.isConnecting = false
|
||||
this.reconnectAttempts = 0
|
||||
this._startHeartbeat()
|
||||
|
||||
this._flushMessageQueue()
|
||||
|
||||
if (this._openCallback) {
|
||||
this._openCallback()
|
||||
}
|
||||
resolve()
|
||||
if (this._openCallback) this._openCallback()
|
||||
succeed()
|
||||
})
|
||||
|
||||
this.socketTask.onClose((res) => {
|
||||
console.log('[AIChatSocket] Connection closed:', res)
|
||||
this.isConnected = false
|
||||
this.isConnecting = false
|
||||
this._stopHeartbeat()
|
||||
|
||||
if (this._closeCallback) {
|
||||
this._closeCallback(res)
|
||||
}
|
||||
|
||||
fail(new Error(`WebSocket 已关闭:${res.code || 'unknown'}`))
|
||||
if (this._closeCallback) this._closeCallback(res)
|
||||
if (this.options.autoReconnect && this.reconnectAttempts < this.options.maxReconnectAttempts) {
|
||||
this._reconnect()
|
||||
}
|
||||
})
|
||||
|
||||
this.socketTask.onError((err) => {
|
||||
console.error('[AIChatSocket] WebSocket error:', err)
|
||||
this.isConnected = false
|
||||
this.isConnecting = false
|
||||
|
||||
if (this._errorCallback) {
|
||||
this._errorCallback(err)
|
||||
}
|
||||
if (this._errorCallback) this._errorCallback(err)
|
||||
fail(new Error(err?.errMsg || 'WebSocket 连接错误'))
|
||||
})
|
||||
|
||||
this.socketTask.onMessage((res) => {
|
||||
if (!this._messageCallback) return
|
||||
try {
|
||||
const data = typeof res.data === 'string' ? JSON.parse(res.data) : res.data
|
||||
if (this._messageCallback) {
|
||||
this._messageCallback(data)
|
||||
}
|
||||
} catch (e) {
|
||||
if (this._messageCallback) {
|
||||
this._messageCallback(res.data)
|
||||
}
|
||||
this._messageCallback(data)
|
||||
} catch (err) {
|
||||
this._messageCallback({
|
||||
source: 'system',
|
||||
type: 'error',
|
||||
content: '收到无法解析的服务消息',
|
||||
id: ''
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return this.connectPromise
|
||||
}
|
||||
|
||||
send(data) {
|
||||
const message = typeof data === 'string' ? data : JSON.stringify(data)
|
||||
|
||||
if (!this.isConnected || !this.socketTask) {
|
||||
console.log('[AIChatSocket] Not connected, queueing message')
|
||||
this.messageQueue.push(message)
|
||||
return false
|
||||
return Promise.reject(new Error('WebSocket 尚未连接'))
|
||||
}
|
||||
|
||||
try {
|
||||
this.socketTask.send({
|
||||
data: message,
|
||||
fail: (err) => {
|
||||
console.error('[AIChatSocket] Send failed:', err)
|
||||
this.messageQueue.push(message)
|
||||
}
|
||||
})
|
||||
return true
|
||||
} catch (err) {
|
||||
console.error('[AIChatSocket] Send error:', err)
|
||||
this.messageQueue.push(message)
|
||||
return false
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
this.socketTask.send({
|
||||
data: message,
|
||||
success: resolve,
|
||||
fail: (err) => reject(new Error(err?.errMsg || '消息发送失败'))
|
||||
})
|
||||
} catch (err) {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
close() {
|
||||
this._stopHeartbeat()
|
||||
this.options.autoReconnect = false
|
||||
|
||||
if (this.socketTask) {
|
||||
this.socketTask.close({
|
||||
code: 1000,
|
||||
reason: 'User closed',
|
||||
fail: (err) => {
|
||||
console.error('[AIChatSocket] Close failed:', err)
|
||||
}
|
||||
})
|
||||
this.socketTask = null
|
||||
}
|
||||
|
||||
const task = this.socketTask
|
||||
this.socketTask = null
|
||||
this.isConnected = false
|
||||
this.isConnecting = false
|
||||
this.messageQueue = []
|
||||
this.connectPromise = null
|
||||
if (task) {
|
||||
task.close({
|
||||
code: 1000,
|
||||
reason: 'User closed',
|
||||
fail: (err) => console.error('[AIChatSocket] Close failed:', err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
onOpen(callback) {
|
||||
@@ -174,21 +167,10 @@ class AIChatSocket {
|
||||
this._messageCallback = callback
|
||||
}
|
||||
|
||||
_flushMessageQueue() {
|
||||
if (this.messageQueue.length === 0) return
|
||||
|
||||
console.log(`[AIChatSocket] Flushing ${this.messageQueue.length} queued messages`)
|
||||
while (this.messageQueue.length > 0) {
|
||||
const message = this.messageQueue.shift()
|
||||
this.send(message)
|
||||
}
|
||||
}
|
||||
|
||||
_reconnect() {
|
||||
this.reconnectAttempts++
|
||||
console.log(`[AIChatSocket] Reconnecting... Attempt ${this.reconnectAttempts}/${this.options.maxReconnectAttempts}`)
|
||||
|
||||
setTimeout(() => {
|
||||
if (!this.options.autoReconnect || this.isConnected) return
|
||||
this.connect().catch((err) => {
|
||||
console.error('[AIChatSocket] Reconnect failed:', err)
|
||||
})
|
||||
@@ -197,17 +179,17 @@ class AIChatSocket {
|
||||
|
||||
_startHeartbeat() {
|
||||
this._stopHeartbeat()
|
||||
|
||||
this._heartbeatTimer = setInterval(() => {
|
||||
if (this.isConnected && this.socketTask) {
|
||||
this.socketTask.send({
|
||||
data: JSON.stringify({ type: 'ping' }),
|
||||
fail: (err) => {
|
||||
console.error('[AIChatSocket] Heartbeat failed:', err)
|
||||
this._stopHeartbeat()
|
||||
}
|
||||
})
|
||||
}
|
||||
if (!this.isConnected || !this.socketTask) return
|
||||
this.send({
|
||||
source: 'client',
|
||||
type: 'ping',
|
||||
content: '',
|
||||
id: `heartbeat_${Date.now()}`
|
||||
}).catch((err) => {
|
||||
console.error('[AIChatSocket] Heartbeat failed:', err)
|
||||
this._stopHeartbeat()
|
||||
})
|
||||
}, this.options.heartbeatInterval)
|
||||
}
|
||||
|
||||
@@ -219,4 +201,4 @@ class AIChatSocket {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AIChatSocket
|
||||
module.exports = AIChatSocket
|
||||
|
||||
+26
-2
@@ -3,10 +3,34 @@ class Request {
|
||||
constructor(baseURL = 'https://api.huashengtec.com') {
|
||||
//constructor(baseURL = 'http://127.0.0.1:9004') {
|
||||
this.baseURL = baseURL
|
||||
// 401 兜底回调由 app.js 注入(静默重登),避免各页面自己处理登录
|
||||
this.onUnauthorized = null
|
||||
}
|
||||
|
||||
async request(options) {
|
||||
const { url, method = 'GET', data = {}, header = {}, skipAuthWait = false, ...rest } = options
|
||||
setUnauthorizedHandler(handler) {
|
||||
this.onUnauthorized = handler
|
||||
}
|
||||
|
||||
request(options) {
|
||||
return this.send(options).then((body) => this.recoverUnauthorized(body, options))
|
||||
}
|
||||
|
||||
// token 失效时后端返回 HTTP 200 + code 401:静默重登一次再重试原请求。
|
||||
// 登录请求自身(skipAuthWait)不再触发重登,避免递归
|
||||
recoverUnauthorized(body, options) {
|
||||
if (!body || body.code !== 401 || options._retried || options.skipAuthWait || !this.onUnauthorized) {
|
||||
return body
|
||||
}
|
||||
|
||||
const notLoggedIn = { code: 401, msg: '请先登录', data: null }
|
||||
return Promise.resolve()
|
||||
.then(() => this.onUnauthorized())
|
||||
.then((ok) => (ok ? this.request({ ...options, _retried: true }) : notLoggedIn))
|
||||
.catch(() => notLoggedIn)
|
||||
}
|
||||
|
||||
async send(options) {
|
||||
const { url, method = 'GET', data = {}, header = {}, skipAuthWait = false, _retried, ...rest } = options
|
||||
|
||||
// 等待登录完成后再携带 token,避免页面请求早于 app.js 登录的竞态
|
||||
// skipAuthWait: 登录请求自身使用,否则会等待自己导致死锁
|
||||
|
||||
Reference in New Issue
Block a user