钉钉微应用,判断是在PC端钉钉还是手机移动端钉钉

1.首先引用两个钉钉的js

<script src="https://g.alicdn.com/dingding/dingtalk-jsapi/2.7.13/dingtalk.open.js"></script><!--钉钉JSAPI库(使用对象dd)-->
<script type="text/javascript" src="http://g.alicdn.com/dingding/dingtalk-pc-api/2.3.1/index.js"></script><!--钉钉JSAPI库(PC端专用——使用对象DingTalkPC)-->
 
2.判断pc端还是移动端的钉钉(此例子是Vue操作,React类似)

mounted: function() {
                dd.device.base.getPhoneInfo({
                    onSuccess: function(data) {
                        /*
                        {
                            screenWidth: 1080, // 手机屏幕宽度
                            screenHeight: 1920, // 手机屏幕高度
                            brand:'Mi', // 手机品牌
                            model:'Note4', // 手机型号
                            version:'7.0', // 版本
                            netInfo:'wifi', // 网络类型 wifi/4g/3g 
                            operatorType:'xx' // 运营商信息
                        }
                        */
                        // alert(JSON.stringify(data));
                        alert('现在是手机移动端');
                    },
                    onFail: function(err) {
                        alert(JSON.stringify(err));

                    }
                });
                //PC端钉钉执行此方法
                if (DingTalkPC.ua.isDesktop && DingTalkPC.ua.isInDingTalk) {
                    alert("你在用电脑看?");
                }
            }

本文的解决方案灵感来自https://blog.csdn.net/qq_29819449/article/details/80328181

原文地址:https://www.cnblogs.com/mooncher/p/14346515.html