|
|
@@ -1,11 +1,57 @@
|
|
|
import Z1titie from '@/components/Z1titie'
|
|
|
-import React from 'react'
|
|
|
+import React, { useRef, useState } from 'react'
|
|
|
+import { ActionSheet } from 'antd-mobile'
|
|
|
import styles from './index.module.scss'
|
|
|
import history from '@/utils/history'
|
|
|
import cardImg from './images/card.png'
|
|
|
import closeIcon from './images/guanbi.png'
|
|
|
|
|
|
+// 保存图片函数
|
|
|
+const saveImage = (imgSrc: string, fileName: string = 'card.png') => {
|
|
|
+ const link = document.createElement('a')
|
|
|
+ link.href = imgSrc
|
|
|
+ link.download = fileName
|
|
|
+ document.body.appendChild(link)
|
|
|
+ link.click()
|
|
|
+ document.body.removeChild(link)
|
|
|
+}
|
|
|
+
|
|
|
function A5ipDetail() {
|
|
|
+ const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
|
|
+ const [visible, setVisible] = useState(false)
|
|
|
+
|
|
|
+ const actions = [
|
|
|
+ {
|
|
|
+ key: 'save',
|
|
|
+ text: '保存图片',
|
|
|
+ onClick: () => {
|
|
|
+ saveImage(cardImg, '文创产品.png')
|
|
|
+ setVisible(false)
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]
|
|
|
+
|
|
|
+ // 桌面右键保存
|
|
|
+ const handleContextMenu = (e: React.MouseEvent<HTMLImageElement>) => {
|
|
|
+ e.preventDefault()
|
|
|
+ saveImage(cardImg, '文创产品.png')
|
|
|
+ }
|
|
|
+
|
|
|
+ // 移动端长按开始
|
|
|
+ const handleTouchStart = () => {
|
|
|
+ timerRef.current = setTimeout(() => {
|
|
|
+ setVisible(true)
|
|
|
+ }, 500)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 移动端长按取消
|
|
|
+ const handleTouchEnd = () => {
|
|
|
+ if (timerRef.current) {
|
|
|
+ clearTimeout(timerRef.current)
|
|
|
+ timerRef.current = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<div
|
|
|
style={{ backgroundImage: `url(${serverUrl}ip/bac.jpg)` }}
|
|
|
@@ -16,9 +62,22 @@ function A5ipDetail() {
|
|
|
toHome={() => history.push('/?mask=1')}
|
|
|
/>
|
|
|
|
|
|
- <img className='A5ipDetailCard' src={cardImg} alt='card' />
|
|
|
+ <img
|
|
|
+ className='A5ipDetailCard'
|
|
|
+ src={cardImg}
|
|
|
+ alt='card'
|
|
|
+ onContextMenu={handleContextMenu}
|
|
|
+ onTouchStart={handleTouchStart}
|
|
|
+ onTouchEnd={handleTouchEnd}
|
|
|
+ />
|
|
|
|
|
|
<img className='A5ipDetailClose' src={closeIcon} alt='close' onClick={() => history.replace('/ip')} />
|
|
|
+
|
|
|
+ <ActionSheet
|
|
|
+ visible={visible}
|
|
|
+ actions={actions}
|
|
|
+ onClose={() => setVisible(false)}
|
|
|
+ />
|
|
|
</div>
|
|
|
)
|
|
|
}
|