index.vue 6.2 KB

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