无人机管理后台前端(已迁走)
张含笑
2025-09-01 2ca94de8ede18ac07ccfd8dec7b6f6a707adde9b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<template>
    <!--二维码位置-->
    <div class="myQrCode" id="myQrCode" ref="myQrCode"></div>
</template>
 
<script setup>
import { wgs84ToGcj02 } from '@/utils/coordinateTransformation';
import QRCode from 'qrcodejs2-fix'
const props = defineProps(['latAndLon'])
 
const myQrCode = ref(null)
let qrCodeInstance = null
 
const createQRcode = content => {
    const transformed = wgs84ToGcj02(content[0], content[1])
    if (!content) return
    if (qrCodeInstance) {
        myQrCode.value.innerHTML = ''
    }
    // 生成新二维码
    qrCodeInstance = new QRCode(myQrCode.value, {
        width: 92,
        height: 91,
        text: `https://uri.amap.com/marker?position=${transformed}&name=%E4%BA%8B%E4%BB%B6%E7%82%B9`,
    })
}
watch(
    () => props.latAndLon,
    newVal => {
        if (newVal) {
            nextTick(() => {
                createQRcode(newVal)
            })
        }
    },
    { immediate: true }
)
onMounted(async () => {})
</script>
 
<style lang="scss" scoped>
.myQrCode {
    padding: 2px;
    background: #fff;
}
</style>