index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <template>
  2. <doc-alert title="邮件配置" url="https://doc.iocoder.cn/mail" />
  3. <ContentWrap>
  4. <el-form
  5. class="-mb-15px"
  6. :model="queryParams"
  7. ref="queryFormRef"
  8. :inline="true"
  9. label-width="68px"
  10. >
  11. <el-form-item label="邮箱" prop="mail">
  12. <el-input
  13. v-model="queryParams.mail"
  14. placeholder="请输入邮箱"
  15. clearable
  16. class="!w-240px"
  17. @keyup.enter="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="用户名" prop="username">
  21. <el-input
  22. v-model="queryParams.username"
  23. placeholder="请输入用户名"
  24. clearable
  25. class="!w-240px"
  26. @keyup.enter="handleQuery"
  27. />
  28. </el-form-item>
  29. <el-form-item label="创建时间" prop="createTime">
  30. <el-date-picker
  31. v-model="queryParams.createTime"
  32. value-format="YYYY-MM-DD HH:mm:ss"
  33. type="daterange"
  34. start-placeholder="开始日期"
  35. end-placeholder="结束日期"
  36. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  37. class="!w-240px"
  38. />
  39. </el-form-item>
  40. <el-form-item>
  41. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  42. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  43. <el-button
  44. type="primary"
  45. plain
  46. @click="openForm('create')"
  47. v-hasPermi="['system:mail-account:create']"
  48. >
  49. <Icon icon="ep:plus" class="mr-5px" /> 新增</el-button
  50. >
  51. <el-button
  52. type="danger"
  53. plain
  54. :disabled="checkedIds.length === 0"
  55. @click="handleDeleteBatch"
  56. v-hasPermi="['system:mail-account:delete']"
  57. >
  58. <Icon icon="ep:delete" class="mr-5px" /> 批量删除
  59. </el-button>
  60. </el-form-item>
  61. </el-form>
  62. </ContentWrap>
  63. <!-- 列表 -->
  64. <ContentWrap>
  65. <el-table v-loading="loading" :data="list" @selection-change="handleRowCheckboxChange">
  66. <el-table-column type="selection" width="55" />
  67. <el-table-column label="编号" align="center" prop="id" />
  68. <el-table-column label="邮箱" align="center" prop="mail" />
  69. <el-table-column label="用户名" align="center" prop="username" />
  70. <el-table-column label="SMTP 服务器域名" align="center" prop="host" />
  71. <el-table-column label="SMTP 服务器端口" align="center" prop="port" />
  72. <el-table-column label="是否开启 SSL" align="center" prop="sslEnable">
  73. <template #default="scope">
  74. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.sslEnable" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column label="是否开启 STARTTLS" align="center" prop="starttlsEnable">
  78. <template #default="scope">
  79. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.starttlsEnable" />
  80. </template>
  81. </el-table-column>
  82. <el-table-column
  83. label="创建时间"
  84. align="center"
  85. prop="createTime"
  86. width="180"
  87. :formatter="dateFormatter"
  88. />
  89. <el-table-column label="操作" align="center">
  90. <template #default="scope">
  91. <el-button
  92. link
  93. type="primary"
  94. @click="openForm('update', scope.row.id)"
  95. v-hasPermi="['system:mail-account:update']"
  96. >
  97. 编辑
  98. </el-button>
  99. <el-button
  100. link
  101. type="danger"
  102. @click="handleDelete(scope.row.id)"
  103. v-hasPermi="['system:mail-account:delete']"
  104. >
  105. 删除
  106. </el-button>
  107. </template>
  108. </el-table-column>
  109. </el-table>
  110. <!-- 分页 -->
  111. <Pagination
  112. :total="total"
  113. v-model:page="queryParams.pageNo"
  114. v-model:limit="queryParams.pageSize"
  115. @pagination="getList"
  116. />
  117. </ContentWrap>
  118. <!-- 表单弹窗:添加/修改 -->
  119. <MailAccountForm ref="formRef" @success="getList" />
  120. </template>
  121. <script lang="ts" setup>
  122. import { DICT_TYPE } from '@/utils/dict'
  123. import { dateFormatter } from '@/utils/formatTime'
  124. import * as MailAccountApi from '@/api/system/mail/account'
  125. import MailAccountForm from './MailAccountForm.vue'
  126. defineOptions({ name: 'SystemMailAccount' })
  127. const { t } = useI18n() // 国际化
  128. const message = useMessage() // 消息弹窗
  129. const loading = ref(false) // 列表的加载中
  130. const total = ref(0) // 列表的总页数
  131. const list = ref([]) // 列表的数据
  132. const queryFormRef = ref() // 搜索的表单
  133. const queryParams = reactive({
  134. pageNo: 1,
  135. pageSize: 10,
  136. mail: '',
  137. username: '',
  138. createTime: []
  139. })
  140. /** 查询列表 */
  141. const getList = async () => {
  142. loading.value = true
  143. try {
  144. const data = await MailAccountApi.getMailAccountPage(queryParams)
  145. list.value = data.list
  146. total.value = data.total
  147. } finally {
  148. loading.value = false
  149. }
  150. }
  151. /** 搜索按钮操作 */
  152. const handleQuery = () => {
  153. queryParams.pageNo = 1
  154. getList()
  155. }
  156. /** 重置按钮操作 */
  157. const resetQuery = () => {
  158. queryFormRef.value.resetFields()
  159. handleQuery()
  160. }
  161. /** 添加/修改操作 */
  162. const formRef = ref()
  163. const openForm = (type: string, id?: number) => {
  164. formRef.value.open(type, id)
  165. }
  166. /** 删除按钮操作 */
  167. const handleDelete = async (id: number) => {
  168. try {
  169. // 删除的二次确认
  170. await message.delConfirm()
  171. // 发起删除
  172. await MailAccountApi.deleteMailAccount(id)
  173. message.success(t('common.delSuccess'))
  174. // 刷新列表
  175. await getList()
  176. } catch {}
  177. }
  178. /** 批量删除按钮操作 */
  179. const checkedIds = ref<number[]>([])
  180. const handleRowCheckboxChange = (rows: MailAccountApi.MailAccountVO[]) => {
  181. checkedIds.value = rows.map((row) => row.id)
  182. }
  183. const handleDeleteBatch = async () => {
  184. try {
  185. // 删除的二次确认
  186. await message.delConfirm()
  187. // 发起批量删除
  188. await MailAccountApi.deleteMailAccountList(checkedIds.value)
  189. message.success(t('common.delSuccess'))
  190. // 刷新列表
  191. await getList()
  192. } catch {}
  193. }
  194. /** 初始化 **/
  195. onMounted(() => {
  196. getList()
  197. })
  198. </script>