默认权限设置为空
parent
21e70b9dfb
commit
23de7481bd
@ -1,59 +1,59 @@
|
|||||||
import { makeAutoObservable, runInAction } from "mobx";
|
import { makeAutoObservable, runInAction } from 'mobx';
|
||||||
import * as dd from "dingtalk-jsapi";
|
import * as dd from 'dingtalk-jsapi';
|
||||||
import * as config from "../config";
|
import * as config from '../config';
|
||||||
|
|
||||||
// 权限管理
|
// 权限管理
|
||||||
class AuthStore {
|
class AuthStore {
|
||||||
constructor(rootStore) {
|
constructor(rootStore) {
|
||||||
this.rootStore = rootStore;
|
this.rootStore = rootStore;
|
||||||
makeAutoObservable(this);
|
makeAutoObservable(this);
|
||||||
if (process.env.NODE_ENV == "production") {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
this.get_auth(); // 放到钉钉环境才能开启
|
this.get_auth(); // 放到钉钉环境才能开启
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auth = ["admin"]; // 开发时候用,正式环境留空
|
auth = process.env.NODE_ENV === 'production' ? [] : ['admin']; // 开发时候用,正式环境留空
|
||||||
user = { name: "loading", userid: "..." }; // 开发时候用,正式环境留空
|
user = { name: 'loading', userid: '...' }; // 开发时候用,正式环境留空
|
||||||
|
|
||||||
has_permission(requireds) {
|
has_permission(requireds) {
|
||||||
if (Object.keys(requireds).length == 0) {
|
if (Object.keys(requireds).length === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const has_permission = requireds.filter(item => this.auth.includes(item));
|
const has_permission = requireds.filter((item) => this.auth.includes(item));
|
||||||
if (Object.keys(has_permission).length !== 0) {
|
if (Object.keys(has_permission).length !== 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求权限
|
// 请求权限
|
||||||
get_auth() {
|
get_auth() {
|
||||||
const _this = this;
|
const _this = this;
|
||||||
const CORPID = "ding48bce8fd3957c96b"; // 企业的id
|
const CORPID = 'ding48bce8fd3957c96b'; // 企业的id
|
||||||
dd.runtime.permission.requestAuthCode({
|
dd.runtime.permission.requestAuthCode({
|
||||||
corpId: CORPID,
|
corpId: CORPID,
|
||||||
onSuccess: function (res) {
|
onSuccess: function (res) {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
const code = res.code;
|
const code = res.code;
|
||||||
const url = "/dingtalk/dingtalkwork/Getusers_auth?code=" + code;
|
const url = '/dingtalk/dingtalkwork/Getusers_auth?code=' + code;
|
||||||
// 请求获取HT接口获取用户权限和用户信息
|
// 请求获取HT接口获取用户权限和用户信息
|
||||||
fetch(config.HT_HOST + url)
|
fetch(config.HT_HOST + url)
|
||||||
.then(response => response.json())
|
.then((response) => response.json())
|
||||||
.then(json => {
|
.then((json) => {
|
||||||
runInAction(() => {
|
runInAction(() => {
|
||||||
_this.user = json.result;
|
_this.user = json.result;
|
||||||
_this.auth = json.result.authlist;
|
_this.auth = json.result.authlist;
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
console.log("fetch data failed", error);
|
console.log('fetch data failed', error);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onFail: function (err) {
|
onFail: function (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default AuthStore;
|
export default AuthStore;
|
||||||
|
Loading…
Reference in New Issue