@gm-mobile/c-qrcode 3.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +13 -0
- package/package.json +30 -0
- package/src/index.ts +2 -0
- package/src/qrcode.tsx +14 -0
- package/src/qrcode.weapp.tsx +38 -0
- package/src/stories.tsx +11 -0
- package/src/type.ts +14 -0
package/index.d.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gm-mobile/c-qrcode",
|
|
3
|
+
"version": "3.9.0",
|
|
4
|
+
"description": "> TODO: description",
|
|
5
|
+
"author": "liyatang <liyatang@qq.com>",
|
|
6
|
+
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "src/index.ts",
|
|
12
|
+
"types": "src/index.ts",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/gmfe/gm-mobile.git"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
19
|
+
},
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"qrcode.react": "^1.0.0",
|
|
25
|
+
"weapp-qrcode": "^1.0.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/qrcode.react": "^1.0.1"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/index.ts
ADDED
package/src/qrcode.tsx
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { FC } from 'react'
|
|
2
|
+
import QRCodeReact from 'qrcode.react'
|
|
3
|
+
import { QRCodeProps } from './type'
|
|
4
|
+
|
|
5
|
+
export const QRCode: FC<QRCodeProps> = (props) => {
|
|
6
|
+
return <QRCodeReact {...props} />
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
QRCode.defaultProps = {
|
|
10
|
+
size: 200,
|
|
11
|
+
level: 'L',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default QRCode
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, FC } from 'react'
|
|
2
|
+
import { Canvas } from '@tarojs/components'
|
|
3
|
+
import drawQrCode from 'weapp-qrcode'
|
|
4
|
+
import { LevelMapProps, QRCodeProps } from './type'
|
|
5
|
+
|
|
6
|
+
const levelMap: LevelMapProps = {
|
|
7
|
+
L: 1,
|
|
8
|
+
M: 0,
|
|
9
|
+
Q: 3,
|
|
10
|
+
H: 2,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const QRCode: FC<QRCodeProps> = ({ value, size = 200, level = 'L' }) => {
|
|
14
|
+
const id = useMemo(() => Math.random().toString(), [])
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
drawQrCode({
|
|
18
|
+
width: size,
|
|
19
|
+
height: size,
|
|
20
|
+
canvasId: id,
|
|
21
|
+
text: value,
|
|
22
|
+
correctLevel: levelMap[level],
|
|
23
|
+
})
|
|
24
|
+
}, [])
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Canvas
|
|
28
|
+
// type='2d'
|
|
29
|
+
canvasId={id}
|
|
30
|
+
style={{
|
|
31
|
+
width: `${size}px`,
|
|
32
|
+
height: `${size}px`,
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default QRCode
|
package/src/stories.tsx
ADDED