12 changed files with 879 additions and 2 deletions
@ -0,0 +1,15 @@ |
|||||
|
<script lang="ts" setup> |
||||
|
import { Page } from '@vben/common-ui'; |
||||
|
|
||||
|
import { MenuTable } from '@abp/platform'; |
||||
|
|
||||
|
defineOptions({ |
||||
|
name: 'PlatformMenus', |
||||
|
}); |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<Page> |
||||
|
<MenuTable /> |
||||
|
</Page> |
||||
|
</template> |
||||
@ -1,4 +1,5 @@ |
|||||
export { useDataDictionariesApi } from './useDataDictionariesApi'; |
export { useDataDictionariesApi } from './useDataDictionariesApi'; |
||||
export { useEmailMessagesApi } from './useEmailMessagesApi'; |
export { useEmailMessagesApi } from './useEmailMessagesApi'; |
||||
export { useLayoutsApi } from './useLayoutsApi'; |
export { useLayoutsApi } from './useLayoutsApi'; |
||||
|
export { useMenusApi } from './useMenusApi'; |
||||
export { useSmsMessagesApi } from './useSmsMessagesApi'; |
export { useSmsMessagesApi } from './useSmsMessagesApi'; |
||||
|
|||||
@ -0,0 +1,56 @@ |
|||||
|
import type { ListResultDto } from '@abp/core'; |
||||
|
|
||||
|
import type { |
||||
|
MenuCreateDto, |
||||
|
MenuDto, |
||||
|
MenuGetAllInput, |
||||
|
MenuUpdateDto, |
||||
|
} from '../types/menus'; |
||||
|
|
||||
|
import { useRequest } from '@abp/request'; |
||||
|
|
||||
|
export function useMenusApi() { |
||||
|
const { cancel, request } = useRequest(); |
||||
|
|
||||
|
function createApi(input: MenuCreateDto): Promise<MenuDto> { |
||||
|
return request<MenuDto>(`/api/platform/menus`, { |
||||
|
data: input, |
||||
|
method: 'POST', |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function getAllApi(input?: MenuGetAllInput): Promise<ListResultDto<MenuDto>> { |
||||
|
return request<ListResultDto<MenuDto>>('/api/platform/menus/all', { |
||||
|
method: 'GET', |
||||
|
params: input, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function getApi(id: string): Promise<MenuDto> { |
||||
|
return request<MenuDto>(`/api/platform/menus/${id}`, { |
||||
|
method: 'GET', |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function deleteApi(id: string): Promise<void> { |
||||
|
return request(`/api/platform/menus/${id}`, { |
||||
|
method: 'DELETE', |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function updateApi(id: string, input: MenuUpdateDto): Promise<MenuDto> { |
||||
|
return request<MenuDto>(`/api/platform/menus/${id}`, { |
||||
|
data: input, |
||||
|
method: 'PUT', |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
return { |
||||
|
cancel, |
||||
|
createApi, |
||||
|
deleteApi, |
||||
|
getAllApi, |
||||
|
getApi, |
||||
|
updateApi, |
||||
|
}; |
||||
|
} |
||||
@ -1,4 +1,5 @@ |
|||||
export { default as DataDictionaryTable } from './data-dictionaries/DataDictionaryTable.vue'; |
export { default as DataDictionaryTable } from './data-dictionaries/DataDictionaryTable.vue'; |
||||
export { default as LayoutTable } from './layouts/LayoutTable.vue'; |
export { default as LayoutTable } from './layouts/LayoutTable.vue'; |
||||
|
export { default as MenuTable } from './menus/MenuTable.vue'; |
||||
export { default as EmailMessageTable } from './messages/email/EmailMessageTable.vue'; |
export { default as EmailMessageTable } from './messages/email/EmailMessageTable.vue'; |
||||
export { default as SmsMessageTable } from './messages/sms/SmsMessageTable.vue'; |
export { default as SmsMessageTable } from './messages/sms/SmsMessageTable.vue'; |
||||
|
|||||
@ -0,0 +1,459 @@ |
|||||
|
<script setup lang="ts"> |
||||
|
import type { MenuDto } from '../../types'; |
||||
|
import type { DataItemDto } from '../../types/dataDictionaries'; |
||||
|
|
||||
|
import { ref } from 'vue'; |
||||
|
|
||||
|
import { useVbenDrawer, useVbenForm } from '@vben/common-ui'; |
||||
|
import { $t } from '@vben/locales'; |
||||
|
|
||||
|
import { |
||||
|
formatToDate, |
||||
|
formatToDateTime, |
||||
|
isNullOrWhiteSpace, |
||||
|
listToTree, |
||||
|
} from '@abp/core'; |
||||
|
import { Button, Card, message, Steps } from 'ant-design-vue'; |
||||
|
|
||||
|
import { useMenusApi } from '../../api'; |
||||
|
import { useDataDictionariesApi } from '../../api/useDataDictionariesApi'; |
||||
|
import { useLayoutsApi } from '../../api/useLayoutsApi'; |
||||
|
import { ValueType } from '../../types/dataDictionaries'; |
||||
|
|
||||
|
const emits = defineEmits<{ |
||||
|
(event: 'change', data: MenuDto): void; |
||||
|
}>(); |
||||
|
|
||||
|
const Step = Steps.Step; |
||||
|
|
||||
|
type TabKey = 'basic' | 'meta'; |
||||
|
type RenderComponentContentType = ( |
||||
|
value: Partial<Record<string, any>>, |
||||
|
) => Record<string, any>; |
||||
|
|
||||
|
const currentStep = ref(0); |
||||
|
const submiting = ref(false); |
||||
|
const showMetaForm = ref(false); |
||||
|
const parentMenu = ref<MenuDto>(); |
||||
|
const menuMetas = ref<DataItemDto[]>([]); |
||||
|
const activeTabKey = ref<TabKey>('basic'); |
||||
|
|
||||
|
const { createApi, getAllApi, getApi, updateApi } = useMenusApi(); |
||||
|
const { getApi: getLayoutApi, getPagedListApi: getLayoutsApi } = |
||||
|
useLayoutsApi(); |
||||
|
const { getApi: getDataDictionaryApi } = useDataDictionariesApi(); |
||||
|
|
||||
|
const [BasicForm, basicFormApi] = useVbenForm({ |
||||
|
commonConfig: { |
||||
|
colon: true, |
||||
|
componentProps: { |
||||
|
class: 'w-full', |
||||
|
}, |
||||
|
}, |
||||
|
handleSubmit: onNextStep, |
||||
|
schema: [ |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
dependencies: { |
||||
|
show: false, |
||||
|
triggerFields: ['name'], |
||||
|
}, |
||||
|
fieldName: 'id', |
||||
|
}, |
||||
|
{ |
||||
|
component: 'ApiSelect', |
||||
|
componentProps: { |
||||
|
allowClear: true, |
||||
|
api: getLayoutsApi, |
||||
|
labelField: 'displayName', |
||||
|
onChange: onLayoutChange, |
||||
|
resultField: 'items', |
||||
|
valueField: 'id', |
||||
|
}, |
||||
|
fieldName: 'layoutId', |
||||
|
label: $t('AppPlatform.DisplayName:Layout'), |
||||
|
rules: 'selectRequired', |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Checkbox', |
||||
|
fieldName: 'isPublic', |
||||
|
label: $t('AppPlatform.DisplayName:IsPublic'), |
||||
|
renderComponentContent: () => { |
||||
|
return { |
||||
|
default: () => [$t('AppPlatform.DisplayName:IsPublic')], |
||||
|
}; |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
component: 'ApiTreeSelect', |
||||
|
componentProps: { |
||||
|
allowClear: true, |
||||
|
api: async () => { |
||||
|
const { items } = await getAllApi(); |
||||
|
return listToTree(items, { |
||||
|
id: 'id', |
||||
|
pid: 'parentId', |
||||
|
}); |
||||
|
}, |
||||
|
labelField: 'displayName', |
||||
|
onChange: onParentIdChange, |
||||
|
valueField: 'id', |
||||
|
childrenField: 'children', |
||||
|
}, |
||||
|
fieldName: 'parentId', |
||||
|
label: $t('AppPlatform.DisplayName:ParentMenu'), |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
fieldName: 'name', |
||||
|
label: $t('AppPlatform.DisplayName:Name'), |
||||
|
rules: 'required', |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
fieldName: 'displayName', |
||||
|
label: $t('AppPlatform.DisplayName:DisplayName'), |
||||
|
rules: 'required', |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
fieldName: 'path', |
||||
|
label: $t('AppPlatform.DisplayName:Path'), |
||||
|
rules: 'required', |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
fieldName: 'component', |
||||
|
label: $t('AppPlatform.DisplayName:Component'), |
||||
|
rules: 'required', |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
fieldName: 'redirect', |
||||
|
label: $t('AppPlatform.DisplayName:Redirect'), |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Textarea', |
||||
|
componentProps: { |
||||
|
autoSize: { |
||||
|
minRows: 3, |
||||
|
}, |
||||
|
}, |
||||
|
fieldName: 'description', |
||||
|
label: $t('AppPlatform.DisplayName:Description'), |
||||
|
}, |
||||
|
], |
||||
|
showDefaultActions: false, |
||||
|
submitButtonOptions: { |
||||
|
content: $t('AppPlatform.NextStep'), |
||||
|
}, |
||||
|
}); |
||||
|
const [MetaForm, metaFormApi] = useVbenForm({ |
||||
|
commonConfig: { |
||||
|
colon: true, |
||||
|
componentProps: { |
||||
|
class: 'w-full', |
||||
|
}, |
||||
|
labelWidth: 150, |
||||
|
}, |
||||
|
handleSubmit: onSubmit, |
||||
|
resetButtonOptions: { |
||||
|
content: $t('AppPlatform.PreStep'), |
||||
|
}, |
||||
|
schema: [], |
||||
|
showDefaultActions: false, |
||||
|
}); |
||||
|
const [Drawer, drawerApi] = useVbenDrawer({ |
||||
|
class: 'w-2/3', |
||||
|
onConfirm: onSubmit, |
||||
|
onOpenChange: async (isOpen) => { |
||||
|
if (isOpen) { |
||||
|
await onInit(); |
||||
|
} |
||||
|
}, |
||||
|
}); |
||||
|
|
||||
|
function onPreStep() { |
||||
|
currentStep.value = 0; |
||||
|
} |
||||
|
|
||||
|
async function onNextStep() { |
||||
|
currentStep.value = 1; |
||||
|
} |
||||
|
|
||||
|
async function onInit() { |
||||
|
metaFormApi.removeSchemaByFields(menuMetas.value.map((x) => x.name)); |
||||
|
activeTabKey.value = 'basic'; |
||||
|
parentMenu.value = undefined; |
||||
|
showMetaForm.value = false; |
||||
|
submiting.value = false; |
||||
|
menuMetas.value = []; |
||||
|
currentStep.value = 0; |
||||
|
const { id, layoutId, parentId } = drawerApi.getData<MenuDto>(); |
||||
|
if (!isNullOrWhiteSpace(layoutId)) { |
||||
|
await onLayoutChange(layoutId); |
||||
|
await basicFormApi.setFieldValue('layoutId', layoutId); |
||||
|
} |
||||
|
if (isNullOrWhiteSpace(id)) { |
||||
|
await basicFormApi.setFieldValue('parentId', parentId); |
||||
|
await onParentIdChange(parentId); |
||||
|
drawerApi.setState({ title: $t('AppPlatform.Menu:AddNew') }); |
||||
|
return; |
||||
|
} |
||||
|
const dto = await getApi(id); |
||||
|
await basicFormApi.setValues(dto); |
||||
|
// 编辑模式无需使用前缀 |
||||
|
await onParentIdChange(undefined); |
||||
|
onInitMetaFormValues(dto.meta); |
||||
|
drawerApi.setState({ title: `${$t('AppPlatform.Menu:Edit')} - ${dto.name}` }); |
||||
|
} |
||||
|
|
||||
|
async function onParentIdChange(menuId?: string) { |
||||
|
basicFormApi.updateSchema([ |
||||
|
{ |
||||
|
componentProps: { |
||||
|
addonBefore: '', |
||||
|
}, |
||||
|
fieldName: 'path', |
||||
|
}, |
||||
|
]); |
||||
|
if (menuId) { |
||||
|
const parentMenuDto = await getApi(menuId); |
||||
|
parentMenu.value = parentMenuDto; |
||||
|
basicFormApi.updateSchema([ |
||||
|
{ |
||||
|
componentProps: { |
||||
|
addonBefore: parentMenuDto.path, |
||||
|
}, |
||||
|
fieldName: 'path', |
||||
|
}, |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
async function onLayoutChange(layoutId?: string) { |
||||
|
metaFormApi.removeSchemaByFields(menuMetas.value.map((x) => x.name)); |
||||
|
if (!layoutId) { |
||||
|
showMetaForm.value = false; |
||||
|
menuMetas.value = []; |
||||
|
return; |
||||
|
} |
||||
|
try { |
||||
|
drawerApi.setState({ loading: true }); |
||||
|
const layoutDto = await getLayoutApi(layoutId); |
||||
|
const dataDto = await getDataDictionaryApi(layoutDto.dataId); |
||||
|
basicFormApi.setFieldValue('component', layoutDto.path); |
||||
|
menuMetas.value = dataDto.items.sort(); |
||||
|
onInitMetaFormSchemas(); |
||||
|
} finally { |
||||
|
drawerApi.setState({ loading: false }); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function onInitMetaFormSchemas() { |
||||
|
metaFormApi.removeSchemaByFields(menuMetas.value.map((x) => x.name)); |
||||
|
menuMetas.value.forEach((dataItem) => { |
||||
|
metaFormApi.setState((pre) => { |
||||
|
let component = 'Input'; |
||||
|
let defaultValue: any | undefined; |
||||
|
let componentProps: Record<string, any> | undefined; |
||||
|
let renderComponentContent: RenderComponentContentType | undefined; |
||||
|
switch (dataItem.valueType) { |
||||
|
case ValueType.Array: { |
||||
|
component = 'Select'; |
||||
|
componentProps = { |
||||
|
mode: 'tags', |
||||
|
}; |
||||
|
if (!isNullOrWhiteSpace(dataItem.defaultValue)) { |
||||
|
defaultValue = dataItem.defaultValue.split(','); |
||||
|
} |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.Boolean: { |
||||
|
component = 'Checkbox'; |
||||
|
defaultValue = dataItem.defaultValue === 'true'; |
||||
|
renderComponentContent = () => { |
||||
|
return { |
||||
|
default: () => [dataItem.displayName], |
||||
|
}; |
||||
|
}; |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.Date: |
||||
|
case ValueType.DateTime: { |
||||
|
component = 'DatePicker'; |
||||
|
defaultValue = dataItem.defaultValue; |
||||
|
componentProps = { |
||||
|
showTime: dataItem.valueType === ValueType.DateTime, |
||||
|
valueFormat: |
||||
|
dataItem.valueType === ValueType.DateTime |
||||
|
? 'YYYY-MM-DD HH:mm:ss' |
||||
|
: 'YYYY-MM-DD', |
||||
|
}; |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.Numeic: { |
||||
|
component = 'InputNumber'; |
||||
|
defaultValue = dataItem.defaultValue |
||||
|
? Number(dataItem.defaultValue) |
||||
|
: undefined; |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.String: { |
||||
|
componentProps = { |
||||
|
autocomplete: 'off', |
||||
|
}; |
||||
|
defaultValue = dataItem.defaultValue; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
return { |
||||
|
schema: [ |
||||
|
...(pre?.schema ?? []), |
||||
|
{ |
||||
|
component, |
||||
|
componentProps, |
||||
|
defaultValue, |
||||
|
fieldName: dataItem.name, |
||||
|
help: dataItem.description, |
||||
|
label: dataItem.displayName, |
||||
|
renderComponentContent, |
||||
|
rules: dataItem.allowBeNull ? undefined : 'required', |
||||
|
}, |
||||
|
], |
||||
|
}; |
||||
|
}); |
||||
|
}); |
||||
|
showMetaForm.value = true; |
||||
|
} |
||||
|
|
||||
|
function onInitMetaFormValues(meta?: Record<string, any>) { |
||||
|
metaFormApi.resetForm(); |
||||
|
if (!meta) { |
||||
|
return; |
||||
|
} |
||||
|
const values: Record<string, any> = {}; |
||||
|
menuMetas.value.forEach((dataItem) => { |
||||
|
const metaValue = meta[dataItem.name]; |
||||
|
if (isNullOrWhiteSpace(metaValue)) { |
||||
|
return; |
||||
|
} |
||||
|
switch (dataItem.valueType) { |
||||
|
case ValueType.Array: { |
||||
|
const metaValueArr = String(metaValue); |
||||
|
values[dataItem.name] = metaValueArr.split(','); |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.Boolean: { |
||||
|
values[dataItem.name] = Boolean(metaValue); |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.Date: { |
||||
|
values[dataItem.name] = formatToDate(metaValue); |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.DateTime: { |
||||
|
values[dataItem.name] = formatToDateTime(metaValue); |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.Numeic: { |
||||
|
values[dataItem.name] = Number(metaValue); |
||||
|
break; |
||||
|
} |
||||
|
case ValueType.String: { |
||||
|
values[dataItem.name] = metaValue; |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
metaFormApi.setValues(values); |
||||
|
} |
||||
|
|
||||
|
async function onSubmit() { |
||||
|
try { |
||||
|
submiting.value = true; |
||||
|
drawerApi.setState({ loading: true }); |
||||
|
const basicInput = await basicFormApi.getValues(); |
||||
|
const metaInput = await metaFormApi.getValues(); |
||||
|
let combPath = String(basicInput.path); |
||||
|
if (!combPath.startsWith('/')) { |
||||
|
combPath = `/${combPath}`; |
||||
|
} |
||||
|
if (parentMenu.value && !combPath.startsWith(parentMenu.value.path)) { |
||||
|
combPath = `${parentMenu.value?.path ?? ''}${combPath}`; |
||||
|
} |
||||
|
const api = basicInput.id |
||||
|
? updateApi(basicInput.id, { |
||||
|
component: basicInput.component, |
||||
|
description: basicInput.description, |
||||
|
displayName: basicInput.displayName, |
||||
|
isPublic: basicInput.isPublic, |
||||
|
meta: metaInput, |
||||
|
name: basicInput.name, |
||||
|
parentId: basicInput.parentId, |
||||
|
path: combPath, |
||||
|
redirect: basicInput.redirect, |
||||
|
}) |
||||
|
: createApi({ |
||||
|
component: basicInput.component, |
||||
|
description: basicInput.description, |
||||
|
displayName: basicInput.displayName, |
||||
|
isPublic: basicInput.isPublic, |
||||
|
layoutId: basicInput.layoutId, |
||||
|
meta: metaInput, |
||||
|
name: basicInput.name, |
||||
|
parentId: basicInput.parentId, |
||||
|
path: combPath, |
||||
|
redirect: basicInput.redirect, |
||||
|
}); |
||||
|
const dto = await api; |
||||
|
message.success($t('AbpUi.SavedSuccessfully')); |
||||
|
emits('change', dto); |
||||
|
drawerApi.close(); |
||||
|
} finally { |
||||
|
submiting.value = false; |
||||
|
drawerApi.setState({ loading: false }); |
||||
|
} |
||||
|
} |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<Drawer> |
||||
|
<Card> |
||||
|
<div class="mx-auto max-w-lg"> |
||||
|
<Steps :current="currentStep"> |
||||
|
<Step :title="$t('AppPlatform.DisplayName:Basic')" /> |
||||
|
<Step :title="$t('AppPlatform.DisplayName:Meta')" /> |
||||
|
</Steps> |
||||
|
</div> |
||||
|
<div class="p-20"> |
||||
|
<BasicForm v-show="currentStep === 0" /> |
||||
|
<MetaForm v-show="currentStep === 1" /> |
||||
|
</div> |
||||
|
</Card> |
||||
|
|
||||
|
<template #footer> |
||||
|
<Button v-if="currentStep === 1" @click="onPreStep"> |
||||
|
{{ $t('AppPlatform.PreStep') }} |
||||
|
</Button> |
||||
|
<Button |
||||
|
v-if="currentStep === 0" |
||||
|
type="primary" |
||||
|
@click="basicFormApi.validateAndSubmitForm" |
||||
|
:loading="submiting" |
||||
|
> |
||||
|
{{ $t('AppPlatform.NextStep') }} |
||||
|
</Button> |
||||
|
<Button |
||||
|
v-if="currentStep === 1" |
||||
|
type="primary" |
||||
|
@click="metaFormApi.validateAndSubmitForm" |
||||
|
:loading="submiting" |
||||
|
> |
||||
|
{{ $t('AbpUi.Submit') }} |
||||
|
</Button> |
||||
|
</template> |
||||
|
</Drawer> |
||||
|
</template> |
||||
|
|
||||
|
<style scoped></style> |
||||
@ -0,0 +1,290 @@ |
|||||
|
<script setup lang="ts"> |
||||
|
import type { VxeGridListeners, VxeGridProps } from '@abp/ui'; |
||||
|
|
||||
|
import type { VbenFormProps } from '@vben/common-ui'; |
||||
|
|
||||
|
import type { MenuDto } from '../../types/menus'; |
||||
|
|
||||
|
import { defineAsyncComponent, h, onMounted, reactive, ref } from 'vue'; |
||||
|
|
||||
|
import { useVbenDrawer } from '@vben/common-ui'; |
||||
|
import { IconifyIcon } from '@vben/icons'; |
||||
|
import { $t } from '@vben/locales'; |
||||
|
|
||||
|
import { listToTree } 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 { useLayoutsApi } from '../../api'; |
||||
|
import { useMenusApi } from '../../api/useMenusApi'; |
||||
|
|
||||
|
defineOptions({ |
||||
|
name: 'MenuTable', |
||||
|
}); |
||||
|
|
||||
|
const { deleteApi, getAllApi } = useMenusApi(); |
||||
|
const { getPagedListApi: getLayoutsApi } = useLayoutsApi(); |
||||
|
|
||||
|
const expandRowKeys = ref<string[]>([]); |
||||
|
const dataDictionaries = ref<MenuDto[]>([]); |
||||
|
const pageState = reactive({ |
||||
|
current: 1, |
||||
|
size: 10, |
||||
|
total: 0, |
||||
|
}); |
||||
|
|
||||
|
const formOptions: VbenFormProps = { |
||||
|
// 默认展开 |
||||
|
collapsed: true, |
||||
|
collapsedRows: 2, |
||||
|
// 所有表单项共用,可单独在表单内覆盖 |
||||
|
commonConfig: { |
||||
|
// 在label后显示一个冒号 |
||||
|
colon: true, |
||||
|
// 所有表单项 |
||||
|
componentProps: { |
||||
|
class: 'w-full', |
||||
|
}, |
||||
|
}, |
||||
|
handleSubmit: onGet, |
||||
|
schema: [ |
||||
|
{ |
||||
|
component: 'ApiSelect', |
||||
|
componentProps: { |
||||
|
allowClear: true, |
||||
|
api: getLayoutsApi, |
||||
|
labelField: 'displayName', |
||||
|
resultField: 'items', |
||||
|
valueField: 'id', |
||||
|
}, |
||||
|
fieldName: 'layoutId', |
||||
|
label: $t('AppPlatform.DisplayName:Layout'), |
||||
|
}, |
||||
|
{ |
||||
|
component: 'Input', |
||||
|
fieldName: 'filter', |
||||
|
formItemClass: 'col-span-2 items-baseline', |
||||
|
label: $t('AbpUi.Search'), |
||||
|
}, |
||||
|
], |
||||
|
// 控制表单是否显示折叠按钮 |
||||
|
showCollapseButton: true, |
||||
|
// 过滤条件变更时是否提交表单 |
||||
|
submitOnChange: true, |
||||
|
// 按下回车时是否提交表单 |
||||
|
submitOnEnter: true, |
||||
|
}; |
||||
|
|
||||
|
const gridOptions: VxeGridProps<MenuDto> = { |
||||
|
columns: [ |
||||
|
{ |
||||
|
align: 'center', |
||||
|
type: 'seq', |
||||
|
width: 50, |
||||
|
}, |
||||
|
{ |
||||
|
align: 'left', |
||||
|
field: 'name', |
||||
|
minWidth: 150, |
||||
|
slots: { default: 'name' }, |
||||
|
title: $t('AppPlatform.DisplayName:Name'), |
||||
|
treeNode: true, |
||||
|
}, |
||||
|
{ |
||||
|
align: 'left', |
||||
|
field: 'displayName', |
||||
|
minWidth: 150, |
||||
|
title: $t('AppPlatform.DisplayName:DisplayName'), |
||||
|
}, |
||||
|
{ |
||||
|
align: 'left', |
||||
|
field: 'description', |
||||
|
minWidth: 150, |
||||
|
title: $t('AppPlatform.DisplayName:Description'), |
||||
|
}, |
||||
|
{ |
||||
|
field: 'action', |
||||
|
fixed: 'right', |
||||
|
slots: { default: 'action' }, |
||||
|
title: $t('AbpUi.Actions'), |
||||
|
width: 350, |
||||
|
}, |
||||
|
], |
||||
|
exportConfig: {}, |
||||
|
keepSource: true, |
||||
|
rowConfig: { |
||||
|
keyField: 'id', |
||||
|
}, |
||||
|
toolbarConfig: { |
||||
|
custom: true, |
||||
|
export: true, |
||||
|
refresh: { |
||||
|
queryMethod: onGet, |
||||
|
}, |
||||
|
zoom: true, |
||||
|
}, |
||||
|
treeConfig: { |
||||
|
accordion: true, |
||||
|
parentField: 'parentId', |
||||
|
rowField: 'id', |
||||
|
transform: false, |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
const gridEvents: VxeGridListeners<MenuDto> = { |
||||
|
pageChange(params) { |
||||
|
pageState.current = params.currentPage; |
||||
|
pageState.size = params.pageSize; |
||||
|
onPageChange(); |
||||
|
}, |
||||
|
toggleTreeExpand(params) { |
||||
|
if (params.expanded) { |
||||
|
expandRowKeys.value.push(params.row.id); |
||||
|
} else { |
||||
|
expandRowKeys.value = expandRowKeys.value.filter( |
||||
|
(key) => key !== params.row.id, |
||||
|
); |
||||
|
} |
||||
|
onExpandChange(); |
||||
|
}, |
||||
|
}; |
||||
|
|
||||
|
const [Grid, gridApi] = useVbenVxeGrid({ |
||||
|
formOptions, |
||||
|
gridEvents, |
||||
|
gridOptions, |
||||
|
}); |
||||
|
|
||||
|
const [MenuDrawer, drawerApi] = useVbenDrawer({ |
||||
|
connectedComponent: defineAsyncComponent(() => import('./MenuDrawer.vue')), |
||||
|
}); |
||||
|
|
||||
|
async function onGet() { |
||||
|
try { |
||||
|
gridApi.setLoading(true); |
||||
|
const input = await gridApi.formApi.getValues(); |
||||
|
const { items } = await getAllApi(input); |
||||
|
const treeItems = listToTree(items, { |
||||
|
id: 'id', |
||||
|
pid: 'parentId', |
||||
|
}); |
||||
|
pageState.total = treeItems.length; |
||||
|
dataDictionaries.value = treeItems; |
||||
|
onPageChange(); |
||||
|
} finally { |
||||
|
gridApi.setLoading(false); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function onExpandChange() { |
||||
|
gridApi.setGridOptions({ |
||||
|
treeConfig: { |
||||
|
expandRowKeys: expandRowKeys.value, |
||||
|
}, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function onPageChange() { |
||||
|
const items = dataDictionaries.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(row?: MenuDto) { |
||||
|
drawerApi.setData({ |
||||
|
layoutId: row?.layoutId, |
||||
|
parentId: row?.id, |
||||
|
}); |
||||
|
drawerApi.open(); |
||||
|
} |
||||
|
|
||||
|
function onUpdate(row: MenuDto) { |
||||
|
drawerApi.setData(row); |
||||
|
drawerApi.open(); |
||||
|
} |
||||
|
|
||||
|
function onDelete(row: MenuDto) { |
||||
|
Modal.confirm({ |
||||
|
afterClose: () => { |
||||
|
gridApi.setLoading(false); |
||||
|
}, |
||||
|
centered: true, |
||||
|
content: `${$t('AbpUi.ItemWillBeDeletedMessage')}`, |
||||
|
onOk: async () => { |
||||
|
try { |
||||
|
gridApi.setLoading(true); |
||||
|
await deleteApi(row.id); |
||||
|
message.success($t('AbpUi.DeletedSuccessfully')); |
||||
|
onGet(); |
||||
|
} finally { |
||||
|
gridApi.setLoading(false); |
||||
|
} |
||||
|
}, |
||||
|
title: $t('AbpUi.AreYouSure'), |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
onMounted(onGet); |
||||
|
</script> |
||||
|
|
||||
|
<template> |
||||
|
<Grid :table-title="$t('AppPlatform.DisplayName:DataDictionary')"> |
||||
|
<template #toolbar-tools> |
||||
|
<Button :icon="h(PlusOutlined)" type="primary" @click="onCreate()"> |
||||
|
{{ $t('AppPlatform.Menu:AddNew') }} |
||||
|
</Button> |
||||
|
</template> |
||||
|
<template #name="{ row }"> |
||||
|
<div class="flex flex-row items-center gap-2"> |
||||
|
<IconifyIcon v-if="row.meta.icon" :icon="row.meta.icon" /> |
||||
|
<span>{{ row.name }}</span> |
||||
|
</div> |
||||
|
</template> |
||||
|
<template #action="{ row }"> |
||||
|
<div class="flex flex-row"> |
||||
|
<Button |
||||
|
:icon="h(PlusOutlined)" |
||||
|
block |
||||
|
type="link" |
||||
|
@click="onCreate(row)" |
||||
|
> |
||||
|
{{ $t('AppPlatform.Menu:AddChildren') }} |
||||
|
</Button> |
||||
|
<Button |
||||
|
:icon="h(EditOutlined)" |
||||
|
block |
||||
|
type="link" |
||||
|
@click="onUpdate(row)" |
||||
|
> |
||||
|
{{ $t('AbpUi.Edit') }} |
||||
|
</Button> |
||||
|
<Button |
||||
|
:icon="h(DeleteOutlined)" |
||||
|
block |
||||
|
danger |
||||
|
type="link" |
||||
|
@click="onDelete(row)" |
||||
|
> |
||||
|
{{ $t('AbpUi.Delete') }} |
||||
|
</Button> |
||||
|
</div> |
||||
|
</template> |
||||
|
</Grid> |
||||
|
<MenuDrawer @change="onGet" /> |
||||
|
</template> |
||||
|
|
||||
|
<style scoped></style> |
||||
@ -1,2 +1,4 @@ |
|||||
export * from './dataDictionaries'; |
export * from './dataDictionaries'; |
||||
|
export * from './layouts'; |
||||
|
export * from './menus'; |
||||
export * from './messages'; |
export * from './messages'; |
||||
|
|||||
@ -0,0 +1,39 @@ |
|||||
|
import type { RouteDto } from './routes'; |
||||
|
|
||||
|
interface MenuDto extends RouteDto { |
||||
|
code: string; |
||||
|
component: string; |
||||
|
framework: string; |
||||
|
isPublic: boolean; |
||||
|
layoutId: string; |
||||
|
parentId?: string; |
||||
|
startup: boolean; |
||||
|
} |
||||
|
|
||||
|
interface MenuCreateOrUpdateDto { |
||||
|
component: string; |
||||
|
description?: string; |
||||
|
displayName: string; |
||||
|
isPublic: boolean; |
||||
|
meta: Record<string, string>; |
||||
|
name: string; |
||||
|
parentId?: string; |
||||
|
path: string; |
||||
|
redirect?: string; |
||||
|
} |
||||
|
|
||||
|
interface MenuCreateDto extends MenuCreateOrUpdateDto { |
||||
|
layoutId: string; |
||||
|
} |
||||
|
|
||||
|
type MenuUpdateDto = MenuCreateOrUpdateDto; |
||||
|
|
||||
|
interface MenuGetAllInput { |
||||
|
filter?: string; |
||||
|
framework?: string; |
||||
|
layoutId?: string; |
||||
|
parentId?: string; |
||||
|
sorting?: string; |
||||
|
} |
||||
|
|
||||
|
export type { MenuCreateDto, MenuDto, MenuGetAllInput, MenuUpdateDto }; |
||||
Loading…
Reference in new issue