gisq-dd-mobile
Version:
gisq dingding mobile lib
2 lines (1 loc) • 4.76 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("dingtalk-jsapi"),require("axios")):"function"==typeof define&&define.amd?define(["exports","dingtalk-jsapi","axios"],e):e((t=t||self).gisq={},t.dd,t.axios)}(this,function(t,c,s){"use strict";c=c&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c,s=s&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s;var e={authorCode:"",accessToken:"",ticket:"",userInfo:"",agentId:"",signature:"",nonceStr:"",timeStamp:"",scenseId:"",locate:function(){console.log("locate")},alert:function(t,e,n,o,i){c&&c.device.notification.alert({message:t,title:e,buttonName:n,onSuccess:function(){o()},onFail:function(t){i(t)}})},axiosGet:function(t,o){return new Promise(function(e,n){s.get(t,{params:o}).then(function(t){e(t.data)}).catch(function(t){n(t.data)})})},axiosPost:function(t,o){return s.defaults.headers.post["Content-Type"]="application/json;charset=UTF-8",new Promise(function(e,n){s.post(t,o).then(function(t){e(t.data)}).catch(function(t){n(t.data)})})},axiosPostFormData:function(i,a){return s.defaults.headers.post["Content-Type"]="application/json",new Promise(function(e,n){var t=new FormData;for(var o in a)t.append(o,a[o]);s.post(i,t).then(function(t){e(t.data)}).catch(function(t){n(t.data)})})},getAccessToken:function(t,e){var n=this;this.axiosGet(t+"/user/getAccessToken",e).then(function(t){localStorage.setItem("gisqDdAccessToken",t),n.accessToken=t})},getTicket:function(t,e,n){var o=this;this.axiosGet(t+"/user/getJsAuthorTicket",e).then(function(t){localStorage.setItem("gisqDdTicket",t),n&&o.jsAuthor(t),o.ticket=t})},jsAuthor:function(t,e,n,o,i,a){c&&c.config({agentId:n,corpId:t,timeStamp:o,nonceStr:i,signature:a,type:0,jsApiList:["device.base.getUUID","biz.util.scanCard","biz.util.open","device.geolocation.get","device.geolocation.start","device.geolocation.stop","biz.map.locate","biz.util.downloadFile"]})},getAuthorCode:function(t){if(c)return new Promise(function(e,n){c.runtime.permission.requestAuthCode({corpId:t,onSuccess:function(t){e(t)},onFail:function(t){n(t)}})})},getUserDetail:function(t,e,n){var o=this,i={accessToken:e,authorCode:n};this.axiosGet(t+"/user/getUserDetail",i).then(function(t){localStorage.setItem("gisqDdUserInfo",t),o.userInfo=t})},freeLogin:function(n,o,i,a,c){var s=this;this.getAuthorCode(n).then(function(t){var e={authorCode:t.code};s.axiosPostFormData(o+"/user/freeLogin",e).then(function(t){t&&t.data.userInfo?(a(t),s.accessToken=t.data.accessToken,s.ticket=t.data.jsTicket,s.userInfo=t.data.userInfo,s.agentId=t.data.agentId,s.nonceStr=t.data.nonceStr,s.signature=t.data.signature,s.timeStamp=t.data.timeStamp,i&&s.jsAuthor(n,s.ticket,s.agentId,s.timeStamp,s.nonceStr,s.signature)):c("failed to login")}).catch(function(t){c(t)})}).catch(function(t){s.alert("获取授权码错误"+JSON.stringify(t))})},freeLoginNew:function(n,o,i,a,c,s,u){var r=this;this.getAuthorCode(i).then(function(t){var e={tdtype:n,authorCode:t.code,indexurl:o};r.axiosPostFormData(a+"/tdLogin",e).then(function(t){t&&t.data.userInfo?(s(t),r.accessToken=t.data.accessToken,r.ticket=t.data.jsTicket,r.userInfo=t.data.userInfo,r.agentId=t.data.agentId,r.nonceStr=t.data.nonceStr,r.signature=t.data.signature,r.timeStamp=t.data.timeStamp,c&&r.jsAuthor(i,r.ticket,r.agentId,r.timeStamp,r.nonceStr,r.signature)):u("failed to login")}).catch(function(t){u(t)})}).catch(function(t){u("获取授权码错误"+JSON.stringify(t)),r.alert("获取授权码错误"+JSON.stringify(t))})},getGeolocation:function(t,e,n){c.device.geolocation.get({targetAccuracy:100,coordinate:1,withReGeocode:!0,useCache:t,onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},getGeolocationCustom:function(t,e,n,o){c.device.geolocation.get(t).then(function(t){n(t)}).catch(function(t){o(t)})},gpsFollowStart:function(t,e,n){var o=(new Date).getTime()+"";this.scenseId=o,c.device.geolocation.start({targetAccuracy:200,iOSDistanceFilter:2,useCache:!1,withReGeocode:!1,callBackInterval:t,sceneId:o,onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},gpsFollowStop:function(e,n){c.device.geolocation.stop({sceneId:this.scenseId,onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},takePhoto:function(t,e){},recordVideo:function(t,e){},getPhoneInfo:function(e,n){c.device.base.getPhoneInfo({onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},getUUID:function(e,n){c.device.base.getUUID({onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},scan:function(t,e,n){c.biz.util.scan({type:t||"qr",onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},downloadFile:function(t){c.biz.util.downloadFile(t)},version:function(t,e){t(c.version)},ready:function(t){c.ready(function(){t()})}};t.gd=e,Object.defineProperty(t,"__esModule",{value:!0})});