|
@@ -1,94 +1,94 @@
|
1
|
|
-import React, { useEffect, useRef, useState } from 'react'
|
2
|
|
-import Taro from '@tarojs/taro'
|
3
|
|
-import { Canvas, View } from '@tarojs/components'
|
4
|
|
-import { getConfig } from './config'
|
5
|
|
-import posterSDKFactory from './sdk'
|
|
1
|
+// import React, { useEffect, useRef, useState } from 'react'
|
|
2
|
+// import Taro from '@tarojs/taro'
|
|
3
|
+// import { Canvas, View } from '@tarojs/components'
|
|
4
|
+// import { getConfig } from './config'
|
|
5
|
+// import posterSDKFactory from './sdk'
|
6
|
6
|
|
7
|
|
-export default (props) => {
|
8
|
|
- const { dataSource, onStart, onEnd, onError } = props
|
|
7
|
+// export default (props) => {
|
|
8
|
+// const { dataSource, onStart, onEnd, onError } = props
|
9
|
9
|
|
10
|
|
- const [sdk, setSDK] = useState()
|
11
|
|
- const processing = useRef(false)
|
|
10
|
+// const [sdk, setSDK] = useState()
|
|
11
|
+// const processing = useRef(false)
|
12
|
12
|
|
13
|
|
- const config = useRef()
|
14
|
|
- config.current = getConfig()
|
|
13
|
+// const config = useRef()
|
|
14
|
+// config.current = getConfig()
|
15
|
15
|
|
16
|
|
- useEffect(() => {
|
17
|
|
- Taro.nextTick(() => {
|
18
|
|
- posterSDKFactory('#canvas-poster').then((res) => {
|
19
|
|
- res.initCanvas({
|
20
|
|
- ...config.current,
|
21
|
|
- })
|
22
|
|
- setSDK(res)
|
23
|
|
- })
|
24
|
|
- })
|
25
|
|
- }, [])
|
|
16
|
+// useEffect(() => {
|
|
17
|
+// Taro.nextTick(() => {
|
|
18
|
+// posterSDKFactory('#canvas-poster').then((res) => {
|
|
19
|
+// res.initCanvas({
|
|
20
|
+// ...config.current,
|
|
21
|
+// })
|
|
22
|
+// setSDK(res)
|
|
23
|
+// })
|
|
24
|
+// })
|
|
25
|
+// }, [])
|
26
|
26
|
|
27
|
|
- useEffect(() => {
|
28
|
|
- const { poster, miniCode, name, avatar, desc = '长按识别在线看房', } = dataSource || {}
|
29
|
|
- if (sdk && poster && !processing.current) {
|
30
|
|
- onStart()
|
31
|
|
- processing.current = true
|
32
|
|
- const conf = config.current
|
|
27
|
+// useEffect(() => {
|
|
28
|
+// const { poster, miniCode, name, avatar, desc = '长按识别在线看房', } = dataSource || {}
|
|
29
|
+// if (sdk && poster && !processing.current) {
|
|
30
|
+// onStart()
|
|
31
|
+// processing.current = true
|
|
32
|
+// const conf = config.current
|
33
|
33
|
|
34
|
|
- sdk.onError((err) => {
|
35
|
|
- if (onError) {
|
36
|
|
- onError(err)
|
37
|
|
- } else {
|
38
|
|
- console.error(err)
|
39
|
|
- }
|
40
|
|
- })
|
|
34
|
+// sdk.onError((err) => {
|
|
35
|
+// if (onError) {
|
|
36
|
+// onError(err)
|
|
37
|
+// } else {
|
|
38
|
+// console.error(err)
|
|
39
|
+// }
|
|
40
|
+// })
|
41
|
41
|
|
42
|
|
- // 名称
|
43
|
|
- sdk.darwText(name, conf.name)
|
44
|
|
- // 小程序码
|
45
|
|
- sdk.darwText(desc, conf.desc)
|
|
42
|
+// // 名称
|
|
43
|
+// sdk.darwText(name, conf.name)
|
|
44
|
+// // 小程序码
|
|
45
|
+// sdk.darwText(desc, conf.desc)
|
46
|
46
|
|
47
|
|
- let cnt = 0
|
48
|
|
- // 封面
|
49
|
|
- sdk.getImage(poster).then((posterImg) => {
|
50
|
|
- sdk.drawImage(posterImg, conf.poster)
|
51
|
|
- cnt += 1
|
52
|
|
- }).catch(() => cnt += 1)
|
53
|
|
- // 头像
|
54
|
|
- sdk.getImage(avatar).then((avatarImg) => {
|
55
|
|
- sdk.drawImage(avatarImg, conf.avatar)
|
56
|
|
- cnt += 1
|
57
|
|
- }).catch(() => cnt += 1)
|
58
|
|
- // 小程序码
|
59
|
|
- sdk.getImage(miniCode).then((miniCodeImg) => {
|
60
|
|
- sdk.drawImage(miniCodeImg, conf.miniCode)
|
61
|
|
- cnt += 1
|
62
|
|
- }).catch(() => cnt += 1)
|
|
47
|
+// let cnt = 0
|
|
48
|
+// // 封面
|
|
49
|
+// sdk.getImage(poster).then((posterImg) => {
|
|
50
|
+// sdk.drawImage(posterImg, conf.poster)
|
|
51
|
+// cnt += 1
|
|
52
|
+// }).catch(() => cnt += 1)
|
|
53
|
+// // 头像
|
|
54
|
+// sdk.getImage(avatar).then((avatarImg) => {
|
|
55
|
+// sdk.drawImage(avatarImg, conf.avatar)
|
|
56
|
+// cnt += 1
|
|
57
|
+// }).catch(() => cnt += 1)
|
|
58
|
+// // 小程序码
|
|
59
|
+// sdk.getImage(miniCode).then((miniCodeImg) => {
|
|
60
|
+// sdk.drawImage(miniCodeImg, conf.miniCode)
|
|
61
|
+// cnt += 1
|
|
62
|
+// }).catch(() => cnt += 1)
|
63
|
63
|
|
64
|
|
- const ticker = setInterval(() => {
|
65
|
|
- if (cnt >= 3) {
|
66
|
|
- // 图片全部处理完
|
67
|
|
- // // console.log('--------download--------->')
|
68
|
|
- // sdk.download('canvas-poster').then((tempPath) => {
|
69
|
|
- // onEnd(tempPath, sdk)
|
70
|
|
- // clearInterval(ticker)
|
71
|
|
- // }).catch(() => {
|
72
|
|
- // clearInterval(ticker)
|
73
|
|
- // })
|
|
64
|
+// const ticker = setInterval(() => {
|
|
65
|
+// if (cnt >= 3) {
|
|
66
|
+// // 图片全部处理完
|
|
67
|
+// // // console.log('--------download--------->')
|
|
68
|
+// // sdk.download('canvas-poster').then((tempPath) => {
|
|
69
|
+// // onEnd(tempPath, sdk)
|
|
70
|
+// // clearInterval(ticker)
|
|
71
|
+// // }).catch(() => {
|
|
72
|
+// // clearInterval(ticker)
|
|
73
|
+// // })
|
74
|
74
|
|
75
|
|
- // const image = sdk.toDataURL();
|
76
|
|
- // Taro.getImageInfo({
|
77
|
|
- // src: image,
|
78
|
|
- // success: (res => {
|
79
|
|
- // onEnd(res.path, sdk)
|
80
|
|
- // clearInterval(ticker)
|
81
|
|
- // })
|
82
|
|
- // })
|
|
75
|
+// // const image = sdk.toDataURL();
|
|
76
|
+// // Taro.getImageInfo({
|
|
77
|
+// // src: image,
|
|
78
|
+// // success: (res => {
|
|
79
|
+// // onEnd(res.path, sdk)
|
|
80
|
+// // clearInterval(ticker)
|
|
81
|
+// // })
|
|
82
|
+// // })
|
83
|
83
|
|
84
|
|
- const image = sdk.toDataURL()
|
85
|
|
- onEnd(image, sdk)
|
86
|
|
- clearInterval(ticker)
|
87
|
|
- }
|
88
|
|
- }, 200);
|
|
84
|
+// const image = sdk.toDataURL()
|
|
85
|
+// onEnd(image, sdk)
|
|
86
|
+// clearInterval(ticker)
|
|
87
|
+// }
|
|
88
|
+// }, 200);
|
89
|
89
|
|
90
|
|
- }
|
91
|
|
- }, [sdk, dataSource, onStart, onEnd, onError])
|
|
90
|
+// }
|
|
91
|
+// }, [sdk, dataSource, onStart, onEnd, onError])
|
92
|
92
|
|
93
|
|
- return <View style={{ width: '1px', height: '1px' }}><Canvas type='2d' id='canvas-poster' /></View>
|
94
|
|
-}
|
|
93
|
+// return <View style={{ width: '1px', height: '1px' }}><Canvas type='2d' id='canvas-poster' /></View>
|
|
94
|
+// }
|