Skip to content

Commit 262874a

Browse files
committed
vue3 重构:邮件账号的新增 + 修改 + 删除
1 parent f1a80fe commit 262874a

File tree

4 files changed

+124
-10
lines changed

4 files changed

+124
-10
lines changed

src/api/system/mail/account/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ export interface MailAccountVO {
1010
sslEnable: boolean
1111
}
1212

13-
export interface MailAccountPageReqVO extends PageParam {
14-
mail?: string
15-
username?: string
16-
}
17-
1813
// 查询邮箱账号列表
19-
export const getMailAccountPageApi = async (params: MailAccountPageReqVO) => {
14+
export const getMailAccountPageApi = async (params: PageParam) => {
2015
return await request.get({ url: '/system/mail-account/page', params })
2116
}
2217

src/views/system/mail/account/account.data.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
22
import { DictTag } from '@/components/DictTag'
33
import { TableColumn } from '@/types/table'
44
import { dateFormatter } from '@/utils/formatTime'
5+
import { getBoolDictOptions } from '@/utils/dict'
56

67
const { t } = useI18n() // 国际化
78

@@ -59,13 +60,27 @@ const crudSchemas = reactive<CrudSchema[]>([
5960
type: DICT_TYPE.INFRA_BOOLEAN_STRING,
6061
value: cellValue
6162
})
63+
},
64+
form: {
65+
component: 'Radio',
66+
componentProps: {
67+
options: getBoolDictOptions(DICT_TYPE.INFRA_BOOLEAN_STRING)
68+
}
6269
}
6370
},
6471
{
6572
label: '创建时间',
6673
field: 'createTime',
6774
isForm: false,
6875
formatter: dateFormatter
76+
},
77+
{
78+
label: '操作',
79+
field: 'action',
80+
width: '260px',
81+
form: {
82+
show: false
83+
}
6984
}
7085
])
7186
export const { allSchemas } = useCrudSchemas(crudSchemas)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<template>
2+
<Dialog :title="modelTitle" v-model="modelVisible">
3+
<!-- TODO 芋艿:loading -->
4+
<Form ref="formRef" :schema="allSchemas.formSchema" :rules="rules" :isCol="false" />
5+
<template #footer>
6+
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
7+
<el-button @click="modelVisible = false">取 消</el-button>
8+
</template>
9+
</Dialog>
10+
</template>
11+
<script setup lang="ts">
12+
import * as MailAccountApi from '@/api/system/mail/account'
13+
import { rules, allSchemas } from './account.data'
14+
15+
const formRef = ref() // 表单 Ref
16+
const { t } = useI18n() // 国际化
17+
const message = useMessage() // 消息弹窗
18+
19+
const modelVisible = ref(false) // 弹窗的是否展示
20+
const modelTitle = ref('') // 弹窗的标题
21+
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
22+
const formType = ref('') // 表单的类型:create - 新增;update - 修改
23+
24+
/** 打开弹窗 */
25+
const openModal = async (type: string, id?: number) => {
26+
modelVisible.value = true
27+
modelTitle.value = t('action.' + type)
28+
formType.value = type
29+
// resetForm()
30+
// 修改时,设置数据
31+
if (id) {
32+
formLoading.value = true
33+
try {
34+
const data = await MailAccountApi.getMailAccountApi(id)
35+
formRef.value.setValues(data)
36+
} finally {
37+
formLoading.value = false
38+
}
39+
}
40+
}
41+
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
42+
43+
/** 提交表单 */
44+
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
45+
const submitForm = async () => {
46+
// 校验表单
47+
if (!formRef) return
48+
const valid = await formRef.value.getElFormRef().validate()
49+
if (!valid) return
50+
// 提交请求
51+
formLoading.value = true
52+
try {
53+
const data = formRef.value.formModel as MailAccountApi.MailAccountVO
54+
if (formType.value === 'create') {
55+
await MailAccountApi.createMailAccountApi(data)
56+
message.success(t('common.createSuccess'))
57+
} else {
58+
await MailAccountApi.updateMailAccountApi(data)
59+
message.success(t('common.updateSuccess'))
60+
}
61+
modelVisible.value = false
62+
// 发送操作成功的事件
63+
emit('success')
64+
} finally {
65+
formLoading.value = false
66+
}
67+
}
68+
</script>

src/views/system/mail/account/index.vue

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
<template>
22
<ContentWrap>
3+
<!-- TODO @芋艿:setSearchParams -->
34
<Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
45
</ContentWrap>
56

7+
<el-button
8+
type="primary"
9+
@click="openModal('create')"
10+
v-hasPermi="['system:mail-account:create']"
11+
>
12+
<Icon icon="ep:plus" class="mr-5px" /> 新增
13+
</el-button>
14+
615
<ContentWrap>
716
<Table
817
v-model:pageSize="tableObject.pageSize"
@@ -16,18 +25,37 @@
1625
@register="register"
1726
>
1827
<template #action="{ row }">
19-
<ElButton type="danger" @click="delData(row, false)">
20-
{{ t('exampleDemo.del') }}
21-
</ElButton>
28+
<el-button
29+
link
30+
type="primary"
31+
@click="openModal('update', row.id)"
32+
v-hasPermi="['system:mail-account:update']"
33+
>
34+
编辑
35+
</el-button>
36+
<el-button
37+
link
38+
type="danger"
39+
v-hasPermi="['system:mail-account:delete']"
40+
@click="delList(row.id, false)"
41+
>
42+
删除
43+
</el-button>
2244
</template>
2345
</Table>
2446
</ContentWrap>
47+
48+
<!-- 表单弹窗:添加/修改 -->
49+
<mail-account-form ref="modalRef" @success="getList" />
2550
</template>
2651
<script setup lang="ts" name="MailAccount">
2752
import { allSchemas } from './account.data'
2853
import { useTable } from '@/hooks/web/useTable'
29-
import { Table } from '@/components/Table'
3054
import * as MailAccountApi from '@/api/system/mail/account'
55+
import MailAccountForm from './form.vue'
56+
57+
// const { t } = useI18n() // 国际化
58+
// const message = useMessage() // 消息弹窗
3159
3260
const { register, tableObject, methods } = useTable<MailAccountApi.MailAccountVO>({
3361
getListApi: MailAccountApi.getMailAccountPageApi,
@@ -36,5 +64,13 @@ const { register, tableObject, methods } = useTable<MailAccountApi.MailAccountVO
3664
3765
const { getList, setSearchParams } = methods
3866
67+
const { delList } = methods
68+
69+
/** 添加/修改操作 */
70+
const modalRef = ref()
71+
const openModal = (type: string, id?: number) => {
72+
modalRef.value.openModal(type, id)
73+
}
74+
3975
getList()
4076
</script>

0 commit comments

Comments
 (0)