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. @click="openModal('create')"
  41. v-hasPermi="['system:notice:create']"
  42. >
  43. <Icon icon="ep:plus" class="mr-5px" /> 新增
  44. </el-button>
  45. </el-form-item>
  46. </el-form>
  47. </content-wrap>
  48. <!-- 列表 -->
  49. <content-wrap>
  50. <el-table v-loading="loading" :data="list">
  51. <el-table-column label="公告编号" align="center" prop="id" />
  52. <el-table-column label="公告标题" align="center" prop="title" />
  53. <el-table-column label="公告类型" align="center" prop="type">
  54. <template #default="scope">
  55. <dict-tag :type="DICT_TYPE.SYSTEM_NOTICE_TYPE" :value="scope.row.type" />
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="状态" align="center" prop="status">
  59. <template #default="scope">
  60. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  61. </template>
  62. </el-table-column>
  63. <el-table-column
  64. label="创建时间"
  65. align="center"
  66. prop="createTime"
  67. width="180"
  68. :formatter="dateFormatter"
  69. />
  70. <el-table-column label="操作" align="center">
  71. <template #default="scope">
  72. <el-button
  73. link
  74. type="primary"
  75. @click="openModal('update', scope.row.id)"
  76. v-hasPermi="['system:notice:update']"
  77. >
  78. 编辑
  79. </el-button>
  80. <el-button
  81. link
  82. type="danger"
  83. @click="handleDelete(scope.row.id)"
  84. v-hasPermi="['system:notice:delete']"
  85. >
  86. 删除
  87. </el-button>
  88. </template>
  89. </el-table-column>
  90. </el-table>
  91. <!-- 分页 -->
  92. <Pagination
  93. :total="total"
  94. v-model:page="queryParams.pageNo"
  95. v-model:limit="queryParams.pageSize"
  96. @pagination="getList"
  97. />
  98. </content-wrap>
  99. <!-- 表单弹窗:添加/修改 -->
  100. <notice-form ref="modalRef" @success="getList" />
  101. </template>
  102. <script setup lang="tsx">
  103. import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  104. import { dateFormatter } from '@/utils/formatTime'
  105. import * as NoticeApi from '@/api/system/notice'
  106. import { DictTag } from '@/components/DictTag'
  107. import NoticeForm from './form.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. title: '',
  115. type: undefined,
  116. status: undefined,
  117. pageNo: 1,
  118. pageSize: 100
  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 modalRef = ref()
  144. const openModal = (type: string, id?: number) => {
  145. modalRef.value.openModal(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>