更新菜单栏中的帮助中心教程和产品介绍的相关文档
This commit is contained in:
32
src/lib/hooks/index.ts
Normal file
32
src/lib/hooks/index.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
import {TradePlatform} from '@/lib/models/trade'
|
||||
|
||||
// 设备检测Hook
|
||||
export const usePlatformType = (): TradePlatform => {
|
||||
// 在SSR环境下返回默认值
|
||||
const [platform, setPlatform] = useState<TradePlatform>(() => {
|
||||
if (typeof window === 'undefined') return TradePlatform.Desktop
|
||||
return window.matchMedia('(max-width: 768px)').matches
|
||||
? TradePlatform.Mobile
|
||||
: TradePlatform.Desktop
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
// 确保在客户端执行
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
const checkPlatform = () => {
|
||||
const isMobile = window.matchMedia('(max-width: 768px)').matches
|
||||
setPlatform(isMobile ? TradePlatform.Mobile : TradePlatform.Desktop)
|
||||
}
|
||||
|
||||
const mediaQuery = window.matchMedia('(max-width: 768px)')
|
||||
mediaQuery.addEventListener('change', checkPlatform)
|
||||
|
||||
return () => {
|
||||
mediaQuery.removeEventListener('change', checkPlatform)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return platform
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
'use client'
|
||||
import {StaticImageData} from 'next/image'
|
||||
import {useEffect, useState} from 'react'
|
||||
import wechat from '@/components/composites/purchase/_assets/wechat.svg'
|
||||
import alipay from '@/components/composites/purchase/_assets/alipay.svg'
|
||||
|
||||
@@ -51,33 +49,3 @@ export type PaymentMethodConfig = {
|
||||
text: string
|
||||
}
|
||||
}
|
||||
|
||||
// 设备检测Hook
|
||||
export const usePlatformType = (): TradePlatform => {
|
||||
// 在SSR环境下返回默认值
|
||||
const [platform, setPlatform] = useState<TradePlatform>(() => {
|
||||
if (typeof window === 'undefined') return TradePlatform.Desktop
|
||||
return window.matchMedia('(max-width: 768px)').matches
|
||||
? TradePlatform.Mobile
|
||||
: TradePlatform.Desktop
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
// 确保在客户端执行
|
||||
if (typeof window === 'undefined') return
|
||||
|
||||
const checkPlatform = () => {
|
||||
const isMobile = window.matchMedia('(max-width: 768px)').matches
|
||||
setPlatform(isMobile ? TradePlatform.Mobile : TradePlatform.Desktop)
|
||||
}
|
||||
|
||||
const mediaQuery = window.matchMedia('(max-width: 768px)')
|
||||
mediaQuery.addEventListener('change', checkPlatform)
|
||||
|
||||
return () => {
|
||||
mediaQuery.removeEventListener('change', checkPlatform)
|
||||
}
|
||||
}, [])
|
||||
|
||||
return platform
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import {ReactNode} from 'react'
|
||||
import {ClassNameValue, twMerge} from 'tailwind-merge'
|
||||
|
||||
export function merge(...inputs: ClassNameValue[]) {
|
||||
return twMerge(inputs)
|
||||
}
|
||||
|
||||
export type Children = {children: ReactNode}
|
||||
Reference in New Issue
Block a user