|
| 1 | +<template> |
| 2 | + <!-- 搜索 --> |
| 3 | + <content-wrap> |
| 4 | + <el-form |
| 5 | + class="-mb-15px" |
| 6 | + :model="queryParams" |
| 7 | + ref="queryFormRef" |
| 8 | + :inline="true" |
| 9 | + label-width="68px" |
| 10 | + > |
| 11 | + <el-form-item label="公众号" prop="accountId"> |
| 12 | + <el-select v-model="queryParams.accountId" placeholder="请选择公众号"> |
| 13 | + <el-option |
| 14 | + v-for="item in accounts" |
| 15 | + :key="parseInt(item.id)" |
| 16 | + :label="item.name" |
| 17 | + :value="parseInt(item.id)" |
| 18 | + /> |
| 19 | + </el-select> |
| 20 | + </el-form-item> |
| 21 | + <el-form-item label="标签名称" prop="name"> |
| 22 | + <el-input |
| 23 | + v-model="queryParams.name" |
| 24 | + placeholder="请输入标签名称" |
| 25 | + clearable |
| 26 | + @keyup.enter="handleQuery" |
| 27 | + /> |
| 28 | + </el-form-item> |
| 29 | + <el-form-item> |
| 30 | + <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> |
| 31 | + <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> |
| 32 | + <el-button type="primary" @click="openModal('create')" v-hasPermi="['mp:tag:create']"> |
| 33 | + <Icon icon="ep:plus" class="mr-5px" /> 新增 |
| 34 | + </el-button> |
| 35 | + <el-button type="info" @click="handleSync" v-hasPermi="['mp:tag:sync']"> |
| 36 | + <Icon icon="ep:refresh" class="mr-5px" /> 同步 |
| 37 | + </el-button> |
| 38 | + <el-button |
| 39 | + type="success" |
| 40 | + plain |
| 41 | + @click="handleExport" |
| 42 | + :loading="exportLoading" |
| 43 | + v-hasPermi="['mp:tag:export']" |
| 44 | + > |
| 45 | + <Icon icon="ep:download" class="mr-5px" /> 导出 |
| 46 | + </el-button> |
| 47 | + </el-form-item> |
| 48 | + </el-form> |
| 49 | + </content-wrap> |
| 50 | + |
| 51 | + <!-- 列表 --> |
| 52 | + <content-wrap> |
| 53 | + <el-table v-loading="loading" :data="list"> |
| 54 | + <el-table-column label="编号" align="center" prop="id" /> |
| 55 | + <el-table-column label="标签名称" align="center" prop="name" /> |
| 56 | + <el-table-column label="粉丝数" align="center" prop="count" /> |
| 57 | + <el-table-column |
| 58 | + label="创建时间" |
| 59 | + align="center" |
| 60 | + prop="createTime" |
| 61 | + width="180" |
| 62 | + :formatter="dateFormatter" |
| 63 | + /> |
| 64 | + <el-table-column label="操作" align="center"> |
| 65 | + <template #default="scope"> |
| 66 | + <el-button |
| 67 | + link |
| 68 | + type="primary" |
| 69 | + size="small" |
| 70 | + @click="openModal('update', scope.row.id)" |
| 71 | + v-hasPermi="['mp:tag:update']" |
| 72 | + ><Icon icon="ep:edit" class="mr-5px" />修改 |
| 73 | + </el-button> |
| 74 | + <el-button |
| 75 | + link |
| 76 | + size="small" |
| 77 | + type="danger" |
| 78 | + @click="handleDelete(scope.row.id)" |
| 79 | + v-hasPermi="['mp:tag:delete']" |
| 80 | + > |
| 81 | + <Icon icon="ep:delete" class="mr-5px" />删除 |
| 82 | + </el-button> |
| 83 | + </template> |
| 84 | + </el-table-column> |
| 85 | + </el-table> |
| 86 | + <!-- 分页 --> |
| 87 | + <Pagination |
| 88 | + :total="total" |
| 89 | + v-model:page="queryParams.pageNo" |
| 90 | + v-model:limit="queryParams.pageSize" |
| 91 | + @pagination="getList" |
| 92 | + /> |
| 93 | + </content-wrap> |
| 94 | + |
| 95 | + <!-- 表单弹窗:添加/修改 --> |
| 96 | + <mpTagForm ref="modalRef" @success="getList" /> |
| 97 | +</template> |
| 98 | +<script setup lang="ts" name="MpTag"> |
| 99 | +import { dateFormatter } from '@/utils/formatTime' |
| 100 | +// import download from '@/utils/download' |
| 101 | +import * as MpTagApi from '@/api/mp/tag' |
| 102 | +import * as MpAccountAPI from '@/api/mp/account' |
| 103 | +import mpTagForm from './form.vue' |
| 104 | +const message = useMessage() // 消息弹窗 |
| 105 | +const { t } = useI18n() // 国际化 |
| 106 | +
|
| 107 | +const loading = ref(true) // 列表的加载中 |
| 108 | +const total = ref(0) // 列表的总页数 |
| 109 | +const list = ref([]) // 列表的数据 |
| 110 | +const queryParams = reactive({ |
| 111 | + pageNo: 1, |
| 112 | + pageSize: 10, |
| 113 | + accountId: '', |
| 114 | + name: null |
| 115 | +}) |
| 116 | +
|
| 117 | +interface accountsType { |
| 118 | + id?: string | number | any |
| 119 | + name?: string | any |
| 120 | +} |
| 121 | +let accounts = [] as accountsType // 公众号账号列表 |
| 122 | +const queryFormRef = ref() // 搜索的表单 |
| 123 | +const exportLoading = ref(false) // 导出的加载中 |
| 124 | +
|
| 125 | +/** 查询参数列表 */ |
| 126 | +const getList = async () => { |
| 127 | + // 如果没有选中公众号账号,则进行提示。 |
| 128 | + try { |
| 129 | + if (!queryParams.accountId) { |
| 130 | + await message.error('未选中公众号,无法查询标签') |
| 131 | + return false |
| 132 | + } |
| 133 | + loading.value = true |
| 134 | +
|
| 135 | + const data = await MpTagApi.getTagPage(queryParams) |
| 136 | + list.value = data.list |
| 137 | + total.value = data.total |
| 138 | + } finally { |
| 139 | + loading.value = false |
| 140 | + } |
| 141 | +} |
| 142 | +/**同步 */ |
| 143 | +const handleSync = async () => { |
| 144 | + try { |
| 145 | + await message.confirm('是否确认同步标签?') //未做国际化处理 |
| 146 | + await MpTagApi.syncTag(queryParams.accountId) |
| 147 | + message.success('同步标签成功') //未做国际化处理 |
| 148 | + getList() |
| 149 | + } catch {} |
| 150 | +} |
| 151 | +/** 搜索按钮操作 */ |
| 152 | +const handleQuery = () => { |
| 153 | + queryParams.pageNo = 1 |
| 154 | + getList() |
| 155 | +} |
| 156 | +
|
| 157 | +/** 重置按钮操作 */ |
| 158 | +const resetQuery = () => { |
| 159 | + queryFormRef.value.resetFields() |
| 160 | + // 默认选中第一个 |
| 161 | + if (accounts.length > 0) { |
| 162 | + queryParams.accountId = accounts[0].id |
| 163 | + } |
| 164 | + handleQuery() |
| 165 | +} |
| 166 | +
|
| 167 | +/** 添加/修改操作 */ |
| 168 | +const modalRef = ref() |
| 169 | +const openModal = (type: string, id?: number) => { |
| 170 | + modalRef.value.openModal(type, id) |
| 171 | +} |
| 172 | +
|
| 173 | +/** 删除按钮操作 */ |
| 174 | +const handleDelete = async (id: number) => { |
| 175 | + try { |
| 176 | + // 删除的二次确认 |
| 177 | + await message.delConfirm('是否确认删除公众号标签编号为"' + id + '"的数据项?') //未做国际化处理 |
| 178 | + // 发起删除 |
| 179 | + await MpTagApi.deleteTag(id) |
| 180 | +
|
| 181 | + // 刷新列表 |
| 182 | + await getList() |
| 183 | + message.success(t('common.delSuccess')) |
| 184 | + } catch {} |
| 185 | +} |
| 186 | +
|
| 187 | +/** 导出按钮操作 */ |
| 188 | +const handleExport = async () => { |
| 189 | + try { |
| 190 | + // 导出的二次确认 |
| 191 | + await message.exportConfirm() |
| 192 | + // 发起导出 |
| 193 | + exportLoading.value = true |
| 194 | + message.info('功能不支持') |
| 195 | + // const data = await MpTagApi.exportConfigApi(queryParams) |
| 196 | + // download.excel(data, '参数配置.xls') |
| 197 | + } catch { |
| 198 | + } finally { |
| 199 | + exportLoading.value = false |
| 200 | + } |
| 201 | +} |
| 202 | +
|
| 203 | +/** 初始化 **/ |
| 204 | +onMounted(async () => { |
| 205 | + accounts = await MpAccountAPI.getSimpleAccounts() |
| 206 | + if (accounts.length > 0) { |
| 207 | + queryParams.accountId = accounts[0].id |
| 208 | + } |
| 209 | + await getList() |
| 210 | +}) |
| 211 | +</script> |
0 commit comments