index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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="文章分类" prop="categoryId">
  81. <template #default="scope">
  82. {{ categoryList.find((item) => item.id === scope.row.categoryId)?.name }}
  83. </template>
  84. </el-table-column>
  85. <el-table-column align="center" label="关联商品" prop="spuId" width="300">
  86. <template #default="scope">
  87. <el-image
  88. :preview-src-list="[spuList.find((item) => item.id === scope.row.spuId)?.picUrl]"
  89. :src="spuList.find((item) => item.id === scope.row.spuId)?.picUrl"
  90. class="mr-[10px] h-40px w-40px v-middle"
  91. preview-teleported
  92. />
  93. {{ spuList.find((item) => item.id === scope.row.spuId)?.name }}
  94. </template>
  95. </el-table-column>
  96. <el-table-column align="center" label="文章标题" prop="title" />
  97. <el-table-column align="center" label="文章作者" prop="author" />
  98. <el-table-column align="center" label="文章封面" prop="picUrl">
  99. <template #default="{ row }">
  100. <el-image :src="row.picUrl" class="h-30px w-30px" @click="imagePreview(row.picUrl)" />
  101. </template>
  102. </el-table-column>
  103. <el-table-column align="center" label="文章简介" prop="introduction" />
  104. <el-table-column align="center" label="浏览次数" prop="browseCount" />
  105. <el-table-column align="center" label="排序" prop="sort" />
  106. <el-table-column align="center" label="状态" prop="status">
  107. <template #default="scope">
  108. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  109. </template>
  110. </el-table-column>
  111. <el-table-column align="center" label="热门" prop="recommendHot">
  112. <template #default="scope">
  113. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.recommendHot" />
  114. </template>
  115. </el-table-column>
  116. <el-table-column align="center" label="轮播图" prop="recommendBanner">
  117. <template #default="scope">
  118. <dict-tag :type="DICT_TYPE.INFRA_BOOLEAN_STRING" :value="scope.row.recommendBanner" />
  119. </template>
  120. </el-table-column>
  121. <el-table-column
  122. :formatter="dateFormatter"
  123. align="center"
  124. label="创建时间"
  125. prop="createTime"
  126. width="180px"
  127. />
  128. <el-table-column align="center" fixed="right" label="操作" width="120">
  129. <template #default="scope">
  130. <el-button
  131. v-hasPermi="['promotion:article:update']"
  132. link
  133. type="primary"
  134. @click="openForm('update', scope.row.id)"
  135. >
  136. 编辑
  137. </el-button>
  138. <el-button
  139. v-hasPermi="['promotion:article:delete']"
  140. link
  141. type="danger"
  142. @click="handleDelete(scope.row.id)"
  143. >
  144. 删除
  145. </el-button>
  146. </template>
  147. </el-table-column>
  148. </el-table>
  149. <!-- 分页 -->
  150. <Pagination
  151. v-model:limit="queryParams.pageSize"
  152. v-model:page="queryParams.pageNo"
  153. :total="total"
  154. @pagination="getList"
  155. />
  156. </ContentWrap>
  157. <!-- 表单弹窗:添加/修改 -->
  158. <ArticleForm ref="formRef" @success="getList" />
  159. </template>
  160. <script lang="ts" setup>
  161. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  162. import { dateFormatter } from '@/utils/formatTime'
  163. import * as ArticleApi from '@/api/mall/promotion/article'
  164. import ArticleForm from './ArticleForm.vue'
  165. import * as ArticleCategoryApi from '@/api/mall/promotion/articleCategory'
  166. import * as ProductSpuApi from '@/api/mall/product/spu'
  167. import { createImageViewer } from '@/components/ImageViewer'
  168. defineOptions({ name: 'PromotionArticle' })
  169. const message = useMessage() // 消息弹窗
  170. const { t } = useI18n() // 国际化
  171. const loading = ref(true) // 列表的加载中
  172. const total = ref(0) // 列表的总页数
  173. const list = ref([]) // 列表的数据
  174. const queryParams = reactive({
  175. pageNo: 1,
  176. pageSize: 10,
  177. categoryId: undefined,
  178. title: null,
  179. status: undefined,
  180. spuId: undefined,
  181. createTime: []
  182. })
  183. const queryFormRef = ref() // 搜索的表单
  184. const exportLoading = ref(false) // 导出的加载中
  185. /** 文章封面预览 */
  186. const imagePreview = (imgUrl: string) => {
  187. createImageViewer({
  188. urlList: [imgUrl]
  189. })
  190. }
  191. /** 查询列表 */
  192. const getList = async () => {
  193. loading.value = true
  194. try {
  195. const data = await ArticleApi.getArticlePage(queryParams)
  196. list.value = data.list
  197. total.value = data.total
  198. } finally {
  199. loading.value = false
  200. }
  201. }
  202. /** 搜索按钮操作 */
  203. const handleQuery = () => {
  204. queryParams.pageNo = 1
  205. getList()
  206. }
  207. /** 重置按钮操作 */
  208. const resetQuery = () => {
  209. queryFormRef.value.resetFields()
  210. handleQuery()
  211. }
  212. /** 添加/修改操作 */
  213. const formRef = ref()
  214. const openForm = (type: string, id?: number) => {
  215. formRef.value.open(type, id)
  216. }
  217. /** 删除按钮操作 */
  218. const handleDelete = async (id: number) => {
  219. try {
  220. // 删除的二次确认
  221. await message.delConfirm()
  222. // 发起删除
  223. await ArticleApi.deleteArticle(id)
  224. message.success(t('common.delSuccess'))
  225. // 刷新列表
  226. await getList()
  227. } catch {}
  228. }
  229. const categoryList = ref<ArticleCategoryApi.ArticleCategoryVO[]>([])
  230. const spuList = ref<ProductSpuApi.Spu[]>([])
  231. onMounted(async () => {
  232. await getList()
  233. // 加载分类、商品列表
  234. categoryList.value =
  235. (await ArticleCategoryApi.getSimpleArticleCategoryList()) as ArticleCategoryApi.ArticleCategoryVO[]
  236. spuList.value = (await ProductSpuApi.getSpuSimpleList()) as ProductSpuApi.Spu[]
  237. })
  238. </script>