-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from HXTIA/feat-mp-clip-page
feat: 新增详情页、海报保存分享 & 修改storage类型推断
- Loading branch information
Showing
37 changed files
with
739 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,10 +14,10 @@ | |
align-items: center; | ||
width: 100%; | ||
height: 100%; | ||
z-index: 1000; | ||
|
||
&__canvas { | ||
width: 100%; | ||
// height: 40%; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { useRef, FC, useCallback, useState } from 'react' | ||
import { pxTransform } from '@tarojs/taro' | ||
import { PosterRender, PosterRenderRef } from '@poster-render/taro-react' | ||
import { View } from '@tarojs/components' | ||
import Button from '@taroify/core/button/button' | ||
import { TTaskItem, getStorage, showToast, trackJsError } from 'src/utils' | ||
import './poster.scss' | ||
|
||
const lists = (data: TTaskItem) => [ | ||
{ | ||
type: 'image', | ||
x: 0, | ||
y: 0, | ||
width: 540, | ||
height: 960, | ||
backgroundColor: 'black', | ||
src: 'https://hx.404fwf.cn/notifyBoard/img/backposter.png', | ||
mode: 'contain', | ||
}, | ||
{ | ||
type: 'text', | ||
textAlign: 'center', | ||
x: 270, | ||
y: 340, | ||
lineNum: 3, | ||
width: 350, | ||
height: 30, | ||
text: data.title, | ||
color: 'black', | ||
fontSize: 30, | ||
baseLine: 'top', | ||
fontWeight: 'Bold', | ||
}, | ||
{ | ||
type: 'text', | ||
textAlign: 'left', | ||
x: 80, | ||
y: 400, | ||
lineNum: 15, | ||
width: 372, | ||
height: 22, | ||
text: data.desc, | ||
color: 'black', | ||
fontSize: 22, | ||
lineHeight: 30, | ||
}, | ||
] | ||
|
||
type TPosterProps = { | ||
posterData: TTaskItem | ||
} | ||
const Index: FC<TPosterProps> = ({ posterData }) => { | ||
const posterRender = useRef<PosterRenderRef>(null) | ||
const [posterPath, setPath] = useState<string>() | ||
|
||
// TODO: 加埋点 | ||
const savePosterToPhoto = useCallback( | ||
() => | ||
posterRender.current?.savePosterToPhoto().then((path) => { | ||
showToast(`已保存到相册 ${path}`) | ||
setPath(path || '') | ||
}), | ||
[posterRender], | ||
) | ||
const trackError = useCallback((type, err) => { | ||
showToast('保存图片失败了,重新进入尝试一下') | ||
trackJsError({ | ||
token: getStorage('userInfo').token || 'no_login', | ||
errMsg: err, | ||
errName: type, | ||
location: 'detail/poster', | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<View className='poster_wrapper'> | ||
<PosterRender | ||
ref={posterRender} | ||
canvasId='taro-poster-render' | ||
renderType='canvas' | ||
canvasWidth={540} | ||
canvasHeight={960} | ||
debug | ||
style={{ | ||
width: pxTransform(650), | ||
height: pxTransform(850), | ||
}} | ||
onRenderFail={(err) => trackError('poster_render_failed', err)} | ||
onSaveFail={(err) => trackError('poster_save_failed', err)} | ||
list={lists(posterData)} | ||
/> | ||
<View className='button_groups'> | ||
{!posterPath ? ( | ||
<Button className='save_button' onClick={savePosterToPhoto}> | ||
保存海报 | ||
</Button> | ||
) : ( | ||
<Button data-poster={{ path: posterPath }} className='share_button' openType='share'> | ||
分享给好友 | ||
</Button> | ||
)} | ||
</View> | ||
</View> | ||
) | ||
} | ||
|
||
export default React.memo<TPosterProps>(Index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.poster_wrapper { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
|
||
.button_groups { | ||
display: flex; | ||
justify-content: space-around; | ||
width: 70%; | ||
margin-top: 80rpx; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.