HTML部分如下
<template>
<a-card :bordered="false">
<!-- 搜索条件 -->
<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
<a-row :gutter="24">
<a-col :span="6">
<a-form-item label="剧名" name="name">
<a-input v-model:value="searchFormState.name" placeholder="请输入剧名" />
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="是否完结" name="isOver">
<a-select v-model:value="searchFormState.isOver" placeholder="请选择是否完结" :options="isOverOptions" />
</a-form-item>
</a-col>
<a-col :span="6">
<a-form-item label="是否上架" name="online">
<a-select v-model:value="searchFormState.online" placeholder="请选择是否上架" :options="onlineOptions" />
</a-form-item>
</a-col>
<!-- 创建时间的时间范围 -->
<a-col :span="6" v-show="advanced">
<a-form-item label="创建时间" name="createTime">
<a-range-picker v-model:value="searchFormState.createTime" show-time />
</a-form-item>
</a-col>
<a-col :span="6" v-show="advanced">
<a-form-item label="创建用户" name="createUser">
<a-input v-model:value="searchFormState.createUser" placeholder="请输入创建用户" />
</a-form-item>
</a-col>
<a-col :span="6">
<a-button type="primary" @click="table.refresh(true)">查询</a-button>
<a-button style="margin: 0 8px" @click="reset">重置</a-button>
<a @click="toggleAdvanced" style="margin-left: 8px">
{{ advanced ? '收起' : '展开' }}
<component :is="advanced ? 'up-outlined' : 'down-outlined'" />
</a>
</a-col>
</a-row>
</a-form>
<!-- s-table 表格部分 -->
<s-table
ref="table"
:columns="columns"
:data="loadData"
:alert="options.alert.show"
bordered
:row-key="(record) => record.id"
:tool-config="toolConfig"
:row-selection="options.rowSelection"
>
<template #operator class="table-operator">
<a-space>
<a-button type="primary" @click="formRef.onOpen()" v-if="hasPerm('sysSeriesAdd')">
<template #icon><plus-outlined /></template>
新增
</a-button>
<xn-batch-delete
v-if="hasPerm('sysSeriesBatchDelete')"
:selectedRowKeys="selectedRowKeys"
@batchDelete="deleteBatchSysSeries"
/>
</a-space>
</template>
<template #bodyCell="{ column, record }">
<!-- 根据传入的url显示图片 -->
<template v-if="column.dataIndex === 'picUrl'">
<img :src="record.picUrl" style="width: 80px; height: 100px">
</template>
<template v-if="column.dataIndex === 'isOver'">
{{ $TOOL.dictTypeData('COMMON_YES_OR_NO', record.isOver) }}
</template>
<template v-if="column.dataIndex === 'online'">
{{ $TOOL.dictTypeData('COMMON_YES_OR_NO', record.online) }}
</template>
<!-- 操作列 -->
<template v-if="column.dataIndex === 'action'">
<a-space>
<a @click="batchBind(record)" v-if="hasPerm('sysSeriesBind')">批量绑定</a>
<a-divider type="vertical" v-if="hasPerm(['sysSeriesBind'], 'and')" />
<a @click="formRef.onOpen(record)" v-if="hasPerm('sysSeriesEdit')">编辑</a>
<a-divider type="vertical" v-if="hasPerm(['sysSeriesEdit', 'sysSeriesDelete'], 'and')" />
<a-popconfirm title="确定要删除吗?" @confirm="deleteSysSeries(record)">
<a-button type="link" danger size="small" v-if="hasPerm('sysSeriesDelete')">删除</a-button>
</a-popconfirm>
</a-space>
</template>
</template>
</s-table>
</a-card>
<Form ref="formRef" @successful="table.refresh(true)" />
<batch-bind-video ref="batchBindVideoRef" @successful="table.refresh(true)" />
</template>
JS部分如下
<script setup name="series">
import tool from '@/utils/tool'
import Form from './form.vue'
import sysSeriesApi from '@/api/biz/sysSeriesApi'
import BatchBindVideo from './batchBindVideo.vue'
let searchFormState = reactive({})
const searchFormRef = ref()
const table = ref()
const formRef = ref()
const batchBindVideoRef = ref()
const toolConfig = { refresh: true, height: true, columnSetting: true, striped: false }
// 查询区域显示更多控制
const advanced = ref(false)
const toggleAdvanced = () => {
advanced.value = !advanced.value
}
// 表格每列数据
const columns = [
{
title: '剧名',
dataIndex: 'name'
},
{
title: '总集数',
dataIndex: 'totalVideo'
},
{
title: '是否完结',
dataIndex: 'isOver'
},
{
title: '封面图',
dataIndex: 'picUrl',
},
{
title: '扩展信息',
dataIndex: 'extJson',
ellipsis: true
},
{
title: '是否上架',
dataIndex: 'online'
},
{
title: '创建时间',
dataIndex: 'createTime'
},
{
title: '创建用户',
dataIndex: 'createrName'
}
]
// 操作栏通过权限判断是否显示
if (hasPerm(['sysSeriesEdit', 'sysSeriesDelete', 'sysSeriesBind'])) {
columns.push({
title: '操作',
dataIndex: 'action',
align: 'center',
width: '300px'
})
}
const selectedRowKeys = ref([])
// 列表选择配置
const options = {
// columns数字类型字段加入 needTotal: true 可以勾选自动算账
alert: {
show: true,
clear: () => {
selectedRowKeys.value = ref([])
}
},
rowSelection: {
onChange: (selectedRowKey, selectedRows) => {
selectedRowKeys.value = selectedRowKey
}
}
}
const loadData = (parameter) => {
const searchFormParam = JSON.parse(JSON.stringify(searchFormState))
// createTime范围查询条件重载
if (searchFormParam.createTime) {
searchFormParam.startCreateTime = searchFormParam.createTime[0]
searchFormParam.endCreateTime = searchFormParam.createTime[1]
delete searchFormParam.createTime
}
return sysSeriesApi.sysSeriesPage(Object.assign(parameter, searchFormParam)).then((data) => {
return data
})
}
// 重置
const reset = () => {
searchFormRef.value.resetFields()
table.value.refresh(true)
}
// 删除
const deleteSysSeries = (record) => {
let params = [
{
id: record.id
}
]
sysSeriesApi.sysSeriesDelete(params).then(() => {
table.value.refresh(true)
})
}
// 批量删除
const deleteBatchSysSeries = (params) => {
sysSeriesApi.sysSeriesDelete(params).then(() => {
table.value.clearRefreshSelected()
})
}
const batchBind = (record) => {
batchBindVideoRef.value.onOpen(record)
}
// 选项
const isOverOptions = tool.dictList('COMMON_YES_OR_NO')
const onlineOptions = tool.dictList('COMMON_YES_OR_NO')
</script>
如果需要图片包含预览,有以下两种方法:
方法一
直接使用 antd 中的 a-image 组件:
<template v-if="column.dataIndex === 'picUrl'">
<a-image :src="record.picUrl" :width="50"/>
</template>
如图:
方法二
点击时打开 a-modal 组件,a-model 组件中只放入图片img,且不包含关闭确定按钮:
<template v-if="column.dataIndex === 'picUrl'">
<img :src="record.picUrl" alt="图片" style="width: 50px; height: 70px" @click="openImg(record.picUrl)">
</template>
<!-- 显示图片 -->
<a-modal v-model:visible="imgVisible" :footer="null" @cancel="close">
<img style="width: 100%" :src="picImg">
</a-modal>
const imgVisible = ref(false)
const picImg = ref('')
// 打开
const openImg = (param) => {
picImg.value = param
imgVisible.value = true
}
// 关闭
const close = () => {
imgVisible.value = false
}
如图: