提交 1bf72b36 编写于 作者: KK's avatar KK

服务调整

上级 d30de9d9
import axios from "axios";
import * as dd from "dingtalk-jsapi";
import { Util, Http } from "@/ibiz-core/utils";
import { Util } from "@/ibiz-core/utils";
import store from "@/store";
import qs from 'qs';
import { Notice } from "../../utils/notice/notice";
/**
* 钉钉服务
......@@ -78,15 +79,6 @@ export class DingTalkService {
*/
public $store: any;
/**
* 请求服务对象
*
* @protected
* @type {Http}
* @memberof DingTalkService
*/
protected http: Http = Http.getInstance();
/**
* Creates an instance of DingTalkService.
* @memberof DingTalkService
......@@ -153,18 +145,17 @@ export class DingTalkService {
} else {
let openAccessId = document.referrer ? document.referrer : "dingtalk";
let url = window.location.href.replace(window.location.hash, '')
const promise: Promise<any> = this.http.get(`/uaa/dingtalk/jsapi/sign`, { openAccessId: openAccessId, url: url });
const promise: Promise<any> = this.get(`/uaa/dingtalk/jsapi/sign` + qs.stringify({ openAccessId: openAccessId, url: url }));
promise.then((response: any) => {
if (response && response.status === 200) {
localStorage.setItem("access_token", JSON.stringify(Object.assign(response.data, { time: new Date().getTime() })));
resolve(response.data);
} else {
resolve(response);
resolve(null);
}
})
.catch((response: any) => {
}).catch((response: any) => {
console.error(response);
reject(response);
resolve(null);
});
}
});
......@@ -176,13 +167,13 @@ export class DingTalkService {
* @memberof DingTalkService
*/
public async login(): Promise<any> {
const access_token: any = await this.http.get(`/uaa/open/dingtalk/access_token`);
const access_token: any = await this.get(`/uaa/open/dingtalk/access_token`);
if (access_token.status == 200 && access_token.data && access_token.data.corp_id) {
localStorage.setItem("access_token", JSON.stringify(Object.assign(access_token, new Date().getTime)));
this.corpId = access_token.data.corp_id;
const res: any = await dd.runtime.permission.requestAuthCode({ corpId: this.corpId, });
if (res && res.code) {
const userInfo: any = await this.http.get(`/uaa/open/dingtalk/auth/${res.code}`);
const userInfo: any = await this.get(`/uaa/open/dingtalk/auth/${res.code}`);
if (userInfo.status == 200 && userInfo.data.token && userInfo.data.user) {
localStorage.setItem("token", userInfo.data.token);
localStorage.setItem("user", JSON.stringify(userInfo.data.user));
......@@ -198,6 +189,26 @@ export class DingTalkService {
}
}
/**
* 请求(需要替换为项目)
*
* @private
* @param {string} url
* @returns {Promise<any>}
* @memberof DingTalkService
*/
private async get(url: string): Promise<any> {
return new Promise((resolve) => {
axios.get(url)
.then((response: any) => {
resolve(response);
}).catch((error: any) => {
resolve(error);
console.log("请求异常");
});
});
}
/**
* 开始录音
*
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册