|
@@ -14,7 +14,7 @@
|
|
|
学校:{{ schoolName }}
|
|
学校:{{ schoolName }}
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
<view class="tw-px-[30rpx] tw-mt-[40rpx] tw-pb-[100rpx]">
|
|
<view class="tw-px-[30rpx] tw-mt-[40rpx] tw-pb-[100rpx]">
|
|
|
<view class="type-list">
|
|
<view class="type-list">
|
|
|
<view class="type-card" @click="handleManualInput">
|
|
<view class="type-card" @click="handleManualInput">
|
|
@@ -28,7 +28,7 @@
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
<van-popup v-model:show="showScanner" position="center" :style="{ width: '90%', height: '80%' }">
|
|
<van-popup v-model:show="showScanner" position="center" :style="{ width: '90%', height: '80%' }">
|
|
|
<view class="scanner-popup">
|
|
<view class="scanner-popup">
|
|
|
<view class="scanner-header">
|
|
<view class="scanner-header">
|
|
@@ -42,12 +42,15 @@
|
|
|
</view>
|
|
</view>
|
|
|
</van-popup>
|
|
</van-popup>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
+ <scan-code ref="scan"></scan-code>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import config from '@/utils/config'
|
|
import config from '@/utils/config'
|
|
|
import { getSchoolInfo } from '@/services/common'
|
|
import { getSchoolInfo } from '@/services/common'
|
|
|
-import jsQR from 'jsqr'
|
|
|
|
|
|
|
+// import jsQR from 'jsqr'
|
|
|
|
|
+import scanCode from '@/components/easy-scancode/easy-scancode'
|
|
|
|
|
+
|
|
|
|
|
|
|
|
const STORAGE_KEY = 'eye_examine_user_info'
|
|
const STORAGE_KEY = 'eye_examine_user_info'
|
|
|
const schoolName = ref('')
|
|
const schoolName = ref('')
|
|
@@ -57,12 +60,14 @@ const canvasRef = ref(null)
|
|
|
let stream = null
|
|
let stream = null
|
|
|
let animationId = null
|
|
let animationId = null
|
|
|
|
|
|
|
|
|
|
+const scan = ref(null)
|
|
|
|
|
+
|
|
|
onLoad(async () => {
|
|
onLoad(async () => {
|
|
|
const savedData = uni.getStorageSync(STORAGE_KEY)
|
|
const savedData = uni.getStorageSync(STORAGE_KEY)
|
|
|
if (savedData) {
|
|
if (savedData) {
|
|
|
const userInfo = JSON.parse(savedData)
|
|
const userInfo = JSON.parse(savedData)
|
|
|
const schoolId = userInfo.schoolId || ''
|
|
const schoolId = userInfo.schoolId || ''
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (schoolId) {
|
|
if (schoolId) {
|
|
|
try {
|
|
try {
|
|
|
const res = await getSchoolInfo(schoolId)
|
|
const res = await getSchoolInfo(schoolId)
|
|
@@ -83,15 +88,27 @@ const handleManualInput = () => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const handleScanInput = async () => {
|
|
const handleScanInput = async () => {
|
|
|
- showScanner.value = true
|
|
|
|
|
- await nextTick()
|
|
|
|
|
- startCamera()
|
|
|
|
|
|
|
+ scan.value.start({
|
|
|
|
|
+ success: (val, res) => {
|
|
|
|
|
+ //val是扫描到的二维码内容
|
|
|
|
|
+ console.log('扫描成功', val, res)
|
|
|
|
|
+ uni.navigateTo({
|
|
|
|
|
+ url: `/pages/index/select-input-type?studentId=${val}`
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: (rej) => {
|
|
|
|
|
+ console.log('扫描失败', rej)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ // showScanner.value = true
|
|
|
|
|
+ // await nextTick()
|
|
|
|
|
+ // startCamera()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const startCamera = async () => {
|
|
const startCamera = async () => {
|
|
|
try {
|
|
try {
|
|
|
- stream = await navigator.mediaDevices.getUserMedia({
|
|
|
|
|
- video: { facingMode: 'environment' }
|
|
|
|
|
|
|
+ stream = await navigator.mediaDevices.getUserMedia({
|
|
|
|
|
+ video: { facingMode: 'environment' }
|
|
|
})
|
|
})
|
|
|
const video = videoRef.value
|
|
const video = videoRef.value
|
|
|
if (video) {
|
|
if (video) {
|
|
@@ -111,20 +128,20 @@ const startCamera = async () => {
|
|
|
const scanQRCode = () => {
|
|
const scanQRCode = () => {
|
|
|
const video = videoRef.value
|
|
const video = videoRef.value
|
|
|
const canvas = canvasRef.value
|
|
const canvas = canvasRef.value
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (!video || !canvas) return
|
|
if (!video || !canvas) return
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const ctx = canvas.getContext('2d')
|
|
const ctx = canvas.getContext('2d')
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const scan = () => {
|
|
const scan = () => {
|
|
|
if (video.readyState === video.HAVE_ENOUGH_DATA) {
|
|
if (video.readyState === video.HAVE_ENOUGH_DATA) {
|
|
|
canvas.width = video.videoWidth
|
|
canvas.width = video.videoWidth
|
|
|
canvas.height = video.videoHeight
|
|
canvas.height = video.videoHeight
|
|
|
ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
|
|
ctx.drawImage(video, 0, 0, canvas.width, canvas.height)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
|
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height)
|
|
|
const code = jsQR(imageData.data, imageData.width, imageData.height)
|
|
const code = jsQR(imageData.data, imageData.width, imageData.height)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (code) {
|
|
if (code) {
|
|
|
onDecode(code.data)
|
|
onDecode(code.data)
|
|
|
return
|
|
return
|
|
@@ -132,7 +149,7 @@ const scanQRCode = () => {
|
|
|
}
|
|
}
|
|
|
animationId = requestAnimationFrame(scan)
|
|
animationId = requestAnimationFrame(scan)
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
scan()
|
|
scan()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -214,6 +231,4 @@ const closeScanner = () => {
|
|
|
height: 100%;
|
|
height: 100%;
|
|
|
object-fit: cover;
|
|
object-fit: cover;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
</style>
|
|
</style>
|