feat: 通知公告(表单)
This commit is contained in:
parent
38173d80b6
commit
d5b37bd03e
32
apps/web-antd/src/api/system/notice/index.ts
Normal file
32
apps/web-antd/src/api/system/notice/index.ts
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
import type { Notice } from './model';
|
||||||
|
|
||||||
|
import type { ID, IDS, PageQuery } from '#/api/common';
|
||||||
|
|
||||||
|
import { requestClient } from '#/api/request';
|
||||||
|
|
||||||
|
enum Api {
|
||||||
|
noticeList = '/system/notice/list',
|
||||||
|
root = '/system/notice',
|
||||||
|
}
|
||||||
|
|
||||||
|
export function noticeList(params?: PageQuery) {
|
||||||
|
return requestClient.get<Notice[]>(Api.noticeList, { params });
|
||||||
|
}
|
||||||
|
|
||||||
|
export function noticeInfo(noticeId: ID) {
|
||||||
|
return requestClient.get<Notice>(`${Api.root}/${noticeId}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function noticeAdd(data: any) {
|
||||||
|
return requestClient.postWithMsg<void>(Api.root, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function noticeUpdate(data: any) {
|
||||||
|
return requestClient.putWithMsg<void>(Api.root, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function noticeRemove(noticeIds: IDS) {
|
||||||
|
return requestClient.deleteWithMsg<void>(
|
||||||
|
`${Api.root}/${noticeIds.join(',')}`,
|
||||||
|
);
|
||||||
|
}
|
11
apps/web-antd/src/api/system/notice/model.d.ts
vendored
Normal file
11
apps/web-antd/src/api/system/notice/model.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
export interface Notice {
|
||||||
|
noticeId: number;
|
||||||
|
noticeTitle: string;
|
||||||
|
noticeType: string;
|
||||||
|
noticeContent: string;
|
||||||
|
status: string;
|
||||||
|
remark: string;
|
||||||
|
createBy: number;
|
||||||
|
createByName: string;
|
||||||
|
createTime: string;
|
||||||
|
}
|
60
apps/web-antd/src/views/system/notice/data.ts
Normal file
60
apps/web-antd/src/views/system/notice/data.ts
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
import type { FormSchemaGetter } from '#/adapter';
|
||||||
|
|
||||||
|
import { DictEnum } from '@vben/constants';
|
||||||
|
|
||||||
|
import { getDictOptions } from '#/utils/dict';
|
||||||
|
|
||||||
|
export const modalSchema: FormSchemaGetter = () => [
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
dependencies: {
|
||||||
|
show: () => false,
|
||||||
|
triggerFields: [''],
|
||||||
|
},
|
||||||
|
fieldName: 'noticeId',
|
||||||
|
label: '主键',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
componentProps: {
|
||||||
|
placeholder: '请输入',
|
||||||
|
},
|
||||||
|
fieldName: 'noticeTitle',
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
label: '公告标题',
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
class: 'grid-cols-2',
|
||||||
|
options: getDictOptions(DictEnum.SYS_NOTICE_STATUS),
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
defaultValue: '0',
|
||||||
|
fieldName: 'status',
|
||||||
|
label: '公告状态',
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'RadioGroup',
|
||||||
|
componentProps: {
|
||||||
|
buttonStyle: 'solid',
|
||||||
|
class: 'grid-cols-2',
|
||||||
|
options: getDictOptions(DictEnum.SYS_NOTICE_TYPE),
|
||||||
|
optionType: 'button',
|
||||||
|
},
|
||||||
|
defaultValue: '1',
|
||||||
|
fieldName: 'noticeType',
|
||||||
|
label: '公告类型',
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
component: 'Input',
|
||||||
|
fieldName: 'noticeContent',
|
||||||
|
formItemClass: 'col-span-2',
|
||||||
|
label: '公告内容',
|
||||||
|
rules: 'required',
|
||||||
|
},
|
||||||
|
];
|
@ -1,9 +1,21 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import CommonSkeleton from '#/views/common';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import noticeModal from './notice-modal.vue';
|
||||||
|
|
||||||
|
const [NoticeModal, modalApi] = useVbenModal({
|
||||||
|
connectedComponent: noticeModal,
|
||||||
|
});
|
||||||
|
|
||||||
|
function handleAdd() {
|
||||||
|
modalApi.setData({ update: false });
|
||||||
|
modalApi.open();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div>
|
<Page>
|
||||||
<CommonSkeleton />
|
<a-button type="primary" @click="handleAdd">新增</a-button>
|
||||||
</div>
|
<NoticeModal />
|
||||||
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
85
apps/web-antd/src/views/system/notice/notice-modal.vue
Normal file
85
apps/web-antd/src/views/system/notice/notice-modal.vue
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
|
import { useVbenForm } from '#/adapter';
|
||||||
|
import { noticeAdd, noticeUpdate } from '#/api/system/notice';
|
||||||
|
import { Tinymce } from '#/components/tinymce';
|
||||||
|
|
||||||
|
import { modalSchema } from './data';
|
||||||
|
|
||||||
|
const emit = defineEmits<{ reload: [] }>();
|
||||||
|
|
||||||
|
interface ModalProps {
|
||||||
|
update: boolean;
|
||||||
|
record?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isUpdate = ref(false);
|
||||||
|
const title = computed(() => {
|
||||||
|
return isUpdate.value ? $t('pages.common.edit') : $t('pages.common.add');
|
||||||
|
});
|
||||||
|
|
||||||
|
const [BasicForm, formApi] = useVbenForm({
|
||||||
|
layout: 'vertical',
|
||||||
|
schema: modalSchema(),
|
||||||
|
showDefaultActions: false,
|
||||||
|
wrapperClass: 'grid-cols-2',
|
||||||
|
});
|
||||||
|
|
||||||
|
const [BasicModal, modalApi] = useVbenModal({
|
||||||
|
fullscreenButton: false,
|
||||||
|
onCancel: handleCancel,
|
||||||
|
onConfirm: handleConfirm,
|
||||||
|
onOpenChange: async (isOpen) => {
|
||||||
|
if (!isOpen) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
modalApi.modalLoading(true);
|
||||||
|
const { record, update } = modalApi.getData() as ModalProps;
|
||||||
|
isUpdate.value = update;
|
||||||
|
if (update && record) {
|
||||||
|
for (const key in record) {
|
||||||
|
await formApi.setFieldValue(key, record[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modalApi.modalLoading(false);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
async function handleConfirm() {
|
||||||
|
try {
|
||||||
|
modalApi.modalLoading(true);
|
||||||
|
const { valid } = await formApi.validate();
|
||||||
|
if (!valid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const data = await formApi.getValues();
|
||||||
|
console.log(data);
|
||||||
|
await (isUpdate.value ? noticeUpdate(data) : noticeAdd(data));
|
||||||
|
emit('reload');
|
||||||
|
await handleCancel();
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
modalApi.modalLoading(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleCancel() {
|
||||||
|
modalApi.close();
|
||||||
|
await formApi.resetForm();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BasicModal :fullscreen-button="true" :title="title" class="w-[800px]">
|
||||||
|
<BasicForm>
|
||||||
|
<template #noticeContent="slotProps">
|
||||||
|
<Tinymce v-bind="slotProps" width="100%" />
|
||||||
|
</template>
|
||||||
|
</BasicForm>
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user