abpcoder 3 недель назад
Родитель
Сommit
469a7714ec

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

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

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

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

+ 82 - 78
src/pagesMain/pages/index/index.vue

@@ -1,33 +1,34 @@
 <template>
 <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">
-          <view class="text-36 text-fore-title font-bold">{{ orgName }}</view>
-          <view class="w-6 h-6 rounded-2 bg-black mx-12"></view>
-          <view>升学备考好帮手</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">
+                    <view class="text-36 text-fore-title font-bold">{{ orgName }}</view>
+                    <view class="w-6 h-6 rounded-2 bg-black mx-12"></view>
+                    <view>升学备考好帮手</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="14" :color="isTransparent ? '#333' : 'var(--primary-color)'"/>
+                    <text class="text-26" :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-guide @detail="handleDetail"/>
+            <index-news @detail="handleDetail"/>
         </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="14" :color="isTransparent ? '#333' : 'var(--primary-color)'" />
-          <text class="text-26" :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-guide @detail="handleDetail" />
-      <index-news @detail="handleDetail" />
-    </view>
-    <template #tabbar>
-      <ie-tabbar :active="0" />
-      <index-popup ref="popupRef" />
-    </template>
-  </ie-page>
+        <template #tabbar>
+            <ie-tabbar :active="0"/>
+            <index-popup ref="popupRef"/>
+        </template>
+    </ie-page>
 </template>
 </template>
 
 
 <script lang="ts" setup>
 <script lang="ts" setup>
@@ -36,79 +37,82 @@ import IndexGuide from './components/index-guide.vue';
 import IndexNews from './components/index-news.vue';
 import IndexNews from './components/index-news.vue';
 import indexPopup from './components/index-popup.vue';
 import indexPopup from './components/index-popup.vue';
 
 
-import { useUserStore } from '@/store/userStore';
+import {useUserStore} from '@/store/userStore';
 // @ts-ignore
 // @ts-ignore
 import mxConst from '@/common/mxConst';
 import mxConst from '@/common/mxConst';
-import { useTransferPage } from '@/hooks/useTransferPage';
-import { useNavbar } from '@/hooks/useNavbar';
-import { onPageShow } from '@dcloudio/uni-app';
-const { transferTo } = useTransferPage();
-const { baseStickyTop } = useNavbar();
+import {useTransferPage} from '@/hooks/useTransferPage';
+import {useNavbar} from '@/hooks/useNavbar';
+import {onPageShow} from '@dcloudio/uni-app';
+
+const {transferTo} = useTransferPage();
+const {baseStickyTop} = useNavbar();
 const scrollTop = ref(0);
 const scrollTop = ref(0);
 const isHide = ref(false);
 const isHide = ref(false);
 const userStore = useUserStore();
 const userStore = useUserStore();
 const orgName = computed(() => userStore.orgInfo.orgName);
 const orgName = computed(() => userStore.orgInfo.orgName);
 
 
-const handleDetail = async (id: number | string, title?: string) => {
-  if (('' + id).includes(',')) {
-    transferTo(mxConst.routes.newsGroup, {
-      data: {
-        ids: id,
-        title: title
-      }
-    });
-  } else {
-    transferTo(mxConst.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(mxConst.routes.newsGroup, {
+            data: {
+                ids: id,
+                title: title
+            }
+        });
+    } else {
+        transferTo(mxConst.routes.newsDetail, {
+            data: {
+                id: id,
+                title: title
+            }
+        })
+    }
 }
 }
 
 
 const popupRef = ref();
 const popupRef = ref();
 const checkProvinceInfo = () => {
 const checkProvinceInfo = () => {
-  if (!userStore.isLogin && !userStore.tempInfo?.location) {
-    popupRef.value.open();
-  }
+    if (!userStore.isLogin && !userStore.tempInfo?.location) {
+        popupRef.value.open();
+    }
 }
 }
 const checkInfo = async () => {
 const checkInfo = async () => {
-  await userStore.checkInfoTeacherComplete();
-  await userStore.checkInfoStudentComplete();
+    await userStore.checkInfoTeacherComplete();
+    await userStore.checkInfoStudentComplete();
 }
 }
 const reloadUserInfo = async () => {
 const reloadUserInfo = async () => {
-  if (userStore.isLogin) {
-    await userStore.reloadInfo();
-  }
+    if (userStore.isLogin) {
+        await userStore.reloadInfo();
+    }
 }
 }
 const handleChangeLocation = () => {
 const handleChangeLocation = () => {
-  if (userStore.isLogin) {
-    return;
-  }
-  popupRef.value.open();
+    if (userStore.isLogin) {
+        return;
+    }
+    popupRef.value.open();
 }
 }
 onHide(() => {
 onHide(() => {
-  isHide.value = true;
+    isHide.value = true;
 })
 })
 onPageScroll((e) => {
 onPageScroll((e) => {
-  if (!isHide.value) {
-    scrollTop.value = e.scrollTop;
-  }
+    if (!isHide.value) {
+        scrollTop.value = e.scrollTop;
+    }
 });
 });
 onShow(() => {
 onShow(() => {
-  setTimeout(() => {
-    uni.pageScrollTo({
-      scrollTop: scrollTop.value,
-      duration: 0
-    });
-  }, 0);
-  setTimeout(() => {
-    checkProvinceInfo();
-    checkInfo();
-    reloadUserInfo();
-  }, 600);
-  isHide.value = false;
+    setTimeout(() => {
+        uni.pageScrollTo({
+            scrollTop: scrollTop.value,
+            duration: 0
+        });
+    }, 0);
+    setTimeout(() => {
+        checkProvinceInfo();
+        checkInfo();
+        reloadUserInfo();
+    }, 600);
+    isHide.value = false;
 });
 });
 </script>
 </script>
 
 

+ 2 - 0
src/types/news.ts

@@ -5,6 +5,7 @@ export interface Guide {
   subType: string;
   subType: string;
   type: string;
   type: string;
   description: string;
   description: string;
+  url?: string;
 }
 }
 
 
 export interface NewsQueryDTO {
 export interface NewsQueryDTO {
@@ -22,5 +23,6 @@ export interface News {
   title: string;
   title: string;
   type: string;
   type: string;
   sendDate: string;
   sendDate: string;
+  url?: string;
 }
 }
 
 

+ 47 - 0
src/utils/uni-tool.ts

@@ -86,6 +86,8 @@ export interface IeTool {
    * @returns 格式化后的时间
    * @returns 格式化后的时间
    */
    */
   formatTime(time: number | string, format: string): string;
   formatTime(time: number | string, format: string): string;
+
+  openBrowser(url: string): void;
 }
 }
 
 
 const defaultModalOptions: IModalOptions = {
 const defaultModalOptions: IModalOptions = {
@@ -179,6 +181,51 @@ const tool: IeTool = {
     }
     }
     // @ts-ignore
     // @ts-ignore
     return uni.$uv.timeFormat(time, format)
     return uni.$uv.timeFormat(time, format)
+  },
+  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
+    // 微信小程序
+    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
+    handleCopy()
+    // #endif
   }
   }
 };
 };