123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <template>
- <hc-card>
- <template #header>
- <div class="w-32">
- <el-select v-model="searchType" placeholder="选择搜索类型" filterable block>
- <el-option label="附件域名" value="domainUrl" />
- <el-option label="附件名称" value="name" />
- <el-option label="附件原名" value="originalName" />
- </el-select>
- </div>
- <div class="ml-2 w-60">
- <hc-search-input v-model="searchName" placeholder="请输入关键词" @search="searchClick" />
- </div>
- </template>
- <template #extra>
- <el-button hc-btn type="primary" @click="addUploadClick">
- <hc-icon name="upload" />
- <span>上传</span>
- </el-button>
- <el-button hc-btn type="danger" @click="delClick">
- <hc-icon name="delete-bin" />
- <span>删除</span>
- </el-button>
- </template>
- <hc-table
- :column="tableColumn" :datas="tableData" :loading="tableLoading" is-check
- :is-index="false" :check-style="{ width: 29 }" @selection-change="tableCheckChange"
- >
- <template #attachSize="{ row }">{{ getRowFilterSize(row) }}</template>
- <template #action="{ row }">
- <el-link type="primary" :href="row.link">下载</el-link>
- <el-link v-del-com:[delRowClick]="row" type="danger">删除</el-link>
- </template>
- </hc-table>
- <template #action>
- <hc-pages :pages="searchForm" @change="pageChange" />
- </template>
- <!-- 上传文件 -->
- <hc-dialog v-model="isUploadShow" widths="460px" :footer="false" title="上传文件" @close="uploadClose">
- <hc-form-upload v-model="uploadFileSrc" :options="{ type: 'list' }" :upload="{ options: uploadFileConfig }" />
- </hc-dialog>
- </hc-card>
- </template>
- <script setup>
- import { onActivated, ref } from 'vue'
- import { HcDelMsg } from 'hc-vue3-ui'
- import { arrToId, filterSize, getArrValue } from 'js-fast-way'
- import mainApi from '~api/resource/attach'
- //激活
- onActivated(() => {
- searchClick()
- })
- //搜索表单
- const searchType = ref('originalName')
- const searchName = ref('')
- const searchForm = ref({ current: 1, size: 30, total: 0 })
- //搜索
- const searchClick = () => {
- searchForm.value.current = 1
- getTableData()
- }
- //分页
- const pageChange = ({ current, size }) => {
- searchForm.value.current = current
- searchForm.value.size = size
- getTableData()
- }
- //表格数据
- const tableColumn = ref([
- { key: 'originalName', name: '原名', width: 240 },
- { key: 'extension', name: '拓展名', width: 80 },
- { key: 'attachSize', name: '大小', width: 100 },
- { key: 'link', name: '资源地址' },
- { key: 'updateTime', name: '上传日期', width: 160 },
- { key: 'action', name: '操作', width: 90, align: 'center' },
- ])
- //获取表格数据
- const tableLoading = ref(true)
- const tableData = ref([])
- const getTableData = async () => {
- tableData.value = []
- tableLoading.value = true
- const { data } = await mainApi.page({
- ...searchForm.value,
- total: null,
- })
- tableLoading.value = false
- tableData.value = getArrValue(data?.records)
- searchForm.value.total = data?.total ?? 0
- }
- //获取过滤后的大小
- const getRowFilterSize = ({ attachSize }) => {
- return attachSize ? filterSize(attachSize) : attachSize + 'B'
- }
- //表格被选择
- const tableCheckKeys = ref([])
- const tableCheckChange = (rows) => {
- tableCheckKeys.value = rows
- }
- //上传文件
- const uploadFileSrc = ref('')
- const uploadFileConfig = {
- url: '/api/blade-resource/oss/endpoint/put-file-attach',
- accept: '*',
- accept_tip: '不限制',
- size: 1024,
- num: 0,
- multiple: true,
- }
- //新增
- const isUploadShow = ref(false)
- const addUploadClick = () => {
- isUploadShow.value = true
- }
- //关闭上传
- const uploadClose = () => {
- isUploadShow.value = false
- }
- //删除
- const delRowClick = async ({ item }, resolve)=> {
- const { isRes } = await mainApi.del(item.id)
- resolve() //关闭弹窗
- if (!isRes) return
- window.$message.success('删除成功')
- getTableData().then()
- }
- //批量删除
- const delClick = () => {
- const rows = tableCheckKeys.value
- if (rows.length <= 0) {
- window.$message.warning('请选择要删除的数据')
- return false
- }
- //确认删除菜单
- HcDelMsg(async (resolve) => {
- //发起请求
- const ids = arrToId(rows)
- const { isRes } = await mainApi.del(ids)
- resolve() //关闭弹窗
- if (!isRes) return
- window.$message.success('删除成功')
- getTableData().then()
- })
- }
- </script>
|