Ver código fonte

📦 页面分享功能添加

imengyu 2 semanas atrás
pai
commit
4c8583a95a

+ 1 - 0
src/common/config/AppCofig.ts

@@ -8,6 +8,7 @@ export default {
   amapKey: '34eb1d57f93720a871bd11a90af0c91c',
   defaultLonLat: [ 118.161270, 24.529196 ],
   defaultImage: 'https://mncdn.wenlvti.net/app_static/minnan/EmptyImage.png',
+  shareTitle: '',
 }
 
 /**

+ 6 - 0
src/common/utils/PageAction.ts

@@ -85,6 +85,12 @@ export {
   callPrevOnPageBack,
 }
 
+export function getCurrentPageUrl() {
+  const pages = getCurrentPages();
+  const currentPagePath = pages[pages.length - 1].route
+  return currentPagePath
+}
+
 export default {
   install(app: App<Element>) : void {
     app.config.globalProperties.$p = {

+ 15 - 0
src/pages/article/common/DetailTabPage.vue

@@ -113,6 +113,8 @@ import ImageSwiper from "@/pages/parts/ImageSwiper.vue";
 import ContentNote from "@/pages/parts/ContentNote.vue";
 import commonParserStyle from "@/common/style/commonParserStyle";
 import type { PropType, Ref } from "vue";
+import { onShareAppMessage } from "@dcloudio/uni-app";
+import { getCurrentPageUrl } from "@/common/utils/PageAction";
 
 const props = defineProps({
   load: {
@@ -186,6 +188,19 @@ const {
 
 useLoadQuerys({ id : 0 }, (p) => loader.loadData(p));
 
+defineExpose({
+  getPageShareData() {
+    const content = loader.content.value;
+    if (!content)
+      return {};
+    const res = {
+      title: content.title,
+      path: `${getCurrentPageUrl()}?id=${content.id}`,
+      imageUrl: content.image,
+    };
+    return res;
+  } 
+})
 </script>
 
 <style lang="scss">

+ 18 - 2
src/pages/article/details.vue

@@ -64,13 +64,14 @@
 
 <script setup lang="ts">
 import type { GetContentDetailItem } from "@/api/CommonContent";
-import { useSimplePageContentLoader } from "@/common/composeabe/SimplePageContentLoader";
+import { onShareTimeline, onShareAppMessage } from "@dcloudio/uni-app";
 import { DataDateUtils } from "@imengyu/js-request-transform";
+import { useSimplePageContentLoader } from "@/common/composeabe/SimplePageContentLoader";
+import { useSwiperImagePreview } from "@/common/composeabe/SwiperImagePreview";
 import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
 import NewsIndexContent from "@/api/news/NewsIndexContent";
 import commonParserStyle from "@/common/style/commonParserStyle";
 import SimplePageContentLoader from "@/common/components/SimplePageContentLoader.vue";
-import { useSwiperImagePreview } from "@/common/composeabe/SwiperImagePreview";
 import ContentNote from "../parts/ContentNote.vue";
 
 const loader = useSimplePageContentLoader<
@@ -88,6 +89,21 @@ const loader = useSimplePageContentLoader<
 const { onPreviewImage } = useSwiperImagePreview(() => loader.content.value?.images || [])
 
 useLoadQuerys({ id : 0, }, (p) => loader.loadData(p));
+
+function getPageShareData() {
+  if (!loader.content.value)
+    return { title: '文章详情', imageUrl: '' }
+  return {
+    title: loader.content.value.title,
+    imageUrl: loader.content.value.images[0],
+  }
+}
+onShareTimeline(() => {
+  return getPageShareData(); 
+})
+onShareAppMessage(() => {
+  return getPageShareData();
+})
 </script>
 
 <style lang="scss" scoped>

+ 8 - 0
src/pages/discover.vue

@@ -144,6 +144,7 @@ import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
 import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
 import { useHomePageMiniCommonListGoMoreAndGoDetail } from './article/common/CommonContent';
 import NewsIndexContent from '@/api/news/NewsIndexContent';
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
 
 const CategoryIcon1 = 'https://mncdn.wenlvti.net/app_static/minnan/images/discover/CategoryIcon1.png';
 const CategoryIcon2 = 'https://mncdn.wenlvti.net/app_static/minnan/images/discover/CategoryIcon2.png';
@@ -310,6 +311,13 @@ const topicsData = useSimpleDataLoader(async () => {
     },
   ]
 });
+
+onShareTimeline(() => {
+  return {}; 
+})
+onShareAppMessage(() => {
+  return {}; 
+})
 </script>
 
 <style lang="scss">

+ 7 - 0
src/pages/home.vue

@@ -206,6 +206,7 @@ import HomeTitle from '@/pages/parts/HomeTitle.vue';
 import Tabbar from '@/common/components/tabs/tabbar.vue';
 import Box1AudioPlay from '@/pages/parts/Box1AudioPlay.vue';
 import SimplePageContentLoader from "@/common/components/SimplePageContentLoader.vue";
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
 
 const subTabs = [
   { 
@@ -464,6 +465,12 @@ function handleGoDetails(item: any) {
   }
 }
 
+onShareTimeline(() => {
+  return {}; 
+})
+onShareAppMessage(() => {
+  return {}; 
+})
 </script>
 
 <style lang="scss">

+ 7 - 0
src/pages/inhert.vue

@@ -216,6 +216,7 @@ import UnmoveableContent from '@/api/inheritor/UnmoveableContent';
 import { useHomePageMiniCommonListGoMoreAndGoDetail } from './article/common/CommonContent';
 import ProductsContent from '@/api/inheritor/ProductsContent';
 import InheritorContent from '@/api/inheritor/InheritorContent';
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
 
 const artifactData = useSimpleDataLoader(async () => 
   (await UnmoveableContent.getContentList(new GetContentListParams(), 1, 4)).list.map(p => ({
@@ -339,6 +340,12 @@ const {
   detailsPage: '/pages/article/details',
 });
 
+onShareTimeline(() => {
+  return {}; 
+})
+onShareAppMessage(() => {
+  return {}; 
+})
 </script>
 
 <style lang="scss">

+ 12 - 1
src/pages/inhert/artifact/details.vue

@@ -1,5 +1,6 @@
 <template>
   <DetailTabPage
+    ref="pageRef"
     :load="load"
     :extraTabs="[
       {
@@ -92,12 +93,13 @@
 </template>
 <script setup lang="ts">
 import type { TabControlItem } from "@/common/composeabe/TabControl";
-import type { Ref } from "vue";
+import { ref, type Ref } from "vue";
 import { navTo } from "@/common/utils/PageAction";
 import UnmoveableContent from "@/api/inheritor/UnmoveableContent";
 import commonParserStyle from "@/common/style/commonParserStyle";
 import IntroBlock from "@/pages/article/common/IntroBlock.vue";
 import DetailTabPage from "@/pages/article/common/DetailTabPage.vue";
+import { onShareTimeline, onShareAppMessage } from "@dcloudio/uni-app";
 
 async function load(id: number, tabsArray: Ref<TabControlItem[]>) {
   const d = await UnmoveableContent.getContentDetail(id);
@@ -117,4 +119,13 @@ function handleNavTo(content: any) {
     longitude: content?.longitude,  
   }) 
 }
+
+const pageRef = ref();
+
+onShareTimeline(() => {
+  return pageRef.value?.getPageShareData() || {}; 
+})
+onShareAppMessage(() => {
+  return pageRef.value?.getPageShareData() || {};
+})
 </script>

+ 7 - 5
src/pages/inhert/artifact/list.vue

@@ -1,7 +1,7 @@
 <template>
   <view class="d-flex flex-column bg-base">
 
-    <view class="top-tab">
+    <view class="top-tab bg-base">
       <u-tabs 
         :list="tabs" 
         lineWidth="30"
@@ -82,10 +82,12 @@ const levelData = useSimpleDataLoader(async () =>
   [{
     id: 0, 
     name: '全部级别'
-  }].concat((await CommonContent.getCategoryList(2)).map((item) => ({
-    id: item.id,
-    name: item.title,
-  })))
+  }].concat(
+    (await CommonContent.getCategoryList(2)).map((item) => ({
+      id: item.id,
+      name: item.title,
+    })).filter((item) => !item.name.includes('非'))
+  )
 , true);
 const regionData = useSimpleDataLoader(async () => 
   [{

+ 14 - 1
src/pages/inhert/inheritor/details.vue

@@ -1,5 +1,6 @@
 <template>
   <DetailTabPage
+    ref="pageRef"
     :load="load"
     :extraTabs="[
       {
@@ -117,7 +118,8 @@
 </template>
 <script setup lang="ts">
 import type { TabControlItem } from "@/common/composeabe/TabControl";
-import type { Ref } from "vue";
+import { ref, type Ref } from "vue";
+import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
 import RoundTags from "@/pages/parts/RoundTags.vue";
 import commonParserStyle from "@/common/style/commonParserStyle";
 import SeminarContent from "@/api/inheritor/SeminarContent";
@@ -150,6 +152,17 @@ async function loadSubList(page: number, pageSize: number, content: any, subList
     total: list.length,
   }
 }
+
+
+const pageRef = ref();
+
+onShareTimeline(() => {
+  return pageRef.value?.getPageShareData() || {}; 
+})
+onShareAppMessage(() => {
+  return pageRef.value?.getPageShareData() || {};
+})
+
 </script>
 
 <style lang="scss">

+ 10 - 1
src/pages/inhert/intangible/DetailsCommon.vue

@@ -1,5 +1,6 @@
 <template>
   <DetailTabPage
+    ref="page"
     :load="load"
     :extraTabs="[
       {
@@ -150,7 +151,7 @@ import CommonListPage from "@/pages/article/common/CommonListPage.vue";
 import IntroBlock from "@/pages/article/common/IntroBlock.vue";
 import { useLoadQuerys } from "@/common/composeabe/LoadQuerys";
 import type { TabControlItem } from "@/common/composeabe/TabControl";
-import type { Ref } from "vue";
+import { ref, type Ref } from "vue";
 import { navTo } from "@/common/utils/PageAction";
 import InheritorContent from "@/api/inheritor/InheritorContent";
 import ProductsContent from "@/api/inheritor/ProductsContent";
@@ -214,7 +215,15 @@ async function loadSubList(page: number, pageSize: number, content: any, subList
   }
 }
 
+const page = ref();
+
 const { querys } = useLoadQuerys({ modelId: 0 })
+
+defineExpose({
+  getPageShareData() {
+    return page.value.getPageShareData();
+  } 
+})
 </script>
 
 <style lang="scss">

+ 12 - 1
src/pages/inhert/intangible/details.vue

@@ -1,7 +1,18 @@
 <template>
-  <DetailsCommon commonRefName="作品" commonRefTarget="product" />
+  <DetailsCommon ref="pageRef" commonRefName="作品" commonRefTarget="product" />
 </template>
 
 <script setup lang="ts">
+import { ref } from 'vue';
 import DetailsCommon from './DetailsCommon.vue';
+import { onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app';
+
+const pageRef = ref();
+
+onShareTimeline(() => {
+  return pageRef.value?.getPageShareData() || {}; 
+})
+onShareAppMessage(() => {
+  return pageRef.value?.getPageShareData() || {};
+})
 </script>

+ 12 - 1
src/pages/inhert/product/details.vue

@@ -1,7 +1,18 @@
 <template>
-  <DetailsCommon commonRefName="相关项目" commonRefTarget="intangible" />
+  <DetailsCommon ref="pageRef" commonRefName="相关项目" commonRefTarget="intangible" />
 </template>
 
 <script setup lang="ts">
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
+import { ref } from 'vue';
 import DetailsCommon from '../intangible/DetailsCommon.vue';
+
+const pageRef = ref();
+
+onShareTimeline(() => {
+  return pageRef.value?.getPageShareData() || {}; 
+})
+onShareAppMessage(() => {
+  return pageRef.value?.getPageShareData() || {};
+})
 </script>

+ 12 - 1
src/pages/inhert/seminar/details.vue

@@ -1,7 +1,18 @@
 <template>
-  <DetailsCommon commonRefName="相关项目" commonRefTarget="intangible" />
+  <DetailsCommon ref="pageRef" commonRefName="相关项目" commonRefTarget="intangible" />
 </template>
 
 <script setup lang="ts">
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
+import { ref } from 'vue';
 import DetailsCommon from '../intangible/DetailsCommon.vue';
+
+const pageRef = ref();
+
+onShareTimeline(() => {
+  return pageRef.value?.getPageShareData() || {}; 
+})
+onShareAppMessage(() => {
+  return pageRef.value?.getPageShareData() || {};
+})
 </script>

+ 14 - 0
src/pages/inhert/village/details.vue

@@ -130,6 +130,7 @@ import { useHomePageMiniCommonListGoMoreAndGoDetail, type IHomePageMiniCommonLis
 import ContentNote from '@/pages/parts/ContentNote.vue';
 import IntroBlock from '@/pages/article/common/IntroBlock.vue';
 import ImagesUrls from '@/common/config/ImagesUrls';
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
 
 const EmptyImage = 'https://mncdn.wenlvti.net/app_static/minnan/EmptyImage.png';
 
@@ -229,4 +230,17 @@ const contentLoader = useSimpleDataLoader(async () => {
   });
 }, false);
 
+
+function getPageShareData() {
+  return {
+    title: data.value.villageName,
+    imageUrl: data.value.images[0],
+  }
+}
+onShareTimeline(() => {
+  return getPageShareData(); 
+})
+onShareAppMessage(() => {
+  return getPageShareData();
+})
 </script>

+ 7 - 0
src/pages/travel.vue

@@ -128,6 +128,7 @@ import { useHomePageMiniCommonListGoMoreAndGoDetail } from './article/common/Com
 import { useSimpleDataLoader } from '@/common/composeabe/SimpleDataLoader';
 import { navTo } from '@/common/utils/PageAction';
 import SimplePageContentLoader from '@/common/components/SimplePageContentLoader.vue';
+import { onShareTimeline, onShareAppMessage } from '@dcloudio/uni-app';
 
 const CategoryIcon1 = 'https://mncdn.wenlvti.net/app_static/minnan/images/travel/CategoryIcon1.png';
 const CategoryIcon2 = 'https://mncdn.wenlvti.net/app_static/minnan/images/travel/CategoryIcon2.png';
@@ -248,6 +249,12 @@ const activityData = useSimpleDataLoader(async () => [
   },
 ]);
 
+onShareTimeline(() => {
+  return {}; 
+})
+onShareAppMessage(() => {
+  return {}; 
+})
 </script>
 
 <style lang="scss">