Skip to content

Commit 506de1a

Browse files
committed
refactor: outsource track default function
Move some complexity from the QrcodeStream component into a dedicated file.
1 parent 60ff03c commit 506de1a

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/components/QrcodeStream.vue

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
<script>
3232
import { keepScanning } from '../misc/scanner.js'
33+
import { thinSquare } from '../misc/track-func.js'
3334
import Camera from '../misc/camera.js'
3435
import CommonAPI from '../mixins/CommonAPI.vue'
3536
import isEqual from 'lodash/isEqual'
@@ -93,26 +94,7 @@ export default {
9394
9495
trackRepaintFunction () {
9596
if (this.track === true) {
96-
return function (location, ctx) {
97-
const {
98-
topLeftCorner,
99-
topRightCorner,
100-
bottomLeftCorner,
101-
bottomRightCorner,
102-
} = location
103-
104-
ctx.strokeStyle = 'red'
105-
106-
ctx.beginPath()
107-
ctx.moveTo(topLeftCorner.x, topLeftCorner.y)
108-
ctx.lineTo(bottomLeftCorner.x, bottomLeftCorner.y)
109-
ctx.lineTo(bottomRightCorner.x, bottomRightCorner.y)
110-
ctx.lineTo(topRightCorner.x, topRightCorner.y)
111-
ctx.lineTo(topLeftCorner.x, topLeftCorner.y)
112-
ctx.closePath()
113-
114-
ctx.stroke()
115-
}
97+
return thinSquare({ color: 'red' })
11698
} else if (this.track === false) {
11799
return null
118100
} else {

src/misc/track-func.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
export function thinSquare ({ color }) {
3+
return function (location, ctx) {
4+
const {
5+
topLeftCorner,
6+
topRightCorner,
7+
bottomLeftCorner,
8+
bottomRightCorner,
9+
} = location
10+
11+
ctx.strokeStyle = 'red'
12+
13+
ctx.beginPath()
14+
ctx.moveTo(topLeftCorner.x, topLeftCorner.y)
15+
ctx.lineTo(bottomLeftCorner.x, bottomLeftCorner.y)
16+
ctx.lineTo(bottomRightCorner.x, bottomRightCorner.y)
17+
ctx.lineTo(topRightCorner.x, topRightCorner.y)
18+
ctx.lineTo(topLeftCorner.x, topLeftCorner.y)
19+
ctx.closePath()
20+
21+
ctx.stroke()
22+
}
23+
}

0 commit comments

Comments
 (0)