Ver código fonte

Merge branch '大连交通技师学院' of https://gogs.mtavip.com/wangguoyu/uniProject into 大连交通技师学院

tanxue 2 meses atrás
pai
commit
a7907d5e0c
4 arquivos alterados com 77 adições e 13 exclusões
  1. 10 5
      components/MtaPDF.vue
  2. 5 3
      manifest.json
  3. 24 4
      pages/zsjyShengxue/zsjyShengxue.vue
  4. 38 1
      utils/common.js

+ 10 - 5
components/MtaPDF.vue

@@ -5,7 +5,8 @@
 	<uni-popup class="dljt-pdf-popup" ref="popup" type="bottom" background-color="#fff" :mask-click="false" :animation="false">
 		<view class="pdf-popup-box">
 			<uni-nav-bar class="pdf-return-btn" shadow left-icon="left" title="PDF预览" @clickLeft="handleBack" />
-			<web-view class="dljt-pdf-view" :src="pdfUrl1" v-if="showPdfUrl" ></web-view>
+			<web-view class="dljt-pdf-view" :src="pdfUrl1" v-if="showPdfUrl" >
+			</web-view>
 		</view>
 	</uni-popup>
 
@@ -14,8 +15,9 @@
 <script setup>
 	import {
 		nextTick,
-		ref
+		ref,
 	} from "vue"
+	import {addClassToWebViewIframe}from "@/utils/common.js"
 	const props = defineProps({
 		pdfUrl: {
 			type: String
@@ -25,21 +27,24 @@
 	let pdfUrl1 = '';
 	const popup = ref(null)
 
-  const emits = defineEmits(['showNav'])
+	const emits = defineEmits(['showNav'])
 
 	function handleOpen() {
 		popup.value.open('bottom')
 		pdfUrl1 = `/hybrid/html/web/viewer.html?file=${encodeURIComponent(props.pdfUrl)}`;
 		setTimeout(() => {
 			showPdfUrl.value = true;
-      emits('showNav', false)
+			emits('showNav', false)
+			setTimeout(() => {
+				addClassToWebViewIframe()
+			},10)
 		}, 50)
 	}
 
 	function handleBack() {
 		popup.value.close()
 		showPdfUrl.value = false;
-    emits('showNav', true)
+		emits('showNav', true)
 	}
 </script>
 

+ 5 - 3
manifest.json

@@ -71,10 +71,12 @@
     "vueVersion" : "3",
     "h5" : {
         "router" : {
-            "mode" : "history",
-            "base" : "/mdist"
+            "mode" : "hash",
+            "base" : "./"
         },
         "title" : "大连交通技师学院",
         "template" : "template.h5.html"
-    }
+    },
+    "fallbackLocale" : "zh-Hans",
+    "locale" : "zh-Hans"
 }

+ 24 - 4
pages/zsjyShengxue/zsjyShengxue.vue

@@ -15,13 +15,13 @@
 				<view class="dljt-detail-box">
 					<view class="dljt-editor-box">
 						<view class="dljt-classify-box">
-							<view class="classify-item" v-for="item in data.list" :key="item.title" @click="handleSelect(item)">{{item.title}}</view>
+							<view class="classify-item" :class="{active: data.activeId == item.id}" v-for="item in data.list" :key="item.title" @click="handleSelect(item)">{{item.title}}</view>
 						</view>
 						<!-- 富文本 -->
 						<MtaMpHtml class="dljt-editor-box" :content="data.activeData.content" ></MtaMpHtml>
 						
 						<!-- 链接 -->
-						<view class="dljt-link-box">
+						<view class="dljt-link-box" v-if="isHasLink(data.activeData.link)">
 							<view class="link-item-box" v-for="cItem in data.activeData.link">
 								<icon></icon>
 								<a :href="cItem.url">{{cItem.name}}</a>
@@ -29,7 +29,7 @@
 							</view>
 						</view>
 						<!-- table -->
-						<view class="dljt-table-box">
+						<view class="dljt-table-box" v-if="isHasLink(data.activeData.ziliao)">
 							<view class="table-th-row">
 								<view style="width: 15%">序号</view>
 								<view style="width: 60%">资料名称</view>
@@ -67,7 +67,7 @@
 	const data = reactive({
 		list: null,
 		activeId: null,
-		activeData: null
+		activeData: {}
 	})
 
 	onLoad(() => {
@@ -84,12 +84,32 @@
 
 	function handleSelect(item) {
 		data.activeId = item.id;
+		httpApi.getCommonZSJYZhuanyeInfo({id: data.activeId}).then(res => {
+			data.activeData = res.data;
+		})
 	}
 	
 	function handleDownFile(ccite) {
 		window.location.href = ccite.url;
 	}
 
+  function isHasLink(list) {
+    if (!list) {
+      return false;
+    }
+    if (list.length>1) {
+      return true
+    }
+    if (list.length == 0 ) {
+      return false
+    }
+    if (list.length == 1 && list[0].name && list[0].url) {
+      return true
+    }
+
+    return false
+  }
+
 	
 	function pageInit() {
 		httpApi.getCommonZSJYShengxueList({page:data.page,size:data.size}).then(res => {

+ 38 - 1
utils/common.js

@@ -69,4 +69,41 @@ export function getStringByHtml3(html) {
 		.replace(/>/g, ' ')
 		.replace(/<?img[^>]*>/g, '')
 		.replace(/<video[^>]*>.*?<\/video>/gi, '') : '';
-}
+}
+
+
+// 在页面/组件的 onReady 或 mounted 生命周期中添加
+export function addClassToWebViewIframe() {
+      const targetSrc = "/hybrid/html/web/viewer.html"; // 替换为你的 WebView URL
+      const className = "custom-iframe-class"; // 要添加的类名
+
+      // 检查是否已存在目标 iframe
+      const existingIframe = Array.from(document.querySelectorAll('iframe')).find(
+        iframe => iframe.src.includes(targetSrc)
+      );
+      if (existingIframe) {
+        existingIframe.classList.add(className);
+        return;
+      }
+
+      // 使用 MutationObserver 监听新增 iframe
+      const observer = new MutationObserver(mutations => {
+        mutations.forEach(mutation => {
+          mutation.addedNodes.forEach(node => {
+            if (node.tagName === 'IFRAME' && node.src.includes(targetSrc)) {
+              node.classList.add(className);
+              observer.disconnect(); // 找到后停止监听
+            }
+          });
+        });
+      });
+
+      // 监听整个 body 的子元素变化
+      observer.observe(document.body, {
+        childList: true,
+        subtree: false
+      });
+
+      // 设置超时停止监听(防止内存泄漏)
+      setTimeout(() => observer.disconnect(), 5000);
+    }