判断当前访问环境是否为移动端
函数体
this.utils.isMobile()
函数说明
1、若当前访问环境为移动端,返回true。反之,返回false。
2、常用于组件样式双端适配,或针对不同端的不同执行逻辑。
使用示例
//下载//PC端直接下载,移动端调用钉钉JSApi查看预览图下载if (this.utils.isMobile()) {//移动端if (window.dd) {dd.biz.util.previewImage({urls: ["your download link"],//图片地址列表current: "your download link",//当前显示的图片链接onSuccess: function (result) {/**/},onFail: function (err) { }})}} else {//非移动端const a = document.createElement('a');a.download = 'image.jpg';a.href = "your download link";document.body.appendChild(a);a.click();document.body.removeChild(a);}
判断当前登录环境是否为钉钉
函数体
export function isDingTalkEnv(win) {win = win || window;return win.navigator && /dingtalk/i.test(win.navigator.userAgent) //true false}
if (window.dd) {}
函数说明
1、若当前登录环境为钉钉,返回true。反之,返回false。
2、常用于调用钉钉JSApi前的环境检测。
使用示例
if (this.isDingTalkEnv()) {dd.biz.util.scan({type: "all",onSuccess: function (res) {// 调用成功时回调window.open(res.text);},onFail: function (err) {// 调用失败时回调console.log(err)}});} else {this.utils.toast({type: "warring",title: "该功能仅手机端钉钉可用!"})}
判断当前宜搭页面是否为提交页面
函数体
this.utils.isSubmissionPage()
函数说明
1、若当前宜搭页面为提交页面,返回true,反之,返回false。
使用示例
if (this.utils.isSubmissionPage()) {//提交页面//your code} else {//非提交页面//your code}
判断当前宜搭页面是否为数据查看页面
函数体
this.utils.isViewPage()
函数说明
1、若当前宜搭页面为数据查看页面,返回true,反之,返回false。
使用示例
if (this.utils.isViewPage()) {//数据查看页面//your code} else {//非数据查看页面//your code}
