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