index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <template>
  2. <content-wrap>
  3. <!-- 搜索工作栏 -->
  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="title">
  12. <el-input
  13. v-model="queryParams.title"
  14. placeholder="请输入公告标题"
  15. clearable
  16. @keyup.enter="handleQuery"
  17. class="!w-240px"
  18. />
  19. </el-form-item>
  20. <el-form-item label="公告状态" prop="status">
  21. <el-select
  22. v-model="queryParams.status"
  23. placeholder="请选择公告状态"
  24. clearable
  25. class="!w-240px"
  26. >
  27. <el-option
  28. v-for="dict in getDictOptions(DICT_TYPE.COMMON_STATUS)"
  29. :key="parseInt(dict.value)"
  30. :label="dict.label"
  31. :value="parseInt(dict.value)"
  32. />
  33. </el-select>
  34. </el-form-item>
  35. <el-form-item>
  36. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  37. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  38. <el-button
  39. type="primary"
  40. plain
  41. @click="openModal('create')"
  42. v-hasPermi="['system:notice:create']"
  43. >
  44. <Icon icon="ep:plus" class="mr-5px" /> 新增
  45. </el-button>
  46. </el-form-item>
  47. </el-form>
  48. </content-wrap>
  49. <!-- 列表 -->
  50. <content-wrap>
  51. <el-table v-loading="loading" :data="list">
  52. <el-table-column label="公告编号" align="center" prop="id" />
  53. <el-table-column label="公告标题" align="center" prop="title" />
  54. <el-table-column label="公告类型" align="center" prop="type">
  55. <template #default="scope">
  56. <dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="scope.row.type" />
  57. </template>
  58. </el-table-column>
  59. <el-table-column label="状态" align="center" prop="status">
  60. <template #default="scope">
  61. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  62. </template>
  63. </el-table-column>
  64. <el-table-column
  65. label="创建时间"
  66. align="center"
  67. prop="createTime"
  68. width="180"
  69. :formatter="dateFormatter"
  70. />
  71. <el-table-column label="操作" align="center">
  72. <template #default="scope">
  73. <el-button
  74. link
  75. type="primary"
  76. @click="openModal('update', scope.row.id)"
  77. v-hasPermi="['system:notice:update']"
  78. >
  79. 编辑
  80. </el-button>
  81. <el-button
  82. link
  83. type="danger"
  84. @click="handleDelete(scope.row.id)"
  85. v-hasPermi="['system:notice:delete']"
  86. >
  87. 删除
  88. </el-button>
  89. </template>
  90. </el-table-column>
  91. </el-table>
  92. <!-- 分页 -->
  93. <Pagination
  94. :total="total"
  95. v-model:page="queryParams.pageNo"
  96. v-model:limit="queryParams.pageSize"
  97. @pagination="getList"
  98. />
  99. </content-wrap>
  100. <!-- 表单弹窗:添加/修改 -->
  101. <notice-form ref="modalRef" @success="getList" />
  102. </template>
  103. <script setup lang="tsx">
  104. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  105. import { dateFormatter } from '@/utils/formatTime'
  106. import * as NoticeApi from '@/api/system/notice'
  107. import { DictTag } from '@/components/DictTag'
  108. import NoticeForm from './form.vue'
  109. const message = useMessage() // 消息弹窗
  110. const { t } = useI18n() // 国际化
  111. const loading = ref(true) // 列表的加载中
  112. const total = ref(0) // 列表的总页数
  113. const list = ref([]) // 列表的数据
  114. const queryParams = reactive({
  115. pageNo: 1,
  116. pageSize: 10,
  117. title: '',
  118. type: undefined,
  119. status: undefined
  120. })
  121. const queryFormRef = ref() // 搜索的表单
  122. /** 查询公告列表 */
  123. const getList = async () => {
  124. loading.value = true
  125. try {
  126. const data = await NoticeApi.getNoticePage(queryParams)
  127. list.value = data.list
  128. total.value = data.total
  129. } finally {
  130. loading.value = false
  131. }
  132. }
  133. /** 搜索按钮操作 */
  134. const handleQuery = () => {
  135. queryParams.pageNo = 1
  136. getList()
  137. }
  138. /** 重置按钮操作 */
  139. const resetQuery = () => {
  140. queryFormRef.value.resetFields()
  141. handleQuery()
  142. }
  143. /** 添加/修改操作 */
  144. const modalRef = ref()
  145. const openModal = (type: string, id?: number) => {
  146. modalRef.value.openModal(type, id)
  147. }
  148. /** 删除按钮操作 */
  149. const handleDelete = async (id: number) => {
  150. try {
  151. // 删除的二次确认
  152. await message.delConfirm()
  153. // 发起删除
  154. await NoticeApi.deleteNotice(id)
  155. message.success(t('common.delSuccess'))
  156. // 刷新列表
  157. await getList()
  158. } catch {}
  159. }
  160. /** 初始化 **/
  161. onMounted(() => {
  162. getList()
  163. })
  164. </script>