index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <ContentWrap>
  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 getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  29. :key="dict.value"
  30. :label="dict.label"
  31. :value="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="openForm('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. </ContentWrap>
  49. <!-- 列表 -->
  50. <ContentWrap>
  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="openForm('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. </ContentWrap>
  100. <!-- 表单弹窗:添加/修改 -->
  101. <NoticeForm ref="formRef" @success="getList" />
  102. </template>
  103. <script setup lang="tsx">
  104. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  105. import { dateFormatter } from '@/utils/formatTime'
  106. import * as NoticeApi from '@/api/system/notice'
  107. import NoticeForm from './NoticeForm.vue'
  108. const message = useMessage() // 消息弹窗
  109. const { t } = useI18n() // 国际化
  110. const loading = ref(true) // 列表的加载中
  111. const total = ref(0) // 列表的总页数
  112. const list = ref([]) // 列表的数据
  113. const queryParams = reactive({
  114. pageNo: 1,
  115. pageSize: 10,
  116. title: '',
  117. type: undefined,
  118. status: undefined
  119. })
  120. const queryFormRef = ref() // 搜索的表单
  121. /** 查询公告列表 */
  122. const getList = async () => {
  123. loading.value = true
  124. try {
  125. const data = await NoticeApi.getNoticePage(queryParams)
  126. list.value = data.list
  127. total.value = data.total
  128. } finally {
  129. loading.value = false
  130. }
  131. }
  132. /** 搜索按钮操作 */
  133. const handleQuery = () => {
  134. queryParams.pageNo = 1
  135. getList()
  136. }
  137. /** 重置按钮操作 */
  138. const resetQuery = () => {
  139. queryFormRef.value.resetFields()
  140. handleQuery()
  141. }
  142. /** 添加/修改操作 */
  143. const formRef = ref()
  144. const openForm = (type: string, id?: number) => {
  145. formRef.value.open(type, id)
  146. }
  147. /** 删除按钮操作 */
  148. const handleDelete = async (id: number) => {
  149. try {
  150. // 删除的二次确认
  151. await message.delConfirm()
  152. // 发起删除
  153. await NoticeApi.deleteNotice(id)
  154. message.success(t('common.delSuccess'))
  155. // 刷新列表
  156. await getList()
  157. } catch {}
  158. }
  159. /** 初始化 **/
  160. onMounted(() => {
  161. getList()
  162. })
  163. </script>