Browse Source

修改部分功能

yangg 1 tuần trước cách đây
mục cha
commit
2366bde2eb

+ 2 - 2
common/config.js

@@ -2,7 +2,7 @@
 //线上 https://minlong.raycos.com.cn
 //测试 http://192.168.66.187:8083
 //https://backend.qicai321.com
-export const apiBaseUrl = 'http://192.168.100.101:8083';//'https://backend.qicai321.com';
+export const apiBaseUrl = 'https://backend.qicai321.com';//'http://192.168.100.101:8083';//
 
 // You can add other global configuration settings here
 export const appVersion = '1.0.0';
@@ -17,4 +17,4 @@ export const appVersion = '1.0.0';
 // };
 
 // WebSocket URL for person detection (do not hardcode elsewhere)
-export const personDetectionWsUrl = `ws://192.168.100.101:8083`; 
+export const personDetectionWsUrl = `ws://backend.qicai321.com`; 

+ 65 - 16
pages/identity-verify/identity-verify.vue

@@ -3016,14 +3016,7 @@ export default {
       return null;
     },
 
-    onShow() {
-      console.log('identity-verify页面onShow');
-      console.log('当前本地存储中的职位信息:', uni.getStorageSync('selectedJob'));
-      
-      // 每次页面显示时重新获取问题
-      this.fetchQuestions();
-      this.fetchFollowUpQuestions(); // 添加获取追问问题的调用
-    },
+
 
     // 添加新方法:重置录制状态,准备重新回答
     resetForRerecording() {
@@ -3139,18 +3132,74 @@ export default {
       this.handleStartRecordingClick();
     },
 
-    // 添加 onUnload 生命周期钩子,移除 WebSocket 关闭
+    // 页面卸载时关闭WebSocket连接
     onUnload() {
-      console.log('页面卸载');
-      // 移除 WebSocket 关闭
-      // this.closeWebSocketConnection();
+      console.log('页面卸载,关闭WebSocket连接');
+      this.cleanupPersonDetectionWebSocket();
+      // 清理其他资源
+      this.stopUserCamera();
+      this.clearCountdown();
+      
+      // 清理录制相关定时器
+      if (this.recordingTimer) {
+        clearInterval(this.recordingTimer);
+        this.recordingTimer = null;
+      }
+      
+      // 停止MediaRecorder
+      if (this.mediaRecorder && this.mediaRecorder.state !== 'inactive') {
+        this.mediaRecorder.stop();
+      }
+      
+      // 关闭屏幕常亮
+      uni.setKeepScreenOn({
+        keepScreenOn: false
+      });
     },
 
-    // 修改 onHide 生命周期钩子,移除 WebSocket 关闭
+    // 页面隐藏时关闭WebSocket连接
     onHide() {
-      console.log('页面隐藏');
-      // 移除 WebSocket 关闭
-      // this.closeWebSocketConnection();
+      console.log('页面隐藏,关闭WebSocket连接');
+      
+      // 完全关闭WebSocket连接和相关定时器
+      this.cleanupPersonDetectionWebSocket();
+      
+      // 如果正在录制,给用户提示
+      if (this.isRecording) {
+        console.log('页面隐藏时正在录制,录制将继续');
+        // 可以选择暂停录制或者给用户提示
+        uni.showToast({
+          title: '请不要离开面试页面',
+          icon: 'none',
+          duration: 2000
+        });
+      }
+    },
+
+    // 页面显示时重新初始化WebSocket连接
+    onShow() {
+      console.log('identity-verify页面onShow');
+      console.log('当前本地存储中的职位信息:', uni.getStorageSync('selectedJob'));
+      
+      // 每次页面显示时重新获取问题
+      this.fetchQuestions();
+      this.fetchFollowUpQuestions(); // 添加获取追问问题的调用
+      
+      // 重新初始化WebSocket连接(仅在小程序环境中)
+      const systemInfo = uni.getSystemInfoSync();
+      const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith('mp-');
+      if (isMiniProgram) {
+        // 如果WebSocket未连接,重新初始化
+        if (!this.personDetectionSocket) {
+          console.log('重新初始化WebSocket连接');
+          this.initPersonDetectionWebSocket();
+        }
+        // 如果WebSocket已连接但检测定时器被停止,重新启动检测
+        else if (!this.personDetectionInterval) {
+          console.log('重新启动人脸检测定时器');
+          this.startPersonDetectionInterval();
+        }
+      }
     },
 
     // 添加新方法:阻止视频控制

+ 31 - 1
pages/index/index.vue

@@ -12,7 +12,7 @@
 					</view>
 					<view class="job-details">
 						<text class="job-salary"></text>
-						<text class="job-location">{{job.location}}</text>
+						<text class="job-location">{{formatLocation(job.location)}}</text>
 					</view>
 					
 				</view>
@@ -604,6 +604,36 @@ import { apiBaseUrl } from '@/common/config.js';
 							});
 						}
 					});
