Эх сурвалжийг харах

增加科目二和科目三

zhangyujun 3 жил өмнө
parent
commit
635a2bd23d

+ 19 - 0
src/hooks/wx/sign.ts

@@ -0,0 +1,19 @@
+import wx from "weixin-js-sdk-ts";
+import { openApi } from "@/api/index";
+import wxSign from '@/utils/wxSign';
+
+export default function useWxSign() {
+    let createWxConfig = (ticket: string) => {
+        let timestamp = wxSign.createTimeStamp()
+        let nonceStr = wxSign.createNonceStr()
+        return {
+            timestamp: timestamp,
+            nonceStr,
+            signature: wxSign.calcSignature(ticket, nonceStr, timestamp, window.location.href)
+
+        }
+    }
+    return {
+        createWxConfig
+    }
+}

+ 1 - 1
src/utils/wxSign.ts

@@ -13,7 +13,7 @@ var calcSignature = function (ticket: string, noncestr: string, timestamp: numbe
 
     var str = 'jsapi_ticket=' + ticket + '&noncestr=' + noncestr + '&timestamp=' + timestamp + '&url=' + url;
     var shaObj = new jsSHA(str, 'TEXT');
-    return shaObj.getHash('SHA-1', 'HEX');
+    return shaObj.getHash('SHA-1', 'HEX') as string;
 }
 
 export default { calcSignature, createNonceStr, createTimeStamp }

+ 41 - 0
src/views/home/children/test/components/sujectThree.vue

@@ -0,0 +1,41 @@
+<template>
+	<div class="container">
+		<div v-html="wxHtml0"></div>
+		<div v-html="wxHtml1"></div>
+		<van-button class="my-button" type="primary">前往灯光模拟</van-button>
+		<van-button class="my-button" type="primary">前往观看视频</van-button>
+	</div>
+</template>
+
+<script setup>
+import { ref } from "@vue/reactivity";
+let sc = "script";
+let sty = "style";
+let wxHtml0 = ref(`	<wx-open-launch-weapp style="display: block;text-align:center;width:75%;height:48px;border: none;position:absolute;top:0.66rem;z-index:9999;opacity:0" id="launch-btn" username="gh_a994fd2f498e" path="pages/carVideo/index.html?living_code=LIVING_CODE">
+			<${sc} v-is="'script'" type="text/wxtag-template">
+				<${sty} v-is="'style'">.openbtn{background-color:#38f;color:#f40;width:100px;height:40px;line-height:40px;}</${sty}>
+				<div class="openbtn">跳转小程序</div>
+			</${sc}>
+		</wx-open-launch-weapp>`);
+
+let wxHtml1 = ref(`	<wx-open-launch-weapp style="display: block;width:75%;height:48px;text-align:center;border: none;position:absolute;top:2.4rem;z-index:9999;opacity:0" id="launch-btn" username="gh_a994fd2f498e" path="pages/lightMock/index.html?living_code=LIVING_CODE">
+			<${sc} v-is="'script'" type="text/wxtag-template">
+				<${sty} v-is="'style'">.openbtn{background-color:#38f;color:#f40;width:100px;height:40px;line-height:40px;}</${sty}>
+				<div class="openbtn">跳转小程序</div>
+			</${sc}>
+		</wx-open-launch-weapp>`);
+</script>
+
+<style lang="scss" scoped>
+.container {
+	width: 100%;
+	display: flex;
+	justify-content: center;
+	position: relative;
+	flex-wrap: wrap;
+}
+.my-button {
+	margin-top: 25px;
+	width: 75%;
+}
+</style>

+ 20 - 0
src/views/home/children/test/components/sujectTwo.vue

@@ -0,0 +1,20 @@
+<template>
+	<div class="container">
+		<van-button class="my-button" type="primary">前往观看视频</van-button>
+	</div>
+</template>
+
+<script setup>
+</script>
+
+<style lang="scss" scoped>
+.container {
+	width: 100%;
+	display: flex;
+	justify-content: center;
+	margin-top: 25px;
+}
+.my-button {
+	width: 75%;
+}
+</style>

+ 106 - 20
src/views/home/children/test/index.vue

@@ -15,7 +15,10 @@
 			</template>
 			<van-tabs class="test-type" animated>
 				<van-tab :title="sujectItem.name" v-for="(sujectItem, index) in carTypeItem.sujectList" :key="index" :name="sujectItem.name">
-					<component :is="sujectOne" :query="{ ...carTypeItem.query, ...sujectItem.query,title:'模拟考试' }"></component>
+					<component v-if="index == 0" :is="sujectOne" :query="{ ...carTypeItem.query, ...sujectItem.query, title: '模拟考试' }"></component>
+					<sujectTwo v-if="index == 1" :is="sujectTwo" :query="{ ...carTypeItem.query, ...sujectItem.query, title: '模拟考试' }"></sujectTwo>
+					<sujectThree v-if="index == 2" :is="sujectThree" :query="{ ...carTypeItem.query, ...sujectItem.query, title: '模拟考试' }"></sujectThree>
+					<component v-if="index == 3" :is="sujectOne" :query="{ ...carTypeItem.query, ...sujectItem.query, title: '模拟考试' }"></component>
 				</van-tab>
 			</van-tabs>
 		</van-tab>
