You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
JavaScript
63 lines
1.7 KiB
JavaScript
3 years ago
|
import {makeAutoObservable, runInAction} from "mobx";
|
||
|
import * as dd from 'dingtalk-jsapi';
|
||
|
import * as config from "../config";
|
||
|
import {Outlet, Navigate} from 'react-router-dom';
|
||
|
|
||
|
|
||
|
//权限管理
|
||
|
class AuthStore {
|
||
|
|
||
|
constructor(rootStore) {
|
||
|
this.rootStore = rootStore;
|
||
|
makeAutoObservable(this);
|
||
|
this.get_auth_info();
|
||
|
}
|
||
|
|
||
|
auth = [];
|
||
|
|
||
|
has_permission(requireds) {
|
||
|
if (Object.keys(requireds).length == 0) {
|
||
|
return true;
|
||
|
}
|
||
|
let has_permission = requireds.filter(item => this.auth.includes(item));
|
||
|
if (Object.keys(has_permission).length !== 0) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
get_auth_info() {
|
||
|
if (this.auth == false) { //如果没有权限,则去请求获取
|
||
|
this.auth = ['customer_care'];
|
||
|
}
|
||
|
return;
|
||
|
const CORPID = 'ding48bce8fd3957c96b';//企业的id
|
||
|
dd.runtime.permission.requestAuthCode({
|
||
|
corpId: CORPID,
|
||
|
onSuccess: function (res) {
|
||
|
let code = res.code;
|
||
|
runInAction(() => {
|
||
|
this.auth = ['admin'];
|
||
|
})
|
||
|
let url = '?code=' + code;
|
||
|
//请求获取HT接口获取用户权限和用户信息
|
||
|
fetch(config.HT_HOST + url)
|
||
|
.then((response) => response.json())
|
||
|
.then((json) => {
|
||
|
console.log(json);
|
||
|
})
|
||
|
.catch((error) => {
|
||
|
console.log('fetch data failed', error);
|
||
|
});
|
||
|
},
|
||
|
onFail: function (err) {
|
||
|
console.log(err)
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
export default AuthStore;
|
||
|
|