移动系统liao
3 天以前 a737f5caf67b75abec3e89296c4321ea6d31bd9b
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<script lang="ts" setup>
import { nextTick, onMounted, ref } from "vue";
import QRCode from 'qrcodejs2-fixes';
 
// 组件属性
const props = defineProps({
    realName: String,
    number: String,
    callbackUrl: String,
    callbackData: String,
  needToken: Boolean,
});
 
// 定义变量内容
const qrcodeRef = ref<HTMLElement | null>(null);
 
// 初始化生成二维码
const initQrcode = () => {
    nextTick(() => {
        const token = props.needToken ? Local.get(accessTokenKey) : '';
        const code = encodeURIComponent(JSON.stringify({
            realName: props.realName,
            number: props.number,
            callbackUrl: props.callbackUrl,
            callbackData: props.callbackData
        }));
        let url = `${location.origin}/$callTel#/$callTel?code=${encodeURIComponent(code)}&token=${encodeURIComponent(token)}`;
        (<HTMLElement>qrcodeRef.value).innerHTML = '';
        new QRCode(qrcodeRef.value, {
            text: url,
            width: 260,
            height: 260,
            colorDark: '#000000',
            colorLight: '#ffffff',
        });
    });
};
 
// 拨打电话
const callTel = () => {
    location.href = 'tel:' + props.number;
}
 
// 页面加载时
onMounted(() => {
    initQrcode();
});
</script>
 
<template>
    <el-popover placement="bottom" width="300" trigger="click">
        <template #reference>
            <i class="iconfont icon-dianhua" v-bind="$attrs" />
        </template>
        <el-descriptions direction="vertical" :column="1" border>
            <el-descriptions-item align="center">
                <template #label>
                    <el-button @click="callTel">直接拨打</el-button>
                </template>
            </el-descriptions-item>
            <el-descriptions-item width="140" align="center">
                手机扫一扫
                <template #label>
                    <div ref="qrcodeRef" />
                </template>
            </el-descriptions-item>
        </el-descriptions>
    </el-popover>
</template>
 
<style scoped lang="scss">
.call-bar-container {
    display: flex;
}
</style>