前端 vue后台管理点击检测电脑是否有App

55 阅读1分钟

前端 vue后台管理点击图标检测电脑是否有该App 没有就安装App 有就开启App 实现免登录 (需要App技术人员支持)

    handleSoftwareLink(){
       let token = sessionStorage.getItem("accesstoken");
      const customProtocol = `自定义协议链接地址?token=${token}`; // 自定义协议
      
      // 创建一个隐藏的iframe,尝试打开自定义协议
      const iframe = document.createElement('iframe');
      iframe.style.display = 'none';
      document.body.appendChild(iframe);
      iframe.src = customProtocol;
      // 设置一个定时器,等待一段时间后检查是否触发了自定义协议
      const timer = setTimeout(() => {
        document.body.removeChild(iframe);
        this.$confirm("您未下载该软件, 确认下载软件吗 ? ", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          window.location.href ="安装包地址链接"; // 替换为实际的下载链接
        })
      }, 3000); // 设置超时时间,单位为毫秒,可以根据实际情况调整

      // 监听 window.onblur 事件,如果触发了则说明协议有效
      window.onblur = () => {
        clearTimeout(timer); // 清除定时器
        document.body.removeChild(iframe);
        window.onblur = null; // 取消事件监听
        alert('检测到该软件,执行相关操作。'); // 提示用户执行相关操作
        // 在这里执行软件存在时的相关操作,比如打开软件等
        window.location.href = `自定义协议链接地址?token=${token}`; // 替换为实际的自定义协议链接
      };
    },