index.vue 7.0 KB

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