diff --git a/tra-app/.env.development b/tra-app/.env.development
index 9a63819..f235ef7 100644
--- a/tra-app/.env.development
+++ b/tra-app/.env.development
@@ -5,21 +5,17 @@ ENV = 'development'
# VITE_APP_BASE_API_Url = 'https://aits.jlbank.com.cn:7001'
-VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
-
-
+VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7001'
# VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
-
-
# VITE_APP_BASE_API_Url = 'http://192.168.247.200'
# VITE_APP_BASE_API_Url = 'http://aitscdn.jlbank.com.cn:7001'
# VITE_APP_BASE_API_Url = 'http://192.168.108.129'
# dev
-# VITE_APP_BASE_API_Url = 'http://25.18.122.65:7001'
+#VITE_APP_BASE_API_Url = 'http://25.18.122.65:7001'
# sit
-# VITE_APP_BASE_API_Url = 'http://25.18.122.91:9786'
+#VITE_APP_BASE_API_Url = 'http://25.18.122.91:9786'
# UAT
# VITE_APP_BASE_API_Url = 'http://25.18.122.78:9786'
@@ -34,6 +30,6 @@ VITE_APP_BASE_API_Url = 'https://aitstest.jlbank.com.cn:7002'
# h5专用地址x2
# VITE_APP_BASE_H5_API_Url_TRAAPP = 'http://25.64.32.150:9601'
# dev
-#VITE_APP_BASE_H5_API_Url = 'http://25.18.122.65:7001'
+# VITE_APP_BASE_H5_API_Url = 'http://25.18.122.65:7001'
# sit
-# VITE_APP_BASE_H5_API_Url = 'http://25.18.122.91:9786'
\ No newline at end of file
+#VITE_APP_BASE_H5_API_Url = 'http://25.18.122.91:9786'
\ No newline at end of file
diff --git a/tra-app/.env.development.yh b/tra-app/.env.development.yh
index c56d90f..193ce29 100644
--- a/tra-app/.env.development.yh
+++ b/tra-app/.env.development.yh
@@ -11,4 +11,5 @@ VITE_APP_BASE_H5_API_Url = 'http://25.18.122.91:9786'
# VITE_APP_BASE_H5_API_Url_TRAPRACTICE = 'http://25.64.32.156:9603'
# VITE_APP_BASE_H5_API_Url_TRAAPP = 'http://25.64.32.154:9601'
# VITE_APP_BASE_H5_API_Url_TRAAPP = 'http://25.64.32.158:9601'
+# VITE_APP_BASE_H5_API_Url_TRASTUDY = 'http://25.64.32.154:9602'
diff --git a/tra-app/package.json b/tra-app/package.json
index b9725b1..b0df4ff 100644
--- a/tra-app/package.json
+++ b/tra-app/package.json
@@ -42,7 +42,8 @@
"terser": "^5.42.0",
"uuid": "^11.1.0",
"vue": "^3.5.11",
- "vue-i18n": "^9.1.9"
+ "vue-i18n": "^9.1.9",
+ "text-encoding": "^0.7.0"
},
"devDependencies": {
"@dcloudio/types": "^3.4.8",
diff --git a/tra-app/src/components/cached-avatar/cached-avatar.vue b/tra-app/src/components/cached-avatar/cached-avatar.vue
index ff1a20b..cc2475d 100644
--- a/tra-app/src/components/cached-avatar/cached-avatar.vue
+++ b/tra-app/src/components/cached-avatar/cached-avatar.vue
@@ -8,7 +8,7 @@
import { ref, reactive, watch, onMounted } from 'vue';
import { defaultAvatar } from '@/enum.js';
import { getUserInfo } from '@/common/common';
-
+
const imagePath = ref('');
const imageAddr = ref('');
diff --git a/tra-app/src/components/image-preview/preview-detail.vue b/tra-app/src/components/image-preview/preview-detail.vue
index 80ea81a..5b369f4 100644
--- a/tra-app/src/components/image-preview/preview-detail.vue
+++ b/tra-app/src/components/image-preview/preview-detail.vue
@@ -22,6 +22,7 @@
import { useStorageStore } from "@/store/storage.js"
import { get_base_url } from '@/api/request.js'
import imagePreviewVue from './image-preview.vue'
+ import { getToken } from '@/common/common.js'
export default {
name:"video-preview",
components:{imagePreviewVue},
@@ -74,11 +75,11 @@
handler(newval, oldval) {
if(this.fileType === 'image'){
if (newval.indexOf('/') === 0) {
- this.fileUrlShow = this.base_url + newval;
+ this.fileUrlShow = this.base_url + newval + '?tk=' + getToken();
return;
}
if (newval.indexOf('http') === 0) {
- this.fileUrlShow = newval;
+ this.fileUrlShow = newval + '?tk=' + getToken();
return;
}
if (newval && this.watching) {
@@ -87,7 +88,7 @@
}
if(this.fileType === 'video'){
if(newval.indexOf('http') === 0){
- this.fileUrlShow = newval
+ this.fileUrlShow = newval + '?tk=' + getToken()
}else{
if (newval && this.watching) {
this.getPreviewUrlBlob(newval);
@@ -102,9 +103,9 @@
src: {
handler(newval, oldval) {
if(newval.indexOf('http') === 0){
- this.fileUrlShow = newval
+ this.fileUrlShow = newval + '?tk=' + getToken()
}else{
- this.fileUrlShow = this.base_url + newval
+ this.fileUrlShow = this.base_url + newval + '?tk=' + getToken()
}
},
immediate: true,
@@ -132,7 +133,7 @@
return;
}
previewCacheThumbImage(id, this.width, this.height).then((res) => {
- this.fileUrlShow = res;
+ this.fileUrlShow = res + '?tk=' + getToken();
this.storageStore.setStorage('image', `/${id}/${this.width}/${this.height}`, res);
});
} else {
@@ -183,7 +184,7 @@
if (this.fileId) {
let _newDate = new Date().getTime()
if(this.fileId.indexOf('http') === 0){
- this.fileUrlShow = this.fileId + '?t=' + _newDate
+ this.fileUrlShow = this.fileId + '?tk=' + getToken() + '&t=' + _newDate
}else{
this.getPreviewUrlBlob(this.fileId);
}
@@ -213,7 +214,7 @@
return
}
let _newDate = new Date().getTime()
- this.fileUrlShow = getPreviewFileUrl(this.fileId)+'?t=' + _newDate
+ this.fileUrlShow = getPreviewFileUrl(this.fileId) + '?tk=' + getToken() + '&t=' + _newDate
// downloadFile(id).then(res=>{
// this.fileUrlShow = res.tempFilePath
// this.storageStore.setStorage('video', id, this.fileUrlShow)
@@ -222,7 +223,7 @@
getPreviewFileUrlNow(id){
let _newDate = new Date().getTime()
if(id.indexOf('http') === 0){
- this.fileUrlShow = id + '?t=' + _newDate
+ this.fileUrlShow = id + '?tk=' + getToken() + '&t=' + _newDate
return
}
if (id && this.watching) {
diff --git a/tra-app/src/components/image-preview/video-preview.vue b/tra-app/src/components/image-preview/video-preview.vue
index bfd3d5d..290596b 100644
--- a/tra-app/src/components/image-preview/video-preview.vue
+++ b/tra-app/src/components/image-preview/video-preview.vue
@@ -31,6 +31,7 @@
import { useStorageStore } from "@/store/storage.js"
import { get_base_url } from '@/api/request.js'
import imagePreviewVue from './image-preview.vue'
+ import { getToken } from '@/common/common.js'
export default {
name:"video-preview",
components:{ imagePreviewVue },
@@ -75,7 +76,7 @@
fileId: {
handler(newval, oldval) {
if(newval.indexOf('http') === 0){
- this.fileUrlShow = newval
+ this.fileUrlShow = newval + '?tk=' + getToken()
}else{
if (newval && this.watching) {
this.getPreviewUrlBlob(newval);
@@ -129,7 +130,7 @@
return
}
let _newDate = new Date().getTime()
- this.fileUrlShow = getPreviewFileUrl(this.fileId)+'?t=' + _newDate
+ this.fileUrlShow = getPreviewFileUrl(this.fileId) + '?tk=' + getToken() + '&t=' + _newDate
// downloadFile(id).then(res=>{
// this.fileUrlShow = res.tempFilePath
// this.storageStore.setStorage('video', id, this.fileUrlShow)
@@ -150,7 +151,7 @@
if (this.fileId) {
let _newDate = new Date().getTime()
if(this.fileId.indexOf('http') === 0){
- this.fileUrlShow = this.fileId + '?t=' + _newDate
+ this.fileUrlShow = this.fileId + '?tk=' + getToken() + '&t=' + _newDate
}else{
this.getPreviewUrlBlob(this.fileId);
}
diff --git a/tra-app/src/components/points-and-badge/check-in.vue b/tra-app/src/components/points-and-badge/check-in.vue
index 3596321..f1a6a7b 100644
--- a/tra-app/src/components/points-and-badge/check-in.vue
+++ b/tra-app/src/components/points-and-badge/check-in.vue
@@ -138,8 +138,11 @@
},
failCb: (res) => {
checkInLoading.value = false;
- console.log('签到失败', res);
- common.msg('签到失败,请稍后再试');
+ if (res.data.rtnCode === '0002') {
+ common.msg(res.data.message);
+ } else {
+ common.msg('签到失败,请稍后再试');
+ }
}
});
};
diff --git a/tra-app/src/components/points-and-badge/usePointsAndBadge.js b/tra-app/src/components/points-and-badge/usePointsAndBadge.js
index a702c17..4e4bb02 100644
--- a/tra-app/src/components/points-and-badge/usePointsAndBadge.js
+++ b/tra-app/src/components/points-and-badge/usePointsAndBadge.js
@@ -34,88 +34,118 @@ export default function usePointsAndBadge() {
* @param {any} res - 接口返回数据
*/
const handlePointsBadgePopup = (points, pointsBadges, complete = () => {}, res = {}) => {
- // AI问答仅弹徽章弹窗
- if (points?.length > 0) {
- // 普通场景:先弹积分弹窗,再弹徽章弹窗
- pointsRef.value?.open(points, pointsBadges, (status, pointsList, badgesList) => {
- pointsRef.value.close();
- // 有徽章则弹徽章弹窗,否则直接完成
- if (badgesList?.length > 0) {
- nextTick(() => {
- setTimeout(() => {
- badgeRef.value.open(pointsList, badgesList, () => {
- badgeRef.value.close();
- complete(true, '积分获取成功', res);
+ // AI问答仅弹徽章弹窗
+ if (points?.length > 0) {
+ // 普通场景:先弹积分弹窗,再弹徽章弹窗
+ pointsRef.value?.open(points, pointsBadges, (status, pointsList, badgesList) => {
+ pointsRef.value.close();
+ if(pointsList.length > 0) {
+ setTimeout(() => {
+ pointsRef.value?.open(pointsList, badgesList, (status, pointsList,
+ badgesList) => {
+ pointsRef.value.close();
+ // 有徽章则弹徽章弹窗,否则直接完成
+ if (badgesList?.length > 0) {
+ nextTick(() => {
+ setTimeout(() => {
+ badgeRef.value.open(pointsList,
+ badgesList, () => {
+ badgeRef.value.close();
+ complete(true, '积分获取成功',
+ res);
+ });
+ }, pop_up_time);
});
- }, pop_up_time);
+ } else {
+ complete(true, '积分获取成功', res);
+ }
});
- } else {
- complete(true, '积分获取成功', res);
- }
- });
- } else if (pointsBadges?.length > 0) {
- badgeRef.value.open([], pointsBadges, () => {
- badgeRef.value.close();
+ }, 300)
+ } else if (badgesList?.length > 0) {
+ // 有徽章则弹徽章弹窗,否则直接完成
+ nextTick(() => {
+ setTimeout(() => {
+ badgeRef.value.open(pointsList, badgesList, () => {
+ badgeRef.value.close();
+ complete(true, '积分获取成功', res);
+ });
+ }, pop_up_time);
+ });
+ } else {
complete(true, '积分获取成功', res);
- });
- }else{
+ }
+ });
+ } else if (pointsBadges?.length > 0) {
+ badgeRef.value.open([], pointsBadges, () => {
+ badgeRef.value.close();
+ complete(true, '积分获取成功', res);
+ });
+ } else {
+ complete(false, '积分接口返回数据异常', res);
+ }
+ };
+
+ /**
+ * 积分和徽章处理主方法
+ * @param {string} type - 任务类型(04:课程练习,06:AI问答,其他:普通任务)
+ * @param {string|null} taskId - 任务ID
+ * @param {Function} complete - 完成回调(status, message, data)
+ */
+ const pointAndBadgesRun = async (type, taskId = '', complete = () => {}) => {
+
+ try {
+ console.log('调用积分接口');
+ const res = await addPointsByTask({
+ type,
+ taskId
+ });
+
+ // 防御性处理:确保res.body存在
+ if (!res?.body) {
complete(false, '积分接口返回数据异常', res);
+ return;
}
- };
-
- /**
- * 积分和徽章处理主方法
- * @param {string} type - 任务类型(04:课程练习,06:AI问答,其他:普通任务)
- * @param {string|null} taskId - 任务ID
- * @param {Function} complete - 完成回调(status, message, data)
- */
- const pointAndBadgesRun = async (type, taskId = '', complete = () => {}) => {
-
- try {
- console.log('调用积分接口');
- const res = await addPointsByTask({
- type,
- taskId
- });
-
- // 防御性处理:确保res.body存在
- if (!res?.body) {
- complete(false, '积分接口返回数据异常', res);
+ const {
+ points,
+ pointsBadges,
+ message = ''
+ } = res.body;
+ // const points = [{
+ // "changePoints": 1,
+ // "message": '学习时长累计1小时'
+ // },
+ // {
+ // "changePoints": 10,
+ // "message": '完成课程学习'
+ // }
+ // ]
+ // 分支逻辑:按类型处理
+ switch (type) {
+ case '04': // 04:课程练习,自定义返回逻辑,不弹弹窗
+ complete(true, '', res.body); // 补充回调,避免调用方等待
return;
- }
- const {
- points,
- pointsBadges,
- message = ''
- } = res.body;
-
- // 分支逻辑:按类型处理
- switch (type) {
- case '04': // 04:课程练习,自定义返回逻辑,不弹弹窗
- complete(true, '', res.body); // 补充回调,避免调用方等待
- return;
- case '06': // 06:AI问答,仅弹徽章弹窗
- if (pointsBadges?.length > 0) {
- handlePointsBadgePopup(points, pointsBadges, complete, res);
- } else {
- complete(true, '', res);
- }
- return;
- // 其他类型:弹积分+徽章弹窗
- default:
+ case '06': // 06:AI问答,仅弹徽章弹窗
+ if (pointsBadges?.length > 0) {
handlePointsBadgePopup(points, pointsBadges, complete, res);
- return;
- }
- } catch (error) {
- // 细化错误信息:区分网络错误/接口错误
- const errorMsg = error?.message || '积分获取失败';
- complete(false, `积分获取失败:${errorMsg}`, error);
+ } else {
+ complete(true, '', res);
+ }
+ return;
+ // 其他类型:弹积分+徽章弹窗
+ default:
+ handlePointsBadgePopup(points, pointsBadges, complete, res);
+ return;
}
- };
- return {
- pointAndBadgesRun,
- handlePointsBadgePopup,
- badgeRef,
- pointsRef
- };
- }
\ No newline at end of file
+ } catch (error) {
+ // 细化错误信息:区分网络错误/接口错误
+ const errorMsg = error?.message || '积分获取失败';
+ complete(false, `积分获取失败:${errorMsg}`, error);
+ }
+ };
+ return {
+ pointAndBadgesRun,
+ handlePointsBadgePopup,
+ badgeRef,
+ pointsRef
+ };
+}
\ No newline at end of file
diff --git a/tra-app/src/pages.json b/tra-app/src/pages.json
index 62ee516..68ecbeb 100644
--- a/tra-app/src/pages.json
+++ b/tra-app/src/pages.json
@@ -516,6 +516,7 @@
"path": "pages/sparring/talk",
"style": {
"navigationBarTitleText": "AI陪练通话",
+ "disableSwipeBack": true,
"app-plus": {
"titleNView": false
}
diff --git a/tra-app/src/pages/analytics/study.vue b/tra-app/src/pages/analytics/study.vue
index 9c52ab1..42a3cf6 100644
--- a/tra-app/src/pages/analytics/study.vue
+++ b/tra-app/src/pages/analytics/study.vue
@@ -6,7 +6,11 @@
-
+
+
+
- {{statisticsObj.completeTaskCnt }}
+ {{statisticsObj.completeTaskCnt }}
@@ -61,7 +65,7 @@
完成考试数
- {{statisticsObj.completedExamCnt }}
+ {{statisticsObj.completedExamCnt }}
@@ -70,7 +74,7 @@
考试及格率
- {{statisticsObj.passExamRate }}
+ {{statisticsObj.passExamRate }}
%
@@ -104,7 +108,7 @@
-
+
@@ -113,7 +117,7 @@
-
+
@@ -122,7 +126,7 @@
-
+
@@ -130,7 +134,7 @@
-
+
@@ -186,15 +190,15 @@
})
const calendarRef = ref()
const statisticsObj = ref({
- crsStdyTmLen: 0,
- completeTaskCnt: 0,
- completedExamCnt: 0,
- passExamRate: 0,
- partnerCnt: 0,
- askCnt: 0,
- completeCrsCnt: 0,
- crsCompleteRate: 0,
- partnerRate: 0
+ crsStdyTmLen: 0,
+ completeTaskCnt: 0,
+ completedExamCnt: 0,
+ passExamRate: 0,
+ partnerCnt: 0,
+ askCnt: 0,
+ completeCrsCnt: 0,
+ crsCompleteRate: 0,
+ partnerRate: 0
})
const dimesionList = ref([])
const studyList = ref([])
@@ -225,17 +229,20 @@
loading.value = true
try {
let _res1 = await queryStudyStatistics(params)
- statisticsObj.value = {..._res1.body}
+ statisticsObj.value = {
+ ..._res1.body
+ }
let _res2 = await queryDimesionInfo(params)
dimesionList.value = [..._res2.body]
let _res3 = await queryHabitInfo(params)
studyList.value = [..._res3.body]
let _res4 = await querySuggestInfo(params)
- if(_res4.body && _res4.body.length > 0){
- suggestObj.value = {..._res4.body[0]}
+ if (_res4.body && _res4.body.length > 0) {
+ suggestObj.value = {
+ ..._res4.body[0]
+ }
}
- } catch {
- } finally{
+ } catch {} finally {
loading.value = false
}
}
@@ -246,9 +253,9 @@
const changeTab = (info) => {
activeTabVal.value = info.value
if (info.value === '04') {
- dateinputRef.value&&dateinputRef.value?.clear()
+ dateinputRef.value && dateinputRef.value?.clear()
daterange.value = ['', '']
- }else{
+ } else {
getInfoNow({
dateType: activeTabVal.value
})
@@ -308,6 +315,11 @@
// position: fixed;
// float: left;
// margin-top: var(--status-bar-height);
+ background-image: url(@/static/images/analytics/title.png);
+ background-repeat: no-repeat;
+ background-position: 26rpx 125rpx;
+ background-size: 277rpx 135rpx;
+
.top-title {
height: 90rpx;
@@ -363,6 +375,33 @@
position: relative;
margin-bottom: 24rpx;
backdrop-filter: blur(10rpx);
+ z-index: 1;
+
+ &.loading-box-cont{
+ background: #ddeafa;
+ &::before {
+ content: '';
+ display: block;
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ border-radius: 15rpx;
+ z-index: 2;
+ // #ddeafa
+ background: url(@/static/images/analytics/bg2.png) no-repeat;
+ background-size: cover;
+ background-position: center;
+ backdrop-filter: blur(10rpx);
+ }
+ }
+
+ .loading-box {
+ position: absolute;
+ z-index: 3;
+ top: 120rpx;
+ left: 50%;
+ transform: translateX(-50%);
+ }
.calendar-box {
position: absolute;
@@ -385,6 +424,7 @@
padding-bottom: 20rpx;
width: 100%;
overflow: hidden;
+ position: relative;
.analytics-item {
padding-bottom: 12rpx;
@@ -405,6 +445,7 @@
&-value {
font-size: 54rpx;
font-weight: 600;
+
&-v {
font-family: DINAlternate, DINAlternate;
}
@@ -428,13 +469,15 @@
margin-bottom: 24rpx;
position: relative;
min-height: 200rpx;
- .loading-box{
+
+ .loading-box {
position: absolute;
top: 120rpx;
left: 50%;
transform: translateX(-50%);
}
- &::before{
+
+ &::before {
content: '';
display: block;
position: absolute;
@@ -445,26 +488,27 @@
top: -12rpx;
background-size: cover;
}
+
&.dens {
- &::before{
+ &::before {
background-image: url(@/static/images/analytics/weidu-1.png);
}
}
&.study {
- &::before{
+ &::before {
background-image: url(@/static/images/analytics/study1-1.png)
}
}
&.study1 {
- &::before{
+ &::before {
background-image: url(@/static/images/analytics/study-1.png);
}
}
&.course {
- &::before{
+ &::before {
background-image: url(@/static/images/analytics/course-1.png);
}
}
@@ -524,11 +568,13 @@
background-repeat: no-repeat;
background-size: 100% 100%;
}
- &.study2-tip{
+
+ &.study2-tip {
&::before {
background-image: url(@/static/images/analytics/den-tips2.png);
}
}
+
&.bg-tm {
padding-left: 54rpx;
background-image: url(@/static/images/analytics/time-icon.png);
diff --git a/tra-app/src/pages/competition/result.vue b/tra-app/src/pages/competition/result.vue
index d607719..ec763a0 100644
--- a/tra-app/src/pages/competition/result.vue
+++ b/tra-app/src/pages/competition/result.vue
@@ -1,5 +1,6 @@
+
diff --git a/tra-app/src/pages/index/preview.vue b/tra-app/src/pages/index/preview.vue
index ff9740b..94ed038 100644
--- a/tra-app/src/pages/index/preview.vue
+++ b/tra-app/src/pages/index/preview.vue
@@ -41,7 +41,7 @@ export default {
this.fileApiSrc = params.fileApiSrc
}
const userInfo = getUserInfo();
- this.userParams = '/' + (userInfo?.loginName??'')
+ this.userParams = '/' + (userInfo?.loginName??'') + '?tk=' + getToken()
},
onShow() {
if (getPhoneEnvBool('AND')) {
@@ -84,8 +84,8 @@ export default {
const base_url = get_base_url(this.fileApiSrc)
let _id = data?.fileId
let fileUrl = base_url + this.fileApiSrc + _id + this.userParams
- this.showUrl = this.viewerUrl + '?url=' + fileUrl
- console.log(this.showUrl)
+ this.showUrl = this.viewerUrl + '?url=' + encodeURIComponent(fileUrl)
+ console.log(this.showUrl)
this.showView = true
}
}
diff --git a/tra-app/src/pages/pointsAndRank/points.vue b/tra-app/src/pages/pointsAndRank/points.vue
index ece5258..cbdd02e 100644
--- a/tra-app/src/pages/pointsAndRank/points.vue
+++ b/tra-app/src/pages/pointsAndRank/points.vue
@@ -38,8 +38,8 @@
积分变化
-
- {{ item.mattrDesc }}
+
+ {{ item.mattrDesc }}
{{ item.ctTime.substr(0, 16) }}
@@ -172,7 +172,7 @@
flex: 1;
}
.time {
- min-width: max(150rpx, 42%);
+ min-width: max(146rpx, 40%);
}
.value {
text-align: right;
@@ -189,18 +189,20 @@
justify-content: space-between;
padding: 40rpx 38rpx 40rpx 26rpx;
.title {
+ margin-right: 10rpx;
font-weight: 700;
font-size: 30rpx;
color: #333333;
flex: 1;
text-align: left;
+ white-space: wrap;
}
.time {
font-family: ArialMT;
font-size: 30rpx;
color: #000000;
text-align: left;
- min-width: max(150rpx, 42%);
+ min-width: max(146rpx, 40%);
}
.value {
font-family: Arial, Arial;
diff --git a/tra-app/src/pages/sparring/components/talk-microphone.vue b/tra-app/src/pages/sparring/components/talk-microphone.vue
new file mode 100644
index 0000000..735be30
--- /dev/null
+++ b/tra-app/src/pages/sparring/components/talk-microphone.vue
@@ -0,0 +1,358 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/tra-app/src/pages/sparring/components/talk-speaker.vue b/tra-app/src/pages/sparring/components/talk-speaker.vue
new file mode 100644
index 0000000..ed364e3
--- /dev/null
+++ b/tra-app/src/pages/sparring/components/talk-speaker.vue
@@ -0,0 +1,99 @@
+
+
+
+
+
+
+
+
diff --git a/tra-app/src/pages/sparring/index.vue b/tra-app/src/pages/sparring/index.vue
index 8f30784..d620118 100644
--- a/tra-app/src/pages/sparring/index.vue
+++ b/tra-app/src/pages/sparring/index.vue
@@ -384,16 +384,16 @@
currentTabSec.value = 0
activeTabId.value = ''
activeTabSecId.value = ''
- queryTraPartnerCatelogList().then(res => {
- catelogList.value = res.body || []
- })
- getTraTagListApi().then(res => {
- tagsTree.value = res.body || []
- })
- changeTab({
- name: '全部',
- value: ''
- })
+ // queryTraPartnerCatelogList().then(res => {
+ // catelogList.value = res.body || []
+ // })
+ // getTraTagListApi().then(res => {
+ // tagsTree.value = res.body || []
+ // })
+ // changeTab({
+ // name: '全部',
+ // value: ''
+ // })
uni.$on('refresh_sparring_list', () => {
changeTab({
name: activeTab.value || '全部',
@@ -415,13 +415,13 @@
activeTabId.value = ''
activeTabSecId.value = ''
// 重新获取标签信息
- getTraTagListApi().then(res => {
- tagsTree.value = res.body || []
- })
- changeTab({
- name: '全部',
- value: ''
- })
+ // getTraTagListApi().then(res => {
+ // tagsTree.value = res.body || []
+ // })
+ // changeTab({
+ // name: '全部',
+ // value: ''
+ // })
})
onShow(() => {
console.log('onShow')
diff --git a/tra-app/src/pages/sparring/js/ProtocolCodec.ts b/tra-app/src/pages/sparring/js/ProtocolCodec.ts
new file mode 100644
index 0000000..3beeeb5
--- /dev/null
+++ b/tra-app/src/pages/sparring/js/ProtocolCodec.ts
@@ -0,0 +1,365 @@
+// 导入 GZIP 处理库(浏览器/Node.js 通用,需提前安装:npm install pako @types/pako)
+// import * as pako from "pako";
+import { TextDecoder } from 'text-encoding';
+/**
+ * 协议常量类:存储协议核心配置(不可修改,确保前后端一致)
+ */
+export class ProtocolConst {
+ /** 协议版本:0~15(4位,存储在字节0低4位) */
+ static readonly PROTOCOL_VERSION = 0b0001;
+
+ /** 头部固定长度:8字节(字节0~7,结构严格定义,不可修改) */
+ static readonly HEADER_SIZE = 8;
+
+ /**
+ * 最大包体大小:16MB(3字节长度最大支持0xFFFFFF=16777215字节≈16MB)
+ * 4-6字节存储(24位),最大支持16MB,满足大部分场景且避免长度字段冗余
+ */
+ static readonly MAX_BODY_SIZE = 0xFFFFFF; // 16777215字节 ≈16MB
+
+ /** 字符串编码格式:UTF-8(统一前后端字符串编解码,避免乱码) */
+ static readonly STRING_ENCODING = "utf-8" as const;
+}
+
+/**
+ * 消息类型枚举(4位,存储在字节0高4位,0~15范围)
+ * 二进制标识,统一编码风格
+ */
+export enum MessageType {
+ PING = 0b0001, // 心跳消息(支持空包体)
+ AUDIO_DATA = 0b0010, // 纯音频数据
+ TEXT_MESSAGE = 0b0011, // 纯文本消息
+ CONTROL_CMD = 0b0100, // 控制指令
+ IDENTITY = 0b0101, // 身份校验包json格式
+ ERROR = 0b0110 // 错误信息json格式
+ // 预留12种类型用于扩展(0b0100 ~ 0b1111)
+}
+
+/**
+ * 序列化方式枚举(3位,存储在字节1高3位,1~8范围)
+ * 二进制标识,统一编码风格(1~8对应0b001~0b111)
+ */
+export enum SerializationType {
+ RAW = 0b001, // 原始二进制(1)
+ JSON = 0b010, // JSON 格式(2)
+ STRING = 0b011, // 直接字符串(3)
+ // 预留5种方式用于扩展(0b100 ~ 0b111)
+}
+
+/**
+ * 压缩方式枚举(3位,存储在字节1中3位,1~8范围)
+ * 二进制标识,统一编码风格(1~8对应0b001~0b111)
+ */
+export enum CompressionType {
+ NONE = 0b001, // 无压缩(1,默认值)
+ GZIP = 0b010, // GZIP 压缩(2)
+ // 预留6种方式用于扩展(0b011 ~ 0b111)
+}
+
+/**
+ * 控制指令枚举(配合 MessageType.CONTROL_CMD 使用)
+ */
+export enum ControlCommand {
+ HEARTBEAT = 0b0001,
+ PAUSE = 0b0010,
+ RESUME = 0b0011,
+ STOP = 0b0100,
+}
+
+/**
+ * 解包返回结果接口
+ */
+export interface UnpackedResult {
+ msgType : MessageType;
+ msgTypeName : keyof typeof MessageType;
+ serialization : SerializationType;
+ serializationName : keyof typeof SerializationType;
+ compression : CompressionType;
+ compressionName : keyof typeof CompressionType;
+ sequence : number; // 消息顺序号(0~65535,默认0)
+ body : Uint8Array | string | object | unknown[] | null; // PING 消息可能返回 null
+}
+
+/**
+ * 打包入参类型别名(支持 PING 消息传入 null)
+ */
+type PackBody = Uint8Array | string | object | unknown[] | null;
+type OptionalSerialization = SerializationType | null | undefined;
+
+/**
+ * 协议编解码工具类(支持 PING 消息空包体)
+ */
+export class ProtocolCodec {
+ /**
+ * 打包协议包
+ * @param msgType 消息类型(二进制枚举,0~15)
+ * @param body 业务数据(PING 消息可传 null/undefined,其他类型必填)
+ * @param sequence 消息顺序号(0~65535,可选,默认0)
+ * @param serialization 序列化方式(二进制枚举,1~8,可选,自动推导)
+ * @param compression 压缩方式(二进制枚举,1~8,可选,默认NONE=0b001)
+ * @returns 完整协议包
+ * @throws 类型错误、范围错误、包体过大等异常
+ */
+ static pack(
+ msgType : MessageType,
+ body : PackBody = null, // 默认为 null,支持 PING 消息空包体
+ sequence : number = 0, // 可选参数,默认0
+ serialization : OptionalSerialization = null,
+ compression : CompressionType = CompressionType.NONE
+ ) : Uint8Array {
+ // 校验顺序号范围(0~65535)
+ if (!Number.isInteger(sequence) || sequence < 0 || sequence > 0xFFFF) {
+ throw new RangeError(`消息顺序号必须是0~65535的整数,当前传入:${sequence}`);
+ }
+
+ // 特殊处理:PING 消息允许空包体,强制 RAW 序列化(空二进制)
+ if (msgType === MessageType.PING) {
+ // PING 消息忽略传入的序列化方式,强制使用 RAW(空二进制最高效)
+ serialization = SerializationType.RAW;
+ // 若传入空包体,统一处理为空 Uint8Array
+ // body = body === null || body === undefined ? new Uint8Array(0) : body;
+ // PING 消息仅支持空包体或 Uint8Array(防止误传其他类型)
+ if (!(body instanceof Uint8Array)) {
+ throw new TypeError(`PING 消息仅支持空包体或 Uint8Array 类型,当前传入:${typeof body}`);
+ }
+ } else {
+ // 非 PING 消息:包体必填
+ if (body === null || body === undefined) {
+ throw new TypeError(`非 PING 消息(${MessageType[msgType]})包体不能为空`);
+ }
+ }
+
+ // 1. 自动推导序列化方式(非 PING 消息)
+ if (serialization === null || serialization === undefined && msgType !== MessageType.PING) {
+ if (msgType === MessageType.AUDIO_DATA) {
+ serialization = SerializationType.RAW;
+ } else if (msgType === MessageType.TEXT_MESSAGE) {
+ serialization = SerializationType.STRING;
+ } else if (msgType === MessageType.CONTROL_CMD) {
+ serialization = SerializationType.JSON;
+ } else if (msgType === MessageType.IDENTITY) {
+ serialization = SerializationType.JSON;
+ } else if (msgType === MessageType.ERROR) {
+ serialization = SerializationType.JSON;
+ } else {
+ throw new Error(`不支持的消息类型:${MessageType[msgType]}(值:${msgType})`);
+ }
+ }
+
+ // 2. 校验枚举值范围(3位存储,1~8即0b001~0b111)
+ if (serialization < 0b001 || serialization > 0b111) {
+ throw new RangeError(`序列化方式必须在1~8(0b001~0b111)范围内,当前传入:${serialization}(0b${serialization.toString(2).padStart(3, '0')})`);
+ }
+ if (compression < 0b001 || compression > 0b111) {
+ throw new RangeError(`压缩方式必须在1~8(0b001~0b111)范围内,当前传入:${compression}(0b${compression.toString(2).padStart(3, '0')})`);
+ }
+
+ // 3. 序列化包体
+ let serializedBody : Uint8Array;
+ const textEncoder = new TextEncoder();
+
+ switch (serialization) {
+ case SerializationType.RAW:
+ // RAW 序列化:支持 Uint8Array(PING 消息可能是空 Uint8Array)
+ // if (!(body instanceof Uint8Array)) {
+ // throw new TypeError(`RAW 序列化要求 body 必须是 Uint8Array 类型,当前传入:${typeof body}`);
+ // }
+ serializedBody = body instanceof Uint8Array ? body : new Uint8Array(body as ArrayBuffer);
+ break;
+
+ case SerializationType.STRING:
+ // STRING 序列化:必须传入字符串(非 PING 消息已校验非空)
+ serializedBody = textEncoder.encode(body as string);
+ break;
+
+ case SerializationType.JSON:
+ // 断言:body 是 string 或 object
+ if (typeof body === 'string') {
+ serializedBody = textEncoder.encode(body);
+ } else {
+ serializedBody = textEncoder.encode(JSON.stringify(body));
+ }
+ break;
+
+ default:
+ throw new Error(`不支持的序列化方式:${SerializationType[serialization]}(值:${serialization},0b${serialization.toString(2).padStart(3, '0')})`);
+ }
+
+ // 4. 压缩:暂不支持,直接赋值
+ const compressedBody = serializedBody;
+
+ // 5. 校验包体大小(24位长度最大支持0xFFFFFF=16777215字节)
+ const bodyLen = compressedBody.length;
+ if (bodyLen > ProtocolConst.MAX_BODY_SIZE) {
+ throw new Error(
+ `包体过大(${bodyLen}字节),最大支持${ProtocolConst.MAX_BODY_SIZE}字节(≈16MB)`
+ );
+ }
+
+ // 6. 构造头部(8字节,按最新结构)
+ const header = new Uint8Array(ProtocolConst.HEADER_SIZE);
+
+ // 字节0:消息类型(高4位) + 协议版本(低4位)
+ header[0] = ((msgType & 0x0F) << 4) | (ProtocolConst.PROTOCOL_VERSION & 0x0F);
+
+ // 字节1:序列化方式(高3位) + 压缩方式(中3位) + 保留位(低2位,填0)
+ header[1] = ((serialization & 0x07) << 5) | ((compression & 0x07) << 2) | 0x00;
+
+ // 字节2~3:消息顺序号(16位大端序,0~65535)
+ header[2] = (sequence >> 8) & 0xFF; // 顺序号高8位
+ header[3] = sequence & 0xFF; // 顺序号低8位
+
+ // 字节4~6:消息体长度(24位大端序,0~0xFFFFFF)
+ header[4] = (bodyLen >> 16) & 0xFF; // 长度高8位
+ header[5] = (bodyLen >> 8) & 0xFF; // 长度中8位
+ header[6] = bodyLen & 0xFF; // 长度低8位
+
+ // 字节7:保留位(固定填0x00)
+ header[7] = 0x00;
+
+ // 7. 拼接头部和包体
+ const totalLen = ProtocolConst.HEADER_SIZE + bodyLen;
+ const packet = new Uint8Array(totalLen);
+ packet.set(header, 0);
+ packet.set(compressedBody, ProtocolConst.HEADER_SIZE);
+
+ return packet;
+ }
+
+ /**
+ * 解包协议包
+ * @param packet 完整协议包
+ * @returns 结构化解包结果(含顺序号)
+ * @throws 各种解析异常
+ */
+ static unpack(packet : Uint8Array | ArrayBuffer) : UnpackedResult {
+ const uint8Packet = packet instanceof ArrayBuffer
+ ? new Uint8Array(packet)
+ : packet;
+
+ // 1. 校验包长度(至少8字节头部)
+ if (uint8Packet.length < ProtocolConst.HEADER_SIZE) {
+ throw new Error(
+ `包长度过短(${uint8Packet.length}字节),至少需要${ProtocolConst.HEADER_SIZE}字节头部`
+ );
+ }
+
+ // 2. 拆分头部和包体
+ const header = uint8Packet.subarray(0, ProtocolConst.HEADER_SIZE);
+ const bodyBuffer = uint8Packet.subarray(ProtocolConst.HEADER_SIZE);
+
+ // 3. 解析头部字段
+ // 字节0:消息类型(高4位) + 协议版本(低4位)
+ const byte0 = header[0];
+ const msgType = (byte0 >> 4) & 0x0F; // 消息类型(0~15)
+ const version = byte0 & 0x0F; // 协议版本(0~15)
+
+ // 校验消息类型
+ if (!Object.values(MessageType).includes(msgType as MessageType)) {
+ throw new Error(`非法消息类型:${msgType}(0b${msgType.toString(2).padStart(4, '0')})`);
+ }
+
+ // 校验版本
+ if (version !== ProtocolConst.PROTOCOL_VERSION) {
+ throw new Error(
+ `协议版本不匹配:收到v${version}(0b${version.toString(2).padStart(4, '0')}),当前支持v${ProtocolConst.PROTOCOL_VERSION}(0b${ProtocolConst.PROTOCOL_VERSION.toString(2).padStart(4, '0')})`
+ );
+ }
+
+ // 字节1:序列化方式(高3位) + 压缩方式(中3位) + 保留位(低2位)
+ const byte1 = header[1];
+ const serialization = (byte1 >> 5) & 0x07; // 高3位(1~8)
+ const compression = (byte1 >> 2) & 0x07; // 中3位(1~8)
+ // 保留位:(byte1 & 0x03),暂不处理
+
+ // 校验序列化方式
+ if (!Object.values(SerializationType).includes(serialization as SerializationType)) {
+ throw new Error(`非法序列化方式:${serialization}(0b${serialization.toString(2).padStart(3, '0')})`);
+ }
+
+ // 校验压缩方式
+ if (!Object.values(CompressionType).includes(compression as CompressionType)) {
+ throw new Error(`非法压缩方式:${compression}(0b${compression.toString(2).padStart(3, '0')})`);
+ }
+
+ // 字节2~3:消息顺序号(16位大端序)
+ const sequence = (header[2] << 8) | header[3]; // 0~65535
+
+ // 字节4~6:消息体长度(24位大端序),字节7:保留位(忽略)
+ const bodyLen = (header[4] << 16) | (header[5] << 8) | header[6];
+
+ // 校验包体长度(空包体时 bodyBuffer.length 应为0)
+ if (bodyBuffer.length !== bodyLen) {
+ throw new Error(
+ `包体长度不匹配:头部声明${bodyLen}字节,实际接收${bodyBuffer.length}字节`
+ );
+ }
+
+ // 4. 解压包体
+ let decompressedBody : Uint8Array;
+ if (compression === CompressionType.NONE) {
+ decompressedBody = bodyBuffer;
+ } else if (compression === CompressionType.GZIP) {
+ // 若需启用GZIP,取消注释下方代码
+ // try {
+ // decompressedBody = pako.ungzip(bodyBuffer);
+ // } catch (e) {
+ // throw new Error(`GZIP 解压失败:${(e as Error).message}`);
+ // }
+ throw new Error("GZIP 解压暂未启用,请导入pako库并取消对应代码注释");
+ } else {
+ throw new Error(`不支持的压缩方式:${CompressionType[compression]}(值:${compression},0b${compression.toString(2).padStart(3, '0')})`);
+ }
+
+ // 5. 反序列化包体(PING 消息空包体返回 null)
+ let body : UnpackedResult["body"];
+ const textDecoder = new TextDecoder();
+
+ // 特殊处理:空包体(PING 消息常见)返回 null
+ if (decompressedBody.length === 0) {
+ body = null;
+ } else {
+ switch (serialization) {
+ case SerializationType.RAW:
+ body = decompressedBody;
+ break;
+
+ case SerializationType.STRING:
+ try {
+ body = textDecoder.decode(decompressedBody);
+ } catch (e) {
+ throw new Error(`STRING 反序列化失败:UTF-8 解码错误`);
+ }
+ break;
+
+ case SerializationType.JSON:
+ try {
+ const jsonStr = textDecoder.decode(decompressedBody);
+ body = JSON.parse(jsonStr);
+ } catch (e) {
+ if (e instanceof SyntaxError) {
+ throw new Error(`JSON 反序列化失败:格式错误(${(e as Error).message})`);
+ } else {
+ throw new Error(`JSON 反序列化失败:${(e as Error).message}`);
+ }
+ }
+ break;
+
+ default:
+ throw new Error(`不支持的序列化方式:${SerializationType[serialization]}(值:${serialization},0b${serialization.toString(2).padStart(3, '0')})`);
+ }
+ }
+
+ // 6. 返回解包结果
+ return {
+ msgType: msgType as MessageType,
+ msgTypeName: MessageType[msgType] as keyof typeof MessageType,
+ serialization: serialization as SerializationType,
+ serializationName: SerializationType[serialization] as keyof typeof SerializationType,
+ compression: compression as CompressionType,
+ compressionName: CompressionType[compression] as keyof typeof CompressionType,
+ sequence: sequence,
+ body: body,
+ };
+ }
+}
\ No newline at end of file
diff --git a/tra-app/src/pages/sparring/js/StreamPlayer.js b/tra-app/src/pages/sparring/js/StreamPlayer.js
new file mode 100644
index 0000000..0e1c7bc
--- /dev/null
+++ b/tra-app/src/pages/sparring/js/StreamPlayer.js
@@ -0,0 +1,200 @@
+/**
+ * 支持安卓、iOS、H5的pcm格式,
+ * 如果想支持mp3,需要增加mp3相关解码合并处理等,个人测试效果不太好,所以没有加
+ */
+export class StreamPlayer {
+ constructor({
+ inputSampleRate = 16000,
+ numChannels = 1,
+ bitDepth = 16,
+ littleEndian = true,
+ pcmType = 'int',
+ callback = ()=>{}
+ } = {}) {
+ // 参数校验
+ if (![16, 32].includes(bitDepth)) throw new Error('bitDepth 必须是 16 或 32');
+ if (inputSampleRate <= 0) throw new Error('采样率必须大于 0');
+ if (!['int', 'float'].includes(pcmType)) throw new Error('pcmType 必须是 int 或 float');
+
+ this.audioContext = new(window.AudioContext || window.webkitAudioContext)();
+ this.inputSampleRate = inputSampleRate;
+ this.numChannels = numChannels;
+ this.bitDepth = bitDepth;
+ this.littleEndian = littleEndian;
+ this.pcmType = pcmType;
+ this.audioQueue = [];
+ this.playbackEndTime = 0;
+ this.currentSource = null;
+ this.lastBlockTail = null; // 用于交叉淡入淡出
+ this.callback = callback;
+ }
+
+ appendChunk(audioData) {
+ this.audioQueue.push(audioData);
+ this._processQueue();
+ }
+
+ destroy() {
+ this.audioQueue = [];
+ this.playbackEndTime = 0;
+ if (this.currentSource) {
+ this.currentSource.stop();
+ this.currentSource = null;
+ }
+ if (this.audioContext) {
+ this.audioContext.close();
+ this.audioContext = null;
+ }
+ }
+
+ async _processQueue() {
+ if(this.audioQueue.length === 0) {
+ this.callback('ended')
+ return
+ }
+ if (!this.audioContext || this.currentSource) return;
+ const buffer = this._mergeArrayBuffers(this.audioQueue)
+ this.audioQueue = []
+ try {
+ const audioBuffer = this._convertPCM(buffer);
+ await this._schedulePlay(audioBuffer);
+ this._processQueue();
+ } catch (err) {
+ console.error('音频处理失败:', err.name, err.message, err.stack);
+ }
+ }
+
+ _convertPCM(buffer) {
+ // 1. 数据对齐:确保长度是样本大小的整数倍
+ const bytesPerSample = this.bitDepth / 8;
+ const requiredBytes = bytesPerSample * this.numChannels;
+ const validByteLength = Math.floor(buffer.byteLength / requiredBytes) * requiredBytes;
+ const validBuffer = buffer.slice(0, validByteLength);
+ const dataView = new DataView(validBuffer);
+ const numSamples = validByteLength / requiredBytes;
+
+ // 2. 创建音频缓冲区
+ const audioBuffer = this.audioContext.createBuffer(
+ this.numChannels,
+ numSamples,
+ this.inputSampleRate
+ );
+
+ // 3. 解析PCM数据
+ for (let ch = 0; ch < this.numChannels; ch++) {
+ const channelData = audioBuffer.getChannelData(ch);
+ for (let i = 0; i < numSamples; i++) {
+ // 计算字节位置(修正后的多声道索引)
+ const pos = (i * this.numChannels * bytesPerSample) + (ch * bytesPerSample);
+ let value;
+
+ // 根据位深和数据类型解析
+ if (this.bitDepth === 16) {
+ value = dataView.getInt16(pos, this.littleEndian) / 32768;
+ } else {
+ if (this.pcmType === 'int') {
+ value = dataView.getInt32(pos, this.littleEndian) / 2147483648;
+ } else {
+ value = dataView.getFloat32(pos, this.littleEndian);
+ }
+ }
+ channelData[i] = value;
+ }
+
+ // 4. 消除直流偏移
+ let sum = 0;
+ for (let i = 0; i < channelData.length; i++) {
+ sum += channelData[i];
+ }
+ const dcOffset = sum / channelData.length;
+ for (let i = 0; i < channelData.length; i++) {
+ channelData[i] -= dcOffset;
+ }
+
+ // 5. 块内淡入淡出(减少边界突变)
+ const fadeLength = Math.min(100, channelData.length);
+ for (let i = 0; i < fadeLength; i++) {
+ channelData[i] *= (i / fadeLength);
+ }
+ const startFadeOut = Math.max(0, channelData.length - fadeLength);
+ for (let i = startFadeOut; i < channelData.length; i++) {
+ const factor = 1 - (i - startFadeOut) / fadeLength;
+ channelData[i] *= factor;
+ }
+ }
+
+ // 6. 块间交叉淡入淡出(解决重音关键点)
+ const crossfadeLength = 50;
+ if (this.lastBlockTail && this.lastBlockTail.length === this.numChannels) {
+ for (let ch = 0; ch < this.numChannels; ch++) {
+ const channelData = audioBuffer.getChannelData(ch);
+ const prevTail = this.lastBlockTail[ch];
+
+ // 只处理有足够长度交叉的情况
+ if (prevTail.length >= crossfadeLength && channelData.length >= crossfadeLength) {
+ for (let i = 0; i < crossfadeLength; i++) {
+ const prevWeight = (crossfadeLength - i) / crossfadeLength;
+ const currWeight = i / crossfadeLength;
+ channelData[i] = channelData[i] * currWeight + prevTail[i] * prevWeight;
+ }
+ }
+ }
+ }
+
+ // 7. 保存当前块尾部用于下一次交叉
+ this.lastBlockTail = [];
+ for (let ch = 0; ch < this.numChannels; ch++) {
+ const channelData = audioBuffer.getChannelData(ch);
+ const tailStart = Math.max(0, channelData.length - crossfadeLength);
+ this.lastBlockTail[ch] = channelData.slice(tailStart);
+ }
+
+ return audioBuffer;
+ }
+ _schedulePlay(audioBuffer) {
+ return new Promise(resolve => {
+ const source = this.audioContext.createBufferSource();
+ source.buffer = audioBuffer;
+ source.connect(this.audioContext.destination);
+
+ const plannedStartTime = this.playbackEndTime;
+ const now = this.audioContext.currentTime;
+ let startTime = Math.max(plannedStartTime, now);
+
+ // 动态速率调整(示例,需根据实际测试调整阈值)
+ const timeDrift = plannedStartTime - now;
+ if (timeDrift < -0.02) {
+ source.playbackRate.value = Math.min(1.04, 1 - (timeDrift / audioBuffer.duration));
+ } else if (timeDrift > 0.02) {
+ source.playbackRate.value = Math.max(0.96, 1 - (timeDrift / audioBuffer.duration));
+ } else {
+ source.playbackRate.value = 1.0;
+ }
+
+ source.start(startTime);
+ this.playbackEndTime = startTime + (audioBuffer.duration / source.playbackRate.value);
+
+ source.onended = () => {
+ this.currentSource = null;
+ resolve();
+ };
+ this.currentSource = source;
+ });
+ }
+
+ // 合并多个 ArrayBuffer 的辅助函数
+ _mergeArrayBuffers(buffers) {
+ let totalLength = 0;
+ for (let buffer of buffers) {
+ totalLength += buffer.byteLength;
+ }
+ const result = new Uint8Array(totalLength);
+ let offset = 0;
+ for (let buffer of buffers) {
+ const view = new Uint8Array(buffer);
+ result.set(view, offset);
+ offset += view.length;
+ }
+ return result.buffer;
+ }
+}
\ No newline at end of file
diff --git a/tra-app/src/pages/sparring/js/useMicrophone.js b/tra-app/src/pages/sparring/js/useMicrophone.js
new file mode 100644
index 0000000..af6863c
--- /dev/null
+++ b/tra-app/src/pages/sparring/js/useMicrophone.js
@@ -0,0 +1,149 @@
+import {
+ ref,
+ onUnmounted,
+ watch
+} from 'vue';
+ import {
+ ProtocolCodec,
+ MessageType,
+ SerializationType,
+ CompressionType,
+ ControlCommand,
+ ProtocolConst
+ } from './ProtocolCodec';
+/**
+ * 麦克风操作Hook(封装开始/停止录音、状态管理)
+ * @param {Object} options - 录音配置项
+ * @param {number} options.duration - 最大录音时长(秒,默认60)
+ * @param {string} options.format - 录音格式(mp3/wav/pcm,默认mp3)
+ * @param {number} options.sampleRate - 采样率(默认16000)
+ * @param {number} options.bitRate - 码率(默认16000)
+ * @param {Function} options.onData - 实时音频数据回调(仅H5/PCM格式生效)
+ * @param {Function} options.onStop - 结束回调
+ * @param {Function} options.onError - 错误回调
+ * @returns {Object} 录音控制方法+状态
+ */
+export default function useMicrophone(options = {}) {
+ console.log('options', options);
+ const send = options.send
+ const recordFrame = ref(null)
+ const renderJSModule = ref(null)
+
+ // 默认配置
+ const defaultOptions = {
+ duration: 60,
+ format: 'mp3',
+ sampleRate: 16000,
+ bitRate: 16000,
+ onData: () => {},
+ onStop: () => {},
+ onError: (err) => console.error('录音错误:', err)
+ };
+ const finalOptions = {
+ ...defaultOptions,
+ ...options
+ };
+
+ // 响应式状态
+ const isRecording = ref(false); // 是否正在录音
+ const recordTime = ref(0); // 录音时长(秒)
+ const recordResult = ref(null); // 录音结果(临时文件路径/Blob)
+ const recorderManager = ref(null); // 录音管理器实例(uniapp/小程序)
+ const audioContext = ref(null); // AudioContext(H5)
+ const mediaRecorder = ref(null); // MediaRecorder(H5)
+ const timer = ref(null); // 录音时长定时器
+
+ // 平台判断
+ const platform = uni.getSystemInfoSync().platform;
+
+ // ==================== 核心方法:开始录音 ====================
+ const startRecording = async () => {
+ // 防止重复点击
+ if (isRecording.value) return;
+
+ // 重置状态
+ recordTime.value = 0;
+ recordResult.value = null;
+ console.log('开始', recordFrame.value);
+ recordFrame.value.start({
+ sampleRate: 16000,
+ frameSize: 1024,
+ gain: 1.0,
+ onFrameRecorded: ({ isLastFrame, frameBuffer }) => {
+ // console.log('录音返回', frameBuffer);
+ const data = ProtocolCodec.pack(MessageType.AUDIO_DATA, frameBuffer)
+ // console.log('录音返回', data);
+ send(data)
+ // try {
+ // ws.value.send({
+ // data: ProtocolCodec.pack(MessageType.AUDIO_DATA, frameBuffer)
+ // });
+ // } catch (e) {}
+ },
+ onDecibels: (decibels) => {
+ // this.currentDecibels = decibels;
+ }
+ });
+ // this.isRecording = true;
+ // this.status = '录音中...';
+ // isRecording.value = true;
+
+ };
+
+ // ==================== 核心方法:停止录音 ====================
+ const stopRecord = () => {
+ // if (!isRecording.value) return;
+
+ // try {
+ // if (isH5) {
+ // mediaRecorder.value?.stop();
+ // } else if (isMiniProgram || platform === 'app-plus') {
+ // recorderManager.value?.stop();
+ // }
+ // isRecording.value = false;
+ // clearInterval(timer.value);
+ // } catch (err) {
+ // finalOptions.onError(`停止录音失败:${err.message}`);
+ // }
+ };
+
+ // ==================== 资源清理 ====================
+ const cleanup = () => {
+ // stopRecord();
+ // // H5端额外清理
+ // if (isH5) {
+ // if (mediaRecorder.value) mediaRecorder.value = null;
+ // if (audioContext.value) audioContext.value.close();
+ // // 释放Blob URL
+ // if (recordResult.value?.url) {
+ // URL.revokeObjectURL(recordResult.value.url);
+ // }
+ // }
+ // // 小程序/APP端清理
+ // if (recorderManager.value) recorderManager.value = null;
+ };
+
+ // 组件卸载时自动清理
+ // onUnmounted(() => {
+ // cleanup();
+ // });
+
+ // 监听最大时长,自动停止
+ // watch(
+ // () => recordTime.value,
+ // (val) => {
+ // if (val >= finalOptions.duration) {
+ // stopRecord();
+ // }
+ // }
+ // );
+
+ // 返回控制方法+状态
+ return {
+
+ isRecording,
+ renderJSModule,
+ startRecording,
+ recordFrame
+ };
+};
\ No newline at end of file
diff --git a/tra-app/src/pages/sparring/js/useSpeaker.js b/tra-app/src/pages/sparring/js/useSpeaker.js
new file mode 100644
index 0000000..568ca08
--- /dev/null
+++ b/tra-app/src/pages/sparring/js/useSpeaker.js
@@ -0,0 +1,129 @@
+import {
+ ref,
+ onUnmounted,
+ watch
+} from 'vue';
+
+/**
+ * 扬声器管理Hook(音频输出)
+ * @param {Object} options - 播放配置
+ * @param {number} options.sampleRate - 播放采样率(默认16000,需与音频源一致)
+ * @param {number} options.volume - 初始音量(0~1,默认1)
+ * @param {boolean} options.autoPlay - 是否自动播放(默认false,需用户交互触发)
+ * @param {Function} options.onPlay - 播放开始回调
+ * @param {Function} options.onError - 播放错误回调
+ * @returns {Object} 播放控制方法+状态
+ */
+export const useSpeaker = (options = {}) => {
+ // 默认配置
+ const defaultOptions = {
+ sampleRate: 16000,
+ volume: 1.0,
+ autoPlay: false,
+ onPlay: () => {},
+ onError: (err) => console.error('扬声器播放错误:', err)
+ };
+ const finalOptions = {
+ ...defaultOptions,
+ ...options
+ };
+
+ // 响应式状态
+ const isPlaying = ref(false); // 是否正在播放
+ const volume = ref(finalOptions.volume); // 播放音量(0~1)
+ const audioContext = ref(null); // 音频播放上下文(H5)
+ const audioBufferSource = ref(null); // 音频缓冲源(播放PCM流)
+ const audioElement = ref(null); // 音频元素(播放文件/URL)
+ const playQueue = ref([]); // 音频数据播放队列(适配实时流)
+
+ // 平台判断
+ const isH5 = uni.getSystemInfoSync().platform === 'h5';
+
+ // ==================== 初始化播放上下文 ====================
+ const initAudioContext = () => {
+
+ };
+
+ // ==================== 核心方法:播放PCM音频流(实时) ====================
+ /**
+ * 播放PCM音频数据(适配WebSocket传输的实时流)
+ * @param {ArrayBuffer} pcmData - PCM音频数据(16位单声道)
+ */
+ const playPCM = (pcmData) => {
+
+
+
+ };
+
+ // ==================== 控制方法:暂停/停止/调节音量 ====================
+ const pausePlay = () => {
+ if (!isPlaying.value) return;
+
+ if (isH5) {
+ if (audioBufferSource.value) {
+ audioBufferSource.value.stop();
+ audioBufferSource.value = null;
+ }
+ audioElement.value?.pause();
+ } else {
+ uni.createInnerAudioContext().pause();
+ }
+ isPlaying.value = false;
+ };
+
+ const stopPlay = () => {
+ pausePlay();
+ playQueue.value = []; // 清空播放队列
+ if (audioContext.value) {
+ audioContext.value.close().then(() => {
+ audioContext.value = null;
+ });
+ }
+ audioElement.value = null;
+ };
+
+ const setVolume = (val) => {
+ if (val < 0) val = 0;
+ if (val > 1) val = 1;
+ volume.value = val;
+
+ if (isH5) {
+ audioContext.value?.destination.setVolume(val);
+ audioElement.value.volume = val;
+ } else {
+ uni.createInnerAudioContext().volume = val;
+ }
+ };
+
+ // ==================== 资源清理 ====================
+ const cleanup = () => {
+ stopPlay();
+ isPlaying.value = false;
+ volume.value = finalOptions.volume;
+ playQueue.value = [];
+ };
+
+ // 组件卸载时自动清理
+ onUnmounted(() => {
+ cleanup();
+ });
+
+ // 监听音量变化,同步更新
+ watch(volume, (newVal) => {
+ setVolume(newVal);
+ });
+
+ // 返回控制方法+状态
+ return {
+ // 响应式状态
+ isPlaying, // 是否正在播放
+ volume, // 当前音量(0~1)
+ // 核心方法
+ playPCM, // 播放实时PCM音频流(适配WebSocket)
+ playAudio, // 播放音频文件/URL
+ pausePlay, // 暂停播放
+ stopPlay, // 停止播放
+ setVolume, // 调节音量(0~1)
+ cleanup // 手动清理资源
+ };
+};
\ No newline at end of file
diff --git a/tra-app/src/pages/sparring/js/useWebSocket.js b/tra-app/src/pages/sparring/js/useWebSocket.js
new file mode 100644
index 0000000..c5d5d02
--- /dev/null
+++ b/tra-app/src/pages/sparring/js/useWebSocket.js
@@ -0,0 +1,118 @@
+import {
+ getToken
+} from '@/common/common'
+import {
+ get_base_url
+} from '@/api/request.js'
+import {
+ ref,
+ onUnmounted,
+ computed,
+ getCurrentInstance
+} from 'vue';
+import {
+ ProtocolCodec,
+ MessageType,
+ SerializationType,
+ CompressionType,
+ ControlCommand,
+ ProtocolConst
+} from './ProtocolCodec';
+const DEFAULT_AUTH_PARAMS = {
+ user_id: '1001', // 默认用户ID(可从缓存/全局状态取)
+ token: '', // 优先从缓存获取,避免硬编码
+ name: '测试用户',
+ device_id: uni.getSystemInfoSync().deviceId || '', // 设备ID(补充)
+ timestamp: Date.now() // 时间戳(防篡改)
+};
+// const wsUrl = 'ws://127.0.0.1:8000/ws/audio'
+const url = '/trapractice/voiceCallSocket/voiceCall'
+const _baseUrl = get_base_url(url).split('http').join('ws')
+export default function useWebSocket(aaas = null, options = {}) {
+ const isRecording = ref(false) //是否接通
+ const ws = ref(null)
+ const initConnection = (authParams = {}, onStartRecord, sssssss) => {
+ const wsUrl = _baseUrl + url + '?summary=' + getToken()
+ console.log('wsUrl', wsUrl);
+ const finalAuthParams = {
+ ...DEFAULT_AUTH_PARAMS,
+ ...authParams,
+ };
+ ws.value = uni.connectSocket({
+ url: wsUrl,
+ fail: () => {
+ console.log('fail');
+ },
+ success: () => {
+ console.log('web');
+ },
+ fail: () => {
+ console.log('fail');
+ }
+ });
+ ws.value.onOpen((res) => {
+ ws.value.send({
+ data: ProtocolCodec.pack(MessageType.IDENTITY, finalAuthParams)
+ });
+ });
+ ws.value.onMessage((res) => {
+ const {
+ msgType,
+ body
+ } = ProtocolCodec.unpack(res.data);
+ switch (msgType) {
+ case MessageType.IDENTITY:
+ console.log('身份校验', body);
+ onStartRecord(body)
+ break;
+ case MessageType.AUDIO_DATA:
+ const buffer = body;
+ if (buffer.byteLength < 2) break;
+ const uint8 = new Uint8Array(buffer);
+ const numArray = Array.from(uint8);
+ // currentPCMChunk.value = numArray;
+ sssssss(numArray)
+ // console.log('音频消息', body);
+ break;
+ case MessageType.ERROR:
+
+ // this.handleErrorMessage(body);
+ break;
+ default:
+ console.log('其他消息', body);
+ break;
+ }
+ });
+ }
+ const send = (data) => {
+ ws.value.send({
+ data
+ });
+ }
+ const close = () => {
+ ws.value.close({
+ code: 1000,
+ reason: '用户挂断',
+ success: () => {
+ console.log('挂断success');
+ },
+ fail: () => {
+ console.log('挂断fail');
+ },
+ complete: () => {
+ console.log('挂断complete');
+ }
+
+ });
+ }
+
+
+
+ return {
+ ws,
+ close,
+ initConnection,
+ send,
+ isRecording
+ };
+}
\ No newline at end of file
diff --git a/tra-app/src/pages/sparring/talk.vue b/tra-app/src/pages/sparring/talk.vue
index 86dc355..fcbeecb 100644
--- a/tra-app/src/pages/sparring/talk.vue
+++ b/tra-app/src/pages/sparring/talk.vue
@@ -1,92 +1,202 @@
-
-
-
-
-
-
-
-
- {{ detailInfo.chaName }}
- {{ timeShow }}
+
+
+
+
+
+ 场景提示
+
+
+
+
+
+ {{ dataInfo.userName }}
+ {{ formattedTime }}
+ 正在接通中
+
+
+
+ {{ dataInfo.sceneDesc }}
+
+
-
-
- {{ detailInfo.sceneDesc }}
-
-
-
+
+
+
\ No newline at end of file
+
diff --git a/tra-app/src/pages/sparring/talk4.vue b/tra-app/src/pages/sparring/talk4.vue
new file mode 100644
index 0000000..ff6c494
--- /dev/null
+++ b/tra-app/src/pages/sparring/talk4.vue
@@ -0,0 +1,492 @@
+
+
+
+
+
+
+ 场景提示
+
+
+
+
+
+ {{ userInfo.userName }}
+ {{ timeShow }}
+ 正在接通中
+
+
+
+ {{ sceneDesc }}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tra-app/src/pages/sparring/tip.vue b/tra-app/src/pages/sparring/tip.vue
index 38bd37a..3ccb531 100644
--- a/tra-app/src/pages/sparring/tip.vue
+++ b/tra-app/src/pages/sparring/tip.vue
@@ -234,6 +234,9 @@
// #endif
}
const toTalking = () => {
+ common.setPageCache({
+ sceneDesc:detailInfo.value.sceneDesc
+ })
common.navigateTo('/pages/sparring/talk?traId=' + traId.value + '&chaId=' + chaId.value + '&type=' + talkingType
.value + '&isPreview=' + (isPreview.value ? '1' : '0'))
}
diff --git a/tra-app/src/pagesB.json b/tra-app/src/pagesB.json
index 2b2f044..5fa2084 100644
--- a/tra-app/src/pagesB.json
+++ b/tra-app/src/pagesB.json
@@ -95,6 +95,7 @@
"path": "pages/sparring/talk",
"style": {
"navigationBarTitleText": "AI陪练通话",
+ "disableSwipeBack": true,
"app-plus": {
"titleNView": false
}
diff --git a/tra-app/src/static/images/analytics/bg1.png b/tra-app/src/static/images/analytics/bg1.png
index c0b764e..cdf6e33 100644
Binary files a/tra-app/src/static/images/analytics/bg1.png and b/tra-app/src/static/images/analytics/bg1.png differ
diff --git a/tra-app/src/static/images/analytics/title.png b/tra-app/src/static/images/analytics/title.png
new file mode 100644
index 0000000..45155be
Binary files /dev/null and b/tra-app/src/static/images/analytics/title.png differ
diff --git a/tra-app/src/uni_modules/yao-RecordFrame/components/yao-RecordFrame/yao-RecordFrame.vue b/tra-app/src/uni_modules/yao-RecordFrame/components/yao-RecordFrame/yao-RecordFrame.vue
index 735be30..fb373ea 100644
--- a/tra-app/src/uni_modules/yao-RecordFrame/components/yao-RecordFrame/yao-RecordFrame.vue
+++ b/tra-app/src/uni_modules/yao-RecordFrame/components/yao-RecordFrame/yao-RecordFrame.vue
@@ -2,6 +2,7 @@
+