|
|
@@ -13,6 +13,18 @@
|
|
|
</view>
|
|
|
<view class="top-toast" v-if="topToast.show">{{ topToast.text }}</view>
|
|
|
<view :class="'treatment ' + (admType == 'graphic' ? 'treatment-graphic' : '')" :style="'height: calc(100vh - ' + (height * 2 + 80) + 'rpx)'">
|
|
|
+ <!-- 遮罩承接手指离开小按钮后的松开/取消事件,避免录音无法停止。 -->
|
|
|
+ <view
|
|
|
+ v-if="inputMode === 'voice' && isPressing"
|
|
|
+ class="voice-record-mask"
|
|
|
+ @touchmove.stop.prevent
|
|
|
+ @touchend.stop="stopVoiceRecord"
|
|
|
+ @touchcancel.stop="onRecordTouchCancel"
|
|
|
+ >
|
|
|
+ <view class="voice-record-hint">
|
|
|
+ <text>{{ recordStatus === 'cancel' ? '松开取消' : '正在录音,松开发送' }}</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
<canvas canvas-id="canvas" :style="'width:' + cWidth + 'px;height:' + cHeight + 'px;position: absolute;left:-1000px;top:-1000px;'"></canvas>
|
|
|
<!-- <view class="top-section">
|
|
|
<view :class="tipsClose == 'N' && admType == 'video' ? 'tips' : 'tipsClose'">
|
|
|
@@ -234,15 +246,15 @@
|
|
|
|
|
|
<view
|
|
|
class="voice-record-area"
|
|
|
- :class="{ 'voice-recording': recording }"
|
|
|
- @touchstart.prevent="startVoiceRecord"
|
|
|
- @touchmove.prevent
|
|
|
- @touchend.prevent="stopVoiceRecord"
|
|
|
+ :class="{ 'voice-recording': isPressing }"
|
|
|
+ @touchstart="startVoiceRecord"
|
|
|
+ @touchmove.stop.prevent
|
|
|
+ @touchend="stopVoiceRecord"
|
|
|
@touchcancel="onRecordTouchCancel"
|
|
|
@contextmenu.prevent
|
|
|
>
|
|
|
- <text v-if="!recording" selectable="false">{{ recordText }}</text>
|
|
|
- <text v-else selectable="false">松开 结束</text>
|
|
|
+ <text v-if="!isPressing" selectable="false">{{ recordText }}</text>
|
|
|
+ <text v-else selectable="false">{{ recordStatus === 'cancel' ? '松开取消' : '松开 结束' }}</text>
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
@@ -343,6 +355,7 @@ import { SDKAPPID, genTestUserSig } from '../../../../utils/GenerateTestUserSig.
|
|
|
import messageUtil from '../../../../utils/message.js';
|
|
|
import Util from '../../../../utils/util.js';
|
|
|
import commonUtil from '../../../../utils/common.js';
|
|
|
+import { createChatPresence } from '../../../../utils/chatPresence.js';
|
|
|
// #ifdef MP-WEIXIN
|
|
|
import TIM from 'tim-wx-sdk';
|
|
|
// #endif
|
|
|
@@ -500,6 +513,8 @@ export default {
|
|
|
recordText: '按住 说话', // 录音按钮提示文字
|
|
|
recordStartTime: 0,
|
|
|
recordCanceled: false, // 录音取消标志(停止但不发送)
|
|
|
+ isPressing: false, // 手指仍按在录音流程中(覆盖录音初始化阶段)
|
|
|
+ recordStatus: 'record', // 'record' 发送;'cancel' 丢弃本次录音
|
|
|
h5StartRecordPromise: null, // H5 录音启动 Promise(wechath5.startRecord)
|
|
|
_h5RecordingPhase: 'idle', // H5 录音阶段: 'idle' | 'starting' | 'recording' | 'stopping'
|
|
|
|
|
|
@@ -564,7 +579,8 @@ export default {
|
|
|
fromMessage,
|
|
|
showMedicalRecordAndDiagnosis: fromMessage ? false : this.showMedicalRecordAndDiagnosis
|
|
|
});
|
|
|
- if (!help && !fromMessage) {
|
|
|
+ this.initChatPresence();
|
|
|
+ if (!help) {
|
|
|
this.getVisitRelatedInformation();
|
|
|
}
|
|
|
},
|
|
|
@@ -604,6 +620,13 @@ export default {
|
|
|
patImageError: false,
|
|
|
userImageError: false
|
|
|
});
|
|
|
+ if (this._chatPresenceState) {
|
|
|
+ this._chatPresenceState.pageVisible = true;
|
|
|
+ this.syncChatPresence();
|
|
|
+ if (!this.help && !this._chatPresenceState.consultID) {
|
|
|
+ this.getVisitRelatedInformation();
|
|
|
+ }
|
|
|
+ }
|
|
|
let { templateFlag } = this;
|
|
|
if (templateFlag) {
|
|
|
this.setData(
|
|
|
@@ -621,11 +644,15 @@ export default {
|
|
|
/**
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
*/
|
|
|
- onHide: function () {},
|
|
|
+ onHide: function () {
|
|
|
+ if (this._chatPresenceState) this._chatPresenceState.pageVisible = false;
|
|
|
+ if (this._chatPresence) this._chatPresence.stop();
|
|
|
+ },
|
|
|
/**
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
*/
|
|
|
onUnload: function () {
|
|
|
+ this.destroyChatPresence();
|
|
|
// 清除顶部 toast 定时器
|
|
|
if (this.topToast && this.topToast.timer) {
|
|
|
clearTimeout(this.topToast.timer);
|
|
|
@@ -641,6 +668,7 @@ export default {
|
|
|
try { wechath5.cancelRecord(); } catch (e) {}
|
|
|
this.h5StartRecordPromise = null;
|
|
|
}
|
|
|
+ this._unbindH5VoiceEndListener();
|
|
|
this._h5RecordingPhase = 'idle';
|
|
|
// #endif
|
|
|
// 注销 TIM 消息监听
|
|
|
@@ -660,7 +688,85 @@ export default {
|
|
|
* 用户点击右上角分享
|
|
|
*/
|
|
|
onShareAppMessage: function () {},
|
|
|
+ beforeUnmount() {
|
|
|
+ this.destroyChatPresence();
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ 'patientData.statusCode'() {
|
|
|
+ this.syncChatPresence();
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
+ initChatPresence() {
|
|
|
+ const state = this._chatPresenceState = {
|
|
|
+ admID: String(this.patientData.admID || ''),
|
|
|
+ consultID: '',
|
|
|
+ pageVisible: false,
|
|
|
+ documentVisible: true,
|
|
|
+ ended: false,
|
|
|
+ disposed: false,
|
|
|
+ visitRequest: null
|
|
|
+ };
|
|
|
+ this._chatPresence = createChatPresence({
|
|
|
+ canReport: () => {
|
|
|
+ const userData = Cache.get('userData');
|
|
|
+ return !state.disposed && !state.ended && state.pageVisible && state.documentVisible &&
|
|
|
+ !!state.consultID && !!state.admID && state.admID === String(this.patientData.admID || '') &&
|
|
|
+ !this.help && !this.record && this.patientData.statusCode !== 'F' &&
|
|
|
+ !!(userData && userData.userID);
|
|
|
+ },
|
|
|
+ send: (complete) => $http.post('urlDeault', this, {
|
|
|
+ code: '12100064',
|
|
|
+ data: { params: [{ consultRecordID: state.consultID, type: '1' }] },
|
|
|
+ success: () => {},
|
|
|
+ complete
|
|
|
+ })
|
|
|
+ });
|
|
|
+ // #ifdef H5
|
|
|
+ state.documentVisible = document.visibilityState === 'visible';
|
|
|
+ this._chatVisibilityChange = () => {
|
|
|
+ state.documentVisible = document.visibilityState === 'visible';
|
|
|
+ this.syncChatPresence();
|
|
|
+ };
|
|
|
+ this._chatPageHide = () => {
|
|
|
+ state.documentVisible = false;
|
|
|
+ this._chatPresence.stop();
|
|
|
+ };
|
|
|
+ document.addEventListener('visibilitychange', this._chatVisibilityChange);
|
|
|
+ window.addEventListener('pagehide', this._chatPageHide);
|
|
|
+ window.addEventListener('pageshow', this._chatVisibilityChange);
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+
|
|
|
+ syncChatPresence() {
|
|
|
+ const state = this._chatPresenceState;
|
|
|
+ if (!state || state.disposed) return;
|
|
|
+ const admID = String(this.patientData.admID || '');
|
|
|
+ if (state.admID !== admID) {
|
|
|
+ this._chatPresence.stop();
|
|
|
+ state.admID = admID;
|
|
|
+ state.consultID = '';
|
|
|
+ state.ended = false;
|
|
|
+ state.visitRequest = null;
|
|
|
+ }
|
|
|
+ this._chatPresence.refresh();
|
|
|
+ },
|
|
|
+
|
|
|
+ endChatPresence() {
|
|
|
+ if (this._chatPresenceState) this._chatPresenceState.ended = true;
|
|
|
+ if (this._chatPresence) this._chatPresence.stop();
|
|
|
+ },
|
|
|
+
|
|
|
+ destroyChatPresence() {
|
|
|
+ if (this._chatPresenceState) this._chatPresenceState.disposed = true;
|
|
|
+ if (this._chatPresence) this._chatPresence.destroy();
|
|
|
+ // #ifdef H5
|
|
|
+ document.removeEventListener('visibilitychange', this._chatVisibilityChange);
|
|
|
+ window.removeEventListener('pagehide', this._chatPageHide);
|
|
|
+ window.removeEventListener('pageshow', this._chatVisibilityChange);
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 拼接图片完整 URL
|
|
|
* 后端返回的 image / patImage 可能是相对路径(如 /images/photo/xxx.png),
|
|
|
@@ -1341,11 +1447,18 @@ export default {
|
|
|
|
|
|
// 根据就诊ID获取挂号就诊相关信息
|
|
|
getVisitRelatedInformation() {
|
|
|
- const patientData = Cache.get('patientData');
|
|
|
+ this.syncChatPresence();
|
|
|
+ const state = this._chatPresenceState;
|
|
|
+ if (!state || state.disposed || this.help || !state.admID || state.visitRequest) return;
|
|
|
+ const userData = Cache.get('userData');
|
|
|
+ if (!userData || !userData.userID) return;
|
|
|
+ const admID = state.admID;
|
|
|
+ const request = {};
|
|
|
+ state.visitRequest = request;
|
|
|
let data = {
|
|
|
params: [
|
|
|
{
|
|
|
- admID: patientData.admID || ''
|
|
|
+ admID
|
|
|
}
|
|
|
]
|
|
|
};
|
|
|
@@ -1354,8 +1467,11 @@ export default {
|
|
|
data: data,
|
|
|
namespace: 'Y',
|
|
|
success: function (res) {
|
|
|
+ if (state.disposed || state.admID !== admID || state.visitRequest !== request) return;
|
|
|
if (+res.errorCode === 0) {
|
|
|
const revisitFlag = res.result && res.result.RevisitFlag;
|
|
|
+ const consultID = res.result && res.result.consultID;
|
|
|
+ state.consultID = consultID == null ? '' : String(consultID).trim();
|
|
|
this.setData({
|
|
|
visitRelatedInformation: res.result,
|
|
|
showMedicalRecordAndDiagnosis: !this.fromMessage && revisitFlag !== 0
|
|
|
@@ -1366,6 +1482,10 @@ export default {
|
|
|
showMedicalRecordAndDiagnosis: !this.fromMessage
|
|
|
});
|
|
|
}
|
|
|
+ this.syncChatPresence();
|
|
|
+ },
|
|
|
+ complete: function () {
|
|
|
+ if (state.visitRequest === request) state.visitRequest = null;
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
@@ -1546,6 +1666,7 @@ export default {
|
|
|
success: function (res) {
|
|
|
let errorCode = res.errorCode;
|
|
|
if (errorCode == '0') {
|
|
|
+ this.endChatPresence();
|
|
|
this.setData({
|
|
|
toURL: res.result.toURL
|
|
|
});
|
|
|
@@ -1586,6 +1707,7 @@ export default {
|
|
|
success: function (res) {
|
|
|
let errorCode = res.errorCode;
|
|
|
if (errorCode == '0') {
|
|
|
+ that.endChatPresence();
|
|
|
messageUtil.handleSendMessage('F', '医生已结束问诊,请您评价!');
|
|
|
let pages = getCurrentPages();
|
|
|
let prevPage = pages[pages.length - 2];
|
|
|
@@ -1659,12 +1781,13 @@ export default {
|
|
|
]
|
|
|
};
|
|
|
// 结束服务
|
|
|
- $http.post('urlDeault', this, {
|
|
|
+ $http.post('urlDeault', that, {
|
|
|
code: '03100061',
|
|
|
data: data,
|
|
|
success: function (res) {
|
|
|
let errorCode = res.errorCode;
|
|
|
if (errorCode == '0') {
|
|
|
+ that.endChatPresence();
|
|
|
messageUtil.handleSendMessage('F', '医生已结束问诊,请您评价!');
|
|
|
let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
|
|
|
let prevPage = pages[pages.length - 2];
|
|
|
@@ -2191,13 +2314,20 @@ export default {
|
|
|
|
|
|
this.recorderManager.onStart(() => {
|
|
|
console.log('录音开始');
|
|
|
+ // 用户在授权/初始化期间已经松手时,不再继续录音。
|
|
|
+ if (!that.isPressing) {
|
|
|
+ that.recordCanceled = true;
|
|
|
+ that.recorderManager.stop();
|
|
|
+ return;
|
|
|
+ }
|
|
|
that.setData({ recording: true });
|
|
|
});
|
|
|
|
|
|
this.recorderManager.onStop((res) => {
|
|
|
- that.setData({ recording: false });
|
|
|
+ that.setData({ recording: false, isPressing: false });
|
|
|
if (that.recordCanceled) {
|
|
|
that.recordCanceled = false;
|
|
|
+ that.setData({ recordStatus: 'record' });
|
|
|
return;
|
|
|
}
|
|
|
// 参考 room.vue:用毫秒判断,>= 1000ms(1秒)即可
|
|
|
@@ -2210,7 +2340,7 @@ export default {
|
|
|
|
|
|
this.recorderManager.onError((err) => {
|
|
|
console.error('录音失败:', err);
|
|
|
- that.setData({ recording: false });
|
|
|
+ that.setData({ recording: false, isPressing: false, recordStatus: 'record' });
|
|
|
uni.showToast({ title: '录音失败', icon: 'none' });
|
|
|
});
|
|
|
// #endif
|
|
|
@@ -2242,7 +2372,45 @@ export default {
|
|
|
this.h5StartRecordPromise = null;
|
|
|
}
|
|
|
this._h5RecordingPhase = 'idle';
|
|
|
- this.setData({ recording: false });
|
|
|
+ this._unbindH5VoiceEndListener();
|
|
|
+ this.setData({ recording: false, isPressing: false });
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * H5 中全局承接松手事件。
|
|
|
+ * 录音提示遮罩会在 touchstart 后才渲染,不能依赖按钮/遮罩本身一定收到 touchend;
|
|
|
+ * 使用 capture 阶段监听 document,手指在任意位置松开都能停止当前录音。
|
|
|
+ */
|
|
|
+ _bindH5VoiceEndListener: function () {
|
|
|
+ // #ifdef H5
|
|
|
+ if (this._h5VoiceEndHandler || typeof document === 'undefined') return;
|
|
|
+ const that = this;
|
|
|
+ this._h5VoiceEndHandler = function () {
|
|
|
+ that.stopVoiceRecord();
|
|
|
+ };
|
|
|
+ this._h5VoiceCancelHandler = function () {
|
|
|
+ that.onRecordTouchCancel();
|
|
|
+ };
|
|
|
+ document.addEventListener('touchend', this._h5VoiceEndHandler, true);
|
|
|
+ document.addEventListener('touchcancel', this._h5VoiceCancelHandler, true);
|
|
|
+ // Chrome 设备模拟和带触控笔/鼠标的设备可能只派发 PointerEvent。
|
|
|
+ document.addEventListener('pointerup', this._h5VoiceEndHandler, true);
|
|
|
+ // #endif
|
|
|
+ },
|
|
|
+
|
|
|
+ _unbindH5VoiceEndListener: function () {
|
|
|
+ // #ifdef H5
|
|
|
+ if (typeof document === 'undefined') return;
|
|
|
+ if (this._h5VoiceEndHandler) {
|
|
|
+ document.removeEventListener('touchend', this._h5VoiceEndHandler, true);
|
|
|
+ document.removeEventListener('pointerup', this._h5VoiceEndHandler, true);
|
|
|
+ }
|
|
|
+ if (this._h5VoiceCancelHandler) {
|
|
|
+ document.removeEventListener('touchcancel', this._h5VoiceCancelHandler, true);
|
|
|
+ }
|
|
|
+ this._h5VoiceEndHandler = null;
|
|
|
+ this._h5VoiceCancelHandler = null;
|
|
|
+ // #endif
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -2255,7 +2423,11 @@ export default {
|
|
|
const that = this;
|
|
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
+ // 同一轮按压只允许启动一次;先记录按压状态,避免授权异步完成后误启动。
|
|
|
+ if (that.isPressing || that.recording) return;
|
|
|
+ that.setData({ isPressing: true, recording: false, recordStatus: 'record' });
|
|
|
const startRecording = () => {
|
|
|
+ if (!that.isPressing) return;
|
|
|
try {
|
|
|
that.recordCanceled = false;
|
|
|
// 参考 room.vue:去掉 duration 限制和多余参数,简化配置
|
|
|
@@ -2275,6 +2447,7 @@ export default {
|
|
|
startRecording();
|
|
|
},
|
|
|
fail: () => {
|
|
|
+ that.setData({ isPressing: false, recording: false, recordStatus: 'record' });
|
|
|
uni.showToast({ title: '请授权录音权限', icon: 'none' });
|
|
|
}
|
|
|
});
|
|
|
@@ -2284,15 +2457,17 @@ export default {
|
|
|
// H5 端:wechath5.startRecord() 内部 JSSDK 优先,失败降级 MediaRecorder
|
|
|
console.log('[H5-录音] 开始录音, _recordApiReady:', wechath5._recordApiReady);
|
|
|
|
|
|
- // 防重入:如果上次录音 Promise 未完成,先取消(解决快速连击问题)
|
|
|
- if (that.h5StartRecordPromise) {
|
|
|
- console.warn('[H5-录音] 检测到未完成的录音启动 Promise,先取消');
|
|
|
- that._cancelPendingRecord();
|
|
|
+ // 防重入:启动、录音或停止中的同一轮按压不再重启录音。
|
|
|
+ // 重启会取消首次的麦克风申请,表现为“松开后没有发送”。
|
|
|
+ if (that._h5RecordingPhase !== 'idle') {
|
|
|
+ console.warn('[H5-录音] 当前录音尚未结束,忽略重复的开始事件, phase:', that._h5RecordingPhase);
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
// 标记"启动中",按钮显示按下状态
|
|
|
that._h5RecordingPhase = 'starting';
|
|
|
- that.setData({ recording: true });
|
|
|
+ that.setData({ recording: true, isPressing: true, recordStatus: 'record' });
|
|
|
+ that._bindH5VoiceEndListener();
|
|
|
that.h5StartRecordPromise = wechath5.startRecord();
|
|
|
that.h5StartRecordPromise.then(() => {
|
|
|
console.log('[H5-录音] 录音已开始');
|
|
|
@@ -2303,8 +2478,18 @@ export default {
|
|
|
}).catch((err) => {
|
|
|
console.error('[H5-录音] ❌ 录音启动失败:', err);
|
|
|
that._h5RecordingPhase = 'idle';
|
|
|
- that.setData({ recording: false });
|
|
|
+ that.setData({ recording: false, isPressing: false });
|
|
|
that.h5StartRecordPromise = null;
|
|
|
+ that._unbindH5VoiceEndListener();
|
|
|
+ if (wechath5.isDingTalk && wechath5.isDingTalk()) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '钉钉语音不可用',
|
|
|
+ content: (err && err.message) || '钉钉录音初始化失败,请查看控制台 [DingTalk-录音] 日志。',
|
|
|
+ confirmText: '我知道了',
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (err && (err.showModal || (err.message && err.message.indexOf('权限') !== -1))) {
|
|
|
uni.showModal({
|
|
|
title: '无法使用录音',
|
|
|
@@ -2325,6 +2510,15 @@ export default {
|
|
|
stopVoiceRecord: function () {
|
|
|
const that = this;
|
|
|
// #ifdef MP-WEIXIN
|
|
|
+ // 遮罩和按钮都可能收到 touchend;只处理当前这一轮按压。
|
|
|
+ if (!this.isPressing && !this.recording) return;
|
|
|
+ this.setData({ isPressing: false });
|
|
|
+ if (!this.recording) {
|
|
|
+ // 授权/初始化尚未结束就松手,后续不可发送半截录音。
|
|
|
+ this.recordCanceled = true;
|
|
|
+ this.setData({ recordStatus: 'record' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (this.recorderManager) {
|
|
|
this.recorderManager.stop();
|
|
|
}
|
|
|
@@ -2337,7 +2531,8 @@ export default {
|
|
|
}
|
|
|
// 标记 stopping 防止重复进入
|
|
|
that._h5RecordingPhase = 'stopping';
|
|
|
- that.setData({ recording: false });
|
|
|
+ that._unbindH5VoiceEndListener();
|
|
|
+ that.setData({ recording: false, isPressing: false });
|
|
|
const startPromise = that.h5StartRecordPromise || Promise.resolve();
|
|
|
startPromise.then(() => {
|
|
|
return wechath5.stopRecord();
|
|
|
@@ -2345,7 +2540,24 @@ export default {
|
|
|
that._h5RecordingPhase = 'idle';
|
|
|
that.h5StartRecordPromise = null;
|
|
|
console.log('recordResult:', recordResult);
|
|
|
- if (recordResult.type === 'jssdk') {
|
|
|
+ if (recordResult.type === 'dingtalk') {
|
|
|
+ // 钉钉路径:必须先转存到现有业务文件服务,得到 filePath 后才允许发 IM 消息。
|
|
|
+ console.log('[DingTalk-录音] 开始转存并上传, mediaId:', recordResult.mediaId);
|
|
|
+ that.addAudioLoadingPlaceholder(recordResult.duration);
|
|
|
+ wechath5.uploadDingTalkVoice(recordResult.mediaId, recordResult.duration, 'consult').then((uploadRes) => {
|
|
|
+ console.log('[DingTalk-录音] 业务上传成功, filePath:', uploadRes.filePath);
|
|
|
+ that.handleSendVoice(uploadRes.filePath, recordResult.duration);
|
|
|
+ }).catch((err) => {
|
|
|
+ console.error('[DingTalk-录音] 语音发送前上传失败:', err);
|
|
|
+ that.deleteAudioLoading();
|
|
|
+ uni.showModal({
|
|
|
+ title: '钉钉语音发送失败',
|
|
|
+ content: (err && err.message) || '钉钉录音上传失败,请查看控制台 [DingTalk-录音] 日志。',
|
|
|
+ confirmText: '我知道了',
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ });
|
|
|
+ } else if (recordResult.type === 'jssdk') {
|
|
|
// JSSDK 路径:serverId 已上传微信服务器,直接发送
|
|
|
console.log('[H5-录音] JSSDK 路径, serverId:', recordResult.serverId, 'duration:', recordResult.duration);
|
|
|
// 添加 loading 占位,后续由 handleSendVoice 替换
|
|
|
@@ -2373,7 +2585,16 @@ export default {
|
|
|
if (err && err.message && err.message.indexOf('语音上传') !== -1) {
|
|
|
that.deleteAudioLoading();
|
|
|
}
|
|
|
- uni.showToast({ title: (err && err.message) || '停止录音失败', icon: 'none' });
|
|
|
+ if (wechath5.isDingTalk && wechath5.isDingTalk()) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '钉钉语音失败',
|
|
|
+ content: (err && err.message) || '钉钉停止录音失败,请查看控制台 [DingTalk-录音] 日志。',
|
|
|
+ confirmText: '我知道了',
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ uni.showToast({ title: (err && err.message) || '停止录音失败', icon: 'none' });
|
|
|
+ }
|
|
|
});
|
|
|
// #endif
|
|
|
},
|
|
|
@@ -2407,17 +2628,19 @@ export default {
|
|
|
*/
|
|
|
cancelVoiceRecord: function () {
|
|
|
const that = this;
|
|
|
- // H5 端:用 phase 状态防止竞态,stopping 防重复取消
|
|
|
- if (that._h5RecordingPhase === 'idle' || that._h5RecordingPhase === 'stopping') return;
|
|
|
// #ifdef MP-WEIXIN
|
|
|
- if (!this.recording) return;
|
|
|
+ if (!this.isPressing && !this.recording) return;
|
|
|
this.recordCanceled = true;
|
|
|
+ this.setData({ isPressing: false, recordStatus: 'cancel' });
|
|
|
if (this.recorderManager) {
|
|
|
this.recorderManager.stop();
|
|
|
}
|
|
|
// #endif
|
|
|
// #ifdef H5
|
|
|
+ // H5 端:用 phase 状态防止竞态,stopping 防重复取消
|
|
|
+ if (that._h5RecordingPhase === 'idle' || that._h5RecordingPhase === 'stopping') return;
|
|
|
that._h5RecordingPhase = 'stopping';
|
|
|
+ that._unbindH5VoiceEndListener();
|
|
|
const startPromise = that.h5StartRecordPromise || Promise.resolve();
|
|
|
startPromise.then(() => {
|
|
|
wechath5.cancelRecord();
|
|
|
@@ -2428,7 +2651,7 @@ export default {
|
|
|
});
|
|
|
that.h5StartRecordPromise = null;
|
|
|
// #endif
|
|
|
- this.setData({ recording: false });
|
|
|
+ this.setData({ recording: false, isPressing: false });
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
@@ -2436,11 +2659,20 @@ export default {
|
|
|
*/
|
|
|
uploadVoiceFile: function (filePath, duration) {
|
|
|
const that = this;
|
|
|
+ const userData = Cache.get('userData') || {};
|
|
|
+ const uploadPath = userData.consultFileUpload || that.upLoadUrl || '/uploadFile?fileType=consult';
|
|
|
+ const origin = httpConfig.domain || (typeof window !== 'undefined' && window.location ? window.location.origin : '');
|
|
|
+ const uploadUrl = /^https?:\/\//i.test(uploadPath) ? uploadPath : origin + uploadPath;
|
|
|
+ if (!/^https?:\/\//i.test(uploadUrl)) {
|
|
|
+ console.error('[语音] 上传地址无效:', uploadUrl);
|
|
|
+ uni.showToast({ title: '语音上传地址未配置', icon: 'none' });
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 添加 loading 占位
|
|
|
that.addAudioLoadingPlaceholder(duration);
|
|
|
|
|
|
uni.uploadFile({
|
|
|
- url: that.upLoadUrl,
|
|
|
+ url: uploadUrl,
|
|
|
filePath: filePath,
|
|
|
name: 'file',
|
|
|
success: (res) => {
|
|
|
@@ -2457,7 +2689,8 @@ export default {
|
|
|
uni.showToast({ title: '语音发送失败', icon: 'none' });
|
|
|
}
|
|
|
},
|
|
|
- fail: () => {
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('[语音] 文件上传失败:', err);
|
|
|
that.deleteAudioLoading();
|
|
|
uni.showToast({ title: '语音上传失败', icon: 'none' });
|
|
|
}
|
|
|
@@ -2566,7 +2799,7 @@ export default {
|
|
|
uni.showToast({ title: res.errorMessage || '发送失败', icon: 'none' });
|
|
|
}
|
|
|
},
|
|
|
- error: function (err) {
|
|
|
+ fail: function (err) {
|
|
|
console.error('[语音] ❌ 请求失败:', err);
|
|
|
that.deleteAudioLoading();
|
|
|
uni.showToast({ title: '网络异常', icon: 'none' });
|
|
|
@@ -2603,9 +2836,15 @@ export default {
|
|
|
* 删除音频 loading 占位
|
|
|
*/
|
|
|
deleteAudioLoading: function () {
|
|
|
- if (this.messageList && this.messageList.length > 1) {
|
|
|
+ if (this.messageList && this.messageList.length) {
|
|
|
this.setData({
|
|
|
- messageList: this.replaceAudioLoading([...this.messageList], {})
|
|
|
+ // 只清理最后一个语音发送占位,避免并发新消息被误删。
|
|
|
+ messageList: [...this.messageList].filter(function (item, index, arr) {
|
|
|
+ const isLastAudioLoading = item.soundLoading && !arr.slice(index + 1).some(function (next) {
|
|
|
+ return next.soundLoading;
|
|
|
+ });
|
|
|
+ return !isLastAudioLoading;
|
|
|
+ })
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
@@ -3869,6 +4108,28 @@ page {
|
|
|
touch-action: manipulation;
|
|
|
}
|
|
|
|
|
|
+/* 录音期间覆盖全屏,保证手指离开按钮后仍能捕获松开/取消事件。 */
|
|
|
+.voice-record-mask {
|
|
|
+ position: fixed;
|
|
|
+ z-index: 10001;
|
|
|
+ top: 0;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ left: 0;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ background: rgba(0, 0, 0, 0.08);
|
|
|
+}
|
|
|
+
|
|
|
+.voice-record-hint {
|
|
|
+ padding: 26rpx 36rpx;
|
|
|
+ border-radius: 16rpx;
|
|
|
+ background: rgba(0, 0, 0, 0.72);
|
|
|
+ color: #fff;
|
|
|
+ font-size: 30rpx;
|
|
|
+}
|
|
|
+
|
|
|
.treatment-graphic .voice-record-area {
|
|
|
height: 72rpx;
|
|
|
line-height: 72rpx;
|