转自 https://www.csdn.net/tags/OtDacg3sMjQ2NTgtYmxvZwO0O0OO0O0O.html

  • 钉钉登录二维码嵌套在vue页面中

    2021-09-04 14:42:45

    <template>
    <div id="app">
    <div id="login_container"></div>
    </div>
    </template>
    <script>
    import axios from "axios"; export default {

    name: "App",

    components: {},

    data() {

    return {

    appid: "dingb3x07ieb8wrwmw81",

    redirectUrl: "https://console.huishouzx.com/login",

    apiUrl:

    "<用户信息接口,把redirectUrl回调获取的CODE给后端用于获取扫码用户信息>",

    dingCodeConfig: {

    id: "login_container",

    style: "border:none;background-color:#FFFFFF;",

    width: "365",

    height: "400",

    },

    };

    },

    computed: {

    getRedirectUrl() {

    return encodeURIComponent(this.redirectUrl);

    },

    getAuthUrl() {

    return https://oapi.dingtalk.com/connect/oauth2/sns_authorize?appid=${this.appid}&amp;response_type=code&amp;scope=snsapi_login&amp;state=STATE&amp;redirect_uri=${this.getRedirectUrl};

    },

    getGoto() {

    return encodeURIComponent(this.getAuthUrl);

    },

    getDingCodeConfig() {

    return { ...this.dingCodeConfig, goto: this.getGoto };

    },

    },

    created() {

    //调用

    this.initDingJs();

    },

    mounted() {

    this.addDingListener();

    this.initDingLogin();

    this.getUser();

    },

    methods: {

    initDingJs() {

    !(function (window, document) {

    function d(a) {

    var e,

    c = document.createElement("iframe"),

    d = "https://login.dingtalk.com/login/qrcode.htm?goto=" + a.goto;

    (d += a.style ? "&style=" + encodeURIComponent(a.style) : ""),

    (d += a.href ? "&href=" + a.href : ""),

    (c.src = d),

    (c.frameBorder = "0"),

    (c.allowTransparency = "true"),

    (c.scrolling = "no"),

    (c.width = a.width ? a.width + "px" : "365px"),

    (c.height = a.height ? a.height + "px" : "400px"),

    (e = document.getElementById(a.id)),

    (e.innerHTML = ""),

    e.appendChild(c);

    }
        window.DDLogin = d;
    })(window, document);
    },
    addDingListener() {
    let self = this; let handleLoginTmpCode = function (loginTmpCode) {
    window.location.href =
    self.getAuthUrl + `&amp;loginTmpCode=${loginTmpCode}`;
    }; let handleMessage = function (event) {
    if (event.origin == "https://login.dingtalk.com") {
    handleLoginTmpCode(event.data);
    }
    }; if (typeof window.addEventListener != "undefined") {
    window.addEventListener("message", handleMessage, false);
    } else if (typeof window.attachEvent != "undefined") {
    window.attachEvent("onmessage", handleMessage);
    }
    },
    initDingLogin() {
    window.DDLogin(this.getDingCodeConfig);
    },
    getUser() {
    let getQueryString = function (name) {
    var reg = new RegExp("(^|&amp;)" + name + "=([^&amp;]*)(&amp;|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
    return unescape(r[2]);
    }
    return null;
    }; let code = getQueryString("code"); if (code !== null) {
    axios
    .get(`${this.apiUrl}?code=${code}`)
    .then((response) =&gt; {
    console.log(response);
    })
    .catch((error) =&gt; {
    console.log(error);
    });
    }
    },

    },

    };

    </script>

    <style>

    app {

    font-family: Avenir, Helvetica, Arial, sans-serif;

    -webkit-font-smoothing: antialiased;

    -moz-osx-font-smoothing: grayscale;

    text-align: center;

    color: #2c3e50;

    margin-top: 60px;

    }

    </style>


    更多相关内容
  • 钉钉登录二维码嵌套在vue页面中的更多相关文章

    1. 微信长按识别二维码,在 vue 项目中的实现

      微信长按识别二维码是 QQ 浏览器的内置功能,该功能的基础一定要使用 img 标签引入图片,其他方式的二维码无法识别. 在 vue 中使用 QrcodeVue 插件 demo1 在 template ...

    2. C#生成二维码,把二维码图片放入Excel中

      /// <summary> /// 把图片保存到excel中 /// </summary> /// <param name="excelFilePath&quo ...

    3. 基于SignalR的消息推送与二维码描登录实现

      1 概要说明 使用微信扫描登录相信大家都不会陌生吧,二维码与手机结合产生了不同应用场景,基于二维码的应用更是比较广泛.为了满足ios.android客户端与web短信平台的结合,特开发了基于Singl ...

    4. 网站实现微信登录之嵌入二维码——基于yii2开发的描述

      之前写了一篇yii2获取登录前的页面url地址的文章,然后发现自己对于网站实现微信扫码登录功能的实现不是很熟悉,所以,我会写2-3篇的文章来描述下一个站点如何实现微信扫码登录的功能,来复习下微信扫码登 ...

    5. spring boot高性能实现二维码扫码登录(上)——单服务器版

      前言 目前网页的主流登录方式是通过手机扫码二维码登录.我看了网上很多关于扫码登录博客后,发现基本思路大致是:打开网页,生成uuid,然后长连接请求后端并等待登录认证相应结果,而后端每个几百毫秒会循环查 ...

    6. spring boot高性能实现二维码扫码登录(中)——Redis版

      前言 本打算用CountDownLatch来实现,但有个问题我没有考虑,就是当用户APP没有扫二维码的时候,线程会阻塞5分钟,这反而造成性能的下降.好吧,现在回归传统方式:前端ajax每隔1秒或2秒发 ...

    7. spring boot高性能实现二维码扫码登录(下)——订阅与发布机制版

       前言 基于之前两篇(<spring boot高性能实现二维码扫码登录(上)——单服务器版>和<spring boot高性能实现二维码扫码登录(中)——Redis版>)的基础, ...

    8. .net实现扫描二维码登录webqq群抓取qq群信息

      一.流程 1. //获得二维码的qrsig,cookie标志 2. //登录二维码获得二维码的状态,及最新的url 3. //登录此网址,获得Cookies 4.//cookies,筛选出skey信息 ...

    9. PC 商城扫描二维码登录

      需求分析: 扫码入口,在pc登录首页新增二维码登录入口 点击扫码入口显示二维码 二维码有效时间为一分钟 超时后显示二维码失效,点击刷新后生成新的二维码 在app端用户登录并扫码后,点击确认登录,进行跳 ...

    随机推荐

    1. 假期任务一:安装好JAVA开发环境并且在Eclipse上面成功运行HelloWorld程序

      (本周主要做了java环境的安装,安装完jdk后又安装了eclipse,平均每天两小时Java吧,这周敲代码的时间比较少,大多是在b站看java入门视频和菜鸟教程的基础语法,也就打开eclipse验证 ...

    2. String和int、long、double等基本数据类型的转换

      学习目标: 掌握Java的基本数据类型与String的转换 学习内容: 1.转化规则 String 转 基本数据类型 基本数据类型 变量 = 包装类.Parse基本数据类型(String); // c ...

    3. js手机号隐藏中间四位

      var tel = "13122223333"; var reg = /^(\d{3})\d{4}(\d{4})$/; tel = tel.replace(reg, "$ ...

    4. 分库分表实现方式Client和Proxy,性能和维护性该怎么选?

      大家好,我是[架构摆渡人],一只十年的程序猿.这是分库分表系列的第一篇文章,这个系列会给大家分享很多在实际工作中有用的经验,如果有收获,还请分享给更多的朋友. 其实这个系列有录过视频给大家学习,但很多 ...

    5. Spring-Bean标签属性scope范围

      scope:指对象的作用范围,取值如下 1.singleton:默认值,单例的 2.prototype:多例的 3.request:WEB项目,Spring创建一个Bean的对象,把对象存入到requ ...

    6. Kafka 使用-安装

      Kafka 使用-安装 官方网站 http://kafka.apache.org/ 官方文档 Kafka 是什么? Apache Kafka is an open-source distributed ...

    7. jquery版本的ajax请求

      首先引入 <script src="https://code.jquery.com/jquery-3.6.0.js"></script>   $ 和 jqu ...

    8. B. Lord of the Values 思维数学建构 附加 英文翻译

      原题链接 Problem - 1523B - Codeforces 题目及部分翻译 While trading on(贸易,利用) his favorite exchange trader Willi ...

    9. go语言编译过程概述

      go语言编译过程概述 总结自<go语言设计与实现> 名词解释: 中间代码 中间代码是编译器或者虚拟机使用的语言,它可以来帮助我们分析计算机程序.在编译过程中,编译器会在将源代码转换到机器码 ...

    10. MyBatis插件 - 通用mapper

      1.简单认识通用mapper 1.1.了解mapper 作用:就是为了帮助我们自动的生成sql语句 [ ps:MyBatis需要编写xxxMapper.xml,而逆向工程是根据entity实体类来进行 ...