abpcoder il y a 3 semaines
Parent
commit
0952b8bdc9

+ 2 - 2
src/pagesMain/pages/index/components/index-guide.vue

@@ -58,11 +58,11 @@ const handleChange = (e: any) => {
 }
 
 const emit = defineEmits<{
-  detail: [id: number | string, title: string]
+  detail: [id: number | string, title: string, url: string|undefined]
 }>();
 
 const handleClick = async (data: Guide) => {
-  emit('detail', data.refIds, data.subType);
+  emit('detail', data.refIds, data.subType, data.url);
 }
 
 const loadData = () => {

+ 2 - 2
src/pagesMain/pages/index/components/index-news.vue

@@ -15,11 +15,11 @@ import { NewsItem } from '@/types/news';
 const newsList = ref<NewsItem[]>([]);
 
 const emit = defineEmits<{
-  detail: [id: number | string]
+  detail: [id: number | string, title: string|null, url: string|undefined]
 }>();
 
 const handleClick = async (data: NewsItem) => {
-  emit('detail', data.id);
+  emit('detail', data.id, null, data.url);
 }
 const loadData = async () => {
   const { rows } = await getNewsListNoToken({

+ 86 - 83
src/pagesMain/pages/index/index.vue

@@ -1,33 +1,34 @@
 <template>
-  <ie-page bg-color="white">
-    <ie-navbar transparent bg-color="#FFFFFF" :placeholder="false" custom-back :click-hover="false">
-      <template #headerLeft>
-        <view class="flex items-center gap-7 text-fore-title">
-          <view class="text-38 font-bold">{{ orgName }}</view>
+    <ie-page bg-color="white">
+        <ie-navbar transparent bg-color="#FFFFFF" :placeholder="false" custom-back :click-hover="false">
+            <template #headerLeft>
+                <view class="flex items-center gap-7 text-fore-title">
+                    <view class="text-38 font-bold">{{ orgName }}</view>
+                </view>
+            </template>
+            <template #headerRight="{ isTransparent }">
+                <view v-if="userStore.getLocation" class="ml-10 flex items-center gap-x-4"
+                      @click="handleChangeLocation">
+                    <uv-icon name="map" size="16" :color="isTransparent ? '#333' : 'var(--primary-color)'"/>
+                    <text class="text-30 font-medium" :class="[isTransparent ? 'text-fore-title' : 'text-primary']">
+                        {{ userStore.getLocation }}
+                    </text>
+                </view>
+            </template>
+        </ie-navbar>
+        <view class="absolute top-0 left-0 right-0 z-0 h-[489rpx] bg-gradient-to-b from-[#6ACAFF] to-white"></view>
+        <view class="relative z-2" :style="{ paddingTop: baseStickyTop + 10 + 'px' }">
+            <index-banner/>
+            <index-map/>
+            <index-guide v-if="false" @detail="handleDetail"/>
+            <index-news @detail="handleDetail"/>
         </view>
-      </template>
-      <template #headerRight="{ isTransparent }">
-        <view v-if="userStore.getLocation" class="ml-10 flex items-center gap-x-4" @click="handleChangeLocation">
-          <uv-icon name="map" size="16" :color="isTransparent ? '#333' : 'var(--primary-color)'" />
-          <text class="text-30 font-medium" :class="[isTransparent ? 'text-fore-title' : 'text-primary']">
-            {{ userStore.getLocation }}
-          </text>
-        </view>
-      </template>
-    </ie-navbar>
-    <view class="absolute top-0 left-0 right-0 z-0 h-[489rpx] bg-gradient-to-b from-[#6ACAFF] to-white"></view>
-    <view class="relative z-2" :style="{ paddingTop: baseStickyTop + 10 + 'px' }">
-      <index-banner />
-      <index-map />
-      <index-guide v-if="false" @detail="handleDetail" />
-      <index-news @detail="handleDetail" />
-    </view>
-    <template #tabbar>
-      <ie-tabbar :active="0" />
-      <index-popup ref="popupRef" />
-      <index-maintain-popup ref="maintainPopupRef" />
-    </template>
-  </ie-page>
+        <template #tabbar>
+            <ie-tabbar :active="0"/>
+            <index-popup ref="popupRef"/>
+            <index-maintain-popup ref="maintainPopupRef"/>
+        </template>
+    </ie-page>
 </template>
 
 <script lang="ts" setup>
@@ -38,88 +39,90 @@ import IndexMap from "./components/index-map.vue";
 import indexPopup from './components/index-popup.vue';
 import indexMaintainPopup from './components/index-maintain-popup.vue';
 
-import { useUserStore } from '@/store/userStore';
+import {useUserStore} from '@/store/userStore';
 // @ts-ignore
-import { useTransferPage } from '@/hooks/useTransferPage';
-import { useAppStore } from '@/store/appStore';
-import { useNavbar } from '@/hooks/useNavbar';
-import { onPageShow } from '@dcloudio/uni-app';
+import {useTransferPage} from '@/hooks/useTransferPage';
+import {useAppStore} from '@/store/appStore';
+import {useNavbar} from '@/hooks/useNavbar';
+import {onPageShow} from '@dcloudio/uni-app';
 
 const appStore = useAppStore();
-const { routes, transferTo } = useTransferPage();
-const { baseStickyTop } = useNavbar();
+const {routes, transferTo} = useTransferPage();
+const {baseStickyTop} = useNavbar();
 const scrollTop = ref(0);
 const isHide = ref(false);
 const userStore = useUserStore();
 const orgName = computed(() => userStore.orgInfo.orgName);
 
-const handleDetail = async (id: number | string, title?: string) => {
-  if (('' + id).includes(',')) {
-    transferTo(routes.newsGroup, {
-      data: {
-        ids: id,
-        title: title
-      }
-    });
-  } else {
-    transferTo(routes.newsDetail, {
-      data: {
-        id: id,
-        title: title
-      }
-    })
-  }
+const handleDetail = async (id: number | string, title?: string, url?: string) => {
+    if (url) {
+        uni.$ie.openBrowser(url)
+    } else if (('' + id).includes(',')) {
+        transferTo(routes.newsGroup, {
+            data: {
+                ids: id,
+                title: title
+            }
+        });
+    } else {
+        transferTo(routes.newsDetail, {
+            data: {
+                id: id,
+                title: title
+            }
+        })
+    }
 }
 
 const popupRef = ref();
 const checkProvinceInfo = () => {
-  if (!userStore.isLogin && !userStore.tempInfo?.location) {
-    popupRef.value.open();
-  }
+    if (!userStore.isLogin && !userStore.tempInfo?.location) {
+        popupRef.value.open();
+    }
 }
 const checkInfo = async () => {
-  await userStore.checkInfoTeacherComplete();
-  await userStore.checkInfoStudentComplete();
+    await userStore.checkInfoTeacherComplete();
+    await userStore.checkInfoStudentComplete();
 }
 const reloadUserInfo = async () => {
-  if (userStore.isLogin) {
-    await userStore.getUserInfo();
-  }
+    if (userStore.isLogin) {
+        await userStore.getUserInfo();
+    }
 }
 const handleChangeLocation = () => {
-  if (userStore.isLogin) {
-    return;
-  }
-  popupRef.value.open();
+    if (userStore.isLogin) {
+        return;
+    }
+    popupRef.value.open();
 }
 onHide(() => {
-  isHide.value = true;
+    isHide.value = true;
 })
 onPageScroll((e) => {
-  if (!isHide.value) {
-    scrollTop.value = e.scrollTop;
-  }
+    if (!isHide.value) {
+        scrollTop.value = e.scrollTop;
+    }
 });
 const maintainPopupRef = ref();
 onMounted(async () => {
-  if (appStore.hasMaintain && !appStore.maintainNotice!.read) {
-    await uni.$uv.sleep(500);
-    await maintainPopupRef.value?.open();
-  }
-  checkProvinceInfo();
-  if (userStore.isLogin) {
-    checkInfo();
-    userStore.getDirectedSchoolList();
-  }
+    if (appStore.hasMaintain && !appStore.maintainNotice!.read) {
+        await uni.$uv.sleep(500);
+        await maintainPopupRef.value?.open();
+    }
+    checkProvinceInfo();
+    if (userStore.isLogin) {
+        checkInfo();
+        userStore.getDirectedSchoolList();
+    }
 });
 onShow(() => {
-  setTimeout(() => {
-    uni.pageScrollTo({
-      scrollTop: scrollTop.value,
-      duration: 0
-    });
-  }, 0);
-  isHide.value = false;
+    setTimeout(() => {
+        uni.pageScrollTo({
+            scrollTop: scrollTop.value,
+            duration: 0
+        });
+    }, 0);
+    isHide.value = false;
 });
 </script>
 

+ 2 - 0
src/types/news.ts

@@ -5,6 +5,7 @@ export interface Guide {
   subType: string;
   type: string;
   description: string;
+  url?: string;
 }
 
 export interface NewsQueryDTO {
@@ -29,5 +30,6 @@ export interface NewsItem {
   title: string;
   type: string;
   sendDate: string;
+  url?: string;
 }
 

+ 28 - 19
src/utils/uni-tool.ts

@@ -188,39 +188,48 @@ const tool: IeTool = {
     });
   },
   openBrowser(url: string) {
+    const handleCopy = function () {
+      uni.setClipboardData({
+        data: url,
+        success: () => {
+          uni.showModal({
+            title: '提示',
+            content: '链接已复制,请在浏览器中打开',
+            showCancel: false
+          })
+        }
+      })
+    }
     // 判断平台
+    // #ifdef APP-PLUS
+    plus.runtime.openURL(url)
+    // #endif
+
     // #ifdef H5
     window.open(url, '_blank')
     // #endif
 
     // #ifdef MP-WEIXIN
     // 微信小程序
-    uni.setClipboardData({
-      data: url,
-      showToast: false,
-      success: () => {
-        uni.showModal({
-          title: '提示',
-          content: '链接已复制,请在浏览器中打开',
-          showCancel: false
+    try {
+      if (url.toLowerCase().startsWith('https://mp.weixin.qq.com/')) {
+        uni.openOfficialAccountArticle({
+          url,
+          fail: handleCopy
         })
+      } else {
+        handleCopy()
       }
-    })
+    } catch (e){
+      console.log('小程序打开链接降级处理', e)
+      handleCopy()
+    }
     // #endif
 
     // 其他平台,如App、快应用等,可以根据需要补充
     // 对于不支持直接打开浏览器的平台,使用降级方案
     // #ifndef H5 || MP-WEIXIN
-    uni.setClipboardData({
-      data: url,
-      success: () => {
-        uni.showModal({
-          title: '提示',
-          content: '链接已复制,请在浏览器中打开',
-          showCancel: false
-        })
-      }
-    })
+    handleCopy()
     // #endif
   }
 };