This commit is contained in:
@@ -2,6 +2,7 @@ import { View, Text, Image, ScrollView, Button } from '@tarojs/components'
|
||||
import Taro, { useDidShow } from '@tarojs/taro'
|
||||
import { useState, useMemo } from 'react'
|
||||
import { getCart, updateQuantity, removeItem, toggleSelect, toggleSelectAll, CartItem } from '../../utils/cart'
|
||||
import { checkLogin } from '../../utils/auth'
|
||||
import './cart.scss'
|
||||
|
||||
export default function Cart() {
|
||||
@@ -60,6 +61,7 @@ export default function Cart() {
|
||||
}, [cartItems])
|
||||
|
||||
const handleCheckout = () => {
|
||||
if (!checkLogin()) return
|
||||
if (selectedCount === 0) {
|
||||
Taro.showToast({ title: '请选择商品', icon: 'none' })
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ import { View, Text, Button, Image, ScrollView, Video } from '@tarojs/components
|
||||
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||
import { useState } from 'react'
|
||||
import { getVBCourseDetail } from '../../api'
|
||||
import { checkLogin } from '../../utils/auth'
|
||||
import './detail.scss'
|
||||
|
||||
export default function CourseDetail() {
|
||||
@@ -33,6 +34,7 @@ export default function CourseDetail() {
|
||||
}
|
||||
|
||||
const handleLaunch = () => {
|
||||
if (!checkLogin()) return
|
||||
if (!detail) return
|
||||
Taro.navigateTo({
|
||||
url: `/pages/order/checkout?id=${detail.id}&type=course`
|
||||
|
||||
@@ -2,6 +2,7 @@ import { View, Text, Image, ScrollView, Button } from '@tarojs/components'
|
||||
import Taro, { useRouter, useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||
import { useState } from 'react'
|
||||
import { getConfigDetail } from '../../api'
|
||||
import { checkLogin } from '../../utils/auth'
|
||||
import ParticleBackground from '../../components/ParticleBackground'
|
||||
import { addToCart } from '../../utils/cart'
|
||||
import './detail.scss'
|
||||
@@ -50,6 +51,7 @@ export default function Detail() {
|
||||
}
|
||||
|
||||
const buyNow = () => {
|
||||
if (!checkLogin()) return
|
||||
if (!product) return
|
||||
Taro.navigateTo({
|
||||
url: `/pages/order/checkout?id=${product.id}&quantity=1`
|
||||
|
||||
@@ -2,6 +2,7 @@ import { View, Text, Button, Image } from '@tarojs/components'
|
||||
import Taro, { useRouter, useLoad } from '@tarojs/taro'
|
||||
import { useState } from 'react'
|
||||
import { getOrder, prepayMiniprogram } from '../../api'
|
||||
import { checkLogin } from '../../utils/auth'
|
||||
import './detail.scss'
|
||||
|
||||
export default function OrderDetail() {
|
||||
@@ -27,6 +28,7 @@ export default function OrderDetail() {
|
||||
}
|
||||
|
||||
const handlePay = async () => {
|
||||
if (!checkLogin()) return
|
||||
if (!order) return
|
||||
setLoading(true)
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { View, Text, Image, Button, Input, Textarea } from '@tarojs/components'
|
||||
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||
import { useState } from 'react'
|
||||
import { getServiceDetail, createServiceOrder } from '../../api'
|
||||
import { checkLogin } from '../../utils/auth'
|
||||
import './detail.scss'
|
||||
|
||||
export default function ServiceDetail() {
|
||||
@@ -134,7 +135,11 @@ export default function ServiceDetail() {
|
||||
<Button
|
||||
className='btn-buy'
|
||||
style={{ background: service.color }}
|
||||
onClick={() => setModalVisible(true)}
|
||||
onClick={() => {
|
||||
if (checkLogin()) {
|
||||
setModalVisible(true)
|
||||
}
|
||||
}}
|
||||
>
|
||||
立即咨询 / 购买
|
||||
</Button>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect } from 'react'
|
||||
import Taro, { useRouter, useShareAppMessage, useDidShow } from '@tarojs/taro'
|
||||
import Taro, { useRouter, useShareAppMessage, useShareTimeline, useDidShow } from '@tarojs/taro'
|
||||
import { View, Text, Image, Video, Input, ScrollView } from '@tarojs/components'
|
||||
import { AtActivityIndicator, AtIcon, AtActionSheet, AtActionSheetItem, AtFloatLayout } from 'taro-ui'
|
||||
import { getTopicDetail, createReply, uploadMedia, getStarUsers } from '../../../api'
|
||||
@@ -70,6 +70,7 @@ const ForumDetail = () => {
|
||||
setShowStarUsers(false)
|
||||
}
|
||||
|
||||
// 分享给好友
|
||||
useShareAppMessage(() => {
|
||||
return {
|
||||
title: topic?.title || '技术社区',
|
||||
@@ -77,6 +78,15 @@ const ForumDetail = () => {
|
||||
}
|
||||
})
|
||||
|
||||
// 分享到朋友圈
|
||||
useShareTimeline(() => {
|
||||
return {
|
||||
title: topic?.title || '技术社区',
|
||||
query: `id=${id}`,
|
||||
imageUrl: topic?.author_info?.avatar_url || 'https://via.placeholder.com/300x300?text=技术社区'
|
||||
}
|
||||
})
|
||||
|
||||
const handleReplyChange = (e) => {
|
||||
setReplyContent(e.detail.value)
|
||||
}
|
||||
|
||||
28
miniprogram/src/utils/auth.ts
Normal file
28
miniprogram/src/utils/auth.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
|
||||
/**
|
||||
* 检查用户是否登录
|
||||
* @returns boolean 是否已登录
|
||||
*/
|
||||
export const checkLogin = (): boolean => {
|
||||
const token = Taro.getStorageSync('token')
|
||||
|
||||
if (!token) {
|
||||
Taro.showModal({
|
||||
title: '提示',
|
||||
content: '请先登录小程序',
|
||||
confirmText: '去登录',
|
||||
cancelText: '取消',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
Taro.switchTab({
|
||||
url: '/pages/user/index'
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user