Browse Source

feat: 补充全局自定义权限指令

main
xuziqiang 3 months ago
parent
commit
edfc11825d
  1. 9
      hx-ai-intelligent/src/directives/index.ts
  2. 48
      hx-ai-intelligent/src/directives/permission.ts
  3. 7
      hx-ai-intelligent/src/main.ts
  4. 4
      hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue

9
hx-ai-intelligent/src/directives/index.ts

@ -0,0 +1,9 @@
/**
* Configure and register global directives
*/
import type { App } from 'vue';
import { setupPermissionDirective } from './permission';
export function setupGlobDirectives(app: App) {
setupPermissionDirective(app);
}

48
hx-ai-intelligent/src/directives/permission.ts

@ -0,0 +1,48 @@
/**
* Global authority directive
* Used for fine-grained control of component permissions
* @Example v-auth="name"
*/
import type { App, Directive, DirectiveBinding } from 'vue';
import { authorizationService } from '/nerv-lib/saas/store/modules/authorization-service';
function isAuth(el: Element, binding: any) {
console.log(el, binding);
const { checkPermission, checkAllPermission, checkPermissionRouter } = authorizationService();
const { value, modifiers } = binding;
if (!value) return;
//操作按钮
if (modifiers.op) {
if (!checkPermission(value)) {
el.parentNode?.removeChild(el);
}
}
// 全部
if (modifiers.all) {
if (!checkAllPermission(value)) {
el.parentNode?.removeChild(el);
}
}
// 路由
if (modifiers.route) {
if (!checkPermissionRouter(value)) {
el.parentNode?.removeChild(el);
}
}
}
const mounted = (el: Element, binding: DirectiveBinding<string | string[]>) => {
isAuth(el, binding);
};
const authDirective: Directive = {
mounted,
};
export function setupPermissionDirective(app: App) {
app.directive('auth', authDirective);
}
export default authDirective;

7
hx-ai-intelligent/src/main.ts

@ -5,8 +5,15 @@ import { apiModule } from '/@/api';
import { appConfig } from '/@/config'; import { appConfig } from '/@/config';
import './theme/global.less'; import './theme/global.less';
import { LeftOutlined } from '@ant-design/icons-vue'; import { LeftOutlined } from '@ant-design/icons-vue';
import { setupGlobDirectives } from '/@/directives';
const app = createApp(App); const app = createApp(App);
app.component('LeftOutlined', LeftOutlined); app.component('LeftOutlined', LeftOutlined);
// Register global directive
// 注册全局指令
setupGlobDirectives(app);
saasInit({ saasInit({
app, app,
apiModule, apiModule,

4
hx-ai-intelligent/src/view/organizationManage/departmentManage/index.vue

@ -79,7 +79,9 @@
<a-row> <a-row>
<a-col :span="8" class="tree"> <a-col :span="8" class="tree">
<a-space wrap style="margin-bottom: 16px; justify-content: flex-start"> <a-space wrap style="margin-bottom: 16px; justify-content: flex-start">
<ns-button type="primary" @click="rolePipe(addUser, true)"> 新增角色 </ns-button> <ns-button v-auth="'userAdd'" type="primary" @click="rolePipe(addUser, true)">
新增角色
</ns-button>
<ns-button type="primary" @click="rolePipe(addUserSon)">新增子角色</ns-button> <ns-button type="primary" @click="rolePipe(addUserSon)">新增子角色</ns-button>
<ns-button type="primary" @click="rolePipe(deleteUser)"> 删除 </ns-button> <ns-button type="primary" @click="rolePipe(deleteUser)"> 删除 </ns-button>
</a-space> </a-space>

Loading…
Cancel
Save