import {Headphones, Share} from '@nutui/icons-react-taro' import navTo from "@/utils/common"; import Taro, { getCurrentInstance } from '@tarojs/taro'; import {getUserInfo} from "@/api/layout"; import {useEffect, useState} from "react"; import {getCmsArticle} from "@/api/cms/cmsArticle"; import {CmsArticle} from "@/api/cms/cmsArticle/model"; function AddCartBar() { const { router } = getCurrentInstance(); const [id, setId] = useState() const [article, setArticle] = useState() const [IsLogin, setIsLogin] = useState(false) const onPay = () => { if (!IsLogin) { Taro.showToast({title: `请先登录`, icon: 'error'}) setTimeout(() => { Taro.switchTab( { url: '/pages/user/user', }, ) }, 1000) return false; } if (article?.model == 'bm') { navTo('/bszx/bm/bm?id=' + id) } if (article?.model == 'pay') { navTo('/bszx/pay/pay?id=' + id) } } const reload = (id: number) => { getCmsArticle(id).then(data => { setArticle(data) }) getUserInfo().then((data) => { if (data) { setIsLogin(true); Taro.setStorageSync('UserId', data.userId) } }).catch(() => { console.log('未登录') }); } useEffect(() => { const id = router?.params.id as number | undefined; setId(id) reload(Number(id)); }, []); return (
{article?.model == 'pay' ? '我要捐款' : '我要报名'}
) } // 监听页面分享事件 export default AddCartBar