3 changed files with 201 additions and 1 deletions
@ -0,0 +1,58 @@ |
|||||||
|
<script lang="ts" setup> |
||||||
|
import { ref, unref } from 'vue' |
||||||
|
import { formSchema } from './config.data' |
||||||
|
import { useI18n } from '@/hooks/web/useI18n' |
||||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||||
|
import { BasicForm, useForm } from '@/components/Form' |
||||||
|
import { BasicModal, useModalInner } from '@/components/Modal' |
||||||
|
import { createNotice, getNotice, updateNotice } from '@/api/system/notice' |
||||||
|
|
||||||
|
defineOptions({ name: 'SignInConfigModal' }) |
||||||
|
|
||||||
|
const emit = defineEmits(['success', 'register']) |
||||||
|
const { t } = useI18n() |
||||||
|
const { createMessage } = useMessage() |
||||||
|
const isUpdate = ref(true) |
||||||
|
|
||||||
|
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ |
||||||
|
labelWidth: 120, |
||||||
|
baseColProps: { span: 24 }, |
||||||
|
schemas: formSchema, |
||||||
|
showActionButtonGroup: false, |
||||||
|
actionColOptions: { span: 23 }, |
||||||
|
}) |
||||||
|
|
||||||
|
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { |
||||||
|
resetFields() |
||||||
|
setModalProps({ confirmLoading: false }) |
||||||
|
isUpdate.value = !!data?.isUpdate |
||||||
|
if (unref(isUpdate)) { |
||||||
|
const res = await getNotice(data.record.id) |
||||||
|
setFieldsValue({ ...res }) |
||||||
|
} |
||||||
|
}) |
||||||
|
|
||||||
|
async function handleSubmit() { |
||||||
|
try { |
||||||
|
const values = await validate() |
||||||
|
setModalProps({ confirmLoading: true }) |
||||||
|
if (unref(isUpdate)) |
||||||
|
await updateNotice(values) |
||||||
|
else |
||||||
|
await createNotice(values) |
||||||
|
|
||||||
|
closeModal() |
||||||
|
emit('success') |
||||||
|
createMessage.success(t('common.saveSuccessText')) |
||||||
|
} |
||||||
|
finally { |
||||||
|
setModalProps({ confirmLoading: false }) |
||||||
|
} |
||||||
|
} |
||||||
|
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<BasicModal v-bind="$attrs" :title="isUpdate ? t('action.edit') : t('action.create')" @register="registerModal" @ok="handleSubmit"> |
||||||
|
<BasicForm @register="registerForm" /> |
||||||
|
</BasicModal> |
||||||
|
</template> |
@ -0,0 +1,70 @@ |
|||||||
|
import type { BasicColumn, FormSchema } from '@/components/Table' |
||||||
|
import { useRender } from '@/components/Table' |
||||||
|
import { DICT_TYPE, getDictOptions } from '@/utils/dict' |
||||||
|
|
||||||
|
export const columns: BasicColumn[] = [ |
||||||
|
{ |
||||||
|
title: '公告编号', |
||||||
|
dataIndex: 'id', |
||||||
|
width: 100, |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '签到天数', |
||||||
|
dataIndex: 'day', |
||||||
|
width: 180, |
||||||
|
customRender: ({ text }) => { |
||||||
|
return useRender.renderTag(`第 ${text} 天`) |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '获得积分', |
||||||
|
dataIndex: 'point', |
||||||
|
width: 180, |
||||||
|
}, |
||||||
|
{ |
||||||
|
title: '状态', |
||||||
|
dataIndex: 'status', |
||||||
|
width: 180, |
||||||
|
customRender: ({ text }) => { |
||||||
|
return useRender.renderDict(text, DICT_TYPE.COMMON_STATUS) |
||||||
|
}, |
||||||
|
}, |
||||||
|
] |
||||||
|
|
||||||
|
export const formSchema: FormSchema[] = [ |
||||||
|
{ |
||||||
|
label: '编号', |
||||||
|
field: 'id', |
||||||
|
show: false, |
||||||
|
component: 'Input', |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '签到天数', |
||||||
|
field: 'day', |
||||||
|
required: true, |
||||||
|
helpMessage: '只允许设置 1-7,默认签到 7 天为一个周期', |
||||||
|
component: 'InputNumber', |
||||||
|
componentProps: { |
||||||
|
max: 7, |
||||||
|
min: 1, |
||||||
|
precision: 0, |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '签到分数', |
||||||
|
field: 'point', |
||||||
|
required: true, |
||||||
|
component: 'InputNumber', |
||||||
|
componentProps: { |
||||||
|
precision: 0, |
||||||
|
}, |
||||||
|
}, |
||||||
|
{ |
||||||
|
label: '状态', |
||||||
|
field: 'status', |
||||||
|
component: 'Select', |
||||||
|
componentProps: { |
||||||
|
options: getDictOptions(DICT_TYPE.COMMON_STATUS), |
||||||
|
}, |
||||||
|
}, |
||||||
|
] |
@ -1,3 +1,75 @@ |
|||||||
<script lang="ts" setup> |
<script lang="ts" setup> |
||||||
defineOptions({ name: 'MemberPointConfig' }) |
import ConfigModal from './ConfigModal.vue' |
||||||
|
import { columns } from './config.data' |
||||||
|
import { useI18n } from '@/hooks/web/useI18n' |
||||||
|
import { useMessage } from '@/hooks/web/useMessage' |
||||||
|
import { useModal } from '@/components/Modal' |
||||||
|
import { IconEnum } from '@/enums/appEnum' |
||||||
|
import { BasicTable, TableAction, useTable } from '@/components/Table' |
||||||
|
import { deleteSignInConfig, getSignInConfigList } from '@/api/member/signin/config' |
||||||
|
|
||||||
|
defineOptions({ name: 'SignInConfig' }) |
||||||
|
|
||||||
|
const { t } = useI18n() |
||||||
|
const { createMessage } = useMessage() |
||||||
|
const [registerModal, { openModal }] = useModal() |
||||||
|
const [registerTable, { reload }] = useTable({ |
||||||
|
api: getSignInConfigList, |
||||||
|
columns, |
||||||
|
showTableSetting: true, |
||||||
|
showIndexColumn: false, |
||||||
|
actionColumn: { |
||||||
|
width: 140, |
||||||
|
title: t('common.action'), |
||||||
|
dataIndex: 'action', |
||||||
|
fixed: 'right', |
||||||
|
}, |
||||||
|
}) |
||||||
|
|
||||||
|
function handleCreate() { |
||||||
|
openModal(true, { isUpdate: false }) |
||||||
|
} |
||||||
|
|
||||||
|
function handleEdit(record: Recordable) { |
||||||
|
openModal(true, { record, isUpdate: true }) |
||||||
|
} |
||||||
|
|
||||||
|
async function handleDelete(record: Recordable) { |
||||||
|
await deleteSignInConfig(record.id) |
||||||
|
createMessage.success(t('common.delSuccessText')) |
||||||
|
reload() |
||||||
|
} |
||||||
</script> |
</script> |
||||||
|
|
||||||
|
<template> |
||||||
|
<div> |
||||||
|
<BasicTable @register="registerTable"> |
||||||
|
<template #toolbar> |
||||||
|
<a-button v-auth="['system:notice:create']" type="primary" :pre-icon="IconEnum.ADD" @click="handleCreate"> |
||||||
|
{{ t('action.create') }} |
||||||
|
</a-button> |
||||||
|
</template> |
||||||
|
<template #bodyCell="{ column, record }"> |
||||||
|
<template v-if="column.key === 'action'"> |
||||||
|
<TableAction |
||||||
|
:actions="[ |
||||||
|
{ icon: IconEnum.EDIT, label: t('action.edit'), auth: 'system:notice:update', onClick: handleEdit.bind(null, record) }, |
||||||
|
{ |
||||||
|
icon: IconEnum.DELETE, |
||||||
|
color: 'error', |
||||||
|
label: t('action.delete'), |
||||||
|
auth: 'system:notice:delete', |
||||||
|
popConfirm: { |
||||||
|
title: t('common.delMessage'), |
||||||
|
placement: 'left', |
||||||
|
confirm: handleDelete.bind(null, record), |
||||||
|
}, |
||||||
|
}, |
||||||
|
]" |
||||||
|
/> |
||||||
|
</template> |
||||||
|
</template> |
||||||
|
</BasicTable> |
||||||
|
<ConfigModal @register="registerModal" @success="reload()" /> |
||||||
|
</div> |
||||||
|
</template> |
||||||
|
Reference in new issue