liushengqiang 1 year ago
parent
commit
40952df2e1
5 changed files with 21 additions and 10 deletions
  1. 1 1
      orchestra.html
  2. 15 6
      src/page-orchestra/App.tsx
  3. 2 1
      src/page-orchestra/evaluat-model/index.tsx
  4. 2 1
      src/utils/request.ts
  5. 1 1
      vite.config.ts

+ 1 - 1
orchestra.html

@@ -36,7 +36,7 @@
       height: '30px',
       loop: true,
       autoplay: true,
-      path: '/loading.json'
+      path: './loading.json'
     });
   </script>
   <script type="module" src="/src/page-orchestra/main.ts"></script>

+ 15 - 6
src/page-orchestra/App.tsx

@@ -7,11 +7,12 @@ import { getRandomKey, setBehaviorId, setToken } from "../utils";
 import { getQuery } from "../utils/queryString";
 import Notfind from "../view/notfind";
 import { employeeQueryUserInfo, studentQueryUserInfo, teacherQueryUserInfo } from "./api";
+import { promisefiyPostMessage } from "../utils/native-message";
 
 export default defineComponent({
 	name: "App",
 	setup() {
-		const query: any = getQuery()
+		const query: any = getQuery();
 		/** 获取用户信息 */
 		const getUserInfo = async () => {
 			// const a = await request.get(`/student/queryUserInfo`)
@@ -29,17 +30,25 @@ export default defineComponent({
 			setUserInfo(student);
 			// console.log("🚀 ~ res:", student);
 		};
-		onBeforeMount(() => {
+		onBeforeMount(async () => {
 			if (query.Authorization) {
 				setToken(query.Authorization);
+			} else {
+				// 获取token
+				const res = await promisefiyPostMessage({ api: "getToken" });
+				const content = res?.content;
+				if (content?.accessToken) {
+					setToken(content.tokenType + " " + content.accessToken);
+				}
+				console.log(content.tokenType + " " + content.accessToken)
 			}
 			setUser();
-			setBehaviorId(getRandomKey())
+			setBehaviorId(getRandomKey());
 		});
 		onMounted(() => {
-			const _loading = document.getElementById("loading")
-			_loading && (document.body.removeChild(_loading))
-		})
+			const _loading = document.getElementById("loading");
+			_loading && document.body.removeChild(_loading);
+		});
 
 		const inited = computed(() => {
 			return storeData.status === "login";

+ 2 - 1
src/page-orchestra/evaluat-model/index.tsx

@@ -152,6 +152,7 @@ export default defineComponent({
 			};
 			await connectWebsocket(content);
 			state.playSource = "music";
+			console.log('连接成功')
 		};
 
 		/** 评测结果按钮处理 */
@@ -217,7 +218,7 @@ export default defineComponent({
 		return () => (
 			<div>
 				<Transition name="pop-center">
-					{!evaluatingData.websocketState && !evaluatingData.startBegin && (
+					{evaluatingData.websocketState && !evaluatingData.startBegin && (
 						<div class={styles.startBtn} onClick={handleStartBegin}>
 							<img src={iconEvaluat.evaluatingStart} />
 						</div>

+ 2 - 1
src/utils/request.ts

@@ -52,8 +52,9 @@ request.interceptors.response.use(
 		const data = await res.clone().json();
 
 		if (data.code !== 200 && data.errCode !== 0) {
-			const msg = data.msg || "处理失败,请重试";
+			const msg = data.msg || data.message || "处理失败,请重试";
 			if (!(data.code === 403 || data.code === 401)) {
+				// storeData.status = 'error'
 				showToast(msg);
 			}
 			if (data.code === 403) {

+ 1 - 1
vite.config.ts

@@ -62,7 +62,7 @@ export default defineConfig({
 				rewrite: (path) => path.replace(/^\/colexiu/, ""),
 			},
 			"^/orchestra/.*": {
-				target: "https://online.lexiaoya.cn",
+				target: "https://test.lexiaoya.cn",
 				changeOrigin: true,
 				rewrite: (path) => path.replace(/^\/orchestra/, ""),
 			},