6 changed files with 275 additions and 1 deletions
@ -0,0 +1,29 @@
|
||||
import type { GetSubscriptionListParams, SubScription } from './types' |
||||
import { defHttp } from '@/utils/http/axios' |
||||
|
||||
export function getSubscriptionList(params: GetSubscriptionListParams) { |
||||
return defHttp.get<PageResult<SubScription>>({ |
||||
url: '/server/subscribe/page', |
||||
params, |
||||
}) |
||||
} |
||||
|
||||
export function createSubscription(data: Pick<SubScription, 'productId' | 'messageType'>) { |
||||
return defHttp.post({ |
||||
url: '/server/subscribe/save', |
||||
data, |
||||
}) |
||||
} |
||||
|
||||
export function updateSubscription(data: Pick<SubScription, 'productId' | 'messageType' | 'id'>) { |
||||
return defHttp.post({ |
||||
url: '/server/subscribe/update', |
||||
data, |
||||
}) |
||||
} |
||||
|
||||
export function deleteSubscription(id: string) { |
||||
return defHttp.post({ |
||||
url: `/server/subscribe/remove?id=${id}`, |
||||
}) |
||||
} |
@ -0,0 +1,60 @@
|
||||
<script lang="ts" setup> |
||||
import { ref } from 'vue' |
||||
import { getFormSchema } from './data' |
||||
import { useMessage } from '@/hooks/web/useMessage' |
||||
import { BasicForm, useForm } from '@/components/Form' |
||||
import { BasicModal, useModalInner } from '@/components/Modal' |
||||
import { createSubscription, updateSubscription } from '@/api/subscription/list' |
||||
import type { SubScription } from '@/api/subscription/list/types' |
||||
|
||||
defineOptions({ name: 'ProductFormModal' }) |
||||
|
||||
const emit = defineEmits(['success', 'register']) |
||||
|
||||
const isUpdate = ref(false) |
||||
const [registerForm, { setFieldsValue, validate }] = useForm({ |
||||
labelWidth: 100, |
||||
baseColProps: { span: 24 }, |
||||
schemas: getFormSchema(isUpdate), |
||||
showActionButtonGroup: false, |
||||
actionColOptions: { span: 23 }, |
||||
}) |
||||
|
||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data: SubScription) => { |
||||
isUpdate.value = true |
||||
setFieldsValue({ |
||||
...data, |
||||
messageType: data.messageType.split(',').map(Number), |
||||
}) |
||||
}) |
||||
|
||||
async function handleSubmit() { |
||||
try { |
||||
const values = await validate<Pick<SubScription, 'productId' | 'id' | 'messageType'>>() |
||||
setModalProps({ confirmLoading: true }) |
||||
values.messageType = (values.messageType as unknown as string[]).join(',') |
||||
await (isUpdate.value ? updateSubscription(values) : createSubscription(values)) |
||||
closeModal() |
||||
emit('success') |
||||
useMessage().createMessage.success('保存成功') |
||||
} |
||||
catch {} |
||||
finally { |
||||
setModalProps({ confirmLoading: false }) |
||||
} |
||||
} |
||||
</script> |
||||
|
||||
<template> |
||||
<BasicModal |
||||
v-bind="$attrs" |
||||
width="30%" |
||||
:min-height="100" |
||||
:title="isUpdate ? '编辑' : '新增'" |
||||
:after-close="() => isUpdate = false" |
||||
@register="registerModal" |
||||
@ok="handleSubmit" |
||||
> |
||||
<BasicForm @register="registerForm" /> |
||||
</BasicModal> |
||||
</template> |
@ -0,0 +1,99 @@
|
||||
import type { Ref } from 'vue' |
||||
import { h } from 'vue' |
||||
import { Space, Tag } from 'ant-design-vue' |
||||
import type { BasicColumn, FormSchema } from '@/components/Table' |
||||
import { useSystemEnumStore } from '@/store/modules/systemEnum' |
||||
import { getAllProducts } from '@/api/product' |
||||
import type { Product } from '@/api/product/types' |
||||
|
||||
const { getSystemEnums } = useSystemEnumStore() |
||||
|
||||
let productsCache: Pick<Product, 'id' | 'productName'>[] = [] |
||||
async function getCachedProducts() { |
||||
if (productsCache.length) |
||||
return productsCache |
||||
|
||||
try { |
||||
return productsCache = await getAllProducts() |
||||
} |
||||
catch { |
||||
return [] |
||||
} |
||||
} |
||||
|
||||
export const columns: BasicColumn[] = [ |
||||
{ |
||||
title: '产品名称', |
||||
dataIndex: 'productId', |
||||
customRender({ value }) { |
||||
return productsCache.find(item => item.id === value)?.productName |
||||
}, |
||||
}, |
||||
{ |
||||
title: '推送消息类型', |
||||
dataIndex: 'messageType', |
||||
customRender({ value }) { |
||||
const values = value.split(',') |
||||
const types = getSystemEnums('eSubscribeMessageType') |
||||
return h( |
||||
Space, |
||||
() => types |
||||
.map(item => values.includes(item.value.toString()) ? item.label : null) |
||||
.filter(Boolean) |
||||
.map(name => h(Tag, () => name)), |
||||
) |
||||
}, |
||||
}, |
||||
{ |
||||
title: '创建时间', |
||||
dataIndex: 'createTime', |
||||
}, |
||||
] |
||||
|
||||
export const searchFormSchema: FormSchema[] = [ |
||||
{ |
||||
field: 'productId', |
||||
label: '产品名称', |
||||
component: 'ApiSelect', |
||||
componentProps: { |
||||
api: getCachedProducts, |
||||
showSearch: true, |
||||
fieldNames: { |
||||
label: 'productName', |
||||
value: 'id', |
||||
}, |
||||
}, |
||||
colProps: { |
||||
span: 6, |
||||
}, |
||||
}, |
||||
] |
||||
|
||||
export function getFormSchema(isUpload: Ref<boolean>): FormSchema[] { |
||||
return [ |
||||
{ |
||||
field: 'productId', |
||||
fields: ['id'], |
||||
label: '产品名称', |
||||
required: true, |
||||
component: 'ApiSelect', |
||||
componentProps: { |
||||
api: getCachedProducts, |
||||
valueField: 'id', |
||||
labelField: 'productName', |
||||
showSearch: true, |
||||
}, |
||||
dynamicDisabled: () => isUpload.value, |
||||
}, |
||||
{ |
||||
field: 'messageType', |
||||
label: '产品名称', |
||||
required: true, |
||||
component: 'Select', |
||||
componentProps: { |
||||
mode: 'multiple', |
||||
options: getSystemEnums('eSubscribeMessageType'), |
||||
}, |
||||
}, |
||||
] |
||||
} |
@ -0,0 +1,82 @@
|
||||
<script lang="ts" setup> |
||||
import { PlusOutlined } from '@ant-design/icons-vue' |
||||
import { columns, searchFormSchema } from './data' |
||||
import SubscriptionFormModal from './SubscriptionFormModal.vue' |
||||
import { BasicTable, TableAction, useTable } from '@/components/Table' |
||||
import { deleteSubscription, getSubscriptionList } from '@/api/subscription/list' |
||||
import { useModal } from '@/components/Modal' |
||||
import type { SubScription } from '@/api/subscription/list/types' |
||||
import { useMessage } from '@/hooks/web/useMessage' |
||||
|
||||
defineOptions({ name: 'Subscription' }) |
||||
|
||||
const [registerModal, { openModal }] = useModal<SubScription>() |
||||
|
||||
const [register, { reload }] = useTable({ |
||||
api: getSubscriptionList, |
||||
columns, |
||||
formConfig: { |
||||
labelWidth: 80, |
||||
schemas: searchFormSchema, |
||||
}, |
||||
bordered: true, |
||||
canResize: false, |
||||
isTreeTable: true, |
||||
useSearchForm: true, |
||||
pagination: false, |
||||
actionColumn: { |
||||
width: 160, |
||||
title: '操作', |
||||
dataIndex: 'action', |
||||
fixed: 'right', |
||||
}, |
||||
}) |
||||
|
||||
async function handleDelete(id: string) { |
||||
try { |
||||
await deleteSubscription(id) |
||||
useMessage().createMessage.success('删除成功') |
||||
reload() |
||||
} |
||||
catch {} |
||||
} |
||||
</script> |
||||
|
||||
<template> |
||||
<div> |
||||
<BasicTable :api="async () => ([] as SubScription[])" @register="register"> |
||||
<template #tableTitle> |
||||
<a-button type="primary" @click="openModal()"> |
||||
<PlusOutlined /> |
||||
创建 |
||||
</a-button> |
||||
</template> |
||||
|
||||
<template #bodyCell="{ column, record }"> |
||||
<template v-if="column.key === 'action'"> |
||||
<TableAction |
||||
:actions="[ |
||||
{ |
||||
icon: 'i-ant-design:edit-outlined', |
||||
label: '修改', |
||||
onClick: () => openModal(true, record), |
||||
}, |
||||
{ |
||||
icon: 'i-ant-design:delete-outlined', |
||||
danger: true, |
||||
label: '删除', |
||||
popConfirm: { |
||||
title: '确定要删除数据吗?', |
||||
placement: 'left', |
||||
confirm: () => handleDelete(record.id), |
||||
}, |
||||
}, |
||||
]" |
||||
/> |
||||
</template> |
||||
</template> |
||||
</BasicTable> |
||||
|
||||
<SubscriptionFormModal @register="registerModal" @success="reload" /> |
||||
</div> |
||||
</template> |
Loading…
Reference in new issue