系统变量增加组权限管理
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 */
|
/** delete group by id */
|
||||||
export function fetchDeleteGroup(groupName: string) {
|
export function fetchDeleteGroup(groupName: string) {
|
||||||
return request<boolean>({
|
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;
|
groupName: string;
|
||||||
/** 组名称 */
|
/** 组名称 */
|
||||||
groupNameCn: string;
|
groupNameCn?: string;
|
||||||
/** 负责人id */
|
/** 负责人id */
|
||||||
ownerId: string;
|
ownerId: string;
|
||||||
/** 负责人名 */
|
/** 负责人名 */
|
||||||
@ -1399,11 +1399,17 @@ declare namespace Api {
|
|||||||
/** value: yyyyMMdd */
|
/** value: yyyyMMdd */
|
||||||
variableValue: string;
|
variableValue: string;
|
||||||
/** 变量类型 1-字符串变量 2-表达式变量 */
|
/** 变量类型 1-字符串变量 2-表达式变量 */
|
||||||
variableType: string;
|
variableType: number;
|
||||||
/** 描述 */
|
/** 描述 */
|
||||||
description: string;
|
description: string;
|
||||||
|
/** 组 */
|
||||||
|
permissions: Permission[];
|
||||||
|
}>;
|
||||||
|
type Permission = Common.CommonRecord<{
|
||||||
|
groupName: string;
|
||||||
|
namespaceId: string;
|
||||||
|
namespaceName?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
/**搜索参数*/
|
/**搜索参数*/
|
||||||
type SystemVariableSearchParams = CommonType.RecordNullable<
|
type SystemVariableSearchParams = CommonType.RecordNullable<
|
||||||
Pick<Api.SystemVariable.SystemVariable, 'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'> &
|
Pick<Api.SystemVariable.SystemVariable, 'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'> &
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NTag } from 'naive-ui';
|
import { NTag } from 'naive-ui';
|
||||||
import { roleRecord } from '@/constants/business';
|
import {roleRecord, systemVariableTypeOptions} from '@/constants/business';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { tagColor } from '@/utils/common';
|
import { tagColor } from '@/utils/common';
|
||||||
|
|
||||||
@ -26,8 +26,17 @@ const visible = defineModel<boolean>('visible', {
|
|||||||
<NDescriptionsItem :label="$t('page.system_variable.variableName')" :span="2">
|
<NDescriptionsItem :label="$t('page.system_variable.variableName')" :span="2">
|
||||||
{{ rowData?.variableName }}
|
{{ rowData?.variableName }}
|
||||||
</NDescriptionsItem>
|
</NDescriptionsItem>
|
||||||
<NDescriptionsItem :label="$t('page.system_variable.variableType')" :span="2">
|
<NDescriptionsItem :label="$t('page.system_variable.variableType')" :span="2" >
|
||||||
{{ rowData?.variableType }}
|
<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>
|
||||||
<NDescriptionsItem :label="$t('page.system_variable.variableKey')" :span="2">
|
<NDescriptionsItem :label="$t('page.system_variable.variableKey')" :span="2">
|
||||||
{{ rowData?.variableKey }}
|
{{ rowData?.variableKey }}
|
||||||
@ -38,6 +47,16 @@ const visible = defineModel<boolean>('visible', {
|
|||||||
<NDescriptionsItem :label="$t('page.system_variable.description')" :span="2">
|
<NDescriptionsItem :label="$t('page.system_variable.description')" :span="2">
|
||||||
{{ rowData?.description }}
|
{{ rowData?.description }}
|
||||||
</NDescriptionsItem>
|
</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">
|
<NDescriptionsItem :label="$t('common.updateDt')" :span="2">
|
||||||
{{ rowData?.updateDt }}
|
{{ rowData?.updateDt }}
|
||||||
</NDescriptionsItem>
|
</NDescriptionsItem>
|
||||||
|
@ -4,9 +4,10 @@ import type { OptionValue } from 'naive-ui/es/transfer/src/interface';
|
|||||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||||
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
import OperateDrawer from '@/components/common/operate-drawer.vue';
|
||||||
import { $t } from '@/locales';
|
import { $t } from '@/locales';
|
||||||
import { fetchGetAllGroupConfigList } from '@/service/api';
|
import {fetchGetAllGroupConfigList, fetchGetAllGroupList} from '@/service/api';
|
||||||
import {systemVariableTypeOptions} from '@/constants/business';
|
import {systemVariableTypeOptions} from '@/constants/business';
|
||||||
import {fetchEditVariable,fetchAddVariable} from "@/service/api/system-variable";
|
import {fetchEditVariable,fetchAddVariable} from "@/service/api/system-variable";
|
||||||
|
import Permission = Api.SystemVariable.Permission;
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'SystemVariableOperateDrawer'
|
name: 'SystemVariableOperateDrawer'
|
||||||
@ -48,7 +49,7 @@ const title = computed(() => {
|
|||||||
|
|
||||||
type Model = Pick<
|
type Model = Pick<
|
||||||
Api.SystemVariable.SystemVariable,
|
Api.SystemVariable.SystemVariable,
|
||||||
'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'
|
'id' | 'variableName' | 'variableKey' | 'variableValue' | 'variableType' | 'description'|'permissions'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
const model: Model = reactive(createDefaultModel());
|
const model: Model = reactive(createDefaultModel());
|
||||||
@ -59,30 +60,43 @@ function createDefaultModel(): Model {
|
|||||||
variableKey: '',
|
variableKey: '',
|
||||||
variableValue: '',
|
variableValue: '',
|
||||||
variableType: 1,
|
variableType: 1,
|
||||||
description: ''
|
description: '',
|
||||||
|
permissions:[]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
type RuleRecord = Partial<Record<keyof Model, App.Global.FormRule[]>>;
|
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> = {
|
const rules: Record<RuleKey, App.Global.FormRule> = {
|
||||||
|
|
||||||
variableName: defaultRequiredRule,
|
variableName: defaultRequiredRule,
|
||||||
variableKey: defaultRequiredRule,
|
variableKey: defaultRequiredRule,
|
||||||
variableValue: defaultRequiredRule,
|
variableValue: defaultRequiredRule,
|
||||||
variableType: defaultRequiredRule,
|
variableType: defaultRequiredRule,
|
||||||
description: defaultRequiredRule
|
description: defaultRequiredRule,
|
||||||
|
permissions:defaultRequiredRule
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function handleUpdateModelWhenEdit() {
|
function handleUpdateModelWhenEdit() {
|
||||||
if (props.operateType === 'add') {
|
if (props.operateType === 'add') {
|
||||||
|
valueRef.value = [];
|
||||||
Object.assign(model, createDefaultModel());
|
Object.assign(model, createDefaultModel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.operateType === 'edit' && props.rowData) {
|
if (props.operateType === 'edit' && props.rowData) {
|
||||||
|
valueRef.value = props.rowData.permissions?.map(v => `${v.groupName}@${v.namespaceId}`);
|
||||||
Object.assign(model, props.rowData);
|
Object.assign(model, props.rowData);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,27 +113,30 @@ async function handleSubmit() {
|
|||||||
variableName,
|
variableName,
|
||||||
variableValue,
|
variableValue,
|
||||||
variableType,
|
variableType,
|
||||||
description } = model;
|
description,
|
||||||
|
permissions} = model;
|
||||||
const { error } = await fetchAddVariable({
|
const { error } = await fetchAddVariable({
|
||||||
variableKey,
|
variableKey,
|
||||||
variableName,
|
variableName,
|
||||||
variableValue,
|
variableValue,
|
||||||
variableType,
|
variableType,
|
||||||
description
|
description,
|
||||||
|
permissions
|
||||||
});
|
});
|
||||||
if (error) return;
|
if (error) return;
|
||||||
window.$message?.success($t('common.addSuccess'));
|
window.$message?.success($t('common.addSuccess'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.operateType === 'edit') {
|
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({
|
const { error } = await fetchEditVariable({
|
||||||
id,
|
id,
|
||||||
variableKey,
|
variableKey,
|
||||||
variableName,
|
variableName,
|
||||||
variableValue,
|
variableValue,
|
||||||
variableType,
|
variableType,
|
||||||
description
|
description,
|
||||||
|
permissions
|
||||||
});
|
});
|
||||||
if (error) return;
|
if (error) return;
|
||||||
window.$message?.success($t('common.updateSuccess'));
|
window.$message?.success($t('common.updateSuccess'));
|
||||||
@ -130,7 +147,7 @@ async function handleSubmit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const getAllGroupConfigList = async () => {
|
const getAllGroupConfigList = async () => {
|
||||||
const res = await fetchGetAllGroupConfigList([]);
|
const res = await fetchGetAllGroupList([]);
|
||||||
groupConfigs.value = res.data?.map(option => ({
|
groupConfigs.value = res.data?.map(option => ({
|
||||||
value: `${option.groupName}@${option.namespaceId}`,
|
value: `${option.groupName}@${option.namespaceId}`,
|
||||||
label: `${option.groupName}(${option.namespaceName})`
|
label: `${option.groupName}(${option.namespaceName})`
|
||||||
@ -148,7 +165,26 @@ watch(visible, () => {
|
|||||||
restoreValidation();
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -190,6 +226,16 @@ watch(visible, () => {
|
|||||||
<NFormItem :label="$t('page.system_variable.description')" path="description">
|
<NFormItem :label="$t('page.system_variable.description')" path="description">
|
||||||
<NInput v-model:value="model.description" :placeholder="$t('page.system_variable.form.description')" />
|
<NInput v-model:value="model.description" :placeholder="$t('page.system_variable.form.description')" />
|
||||||
</NFormItem>
|
</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>
|
</NForm>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<NSpace :size="16">
|
<NSpace :size="16">
|
||||||
|
Loading…
Reference in New Issue
Block a user