@@ -24,17 +27,46 @@
 
 <script lang="ts" setup>
 import sujectOne from "./components/sujectOne.vue";
+import sujectTwo from "./components/sujectTwo.vue";
+import sujectThree from "./components/sujectThree.vue";
 import userData from "./components/userData.vue";
 import swiper from "./components/swiper.vue";
 import { ref, nextTick, onBeforeMount } from "vue";
 import { useLogin, useUpdateUserInfo } from "@/hooks";
 import { useStore } from "vuex";
+import useWxSign from '@/hooks/wx/sign'
 import { Toast } from "vant";
 import { useRouter } from "vue-router";
+import { openApi } from "@/api/index";
+import wx from "weixin-js-sdk-ts";
 const store = useStore();
 const carTypeRef = ref<any>(null);
+const { createWxConfig } = useWxSign()
+	openApi
+			.jspapi({
+				url: window.location.href,
+		
+			})
+			.then((res) => {
+				// let wxConfig = {
+				// 	debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印
+				// 	appId: res.data.data.appId as string, // 必填,公众号的唯一标识
+				// 	timestamp: res.data.data.timestamp as number, // 必填,生成签名的时间戳
+				// 	nonceStr: res.data.data.nonceStr as string, // 必填,生成签名的随机串
+				// 	signature: res.data.data.signature as string, // 必填,签名
+				// 	jsApiList: ["previewImage"], // 必填,需要使用的JS接口列表
+				// 	openTagList: ["wx-open-launch-weapp"], // 可选,需要使用的开放标签列表,例如['wx-open-launch-app']
+				// };
+				wx.config({
+					debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印
+					appId: res.data.data.appId as string, // 必填,公众号的唯一标识
+					...createWxConfig(res.data.data.ticket as string),
+					jsApiList: ["previewImage"], // 必填,需要使用的JS接口列表
+					openTagList: ["wx-open-launch-weapp"], // 可选,需要使用的开放标签列表,例如['wx-open-launch-app']
+				});
+			});
 //打印环境变量
-console.log(import.meta.env.MODE,"环境变量");
+console.log(import.meta.env.MODE, "环境变量");
 nextTick(() => {
 	carTypeRef.value.scrollTo(store.state.carType);
 });
@@ -62,24 +94,24 @@ const carTypeList = ref([
 					subject: 1,
 				},
 			},
-			// {
-			// 	name: "科目二",
-			// 	query: {
-			// 		name: "科目二",
-			// 		cert: "C1/C2/C3",
-			// 		vehicle: "小车",
-			// 		subject: 2,
-			// 	},
-			// },
-			// {
-			// 	name: "科目三",
-			// 	query: {
-			// 		name: "科目三",
-			// 		cert: "C1/C2/C3",
-			// 		vehicle: "小车",
-			// 		subject: 3,
-			// 	},
-			// },
+			{
+				name: "科目二",
+				query: {
+					name: "科目二",
+					cert: "C1/C2/C3",
+					vehicle: "小车",
+					subject: 2,
+				},
+			},
+			{
+				name: "科目三",
+				query: {
+					name: "科目三",
+					cert: "C1/C2/C3",
+					vehicle: "小车",
+					subject: 3,
+				},
+			},
 			{
 				name: "科目四",
 				query: {
@@ -106,6 +138,24 @@ const carTypeList = ref([
 					subject: 1,
 				},
 			},
+			{
+				name: "科目二",
+				query: {
+					name: "科目二",
+					cert: "A1/A3/B1",
+					vehicle: "客车",
+					subject: 1,
+				},
+			},
+			{
+				name: "科目三",
+				query: {
+					name: "科目三",
+					cert: "A1/A3/B1",
+					vehicle: "客车",
+					subject: 4,
+				},
+			},
 			{
 				name: "科目四",
 				query: {
@@ -132,6 +182,24 @@ const carTypeList = ref([
 					subject: 1,
 				},
 			},
+			{
+				name: "科目二",
+				query: {
+					name: "科目二",
+					cert: "A2/B2",
+					vehicle: "货车",
+					subject: 2,
+				},
+			},
+			{
+				name: "科目三",
+				query: {
+					name: "科目三",
+					cert: "A2/B2",
+					vehicle: "货车",
+					subject: 3,
+				},
+			},
 			{
 				name: "科目四",
 				query: {
@@ -158,6 +226,24 @@ const carTypeList = ref([
 					subject: 1,
 				},
 			},
+			{
+				name: "科目二",
+				query: {
+					name: "科目二",
+					cert: "D/E/F",
+					vehicle: "摩托车",
+					subject: 2,
+				},
+			},
+			{
+				name: "科目三",
+				query: {
+					name: "科目三",
+					cert: "D/E/F",
+					vehicle: "摩托车",
+					subject: 3,
+				},
+			},
 			{
 				name: "科目四",
 				query: {