Browse Source

页面更新

wangxy 2 months ago
parent
commit
cc1b04dd5b
2 changed files with 57 additions and 3 deletions
  1. 19 2
      pages/zsjyShengxue/zsjyShengxue.vue
  2. 38 1
      utils/common.js

+ 19 - 2
pages/zsjyShengxue/zsjyShengxue.vue

@@ -21,7 +21,7 @@
 						<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>
@@ -93,6 +93,23 @@
 		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);
+    }