index.vue 6.9 KB

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