feat(product): 新增产品管理模块与字典组件功能
- 新增产品管理相关路由和页面(dashboard、list、requirement、setting) - 实现产品基础信息编辑弹窗组件(base-info-dialog.vue) - 添加运行时字典功能(dict-select、dict-text、dict-tag组件) - 集成字典管理store和API调用 - 规范ID类型定义为string避免精度丢失问题 - 完善国际化资源文件支持中英文对照 - 新增对象上下文业务域入口页导航实现说明 - 添加Vue DevTools浮动入口注释说明 - 统一权限控制支持全局和对象作用域区分 - 规范分页查询参数类型定义与使用方式
This commit is contained in:
46
src/directives/auth-shared.ts
Normal file
46
src/directives/auth-shared.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
export type AuthSource = 'global' | 'object' | 'both';
|
||||
|
||||
export interface AuthDirectiveBindingValue {
|
||||
code: string | string[];
|
||||
source?: AuthSource;
|
||||
}
|
||||
|
||||
export interface AuthDirectiveCodeSource {
|
||||
globalButtonCodes: string[];
|
||||
objectButtonCodes: string[];
|
||||
}
|
||||
|
||||
function normalizeCodes(codes: string | string[]) {
|
||||
return Array.isArray(codes) ? codes : [codes];
|
||||
}
|
||||
|
||||
function includesAny(sourceCodes: string[], targetCodes: string[]) {
|
||||
return targetCodes.some(code => sourceCodes.includes(code));
|
||||
}
|
||||
|
||||
export function resolveAuthVisible(
|
||||
bindingValue: string | AuthDirectiveBindingValue,
|
||||
codeSource: AuthDirectiveCodeSource
|
||||
) {
|
||||
const resolvedBinding =
|
||||
typeof bindingValue === 'string'
|
||||
? {
|
||||
code: bindingValue,
|
||||
source: 'global' as const
|
||||
}
|
||||
: bindingValue;
|
||||
|
||||
const targetCodes = normalizeCodes(resolvedBinding.code);
|
||||
const hasGlobal = includesAny(codeSource.globalButtonCodes, targetCodes);
|
||||
const hasObject = includesAny(codeSource.objectButtonCodes, targetCodes);
|
||||
|
||||
if (resolvedBinding.source === 'object') {
|
||||
return hasObject;
|
||||
}
|
||||
|
||||
if (resolvedBinding.source === 'both') {
|
||||
return hasGlobal || hasObject;
|
||||
}
|
||||
|
||||
return hasGlobal;
|
||||
}
|
||||
44
src/directives/auth.ts
Normal file
44
src/directives/auth.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { watchEffect } from 'vue';
|
||||
import type { Directive } from 'vue';
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
import { useObjectContextStore } from '@/store/modules/object-context';
|
||||
import { type AuthDirectiveBindingValue, resolveAuthVisible } from './auth-shared';
|
||||
|
||||
type AuthDirectiveElement = HTMLElement & {
|
||||
authStopHandle?: (() => void) | null;
|
||||
};
|
||||
|
||||
function toggleElementVisible(el: HTMLElement, visible: boolean) {
|
||||
el.style.display = visible ? '' : 'none';
|
||||
}
|
||||
|
||||
function getVisible(bindingValue: string | AuthDirectiveBindingValue) {
|
||||
const authStore = useAuthStore();
|
||||
const objectContextStore = useObjectContextStore();
|
||||
|
||||
return resolveAuthVisible(bindingValue, {
|
||||
globalButtonCodes: authStore.userInfo.buttons,
|
||||
objectButtonCodes: objectContextStore.buttonCodes
|
||||
});
|
||||
}
|
||||
|
||||
function bindAuthEffect(el: AuthDirectiveElement, bindingValue: string | AuthDirectiveBindingValue) {
|
||||
el.authStopHandle?.();
|
||||
|
||||
el.authStopHandle = watchEffect(() => {
|
||||
toggleElementVisible(el, getVisible(bindingValue));
|
||||
});
|
||||
}
|
||||
|
||||
export const authDirective: Directive<AuthDirectiveElement, string | AuthDirectiveBindingValue> = {
|
||||
mounted(el, binding) {
|
||||
bindAuthEffect(el, binding.value);
|
||||
},
|
||||
updated(el, binding) {
|
||||
bindAuthEffect(el, binding.value);
|
||||
},
|
||||
unmounted(el) {
|
||||
el.authStopHandle?.();
|
||||
el.authStopHandle = null;
|
||||
}
|
||||
};
|
||||
6
src/directives/index.ts
Normal file
6
src/directives/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import type { App } from 'vue';
|
||||
import { authDirective } from './auth';
|
||||
|
||||
export function setupDirectives(app: App) {
|
||||
app.directive('auth', authDirective);
|
||||
}
|
||||
Reference in New Issue
Block a user