index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <ContentWrap>
  3. <!-- 搜索工作栏 -->
  4. <el-form
  5. ref="queryFormRef"
  6. :inline="true"
  7. :model="queryParams"
  8. class="-mb-15px"
  9. label-width="68px"
  10. >
  11. <el-form-item label="分类名称" prop="name">
  12. <el-input
  13. v-model="queryParams.name"
  14. class="!w-240px"
  15. clearable
  16. placeholder="请输入分类名称"
  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:article-category: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="编号" prop="id" min-width="100" />
  66. <el-table-column align="center" label="分类名称" prop="name" min-width="240" />
  67. <el-table-column label="分类图图" min-width="80">
  68. <template #default="{ row }">
  69. <el-image :src="row.picUrl" class="h-30px w-30px" @click="imagePreview(row.picUrl)" />
  70. </template>
  71. </el-table-column>
  72. <el-table-column align="center" label="状态" prop="status" min-width="150">
  73. <template #default="scope">
  74. <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
  75. </template>
  76. </el-table-column>
  77. <el-table-column align="center" label="排序" prop="sort" min-width="150" />
  78. <el-table-column
  79. :formatter="dateFormatter"
  80. align="center"
  81. label="创建时间"
  82. prop="createTime"
  83. width="180px"
  84. />
  85. <el-table-column align="center" label="操作">
  86. <template #default="scope">
  87. <el-button
  88. v-hasPermi="['promotion:article-category:update']"
  89. link
  90. type="primary"
  91. @click="openForm('update', scope.row.id)"
  92. >
  93. 编辑
  94. </el-button>
  95. <el-button
  96. v-hasPermi="['promotion:article-category:delete']"
  97. link
  98. type="danger"
  99. @click="handleDelete(scope.row.id)"
  100. >
  101. 删除
  102. </el-button>
  103. </template>
  104. </el-table-column>
  105. </el-table>
  106. <!-- 分页 -->
  107. <Pagination
  108. v-model:limit="queryParams.pageSize"
  109. v-model:page="queryParams.pageNo"
  110. :total="total"
  111. @pagination="getList"
  112. />
  113. </ContentWrap>
  114. <!-- 表单弹窗:添加/修改 -->
  115. <ArticleCategoryForm ref="formRef" @success="getList" />
  116. </template>
  117. <script lang="ts" setup>
  118. import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
  119. import { dateFormatter } from '@/utils/formatTime'
  120. import * as ArticleCategoryApi from '@/api/mall/promotion/articleCategory'
  121. import ArticleCategoryForm from './ArticleCategoryForm.vue'
  122. import { createImageViewer } from '@/components/ImageViewer'
  123. defineOptions({ name: 'PromotionArticleCategory' })
  124. const message = useMessage() // 消息弹窗
  125. const { t } = useI18n() // 国际化
  126. const loading = ref(true) // 列表的加载中
  127. const total = ref(0) // 列表的总页数
  128. const list = ref([]) // 列表的数据
  129. const queryParams = reactive({
  130. pageNo: 1,
  131. pageSize: 10,
  132. name: null,
  133. status: null,
  134. createTime: []
  135. })
  136. const queryFormRef = ref() // 搜索的表单
  137. const exportLoading = ref(false) // 导出的加载中
  138. /** 分类图预览 */
  139. const imagePreview = (imgUrl: string) => {
  140. createImageViewer({
  141. urlList: [imgUrl]
  142. })
  143. }
  144. /** 查询列表 */
  145. const getList = async () => {
  146. loading.value = true
  147. try {
  148. const data = await ArticleCategoryApi.getArticleCategoryPage(queryParams)
  149. list.value = data.list
  150. total.value = data.total
  151. } finally {
  152. loading.value = false
  153. }
  154. }
  155. /** 搜索按钮操作 */
  156. const handleQuery = () => {
  157. queryParams.pageNo = 1
  158. getList()
  159. }
  160. /** 重置按钮操作 */
  161. const resetQuery = () => {
  162. queryFormRef.value.resetFields()
  163. handleQuery()
  164. }
  165. /** 添加/修改操作 */
  166. const formRef = ref()
  167. const openForm = (type: string, id?: number) => {
  168. formRef.value.open(type, id)
  169. }
  170. /** 删除按钮操作 */
  171. const handleDelete = async (id: number) => {
  172. try {
  173. // 删除的二次确认
  174. await message.delConfirm()
  175. // 发起删除
  176. await ArticleCategoryApi.deleteArticleCategory(id)
  177. message.success(t('common.delSuccess'))
  178. // 刷新列表
  179. await getList()
  180. } catch {}
  181. }
  182. /** 初始化 **/
  183. onMounted(() => {
  184. getList()
  185. })
  186. </script>