系统变量增加组权限管理
This commit is contained in:
parent
b53b63532e
commit
862bb03efb
@ -60,6 +60,15 @@ export function fetchGetAllGroupConfigList(data: string[]) {
|
||||
});
|
||||
}
|
||||
|
||||
/** get all group config list */
|
||||
export function fetchGetAllGroupList(data: string[]) {
|
||||
return request<Api.GroupConfig.GroupConfig[]>({
|
||||
url: '/group/all/group/list',
|
||||
method: 'post',
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/** delete group by id */
|
||||
export function fetchDeleteGroup(groupName: string) {
|
||||
return request<boolean>({
|
||||
|
12
src/typings/api.d.ts
vendored
12
src/typings/api.d.ts
vendored
@ -998,7 +998,7 @@ declare namespace Api {
|
||||
/** 组名称 */
|
||||
groupName: string;
|
||||
/** 组名称 */
|
||||
groupNameCn: string;
|
||||
groupNameCn?: string;
|
||||
/** 负责人id */
|
||||
ownerId: string;
|
||||
/** 负责人名 */
|
||||
@ -1399,11 +1399,17 @@ declare namespace Api {
|
||||
/** value: yyyyMMdd */
|
||||
variableValue: string;
|
||||
/** 变量类型 1-字符串变量 2-表达式变量 */
|
||||
variableType: string;
|
||||
variableType: number;
|
||||
/** 描述 */
|
||||
description: string;
|
||||
/** 组 */
|
||||
permissions: Permission[];
|
||||
}>;
|
||||
type Permission = Common.CommonRecord<{
|
||||
groupName: string;
|
||||
namespaceId: string;
|
||||
namespaceName?: string;
|
||||
}>;
|
||||
|
||||
/**搜索参数*/
|
||||
type SystemVariableSearchParams = CommonType.RecordNullable<
|
||||
Pick<Api.SystemVariable.SystemVariable, 'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'> &
|
||||
|
@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { NTag } from 'naive-ui';
|
||||
import { roleRecord } from '@/constants/business';
|
||||
import {roleRecord, systemVariableTypeOptions} from '@/constants/business';
|
||||
import { $t } from '@/locales';
|
||||
import { tagColor } from '@/utils/common';
|
||||
|
||||
@ -26,8 +26,17 @@ const visible = defineModel<boolean>('visible', {
|
||||
<NDescriptionsItem :label="$t('page.system_variable.variableName')" :span="2">
|
||||
{{ rowData?.variableName }}
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem :label="$t('page.system_variable.variableType')" :span="2">
|
||||
{{ rowData?.variableType }}
|
||||
<NDescriptionsItem :label="$t('page.system_variable.variableType')" :span="2" >
|
||||
<NRadioGroup v-model:value="rowData?.variableType" name="initScene" disabled>
|
||||
<NSpace>
|
||||
<NRadio
|
||||
v-for="item in systemVariableTypeOptions"
|
||||
:key="item.value"
|
||||
:value="item.value"
|
||||
:label="$t(item.label)"
|
||||
/>
|
||||
</NSpace>
|
||||
</NRadioGroup>
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem :label="$t('page.system_variable.variableKey')" :span="2">
|
||||
{{ rowData?.variableKey }}
|
||||
@ -38,6 +47,16 @@ const visible = defineModel<boolean>('visible', {
|
||||
<NDescriptionsItem :label="$t('page.system_variable.description')" :span="2">
|
||||
{{ rowData?.description }}
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem
|
||||
v-if="rowData?.permissions !== undefined"
|
||||
:label="$t('page.userManager.permissionList')"
|
||||
:span="2"
|
||||
>
|
||||
<NTag v-for="(item, index) in rowData?.permissions" :key="index" type="info">
|
||||
<span class="title">{{ item.groupName }}</span>
|
||||
({{ item.namespaceName }})
|
||||
</NTag>
|
||||
</NDescriptionsItem>
|
||||
<NDescriptionsItem :label="$t('common.updateDt')" :span="2">
|
||||
{{ rowData?.updateDt }}
|
||||
</NDescriptionsItem>
|
||||
|
@ -4,9 +4,10 @@ import type { OptionValue } from 'naive-ui/es/transfer/src/interface';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
||||
import { $t } from '@/locales';
|
||||
import { fetchGetAllGroupConfigList } from '@/service/api';
|
||||
import {fetchGetAllGroupConfigList, fetchGetAllGroupList} from '@/service/api';
|
||||
import {systemVariableTypeOptions} from '@/constants/business';
|
||||
import {fetchEditVariable,fetchAddVariable} from "@/service/api/system-variable";
|
||||
import Permission = Api.SystemVariable.Permission;
|
||||
|
||||
defineOptions({
|
||||
name: 'SystemVariableOperateDrawer'
|
||||
@ -48,7 +49,7 @@ const title = computed(() => {
|
||||
|
||||
type Model = Pick<
|
||||
Api.SystemVariable.SystemVariable,
|
||||
'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'
|
||||
'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'|'permissions'
|
||||
>;
|
||||
|
||||
const model: Model = reactive(createDefaultModel());
|
||||
@ -59,30 +60,43 @@ function createDefaultModel(): Model {
|
||||
variableKey: '',
|
||||
variableValue: '',
|
||||
variableType: 1,
|
||||
description: ''
|
||||
description: '',
|
||||
permissions:[]
|
||||
};
|
||||
}
|
||||
|
||||
type RuleRecord = Partial<Record<keyof Model, App.Global.FormRule[]>>;
|
||||
|
||||
type RuleKey = Extract<
|
||||
keyof Model,
|
||||
| 'variableName'
|
||||
| 'variableKey'
|
||||
| 'variableValue'
|
||||
| 'variableType'
|
||||
| 'description'
|
||||
| 'permissions'
|
||||
>;
|
||||
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||
|
||||
variableName: defaultRequiredRule,
|
||||
variableKey: defaultRequiredRule,
|
||||
variableValue: defaultRequiredRule,
|
||||
variableType: defaultRequiredRule,
|
||||
description: defaultRequiredRule
|
||||
description: defaultRequiredRule,
|
||||
permissions:defaultRequiredRule
|
||||
|
||||
};
|
||||
|
||||
function handleUpdateModelWhenEdit() {
|
||||
if (props.operateType === 'add') {
|
||||
valueRef.value = [];
|
||||
Object.assign(model, createDefaultModel());
|
||||
return;
|
||||
}
|
||||
|
||||
if (props.operateType === 'edit' && props.rowData) {
|
||||
valueRef.value = props.rowData.permissions?.map(v => `${v.groupName}@${v.namespaceId}`);
|
||||
Object.assign(model, props.rowData);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,27 +113,30 @@ async function handleSubmit() {
|
||||
variableName,
|
||||
variableValue,
|
||||
variableType,
|
||||
description } = model;
|
||||
description,
|
||||
permissions} = model;
|
||||
const { error } = await fetchAddVariable({
|
||||
variableKey,
|
||||
variableName,
|
||||
variableValue,
|
||||
variableType,
|
||||
description
|
||||
description,
|
||||
permissions
|
||||
});
|
||||
if (error) return;
|
||||
window.$message?.success($t('common.addSuccess'));
|
||||
}
|
||||
|
||||
if (props.operateType === 'edit') {
|
||||
const { id, variableKey,variableName,variableValue,variableType,description } = model;
|
||||
const { id, variableKey,variableName,variableValue,variableType,description,permissions} = model;
|
||||
const { error } = await fetchEditVariable({
|
||||
id,
|
||||
variableKey,
|
||||
variableName,
|
||||
variableValue,
|
||||
variableType,
|
||||
description
|
||||
description,
|
||||
permissions
|
||||
});
|
||||
if (error) return;
|
||||
window.$message?.success($t('common.updateSuccess'));
|
||||
@ -130,7 +147,7 @@ async function handleSubmit() {
|
||||
}
|
||||
|
||||
const getAllGroupConfigList = async () => {
|
||||
const res = await fetchGetAllGroupConfigList([]);
|
||||
const res = await fetchGetAllGroupList([]);
|
||||
groupConfigs.value = res.data?.map(option => ({
|
||||
value: `${option.groupName}@${option.namespaceId}`,
|
||||
label: `${option.groupName}(${option.namespaceName})`
|
||||
@ -148,7 +165,26 @@ watch(visible, () => {
|
||||
restoreValidation();
|
||||
}
|
||||
});
|
||||
function updatePermissions(p: OptionValue[]) {
|
||||
// ['snail_job_demo_group@764d604ec6fc45f68cd92514c40e9e1a']
|
||||
model.permissions = p?.map(value => {
|
||||
return getPermission(value as string);
|
||||
});
|
||||
}
|
||||
|
||||
type PermissionModel = Pick<Permission, 'groupName' | 'namespaceId'>;
|
||||
|
||||
function getPermission(str: string): PermissionModel {
|
||||
const permissionModelComputedRef = computed<PermissionModel>(() => {
|
||||
const [groupName, namespaceId] = str.split('@'); // 将字符串分割成数组
|
||||
return {
|
||||
groupName,
|
||||
namespaceId
|
||||
};
|
||||
});
|
||||
|
||||
return permissionModelComputedRef.value;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -190,6 +226,16 @@ watch(visible, () => {
|
||||
<NFormItem :label="$t('page.system_variable.description')" path="description">
|
||||
<NInput v-model:value="model.description" :placeholder="$t('page.system_variable.form.description')" />
|
||||
</NFormItem>
|
||||
<NFormItem :label="$t('page.userManager.permissions')" path="permissions">
|
||||
<NTransfer
|
||||
v-model:value="valueRef"
|
||||
virtual-scroll
|
||||
:options="groupConfigs"
|
||||
target-filterable
|
||||
source-filterable
|
||||
@update-value="updatePermissions"
|
||||
/>
|
||||
</NFormItem>
|
||||
</NForm>
|
||||
<template #footer>
|
||||
<NSpace :size="16">
|
||||
|
Loading…
Reference in New Issue
Block a user