UNPKG

gisq-dd-mobile

Version:

gisq dingding mobile lib

2 lines (1 loc) 5.2 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("gdt-jsapi"),require("axios")):"function"==typeof define&&define.amd?define(["exports","gdt-jsapi","axios"],e):e((t=t||self).gisq={},t.dd,t.axios)}(this,function(t,c,i){"use strict";c=c&&Object.prototype.hasOwnProperty.call(c,"default")?c.default:c,i=i&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i;var e={authorCode:"",accessToken:"",ticket:"",userInfo:"",agentId:"",signature:"",nonceStr:"",timeStamp:"",scenseId:"",locate:function(){console.log("locate")},alert:function(t){console.log("locate"),c&&c.alert({message:t})},axiosGet:function(t,o){return new Promise(function(e,n){i.get(t,{params:o}).then(function(t){e(t.data)}).catch(function(t){n(t.data)})})},axiosPost:function(t,o){return i.defaults.headers.post["Content-Type"]="application/json;charset=UTF-8",new Promise(function(e,n){i.post(t,o).then(function(t){e(t.data)}).catch(function(t){n(t.data)})})},axiosPostFormData:function(c,a){return i.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]);i.post(c,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){if(c){var n=this;c.authConfig({ticket:t,jsApiList:["alert","createChatGroup","openChat","copyToClipboard","getGeolocation","chooseDepartments","chooseContactWithComplexPicker","chooseContact","takePhoto","startGeolocation","stopGeolocation","downloadFile"]}).then(function(t){console.log(t),e()}).catch(function(t){console.log(t),n.alert("js授权错误"+JSON.stringify(t))})}},getAuthorCode:function(t){if(c)return new Promise(function(e,n){c.getAuthCode({corpId:t}).then(function(t){console.log(t),e(t)}).catch(function(t){n(t)})})},getUserDetail:function(t,e,n){var o=this,c={accessToken:e,authorCode:n};this.axiosGet(t+"/user/getUserDetail",c).then(function(t){localStorage.setItem("gisqDdUserInfo",t),o.userInfo=t})},freeLogin:function(t,n,o,c,a){var i=this;this.getAuthorCode(t).then(function(t){var e={authorCode:t.code};i.axiosPostFormData(n+"/user/freeLogin",e).then(function(t){t&&t.data.userInfo?(i.accessToken=t.data.accessToken,i.ticket=t.data.jsTicket,i.userInfo=t.data.userInfo,c(t),o&&i.jsAuthor(i.ticket,function(){})):a("failed to login")})}).catch(function(t){i.alert("获取授权码错误"+JSON.stringify(t))})},freeLoginNew:function(n,o,t,c,a,i,s){var u=this;this.getAuthorCode(t).then(function(t){var e={tdtype:n,authorCode:t.code,indexurl:o};u.axiosPostFormData(c+"/tdLogin",e).then(function(t){t&&t.data.userInfo?(u.accessToken=t.data.accessToken,u.ticket=t.data.jsTicket,u.userInfo=t.data.userInfo,u.agentId=t.data.agentId,u.nonceStr=t.data.nonceStr,u.signature=t.data.signature,u.timeStamp=t.data.timeStamp,i(t),a&&u.jsAuthor(u.ticket,function(){})):s("failed to login")})}).catch(function(t){u.alert("获取授权码错误"+JSON.stringify(t))})},getGeolocation:function(t,e,n){c.getGeolocation({targetAccuracy:200,coordinate:1,withReGeocode:!0,useCache:t}).then(function(t){e(t)}).catch(function(t){n(t)})},getGeolocationCustom:function(t,e,n,o){c.getGeolocation(t).then(function(t){n(t)}).catch(function(t){o(t)})},takePhoto:function(e,n){c.takePhoto().then(function(t){e(t)}).catch(function(t){n(t)})},recordVideo:function(e,n){c.shootVideo().then(function(t){e(t)}).catch(function(t){n(t)})},getPhoneInfo:function(e,n){c.getPhoneInfo().then(function(t){e(t)}).catch(function(t){n(t)})},getUUID:function(e,n){c.getUUID().then(function(t){e(t)}).catch(function(t){n(t)})},scan:function(t,e,n){c.scan({type:t||"qr"}).then(function(t){e(t)}).catch(function(t){n(t)})},version:function(e,n){c.version().then(function(t){e(t)}).catch(function(t){n(t)})},ready:function(t){c.ready(function(){t()})},getLoginUser:function(e,n){c.getLoginUser().then(function(t){e(t)}).catch(function(t){n(t)})},fetchLocal:function(o){return new Promise(function(t,e){var n=new XMLHttpRequest;n.responseType="arraybuffer",n.onload=function(){0==n.status&&(n.status=200),t(new Response(n.response,{status:n.status}))},n.onerror=function(){e(new TypeError("Local request failed"))},n.open("GET",o),n.send(null)})},getMobileLocalFile:function(t,n,o,e){this.fetchLocal(t).then(function(t){return t.arrayBuffer()}).then(function(t){var e=new File([new Blob([t])],n,{type:"text/plain",lastModified:""+new Date});o(e)}).catch(function(t){e(t)})},gpsFollowStart:function(t,e,n){var o=(new Date).getTime()+"";this.scenseId=o,c.startGeolocation({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.stopGeolocation({sceneId:this.scenseId,onSuccess:function(t){e(t)},onFail:function(t){n(t)}})},downloadFile:function(t){c.downloadFile(t)}};t.gd=e,Object.defineProperty(t,"__esModule",{value:!0})});