index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="100px"
  10. >
  11. <el-form-item label="Banner标题" prop="title">
  12. <el-input
  13. v-model="queryParams.title"
  14. class="!w-240px"
  15. clearable
  16. placeholder="请输入Banner标题"
  17. @keyup.enter="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item label="活动状态" prop="status">
  21. <el-select v-model="queryParams.status" class="!w-240px" clearable placeholder="全部">
  22. <el-option
  23. v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
  24. :key="dict.value"
  25. :label="dict.label"
  26. :value="dict.value"
  27. />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="创建时间" prop="createTime">
  31. <el-date-picker
  32. v-model="queryParams.createTime"
  33. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  34. class="!w-240px"
  35. end-placeholder="结束日期"
  36. start-placeholder="开始日期"
  37. type="daterange"
  38. value-format="YYYY-MM-DD HH:mm:ss"
  39. />
  40. </el-form-item>
  41. <el-form-item>
  42. <el-button @click="handleQuery">
  43. <Icon class="mr-5px" icon="ep:search" />
  44. 搜索
  45. </el-button>
  46. <el-button @click="resetQuery">
  47. <Icon class="mr-5px" icon="ep:refresh" />
  48. 重置
  49. </el-button>
  50. <el-button
  51. v-hasPermi="['promotion:banner:create']"
  52. plain
  53. type="primary"
  54. @click="openForm('create')"
  55. >
  56. <Icon class="mr-5px" icon="ep:plus" />
  57. 新增
  58. </el-button>
  59. </el-form-item>
  60. </el-form>
  61. </ContentWrap>
  62. <!-- 列表 -->
  63. <ContentWrap>
  64. <el-table v-loading="loading" :data="list" :show-overflow-tooltip="true" :stripe="true">
  65. <el-table-column align="center" label="Banner标题" prop="title" />
  66. <el-table-column align="center" label="图片" min-width="80" prop="picUrl">
  67. <template #default="{ row }">
  68. <el-image :src="row.picUrl" class="h-30px w-30px" @click="imagePreview(row.picUrl)" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column align="center" label="状态" prop="status">
  72. <template #default="scope">
  73. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  74. </template>
  75. </el-table-column>
  76. <el-table-column align="center" label="定位" prop="position">
  77. <template #default="scope">
  78. <dict-tag :type="DICT_TYPE.PROMOTION_BANNER_POSITION" :value="scope.row.position" />
  79. </template>
  80. </el-table-column>
  81. <el-table-column align="center" label="跳转地址" prop="url" />
  82. <el-table-column
  83. :formatter="dateFormatter"
  84. align="center"
  85. label="创建时间"
  86. prop="createTime"
  87. width="180px"
  88. />
  89. <el-table-column align="center" label="排序" prop="sort" />
  90. <el-table-column align="center" label="描述" prop="memo" />
  91. <el-table-column align="center" label="操作">
  92. <template #default="scope">
  93. <el-button
  94. v-hasPermi="['promotion:banner:update']"
  95. link
  96. type="primary"
  97. @click="openForm('update', scope.row.id)"
  98. >
  99. 编辑
  100. </el-button>
  101. <el-button
  102. v-hasPermi="['promotion:banner:delete']"
  103. link
  104. type="danger"
  105. @click="handleDelete(scope.row.id)"
  106. >
  107. 删除
  108. </el-button>
  109. </template>
  110. </el-table-column>
  111. </el-table>
  112. <!-- 分页 -->
  113. <Pagination
  114. v-model:limit="queryParams.pageSize"
  115. v-model:page="queryParams.pageNo"
  116. :total="total"
  117. @pagination="getList"
  118. />
  119. </ContentWrap>
  120. <!-- 表单弹窗:添加/修改 -->
  121. <BannerForm ref="formRef" @success="getList" />
  122. </template>
  123. <script lang="ts" setup>
  124. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  125. import { dateFormatter } from '@/utils/formatTime'
  126. import * as BannerApi from '@/api/mall/market/banner'
  127. import BannerForm from './BannerForm.vue'
  128. import { createImageViewer } from '@/components/ImageViewer'
  129. defineOptions({ name: 'Banner' })
  130. const message = useMessage() // 消息弹窗
  131. const { t } = useI18n() // 国际化
  132. const loading = ref(true) // 列表的加载中
  133. const total = ref(0) // 列表的总页数
  134. const list = ref([]) // 列表的数据
  135. const queryParams = reactive({
  136. pageNo: 1,
  137. pageSize: 10,
  138. title: null,
  139. status: null,
  140. createTime: []
  141. })
  142. const queryFormRef = ref() // 搜索的表单
  143. /** 文章封面预览 */
  144. const imagePreview = (imgUrl: string) => {
  145. createImageViewer({
  146. urlList: [imgUrl]
  147. })
  148. }
  149. /** 查询列表 */
  150. const getList = async () => {
  151. loading.value = true
  152. try {
  153. const data = await BannerApi.getBannerPage(queryParams)
  154. list.value = data.list
  155. total.value = data.total
  156. } finally {
  157. loading.value = false
  158. }
  159. }
  160. /** 搜索按钮操作 */
  161. const handleQuery = () => {
  162. queryParams.pageNo = 1
  163. getList()
  164. }
  165. /** 重置按钮操作 */
  166. const resetQuery = () => {
  167. queryFormRef.value.resetFields()
  168. handleQuery()
  169. }
  170. /** 添加/修改操作 */
  171. const formRef = ref()
  172. const openForm = (type: string, id?: number) => {
  173. formRef.value.open(type, id)
  174. }
  175. /** 删除按钮操作 */
  176. const handleDelete = async (id: number) => {
  177. try {
  178. // 删除的二次确认
  179. await message.delConfirm()
  180. // 发起删除
  181. await BannerApi.deleteBanner(id)
  182. message.success(t('common.delSuccess'))
  183. // 刷新列表
  184. await getList()
  185. } catch {}
  186. }
  187. /** 初始化 **/
  188. onMounted(() => {
  189. getList()
  190. })
  191. </script>