<template> 
 | 
    <div class="box"> 
 | 
    </div> 
 | 
</template> 
 | 
  
 | 
<script setup lang="ts"> 
 | 
    import { getCurrentInstance, watch } from 'vue' 
 | 
    import { Toast, Dialog } from 'vant' 
 | 
    const { proxy }: any = getCurrentInstance() 
 | 
  
 | 
    const props = defineProps({ 
 | 
        openCode: { // 是否打开钉钉扫一扫 
 | 
            type: Boolean, 
 | 
            required: false, 
 | 
            default: false 
 | 
        }, 
 | 
        infos: { // 弹框提示字 
 | 
            type: Array, 
 | 
            required: true 
 | 
        }, 
 | 
        promptOrNot: { // 是否需要弹框提示 
 | 
            type: Boolean, 
 | 
            required: false, 
 | 
            default: true 
 | 
        } 
 | 
    }) 
 | 
  
 | 
    let arrCode: string[] = []  // 存放扫码数组 
 | 
  
 | 
    const emit = defineEmits(['onDecode', 'closePopup']) 
 | 
  
 | 
    // 核心方法 
 | 
    const init = (index: number): void => { 
 | 
        if (proxy.$dd.env.platform !== 'notInDingTalk') { 
 | 
            if (props.promptOrNot) { 
 | 
                Dialog.alert({ 
 | 
                    title: '扫码提示', 
 | 
                    confirmButtonColor: '#4275FC', 
 | 
                    message: `${props.infos[index]}`, 
 | 
                }).then(() => { 
 | 
                    proxy.$dd.biz.util.scan({ 
 | 
                        type: 'all', 
 | 
                        onSuccess: function(data: any) { 
 | 
                            arrCode.push(data.text) 
 | 
                            // 最后一次返回父组件扫码数据 
 | 
                            if (index === props.infos.length - 1) { 
 | 
                                emit('onDecode', arrCode) 
 | 
                            } else { 
 | 
                                init(index + 1) 
 | 
                            } 
 | 
                        }, 
 | 
                        onFail : function(err: any) { 
 | 
                            arrCode = [] 
 | 
                            emit('closePopup') 
 | 
                        } 
 | 
                    }) 
 | 
                }).catch(() => { 
 | 
                    emit('closePopup') 
 | 
                }) 
 | 
            } else { 
 | 
                proxy.$dd.biz.util.scan({ 
 | 
                    type: 'all', 
 | 
                    onSuccess: function(data: any) { 
 | 
                        arrCode.push(data.text) 
 | 
                        // 最后一次返回父组件扫码数据 
 | 
                        if (index === props.infos.length - 1) { 
 | 
                            emit('onDecode', arrCode) 
 | 
                        } else { 
 | 
                            init(index + 1) 
 | 
                        } 
 | 
                    }, 
 | 
                    onFail : function(err: any) { 
 | 
                        arrCode = [] 
 | 
                        emit('closePopup') 
 | 
                    } 
 | 
                }) 
 | 
            } 
 | 
        } else { 
 | 
            Toast.fail({ message: '当前不是钉钉环境' }) 
 | 
            emit('closePopup') 
 | 
        } 
 | 
    } 
 | 
  
 | 
    // 监听openCode触发扫码方法 
 | 
    watch(() => props.openCode, (news: boolean) => { 
 | 
        if (news) { 
 | 
            init(0) 
 | 
        } else { 
 | 
            arrCode = [] 
 | 
        } 
 | 
    }) 
 | 
</script> 
 | 
  
 | 
<style lang="scss" scoped> 
 | 
    .box_video { 
 | 
  
 | 
    } 
 | 
</style> 
 |