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