+			},
+			formatLocation(location) {
+				if (!location) return '';
+				
+				// 处理字符串形式的数组
+				if (typeof location === 'string' && location.startsWith('[')) {
+					try {
+						const locationArray = JSON.parse(location.replace(/'/g, '"'));
+						return locationArray.join(' ');
+					} catch (e) {
+						console.error('解析location失败:', e);
+						return location;
+					}
+				}
+				
+				// 处理数组格式
+				if (Array.isArray(location)) {
+					return location.join(' ');
+				}
+				
+				// 处理对象格式
+				if (typeof location === 'object' && location !== null) {
+					const { province, city, district } = location;
+					if (province && city) {
+						return province + ' ' + city + (district ? ' ' + district : '');
+					}
+				}
+				
+				// 处理普通字符串格式
+				return location;
 			}
 		}
 	}

+ 2 - 2
unpackage/dist/dev/mp-weixin/common/config.js

@@ -1,5 +1,5 @@
 "use strict";
-const apiBaseUrl = "http://192.168.100.101:8083";
-const personDetectionWsUrl = `ws://192.168.100.101:8083`;
+const apiBaseUrl = "https://backend.qicai321.com";
+const personDetectionWsUrl = `ws://backend.qicai321.com`;
 exports.apiBaseUrl = apiBaseUrl;
 exports.personDetectionWsUrl = personDetectionWsUrl;

+ 44 - 10
unpackage/dist/dev/mp-weixin/pages/identity-verify/identity-verify.js

@@ -2112,12 +2112,6 @@ const _sfc_main = {
       }
       return null;
     },
-    onShow() {
-      console.log("identity-verify页面onShow");
-      console.log("当前本地存储中的职位信息:", common_vendor.index.getStorageSync("selectedJob"));
-      this.fetchQuestions();
-      this.fetchFollowUpQuestions();
-    },
     // 添加新方法:重置录制状态,准备重新回答
     resetForRerecording() {
       console.log("重置录制状态,准备重新回答");
@@ -2191,13 +2185,53 @@ const _sfc_main = {
       this.showRerecordButton = false;
       this.handleStartRecordingClick();
     },
-    // 添加 onUnload 生命周期钩子,移除 WebSocket 关闭
+    // 页面卸载时关闭WebSocket连接
     onUnload() {
-      console.log("页面卸载");
+      console.log("页面卸载,关闭WebSocket连接");
+      this.cleanupPersonDetectionWebSocket();
+      this.stopUserCamera();
+      this.clearCountdown();
+      if (this.recordingTimer) {
+        clearInterval(this.recordingTimer);
+        this.recordingTimer = null;
+      }
+      if (this.mediaRecorder && this.mediaRecorder.state !== "inactive") {
+        this.mediaRecorder.stop();
+      }
+      common_vendor.index.setKeepScreenOn({
+        keepScreenOn: false
+      });
     },
-    // 修改 onHide 生命周期钩子,移除 WebSocket 关闭
+    // 页面隐藏时关闭WebSocket连接
     onHide() {
-      console.log("页面隐藏");
+      console.log("页面隐藏,关闭WebSocket连接");
+      this.cleanupPersonDetectionWebSocket();
+      if (this.isRecording) {
+        console.log("页面隐藏时正在录制,录制将继续");
+        common_vendor.index.showToast({
+          title: "请不要离开面试页面",
+          icon: "none",
+          duration: 2e3
+        });
+      }
+    },
+    // 页面显示时重新初始化WebSocket连接
+    onShow() {
+      console.log("identity-verify页面onShow");
+      console.log("当前本地存储中的职位信息:", common_vendor.index.getStorageSync("selectedJob"));
+      this.fetchQuestions();
+      this.fetchFollowUpQuestions();
+      const systemInfo = common_vendor.index.getSystemInfoSync();
+      const isMiniProgram = systemInfo.uniPlatform && systemInfo.uniPlatform.startsWith("mp-");
+      if (isMiniProgram) {
+        if (!this.personDetectionSocket) {
+          console.log("重新初始化WebSocket连接");
+          this.initPersonDetectionWebSocket();
+        } else if (!this.personDetectionInterval) {
+          console.log("重新启动人脸检测定时器");
+          this.startPersonDetectionInterval();
+        }
+      }
     },
     // 添加新方法:阻止视频控制
     preventVideoControl(e) {

+ 24 - 1
unpackage/dist/dev/mp-weixin/pages/index/index.js

@@ -446,6 +446,29 @@ const _sfc_main = {
           });
         }
       });
+    },
+    formatLocation(location) {
+      if (!location)
+        return "";
+      if (typeof location === "string" && location.startsWith("[")) {
+        try {
+          const locationArray = JSON.parse(location.replace(/'/g, '"'));
+          return locationArray.join(" ");
+        } catch (e) {
+          console.error("解析location失败:", e);
+          return location;
+        }
+      }
+      if (Array.isArray(location)) {
+        return location.join(" ");
+      }
+      if (typeof location === "object" && location !== null) {
+        const { province, city, district } = location;
+        if (province && city) {
+          return province + " " + city + (district ? " " + district : "");
+        }
+      }
+      return location;
     }
   }
 };
@@ -455,7 +478,7 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
       return {
         a: common_vendor.t(job.title),
         b: common_vendor.o(($event) => $options.viewJobDetail(job), index),
-        c: common_vendor.t(job.location),
+        c: common_vendor.t($options.formatLocation(job.location)),
         d: index,
         e: $data.selectedJobId === job.id ? 1 : "",
         f: common_vendor.o(($event) => $options.selectJob(job), index)