|
@@ -1,5 +1,5 @@
|
|
|
import { forwardRef, useEffect, useState } from 'react'
|
|
|
-import Taro from '@tarojs/taro'
|
|
|
+import Taro, { useShareAppMessage } from '@tarojs/taro'
|
|
|
import { useDidHide, useDidShow } from '@tarojs/taro'
|
|
|
import { observer, inject } from 'mobx-react'
|
|
|
import { View } from '@tarojs/components'
|
|
@@ -13,6 +13,7 @@ import Empty from '@src/components/Empty'
|
|
|
import { Store } from '@src/app'
|
|
|
import useApi from '@src/Hook/useApi'
|
|
|
import { getBookCategoryList } from '@src/server/classify'
|
|
|
+import { share } from '@src/utils'
|
|
|
|
|
|
|
|
|
interface Props {
|
|
@@ -20,7 +21,7 @@ interface Props {
|
|
|
}
|
|
|
|
|
|
const Index = forwardRef((props: Props) => {
|
|
|
- const { bookStore, classifyStore, indexStore } = props.store
|
|
|
+ const { bookStore, classifyStore, indexStore } = props.store
|
|
|
const { getBookPageList } = useApi()
|
|
|
const [pageShow, setPageShow] = useState(false)//防止小程序切换页面组件不会被真实卸载,阻止不必要的操作
|
|
|
const [isFixed, setIsFixed] = useState(false)
|
|
@@ -81,6 +82,25 @@ const Index = forwardRef((props: Props) => {
|
|
|
const getList = async (params) => {
|
|
|
return getBookPageList(params)
|
|
|
}
|
|
|
+ // 分享
|
|
|
+ useShareAppMessage(async () => {
|
|
|
+ // 获取当前页面栈
|
|
|
+ const pages = Taro.getCurrentPages()
|
|
|
+ // 获取栈顶的页面,即当前页面
|
|
|
+ const currentPage = pages[pages.length - 1]
|
|
|
+ // 获取页面的路径和参数
|
|
|
+ const route = currentPage.route // 页面路径
|
|
|
+ if (route) {
|
|
|
+ let shareInfo = await share({ pagePath: route })
|
|
|
+ let { sharePicUrl, shareTitles, pageName, pagePath } = shareInfo
|
|
|
+ return {
|
|
|
+ title: shareTitles || app.appInfo?.appName + '-' + pageName,
|
|
|
+ path: pagePath || undefined,
|
|
|
+ imageUrl: sharePicUrl || undefined
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {}
|
|
|
+ })
|
|
|
return (
|
|
|
|
|
|
<View className='index'>
|