8 changed files with 511 additions and 0 deletions
@ -0,0 +1,100 @@ |
|||
import type { ListResultDto } from '@abp/core'; |
|||
|
|||
import type { |
|||
FeatureGroupDefinitionCreateDto, |
|||
FeatureGroupDefinitionDto, |
|||
FeatureGroupDefinitionGetListInput, |
|||
FeatureGroupDefinitionUpdateDto, |
|||
} from '../types/groups'; |
|||
|
|||
import { useRequest } from '@abp/request'; |
|||
|
|||
export function useFeatureGroupDefinitionsApi() { |
|||
const { cancel, request } = useRequest(); |
|||
|
|||
/** |
|||
* 删除功能定义 |
|||
* @param name 功能名称 |
|||
*/ |
|||
function deleteApi(name: string): Promise<void> { |
|||
return request(`/api/feature-management/definitions/groups/${name}`, { |
|||
method: 'DELETE', |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* 查询功能定义 |
|||
* @param name 功能名称 |
|||
* @returns 功能定义数据传输对象 |
|||
*/ |
|||
function getApi(name: string): Promise<FeatureGroupDefinitionDto> { |
|||
return request<FeatureGroupDefinitionDto>( |
|||
`/api/feature-management/definitions/groups/${name}`, |
|||
{ |
|||
method: 'GET', |
|||
}, |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 查询功能定义列表 |
|||
* @param input 功能过滤条件 |
|||
* @returns 功能定义数据传输对象列表 |
|||
*/ |
|||
function getListApi( |
|||
input?: FeatureGroupDefinitionGetListInput, |
|||
): Promise<ListResultDto<FeatureGroupDefinitionDto>> { |
|||
return request<ListResultDto<FeatureGroupDefinitionDto>>( |
|||
`/api/feature-management/definitions/groups`, |
|||
{ |
|||
method: 'GET', |
|||
params: input, |
|||
}, |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 创建功能定义 |
|||
* @param input 功能定义参数 |
|||
* @returns 功能定义数据传输对象 |
|||
*/ |
|||
function createApi( |
|||
input: FeatureGroupDefinitionCreateDto, |
|||
): Promise<FeatureGroupDefinitionDto> { |
|||
return request<FeatureGroupDefinitionDto>( |
|||
'/api/feature-management/definitions/groups', |
|||
{ |
|||
data: input, |
|||
method: 'POST', |
|||
}, |
|||
); |
|||
} |
|||
|
|||
/** |
|||
* 更新功能定义 |
|||
* @param name 功能名称 |
|||
* @param input 功能定义参数 |
|||
* @returns 功能定义数据传输对象 |
|||
*/ |
|||
function updateApi( |
|||
name: string, |
|||
input: FeatureGroupDefinitionUpdateDto, |
|||
): Promise<FeatureGroupDefinitionDto> { |
|||
return request<FeatureGroupDefinitionDto>( |
|||
`/api/feature-management/definitions/groups/${name}`, |
|||
{ |
|||
data: input, |
|||
method: 'PUT', |
|||
}, |
|||
); |
|||
} |
|||
|
|||
return { |
|||
cancel, |
|||
createApi, |
|||
deleteApi, |
|||
getApi, |
|||
getListApi, |
|||
updateApi, |
|||
}; |
|||
} |
|||
@ -0,0 +1,150 @@ |
|||
<script setup lang="ts"> |
|||
import type { PropertyInfo } from '@abp/ui'; |
|||
import type { FormInstance } from 'ant-design-vue'; |
|||
|
|||
import type { FeatureGroupDefinitionDto } from '../../../types/groups'; |
|||
|
|||
import { defineEmits, defineOptions, ref, toValue, useTemplateRef } from 'vue'; |
|||
|
|||
import { useVbenModal } from '@vben/common-ui'; |
|||
import { $t } from '@vben/locales'; |
|||
|
|||
import { LocalizableInput, PropertyTable } from '@abp/ui'; |
|||
import { Form, Input, message, Tabs } from 'ant-design-vue'; |
|||
|
|||
import { useFeatureGroupDefinitionsApi } from '../../../api/useFeatureGroupDefinitionsApi'; |
|||
|
|||
defineOptions({ |
|||
name: 'FeatureGroupDefinitionModal', |
|||
}); |
|||
const emits = defineEmits<{ |
|||
(event: 'change', data: FeatureGroupDefinitionDto): void; |
|||
}>(); |
|||
|
|||
const FormItem = Form.Item; |
|||
const TabPane = Tabs.TabPane; |
|||
|
|||
type TabKeys = 'basic' | 'props'; |
|||
|
|||
const defaultModel = {} as FeatureGroupDefinitionDto; |
|||
|
|||
const isEditModel = ref(false); |
|||
const activeTab = ref<TabKeys>('basic'); |
|||
const form = useTemplateRef<FormInstance>('form'); |
|||
const formModel = ref<FeatureGroupDefinitionDto>({ ...defaultModel }); |
|||
|
|||
const { cancel, createApi, getApi, updateApi } = |
|||
useFeatureGroupDefinitionsApi(); |
|||
const [Modal, modalApi] = useVbenModal({ |
|||
class: 'w-1/2', |
|||
draggable: true, |
|||
fullscreenButton: false, |
|||
onCancel() { |
|||
modalApi.close(); |
|||
}, |
|||
onClosed() { |
|||
cancel('FeatureGroupDefinitionModal has closed!'); |
|||
}, |
|||
onConfirm: async () => { |
|||
await form.value?.validate(); |
|||
const api = isEditModel.value |
|||
? updateApi(formModel.value.name, toValue(formModel)) |
|||
: createApi(toValue(formModel)); |
|||
modalApi.setState({ confirmLoading: true, loading: true }); |
|||
api |
|||
.then((res) => { |
|||
message.success($t('AbpUi.SavedSuccessfully')); |
|||
emits('change', res); |
|||
modalApi.close(); |
|||
}) |
|||
.finally(() => { |
|||
modalApi.setState({ confirmLoading: false, loading: false }); |
|||
}); |
|||
}, |
|||
onOpenChange: async (isOpen: boolean) => { |
|||
if (isOpen) { |
|||
isEditModel.value = false; |
|||
activeTab.value = 'basic'; |
|||
formModel.value = { ...defaultModel }; |
|||
modalApi.setState({ |
|||
showConfirmButton: true, |
|||
title: $t('AbpFeatureManagement.GroupDefinitions:AddNew'), |
|||
}); |
|||
try { |
|||
modalApi.setState({ loading: true }); |
|||
const { name } = modalApi.getData<FeatureGroupDefinitionDto>(); |
|||
name && (await onGet(name)); |
|||
} finally { |
|||
modalApi.setState({ loading: false }); |
|||
} |
|||
} |
|||
}, |
|||
title: $t('AbpFeatureManagement.GroupDefinitions:AddNew'), |
|||
}); |
|||
async function onGet(name: string) { |
|||
isEditModel.value = true; |
|||
const dto = await getApi(name); |
|||
formModel.value = dto; |
|||
modalApi.setState({ |
|||
showConfirmButton: !dto.isStatic, |
|||
title: `${$t('AbpFeatureManagement.GroupDefinitions')} - ${dto.name}`, |
|||
}); |
|||
} |
|||
function onPropChange(prop: PropertyInfo) { |
|||
formModel.value.extraProperties ??= {}; |
|||
formModel.value.extraProperties[prop.key] = prop.value; |
|||
} |
|||
function onPropDelete(prop: PropertyInfo) { |
|||
formModel.value.extraProperties ??= {}; |
|||
delete formModel.value.extraProperties[prop.key]; |
|||
} |
|||
</script> |
|||
|
|||
<template> |
|||
<Modal> |
|||
<Form |
|||
ref="form" |
|||
:label-col="{ span: 6 }" |
|||
:model="formModel" |
|||
:wrapper-col="{ span: 18 }" |
|||
> |
|||
<Tabs v-model:active-key="activeTab"> |
|||
<!-- 基本信息 --> |
|||
<TabPane key="basic" :tab="$t('AbpFeatureManagement.BasicInfo')"> |
|||
<FormItem |
|||
:label="$t('AbpFeatureManagement.DisplayName:Name')" |
|||
name="name" |
|||
required |
|||
> |
|||
<Input |
|||
v-model:value="formModel.name" |
|||
:disabled="formModel.isStatic" |
|||
autocomplete="off" |
|||
/> |
|||
</FormItem> |
|||
<FormItem |
|||
:label="$t('AbpFeatureManagement.DisplayName:DisplayName')" |
|||
name="displayName" |
|||
required |
|||
> |
|||
<LocalizableInput |
|||
v-model:value="formModel.displayName" |
|||
:disabled="formModel.isStatic" |
|||
/> |
|||
</FormItem> |
|||
</TabPane> |
|||
<!-- 属性 --> |
|||
<TabPane key="props" :tab="$t('AbpFeatureManagement.Properties')"> |
|||
<PropertyTable |
|||
:data="formModel.extraProperties" |
|||
:disabled="formModel.isStatic" |
|||
@change="onPropChange" |
|||
@delete="onPropDelete" |
|||
/> |
|||
</TabPane> |
|||
</Tabs> |
|||
</Form> |
|||
</Modal> |
|||
</template> |
|||
|
|||
<style scoped></style> |
|||
@ -0,0 +1,217 @@ |
|||
<script setup lang="ts"> |
|||
import type { VbenFormProps, VxeGridListeners, VxeGridProps } from '@abp/ui'; |
|||
|
|||
import type { FeatureGroupDefinitionDto } from '../../../types/groups'; |
|||
|
|||
import { defineAsyncComponent, h, onMounted, reactive, ref } from 'vue'; |
|||
|
|||
import { useVbenModal } from '@vben/common-ui'; |
|||
import { $t } from '@vben/locales'; |
|||
|
|||
import { useLocalization, useLocalizationSerializer } from '@abp/core'; |
|||
import { useVbenVxeGrid } from '@abp/ui'; |
|||
import { |
|||
DeleteOutlined, |
|||
EditOutlined, |
|||
PlusOutlined, |
|||
} from '@ant-design/icons-vue'; |
|||
import { Button, message, Modal } from 'ant-design-vue'; |
|||
|
|||
import { useFeatureGroupDefinitionsApi } from '../../../api/useFeatureGroupDefinitionsApi'; |
|||
import { GroupDefinitionsPermissions } from '../../../constants/permissions'; |
|||
|
|||
defineOptions({ |
|||
name: 'FeatureGroupDefinitionTable', |
|||
}); |
|||
|
|||
const permissionGroups = ref<FeatureGroupDefinitionDto[]>([]); |
|||
const pageState = reactive({ |
|||
current: 1, |
|||
size: 10, |
|||
total: 0, |
|||
}); |
|||
|
|||
const { Lr } = useLocalization(); |
|||
const { deserialize } = useLocalizationSerializer(); |
|||
const { deleteApi, getListApi } = useFeatureGroupDefinitionsApi(); |
|||
|
|||
const formOptions: VbenFormProps = { |
|||
// 默认展开 |
|||
collapsed: false, |
|||
handleReset: onReset, |
|||
async handleSubmit(params) { |
|||
pageState.current = 1; |
|||
await onGet(params); |
|||
}, |
|||
schema: [ |
|||
{ |
|||
component: 'Input', |
|||
fieldName: 'filter', |
|||
formItemClass: 'col-span-2 items-baseline', |
|||
label: $t('AbpUi.Search'), |
|||
}, |
|||
], |
|||
// 控制表单是否显示折叠按钮 |
|||
showCollapseButton: true, |
|||
// 按下回车时是否提交表单 |
|||
submitOnEnter: true, |
|||
}; |
|||
|
|||
const gridOptions: VxeGridProps<FeatureGroupDefinitionDto> = { |
|||
columns: [ |
|||
{ |
|||
align: 'left', |
|||
field: 'name', |
|||
minWidth: 150, |
|||
title: $t('AbpFeatureManagement.DisplayName:Name'), |
|||
}, |
|||
{ |
|||
align: 'left', |
|||
field: 'displayName', |
|||
minWidth: 150, |
|||
title: $t('AbpFeatureManagement.DisplayName:DisplayName'), |
|||
}, |
|||
{ |
|||
field: 'action', |
|||
fixed: 'right', |
|||
slots: { default: 'action' }, |
|||
title: $t('AbpUi.Actions'), |
|||
width: 220, |
|||
}, |
|||
], |
|||
exportConfig: {}, |
|||
keepSource: true, |
|||
toolbarConfig: { |
|||
custom: true, |
|||
export: true, |
|||
refresh: false, |
|||
zoom: true, |
|||
}, |
|||
}; |
|||
|
|||
const gridEvents: VxeGridListeners<FeatureGroupDefinitionDto> = { |
|||
pageChange(params) { |
|||
pageState.current = params.currentPage; |
|||
pageState.size = params.pageSize; |
|||
onPageChange(); |
|||
}, |
|||
}; |
|||
|
|||
const [Grid, gridApi] = useVbenVxeGrid({ |
|||
formOptions, |
|||
gridEvents, |
|||
gridOptions, |
|||
}); |
|||
|
|||
const [FeatureGroupDefinitionModal, groupModalApi] = useVbenModal({ |
|||
connectedComponent: defineAsyncComponent( |
|||
() => import('./FeatureGroupDefinitionModal.vue'), |
|||
), |
|||
}); |
|||
|
|||
async function onGet(input?: Record<string, string>) { |
|||
try { |
|||
gridApi.setLoading(true); |
|||
const { items } = await getListApi(input); |
|||
pageState.total = items.length; |
|||
permissionGroups.value = items.map((item) => { |
|||
const localizableString = deserialize(item.displayName); |
|||
return { |
|||
...item, |
|||
displayName: Lr(localizableString.resourceName, localizableString.name), |
|||
}; |
|||
}); |
|||
onPageChange(); |
|||
} finally { |
|||
gridApi.setLoading(false); |
|||
} |
|||
} |
|||
|
|||
async function onReset() { |
|||
await gridApi.formApi.resetForm(); |
|||
const input = await gridApi.formApi.getValues(); |
|||
await onGet(input); |
|||
} |
|||
|
|||
function onPageChange() { |
|||
const items = permissionGroups.value.slice( |
|||
(pageState.current - 1) * pageState.size, |
|||
pageState.current * pageState.size, |
|||
); |
|||
gridApi.setGridOptions({ |
|||
data: items, |
|||
pagerConfig: { |
|||
currentPage: pageState.current, |
|||
pageSize: pageState.size, |
|||
total: pageState.total, |
|||
}, |
|||
}); |
|||
} |
|||
|
|||
function onCreate() { |
|||
groupModalApi.setData({}); |
|||
groupModalApi.open(); |
|||
} |
|||
|
|||
function onUpdate(row: FeatureGroupDefinitionDto) { |
|||
groupModalApi.setData(row); |
|||
groupModalApi.open(); |
|||
} |
|||
|
|||
function onDelete(row: FeatureGroupDefinitionDto) { |
|||
Modal.confirm({ |
|||
centered: true, |
|||
content: `${$t('AbpUi.ItemWillBeDeletedMessageWithFormat', [row.name])}`, |
|||
onOk: async () => { |
|||
await deleteApi(row.name); |
|||
message.success($t('AbpUi.SuccessfullyDeleted')); |
|||
onGet(); |
|||
}, |
|||
title: $t('AbpUi.AreYouSure'), |
|||
}); |
|||
} |
|||
|
|||
onMounted(onGet); |
|||
</script> |
|||
|
|||
<template> |
|||
<Grid :table-title="$t('AbpFeatureManagement.GroupDefinitions')"> |
|||
<template #toolbar-tools> |
|||
<Button |
|||
:icon="h(PlusOutlined)" |
|||
type="primary" |
|||
v-access:code="[GroupDefinitionsPermissions.Create]" |
|||
@click="onCreate" |
|||
> |
|||
{{ $t('AbpFeatureManagement.GroupDefinitions:AddNew') }} |
|||
</Button> |
|||
</template> |
|||
<template #action="{ row }"> |
|||
<div class="flex flex-row"> |
|||
<Button |
|||
:icon="h(EditOutlined)" |
|||
block |
|||
type="link" |
|||
v-access:code="[GroupDefinitionsPermissions.Update]" |
|||
@click="onUpdate(row)" |
|||
> |
|||
{{ $t('AbpUi.Edit') }} |
|||
</Button> |
|||
<Button |
|||
v-if="!row.isStatic" |
|||
:icon="h(DeleteOutlined)" |
|||
block |
|||
danger |
|||
type="link" |
|||
v-access:code="[GroupDefinitionsPermissions.Delete]" |
|||
@click="onDelete(row)" |
|||
> |
|||
{{ $t('AbpUi.Delete') }} |
|||
</Button> |
|||
</div> |
|||
</template> |
|||
</Grid> |
|||
<FeatureGroupDefinitionModal @change="() => onGet()" /> |
|||
</template> |
|||
|
|||
<style scoped></style> |
|||
@ -1 +1,2 @@ |
|||
export { default as FeatureGroupDefinitionTable } from './definitions/groups/FeatureGroupDefinitionTable.vue'; |
|||
export { default as FeatureModal } from './features/FeatureModal.vue'; |
|||
|
|||
@ -0,0 +1,10 @@ |
|||
/** 分组权限 */ |
|||
export const GroupDefinitionsPermissions = { |
|||
/** 新增 */ |
|||
Create: 'FeatureManagement.GroupDefinitions.Create', |
|||
Default: 'FeatureManagement.GroupDefinitions', |
|||
/** 删除 */ |
|||
Delete: 'FeatureManagement.GroupDefinitions.Delete', |
|||
/** 更新 */ |
|||
Update: 'FeatureManagement.GroupDefinitions.Update', |
|||
}; |
|||
@ -0,0 +1,31 @@ |
|||
import type { IHasConcurrencyStamp, IHasExtraProperties } from '@abp/core'; |
|||
|
|||
interface FeatureGroupDefinitionDto extends IHasExtraProperties { |
|||
displayName: string; |
|||
isStatic: boolean; |
|||
name: string; |
|||
} |
|||
|
|||
interface FeatureGroupDefinitionGetListInput { |
|||
filter?: string; |
|||
} |
|||
|
|||
interface FeatureGroupDefinitionCreateOrUpdateDto extends IHasExtraProperties { |
|||
displayName: string; |
|||
} |
|||
|
|||
interface FeatureGroupDefinitionUpdateDto |
|||
extends FeatureGroupDefinitionCreateOrUpdateDto, |
|||
IHasConcurrencyStamp {} |
|||
|
|||
interface FeatureGroupDefinitionCreateDto |
|||
extends FeatureGroupDefinitionCreateOrUpdateDto { |
|||
name: string; |
|||
} |
|||
|
|||
export type { |
|||
FeatureGroupDefinitionCreateDto, |
|||
FeatureGroupDefinitionDto, |
|||
FeatureGroupDefinitionGetListInput, |
|||
FeatureGroupDefinitionUpdateDto, |
|||
}; |
|||
@ -1 +1,3 @@ |
|||
export * from './definitions'; |
|||
export * from './features'; |
|||
export * from './groups'; |
|||
|
|||
Loading…
Reference in new issue