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 Taro, { useDidShow } from '@tarojs/taro'
|
||||||
import { useState, useMemo } from 'react'
|
import { useState, useMemo } from 'react'
|
||||||
import { getCart, updateQuantity, removeItem, toggleSelect, toggleSelectAll, CartItem } from '../../utils/cart'
|
import { getCart, updateQuantity, removeItem, toggleSelect, toggleSelectAll, CartItem } from '../../utils/cart'
|
||||||
|
import { checkLogin } from '../../utils/auth'
|
||||||
import './cart.scss'
|
import './cart.scss'
|
||||||
|
|
||||||
export default function Cart() {
|
export default function Cart() {
|
||||||
@@ -60,6 +61,7 @@ export default function Cart() {
|
|||||||
}, [cartItems])
|
}, [cartItems])
|
||||||
|
|
||||||
const handleCheckout = () => {
|
const handleCheckout = () => {
|
||||||
|
if (!checkLogin()) return
|
||||||
if (selectedCount === 0) {
|
if (selectedCount === 0) {
|
||||||
Taro.showToast({ title: '请选择商品', icon: 'none' })
|
Taro.showToast({ title: '请选择商品', icon: 'none' })
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { View, Text, Button, Image, ScrollView, Video } from '@tarojs/components
|
|||||||
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { getVBCourseDetail } from '../../api'
|
import { getVBCourseDetail } from '../../api'
|
||||||
|
import { checkLogin } from '../../utils/auth'
|
||||||
import './detail.scss'
|
import './detail.scss'
|
||||||
|
|
||||||
export default function CourseDetail() {
|
export default function CourseDetail() {
|
||||||
@@ -33,6 +34,7 @@ export default function CourseDetail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleLaunch = () => {
|
const handleLaunch = () => {
|
||||||
|
if (!checkLogin()) return
|
||||||
if (!detail) return
|
if (!detail) return
|
||||||
Taro.navigateTo({
|
Taro.navigateTo({
|
||||||
url: `/pages/order/checkout?id=${detail.id}&type=course`
|
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 Taro, { useRouter, useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { getConfigDetail } from '../../api'
|
import { getConfigDetail } from '../../api'
|
||||||
|
import { checkLogin } from '../../utils/auth'
|
||||||
import ParticleBackground from '../../components/ParticleBackground'
|
import ParticleBackground from '../../components/ParticleBackground'
|
||||||
import { addToCart } from '../../utils/cart'
|
import { addToCart } from '../../utils/cart'
|
||||||
import './detail.scss'
|
import './detail.scss'
|
||||||
@@ -50,6 +51,7 @@ export default function Detail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const buyNow = () => {
|
const buyNow = () => {
|
||||||
|
if (!checkLogin()) return
|
||||||
if (!product) return
|
if (!product) return
|
||||||
Taro.navigateTo({
|
Taro.navigateTo({
|
||||||
url: `/pages/order/checkout?id=${product.id}&quantity=1`
|
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 Taro, { useRouter, useLoad } from '@tarojs/taro'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { getOrder, prepayMiniprogram } from '../../api'
|
import { getOrder, prepayMiniprogram } from '../../api'
|
||||||
|
import { checkLogin } from '../../utils/auth'
|
||||||
import './detail.scss'
|
import './detail.scss'
|
||||||
|
|
||||||
export default function OrderDetail() {
|
export default function OrderDetail() {
|
||||||
@@ -27,6 +28,7 @@ export default function OrderDetail() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handlePay = async () => {
|
const handlePay = async () => {
|
||||||
|
if (!checkLogin()) return
|
||||||
if (!order) return
|
if (!order) return
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { View, Text, Image, Button, Input, Textarea } from '@tarojs/components'
|
|||||||
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
import Taro, { useLoad, useShareAppMessage, useShareTimeline } from '@tarojs/taro'
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { getServiceDetail, createServiceOrder } from '../../api'
|
import { getServiceDetail, createServiceOrder } from '../../api'
|
||||||
|
import { checkLogin } from '../../utils/auth'
|
||||||
import './detail.scss'
|
import './detail.scss'
|
||||||
|
|
||||||
export default function ServiceDetail() {
|
export default function ServiceDetail() {
|
||||||
@@ -134,7 +135,11 @@ export default function ServiceDetail() {
|
|||||||
<Button
|
<Button
|
||||||
className='btn-buy'
|
className='btn-buy'
|
||||||
style={{ background: service.color }}
|
style={{ background: service.color }}
|
||||||
onClick={() => setModalVisible(true)}
|
onClick={() => {
|
||||||
|
if (checkLogin()) {
|
||||||
|
setModalVisible(true)
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
立即咨询 / 购买
|
立即咨询 / 购买
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useState, useEffect } from 'react'
|
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 { View, Text, Image, Video, Input, ScrollView } from '@tarojs/components'
|
||||||
import { AtActivityIndicator, AtIcon, AtActionSheet, AtActionSheetItem, AtFloatLayout } from 'taro-ui'
|
import { AtActivityIndicator, AtIcon, AtActionSheet, AtActionSheetItem, AtFloatLayout } from 'taro-ui'
|
||||||
import { getTopicDetail, createReply, uploadMedia, getStarUsers } from '../../../api'
|
import { getTopicDetail, createReply, uploadMedia, getStarUsers } from '../../../api'
|
||||||
@@ -70,6 +70,7 @@ const ForumDetail = () => {
|
|||||||
setShowStarUsers(false)
|
setShowStarUsers(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分享给好友
|
||||||
useShareAppMessage(() => {
|
useShareAppMessage(() => {
|
||||||
return {
|
return {
|
||||||
title: topic?.title || '技术社区',
|
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) => {
|
const handleReplyChange = (e) => {
|
||||||
setReplyContent(e.detail.value)
|
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