285 lines
7.4 KiB
Vue
285 lines
7.4 KiB
Vue
<template>
|
|
<div class="page">
|
|
<div class="ele-body">
|
|
<a-card :bordered="false" :body-style="{ padding: '16px' }">
|
|
<ele-pro-table
|
|
ref="tableRef"
|
|
row-key="adId"
|
|
:columns="columns"
|
|
:datasource="datasource"
|
|
:customRow="customRow"
|
|
tool-class="ele-toolbar-form"
|
|
class="sys-org-table"
|
|
>
|
|
<template #toolbar>
|
|
<search
|
|
@search="reload"
|
|
:selection="selection"
|
|
@add="openEdit"
|
|
@remove="removeBatch"
|
|
@batchMove="openMove"
|
|
/>
|
|
</template>
|
|
<template #bodyCell="{ column, record }">
|
|
<template v-if="column.key === 'adType'">
|
|
<a-tag>{{ record.adType }}</a-tag>
|
|
</template>
|
|
<template v-if="column.key === 'images'">
|
|
<template
|
|
v-for="(item, index) in JSON.parse(record.images)"
|
|
:key="index"
|
|
>
|
|
<a-image :src="item.url" :width="80" />
|
|
</template>
|
|
<span></span>
|
|
</template>
|
|
<template v-if="column.key === 'status'">
|
|
<a-tag v-if="record.status === 0" color="green">开启</a-tag>
|
|
<a-tag v-if="record.status === 1" color="red">关闭</a-tag>
|
|
</template>
|
|
<template v-if="column.key === 'action'">
|
|
<a-space>
|
|
<a @click="openEdit(record)">修改</a>
|
|
<a-divider type="vertical" />
|
|
<a-popconfirm
|
|
title="确定要删除此记录吗?"
|
|
@confirm="remove(record)"
|
|
>
|
|
<a class="ele-text-danger">删除</a>
|
|
</a-popconfirm>
|
|
</a-space>
|
|
</template>
|
|
</template>
|
|
</ele-pro-table>
|
|
</a-card>
|
|
|
|
<!-- 编辑弹窗 -->
|
|
<AdEdit v-model:visible="showEdit" :data="current" @done="reload" />
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { createVNode, ref } from 'vue';
|
|
import { message, Modal } from 'ant-design-vue';
|
|
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
|
import type { EleProTable } from 'ele-admin-pro';
|
|
import type {
|
|
DatasourceFunction,
|
|
ColumnItem
|
|
} from 'ele-admin-pro/es/ele-pro-table/types';
|
|
import Search from './components/search.vue';
|
|
import AdEdit from './components/ad-edit.vue';
|
|
import { pageAd, removeAd, removeBatchAd } from '@/api/cms/ad';
|
|
import type { Ad, AdParam } from '@/api/cms/ad/model';
|
|
import { getMerchantId } from "@/utils/merchant";
|
|
|
|
// 表格实例
|
|
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
|
|
|
// 表格选中数据
|
|
const selection = ref<Ad[]>([]);
|
|
// 当前编辑数据
|
|
const current = ref<Ad | null>(null);
|
|
// 是否显示资产详情
|
|
const showInfo = ref(false);
|
|
// 是否显示编辑弹窗
|
|
const showEdit = ref(false);
|
|
// 是否显示批量移动弹窗
|
|
const showMove = ref(false);
|
|
// 加载状态
|
|
const loading = ref(true);
|
|
|
|
// 表格数据源
|
|
const datasource: DatasourceFunction = ({
|
|
page,
|
|
limit,
|
|
where,
|
|
orders,
|
|
filters
|
|
}) => {
|
|
if (filters) {
|
|
where.status = filters.status;
|
|
}
|
|
where.merchantId = getMerchantId();
|
|
return pageAd({
|
|
...where,
|
|
...orders,
|
|
page,
|
|
limit
|
|
});
|
|
};
|
|
|
|
// 表格列配置
|
|
const columns = ref<ColumnItem[]>([
|
|
{
|
|
title: 'ID',
|
|
width: 90,
|
|
dataIndex: 'adId'
|
|
},
|
|
{
|
|
title: '类型',
|
|
dataIndex: 'adType',
|
|
key: 'adType',
|
|
width: 120
|
|
},
|
|
{
|
|
title: '广告图片',
|
|
dataIndex: 'images',
|
|
key: 'images'
|
|
},
|
|
{
|
|
title: '跳转路径',
|
|
dataIndex: 'path',
|
|
key: 'path',
|
|
width: 280,
|
|
ellipsis: true
|
|
},
|
|
{
|
|
title: '描述',
|
|
dataIndex: 'comments',
|
|
key: 'path',
|
|
width: 280,
|
|
ellipsis: true
|
|
},
|
|
{
|
|
title: '状态',
|
|
dataIndex: 'status',
|
|
key: 'status',
|
|
align: 'center',
|
|
width: 120
|
|
},
|
|
{
|
|
title: '操作',
|
|
key: 'action',
|
|
width: 120,
|
|
fixed: 'right',
|
|
align: 'center',
|
|
hideInSetting: true
|
|
}
|
|
]);
|
|
|
|
/* 搜索 */
|
|
const reload = (where?: AdParam) => {
|
|
console.log(where);
|
|
selection.value = [];
|
|
tableRef?.value?.reload({ where: where });
|
|
};
|
|
|
|
/* 打开编辑弹窗 */
|
|
const openEdit = (row?: Ad) => {
|
|
current.value = row ?? null;
|
|
showEdit.value = true;
|
|
};
|
|
|
|
/* 打开批量移动弹窗 */
|
|
const openMove = () => {
|
|
showMove.value = true;
|
|
};
|
|
|
|
/* 打开用户详情弹窗 */
|
|
const openInfo = (row?: Ad) => {
|
|
current.value = row ?? null;
|
|
showInfo.value = true;
|
|
};
|
|
|
|
/* 删除单个 */
|
|
const remove = (row: Ad) => {
|
|
const hide = message.loading('请求中..', 0);
|
|
removeAd(row.adId)
|
|
.then((msg) => {
|
|
hide();
|
|
message.success(msg);
|
|
reload();
|
|
})
|
|
.catch((e) => {
|
|
hide();
|
|
message.error(e.message);
|
|
});
|
|
};
|
|
|
|
/* 批量转移 */
|
|
const batchMove = (userId) => {
|
|
console.log(userId, '批量转移0000');
|
|
console.log(selection.value);
|
|
};
|
|
|
|
/* 批量删除 */
|
|
const removeBatch = () => {
|
|
if (!selection.value.length) {
|
|
message.error('请至少选择一条数据');
|
|
return;
|
|
}
|
|
Modal.confirm({
|
|
title: '提示',
|
|
content: '确定要删除选中的记录吗?',
|
|
icon: createVNode(ExclamationCircleOutlined),
|
|
maskClosable: true,
|
|
onOk: () => {
|
|
const hide = message.loading('请求中..', 0);
|
|
removeBatchAd(selection.value.map((d) => d.adId))
|
|
.then((msg) => {
|
|
hide();
|
|
message.success(msg);
|
|
reload();
|
|
})
|
|
.catch((e) => {
|
|
hide();
|
|
message.error(e.message);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
/* 查询 */
|
|
const query = () => {
|
|
loading.value = true;
|
|
};
|
|
|
|
/* 自定义行属性 */
|
|
const customRow = (record: Ad) => {
|
|
return {
|
|
// 行点击事件
|
|
onClick: () => {
|
|
// console.log(record);
|
|
},
|
|
// 行双击事件
|
|
onDblclick: () => {
|
|
openEdit(record);
|
|
}
|
|
};
|
|
};
|
|
|
|
query();
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
export default {
|
|
name: 'Ad'
|
|
};
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.sys-org-table :deep(.ant-table-body) {
|
|
overflow: auto !important;
|
|
overflow: overlay !important;
|
|
}
|
|
|
|
.sys-org-table :deep(.ant-table-pagination.ant-pagination) {
|
|
padding: 0 4px;
|
|
margin-bottom: 0;
|
|
}
|
|
.ad-item {
|
|
margin: auto;
|
|
display: flex;
|
|
text-align: center;
|
|
flex-direction: column;
|
|
justify-content: center;
|
|
align-items: center;
|
|
width: 70px;
|
|
height: 70px;
|
|
border-radius: 70px;
|
|
background: url('data:image/svg+xml;charset=utf8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%221%22%20x1%3D%220%22%20x2%3D%221%22%20y1%3D%220%22%20y2%3D%220%22%20gradientTransform%3D%22matrix(6.123233995736766e-17%2C%201%2C%20-0.024693877551020406%2C%206.123233995736766e-17%2C%200.5%2C%200)%22%3E%3Cstop%20stop-color%3D%22%230a060d%22%20stop-opacity%3D%221%22%20offset%3D%220%22%3E%3C%2Fstop%3E%3Cstop%20stop-color%3D%22%23660061%22%20stop-opacity%3D%221%22%20offset%3D%220.95%22%3E%3C%2Fstop%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20fill%3D%22url(%231)%22%3E%3C%2Frect%3E%3C%2Fsvg%3E');
|
|
}
|
|
</style>
|