1、新增首页轮播图切换效果

2、其他调整
This commit is contained in:
2024-09-30 18:20:29 +08:00
parent 7a180ee5a7
commit 713f24ca3e
22 changed files with 3239 additions and 1603 deletions

View File

@@ -1,142 +1,176 @@
<template>
<ele-modal
width="75%"
:visible="visible"
:maskClosable="false"
:title="title"
:footer="null"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
>
<ele-pro-table
ref="tableRef"
row-key="id"
:datasource="datasource"
:columns="columns"
:customRow="customRow"
:pagination="false"
<ele-modal
width="75%"
:visible="visible"
:maskClosable="false"
:title="title"
:footer="null"
:body-style="{ paddingBottom: '28px' }"
@update:visible="updateVisible"
>
<template #toolbar>
<div class="ele-cell">
<div class="ele-cell-content">
<a-space>
<a-upload
v-if="type == 'video'"
:show-upload-list="false"
:customRequest="onUpload"
>
<a-button type="primary" class="ele-btn-icon">
<template #icon>
<UploadOutlined />
</template>
<span>上传视频</span>
</a-button>
</a-upload>
<a-upload
v-else
:show-upload-list="false"
:accept="'image/*,application/*'"
:customRequest="onUpload"
>
<a-button type="primary" class="ele-btn-icon">
<template #icon>
<UploadOutlined />
</template>
<span>上传图片</span>
</a-button>
</a-upload>
<a-select
show-search
allow-clear
v-model:value="dictDataId"
optionFilterProp="label"
:options="groupList"
style="margin-left: 20px; width: 200px"
placeholder="请选择分组"
@select="onGroupId"
/>
<a-input-search
allow-clear
v-model:value="searchText"
placeholder="请输入搜索关键词"
style="width: 240px"
@search="reload"
@pressEnter="reload"
/>
</a-space>
</div>
<a-button
style="margin-right: 20px"
@click="openUrl('/cms/photo/dict')"
>管理分组</a-button
>
</div>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'path'">
<!-- 文件类型 -->
<template v-if="!isImage(record.path)">
<span class="ele-text-secondary">[文件]</span>
</template>
<!-- 含http -->
<template v-else-if="record.path.indexOf('http') == 0">
<a-image
:src="`${record.path}`"
:preview="{
<ele-pro-table
ref="tableRef"
row-key="id"
:datasource="datasource"
:columns="columns"
:customRow="customRow"
:pagination="false"
>
<template #toolbar>
<div class="ele-cell">
<div class="ele-cell-content">
<a-space>
<a-upload
v-if="type == 'video'"
:show-upload-list="false"
:customRequest="onUpload"
:accept="'.mp4'"
>
<a-button type="primary" class="ele-btn-icon">
<template #icon>
<UploadOutlined/>
</template>
<span>上传视频</span>
</a-button>
</a-upload>
<a-upload
v-else-if="type == 'audio'"
:show-upload-list="false"
:customRequest="onUpload"
:accept="'.mp3'"
>
<a-button type="primary" class="ele-btn-icon">
<template #icon>
<UploadOutlined/>
</template>
<span>上传音频</span>
</a-button>
</a-upload>
<a-upload
v-else-if="type == 'file'"
:show-upload-list="false"
:customRequest="onUpload"
:accept="'.xls,.xlsx,.pdf,.doc,.docx'"
>
<a-button type="primary" class="ele-btn-icon">
<template #icon>
<UploadOutlined/>
</template>
<span>上传文件</span>
</a-button>
</a-upload>
<a-upload
v-else
:show-upload-list="false"
:accept="'image/*,application/*'"
:customRequest="onUpload"
>
<a-button type="primary" class="ele-btn-icon">
<template #icon>
<UploadOutlined/>
</template>
<span>上传图片</span>
</a-button>
</a-upload>
<a-select
show-search
allow-clear
v-model:value="dictDataId"
optionFilterProp="label"
:options="groupList"
style="margin-left: 20px; width: 200px"
placeholder="请选择分组"
@select="onGroupId"
/>
<a-input-search
allow-clear
v-model:value="searchText"
placeholder="请输入搜索关键词"
style="width: 240px"
@search="reload"
@pressEnter="reload"
/>
</a-space>
</div>
<a-button
style="margin-right: 20px"
@click="openUrl('/cms/photo/dict')"
>管理分组
</a-button
>
</div>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'path'">
<!-- 文件类型 -->
<template v-if="!isImage(record.path)">
<span class="ele-text-secondary">[文件]</span>
</template>
<!-- 含http -->
<template v-else-if="record.path.indexOf('http') == 0">
<a-image
:src="`${record.path}`"
:preview="{
src: `${record.downloadUrl}`
}"
:width="100"
/>
</template>
<!-- path -->
<template v-else>
<a-image
:src="`https://oss.wsdns.cn/${record.path}`"
:width="120"
/>
</template>
</template>
<template v-if="column.dataIndex === 'name'">
<a-space class="ele-cell" style="display: flex">
<span>{{ record.name }}</span>
<EditOutlined title="编辑" @click="openEdit(record)" />
</a-space>
</template>
<template v-if="column.key === 'action'">
<template v-if="pageId == record.pageId">
<a-radio v-model:checked="checked" @click="onRadio(record)" />
</template>
<template v-else>
<lebal>
<a-radio @click="onRadio(record)" />
<a class="ele-text-success">选择</a>
</lebal>
</template>
</template>
</template>
</ele-pro-table>
</ele-modal>
<!-- 编辑弹窗 -->
<FileRecordEdit v-model:visible="showEdit" :data="current" @done="reload" />
:width="100"
/>
</template>
<!-- path -->
<template v-else>
<a-image
:src="`https://oss.wsdns.cn/${record.path}`"
:width="120"
/>
</template>
</template>
<template v-if="column.dataIndex === 'name'">
<a-space class="ele-cell" style="display: flex">
<span>{{ record.name }}</span>
<EditOutlined title="编辑" @click="openEdit(record)"/>
</a-space>
</template>
<template v-if="column.key === 'action'">
<template v-if="pageId == record.pageId">
<a-radio v-model:checked="checked" @click="onRadio(record)"/>
</template>
<template v-else>
<a-space>
<lebal>
<a-radio @click="onRadio(record)"/>
<a class="ele-text-success">选择</a>
</lebal>
<a-divider type="vertical"/>
<a class="ele-text-placeholder">编辑</a>
<a-divider type="vertical"/>
<a class="ele-text-placeholder">删除</a>
</a-space>
</template>
</template>
</template>
</ele-pro-table>
</ele-modal>
<!-- 编辑弹窗 -->
<FileRecordEdit v-model:visible="showEdit" :data="current" @done="reload"/>
</template>
<script lang="ts" setup>
import { ref, watch } from 'vue';
import {
import {ref, watch} from 'vue';
import {
ColumnItem,
DatasourceFunction
} from 'ele-admin-pro/es/ele-pro-table/types';
import { pageFiles, uploadOss, uploadOssByGroupId } from '@/api/system/file';
import { EleProTable, messageLoading } from 'ele-admin-pro';
import { FileRecord, FileRecordParam } from '@/api/system/file/model';
import { EditOutlined, UploadOutlined } from '@ant-design/icons-vue';
import { DictData } from '@/api/system/dict-data/model';
import { pageDictData } from '@/api/system/dict-data';
import {isImage, openNew, openUrl} from '@/utils/common';
import { message } from 'ant-design-vue/es';
import FileRecordEdit from './file-record-edit.vue';
} from 'ele-admin-pro/es/ele-pro-table/types';
import {pageFiles, uploadOss, uploadOssByGroupId} from '@/api/system/file';
import {EleProTable, messageLoading} from 'ele-admin-pro';
import {FileRecord, FileRecordParam} from '@/api/system/file/model';
import {EditOutlined, UploadOutlined} from '@ant-design/icons-vue';
import {DictData} from '@/api/system/dict-data/model';
import {pageDictData} from '@/api/system/dict-data';
import {isImage, openUrl} from '@/utils/common';
import {message} from 'ant-design-vue/es';
import FileRecordEdit from './file-record-edit.vue';
const props = defineProps<{
const props = defineProps<{
// 弹窗是否打开
visible: boolean;
// 标题
@@ -145,189 +179,216 @@
type?: string;
// 修改回显的数据
data?: FileRecord | null;
}>();
}>();
const emit = defineEmits<{
const emit = defineEmits<{
(e: 'done', data: FileRecord): void;
(e: 'update:visible', visible: boolean): void;
}>();
}>();
/* 更新visible */
const updateVisible = (value: boolean) => {
/* 更新visible */
const updateVisible = (value: boolean) => {
emit('update:visible', value);
};
};
// 搜索内容
const searchText = ref(null);
const pageId = ref<number>(0);
const checked = ref<boolean>(true);
const groupList = ref<DictData[]>();
const showEdit = ref<boolean>(false);
const current = ref<FileRecord | null>();
const dictDataId = ref<any>(undefined);
// 搜索内容
const searchText = ref(null);
const pageId = ref<number>(0);
const checked = ref<boolean>(true);
const groupList = ref<DictData[]>();
const showEdit = ref<boolean>(false);
const current = ref<FileRecord | null>();
const dictDataId = ref<any>(undefined);
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格实例
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
// 表格配置
const columns = ref<ColumnItem[]>([
// 表格配置
const columns = ref<ColumnItem[]>([
{
title: 'ID',
dataIndex: 'id'
title: 'ID',
dataIndex: 'id'
},
{
title: '图片',
dataIndex: 'path',
key: 'path'
title: '图片',
dataIndex: 'path',
key: 'path'
},
{
title: '名称',
dataIndex: 'name',
key: 'name'
title: '名称',
dataIndex: 'name',
key: 'name'
},
{
title: '大小',
dataIndex: 'length',
key: 'length',
customRender: ({ text }) => {
if (text < 1024) {
return text + 'B';
} else if (text < 1024 * 1024) {
return (text / 1024).toFixed(1) + 'KB';
} else if (text < 1024 * 1024 * 1024) {
return (text / 1024 / 1024).toFixed(1) + 'M';
} else {
return (text / 1024 / 1024 / 1024).toFixed(1) + 'G';
title: '大小',
dataIndex: 'length',
key: 'length',
customRender: ({text}) => {
if (text < 1024) {
return text + 'B';
} else if (text < 1024 * 1024) {
return (text / 1024).toFixed(1) + 'KB';
} else if (text < 1024 * 1024 * 1024) {
return (text / 1024 / 1024).toFixed(1) + 'M';
} else {
return (text / 1024 / 1024 / 1024).toFixed(1) + 'G';
}
}
}
},
{
title: '操作',
key: 'action',
align: 'center'
title: '操作',
key: 'action',
align: 'center'
}
]);
]);
// 表格数据源
const datasource: DatasourceFunction = ({ page, limit, where, orders }) => {
// 表格数据源
const datasource: DatasourceFunction = ({page, limit, where, orders}) => {
where = {};
// 搜索条件
if (searchText.value) {
where.name = searchText.value;
where.name = searchText.value;
}
if (dictDataId.value) {
where.groupId = dictDataId.value;
where.groupId = dictDataId.value;
}
if (props.type) {
let contentTypes = ''
switch (props.type) {
case 'audio' : {
contentTypes = 'audio/mpeg';
}
break;
case 'file' : {
contentTypes = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
}
break;
case 'video' : {
contentTypes = 'video/mp4';
}
break;
default : {
contentTypes = 'image/jpeg,image/png,image/jpg';
}
break;
}
where.contentTypes = contentTypes;
}
return pageFiles({
...where,
...orders,
page,
limit
...where,
...orders,
page,
limit
});
};
};
/* 搜索 */
const reload = (where?: FileRecordParam) => {
tableRef?.value?.reload({ page: 1, where });
};
/* 搜索 */
const reload = (where?: FileRecordParam) => {
tableRef?.value?.reload({page: 1, where});
};
const onRadio = (record: FileRecord) => {
const onRadio = (record: FileRecord) => {
pageId.value = Number(record.id);
updateVisible(false);
emit('done', record);
};
};
const getGroupList = () => {
pageDictData({ dictCode: 'groupId' }).then((res) => {
groupList.value = res?.list.map((d) => {
return {
label: d.dictDataName,
value: d.dictDataId
};
});
const getGroupList = () => {
pageDictData({dictCode: 'groupId'}).then((res) => {
groupList.value = res?.list.map((d) => {
return {
label: d.dictDataName,
value: d.dictDataId
};
});
});
};
};
const onGroupId = (index: number) => {
const onGroupId = (index: number) => {
dictDataId.value = index;
reload();
};
};
// 上传文件
const onUpload = (item) => {
const { file } = item;
if (!file.type.startsWith('image') && props.type != 'video') {
message.error('只能选择图片');
return;
// 上传文件
const onUpload = (item) => {
const {file} = item;
if (!file.type.startsWith('image') && props.type && !['video', 'audio', 'file'].includes(props.type)) {
message.error('只能选择图片');
return;
}
if (props.type == 'video') {
if (file.size / 1024 / 1024 > 100) {
message.error('大小不能超过 100MB');
return;
}
if (file.size / 1024 / 1024 > 100) {
message.error('大小不能超过 100MB');
return;
}
} else if (props.type == 'audio') {
if (file.size / 1024 / 1024 > 20) {
message.error('大小不能超过 20MB');
return;
}
} else {
if (file.size / 1024 / 1024 > 10) {
message.error('大小不能超过 10MB');
return;
}
if (file.size / 1024 / 1024 > 10) {
message.error('大小不能超过 10MB');
return;
}
}
const hide = messageLoading({
content: '上传中..',
duration: 0,
mask: true
content: '上传中..',
duration: 0,
mask: true
});
if (dictDataId.value > 0) {
uploadOssByGroupId(file, dictDataId.value)
.then(() => {
hide();
message.success('上传成功');
reload();
})
.catch((e) => {
message.error(e.message);
hide();
});
uploadOssByGroupId(file, dictDataId.value)
.then(() => {
hide();
message.success('上传成功');
reload();
})
.catch((e) => {
message.error(e.message);
hide();
});
} else {
uploadOss(file)
.then(() => {
hide();
message.success('上传成功');
reload();
})
.catch((e) => {
message.error(e.message);
hide();
});
uploadOss(file)
.then(() => {
hide();
message.success('上传成功');
reload();
})
.catch((e) => {
message.error(e.message);
hide();
});
}
};
};
const openEdit = (row?: FileRecord) => {
const openEdit = (row?: FileRecord) => {
current.value = row ?? null;
showEdit.value = true;
};
};
/* 自定义行属性 */
const customRow = (record: FileRecord) => {
/* 自定义行属性 */
const customRow = (record: FileRecord) => {
return {
// 行点击事件
// onClick: () => {
// updateVisible(false);
// emit('done', record);
// },
// 行双击事件
onDblclick: () => {
updateVisible(false);
emit('done', record);
}
// 行点击事件
// onClick: () => {
// updateVisible(false);
// emit('done', record);
// },
// 行双击事件
onDblclick: () => {
updateVisible(false);
emit('done', record);
}
};
};
};
watch(
watch(
() => props.visible,
(visible) => {
if (visible) {
getGroupList();
}
if (visible) {
getGroupList();
}
}
);
);
</script>

View File

@@ -1,38 +1,51 @@
<template>
<a-image-preview-group>
<a-space>
<template v-for="(item, index) in data" :key="index">
<div class="image-upload-item" v-if="isImage(item.url)">
<a-space style="display: flex;
align-items: center;
justify-content: flex-start;flex-wrap: wrap">
<template v-for="(item, index) in data" :key="index">
<video v-if="type === 'video'" :src="item.url" style="width: 400px; height: 200px" controls="controls"></video>
<a-tag :key="item.url" closable @close="onDeleteItem(index)"
@click.native="open(item.url)" style="cursor: pointer"
v-else-if="type && ['audio', 'file'].includes(type)"> {{ item.url }}
</a-tag>
<div class="image-upload-item" v-else>
<a-image-preview-group>
<a-image
:style="{
border: '1px dashed var(--grey-7)',
width: width + 'px',
height: height + 'px'
}"
:width="width"
:height="width"
style="border: 1px dashed var(--grey-7)"
:src="item.url"
/>
<a class="image-upload-close" @click="onDeleteItem(index)">
<CloseOutlined />
<CloseOutlined/>
</a>
</div>
<div v-else class="image-upload-item">
<YoutubeOutlined />
<a class="image-upload-close" @click="onDeleteItem(index)">
<CloseOutlined />
</a>
</div>
</template>
</a-image-preview-group>
</div>
</template>
<template v-if="type === 'video'">
<a-button type="primary"
@click="openEdit"
v-if="data?.length < limit">
选择视频
</a-button>
</template>
<template v-else-if="type === 'audio'">
<a-button type="primary"
@click="openEdit"
v-if="data?.length < limit">
选择音频
</a-button>
</template>
<template v-else>
<a-button
@click="openEdit"
v-if="data?.length < limit"
:style="{ width: width + 'px', height: height + 'px' }"
v-if="data?.length < limit || limit === -1"
class="select-picture-btn ele-text-placeholder"
>
<PlusOutlined />
<PlusOutlined/>
</a-button>
</a-space>
</a-image-preview-group>
</template>
</a-space>
<!-- 选择弹窗 -->
<SelectData
v-model:visible="showEdit"
@@ -44,92 +57,100 @@
</template>
<script lang="ts" setup>
import { PlusOutlined, CloseOutlined, YoutubeOutlined } from '@ant-design/icons-vue';
import { ref } from 'vue';
import SelectData from './components/select-data.vue';
import { FileRecord } from '@/api/system/file/model';
import { isImage } from "@/utils/common";
import {PlusOutlined, CloseOutlined} from '@ant-design/icons-vue';
import {ref} from 'vue';
import SelectData from './components/select-data.vue';
import {FileRecord} from '@/api/system/file/model';
const props = withDefaults(
defineProps<{
value?: any;
data?: any[];
width?: number;
height?: number;
type?: string;
limit?: number;
placeholder?: string;
index?: number;
}>(),
{
placeholder: '请选择数据',
width: 80,
height: 80,
limit: 1
}
);
const props = withDefaults(
defineProps<{
value?: any;
data?: any[];
width?: number;
type?: string;
limit?: number;
placeholder?: string;
index?: number;
}>(),
{
placeholder: '请选择数据',
width: 80,
limit: 1
}
);
const emit = defineEmits<{
(e: 'done', data: FileRecord): void;
(e: 'del', index: number): void;
(e: 'clear'): void;
}>();
const emit = defineEmits<{
(e: 'done', data: FileRecord): void;
(e: 'del', index: number): void;
(e: 'clear'): void;
}>();
// 是否显示编辑弹窗
const showEdit = ref(false);
// 当前编辑数据
const current = ref<FileRecord | null>(null);
// 是否显示编辑弹窗
const showEdit = ref(false);
// 当前编辑数据
const current = ref<FileRecord | null>(null);
/* 打开编辑弹窗 */
const openEdit = (row?: FileRecord) => {
current.value = row ?? null;
showEdit.value = true;
};
/* 打开编辑弹窗 */
const openEdit = (row?: FileRecord) => {
current.value = row ?? null;
showEdit.value = true;
};
const onChange = (row) => {
row.index = props.index;
emit('done', row);
};
const onChange = (row) => {
row.index = props.index;
emit('done', row);
};
const onDeleteItem = (index: number) => {
emit('del', index);
};
const onDeleteItem = (index: number) => {
emit('del', index);
};
const open = (url: string) => {
if (['docx', 'doc', 'xlsx', 'xls', 'pdf'].includes(url.split('.').pop()!)) {
window.open(`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(url)}`);
} else window.open(url)
}
</script>
<style lang="less" scoped>
.select-picture-btn {
background-color: var(--grey-9);
border: 1px dashed var(--border-color-base);
font-size: 16px;
}
//.ant-image-img {
// width: 100px !important;
// height: 100px !important;
//}
.image-upload-item {
position: relative;
}
.image-upload-close {
width: 18px;
height: 18px;
color: rgb(255, 255, 255);
font-size: 10px;
border-bottom-left-radius: 18px;
border-top-right-radius: 2px;
background: rgba(0, 0, 0, 0.6);
position: absolute;
top: 1px;
right: 1px;
line-height: 1;
box-sizing: border-box;
padding: 2px 0 0 5px;
transition: background-color 0.2s ease-in-out 0s;
cursor: pointer;
z-index: 2;
//display: flex;
//justify-content: center;
//align-items: center;
}
.image-upload-close:hover {
background-color: var(--red-6);
}
.select-picture-btn {
background-color: var(--grey-9);
border: 1px dashed var(--border-color-base);
width: 80px;
height: 80px;
font-size: 16px;
}
//.ant-image-img {
// width: 100px !important;
// height: 100px !important;
//}
.image-upload-item {
position: relative;
}
.image-upload-close {
width: 18px;
height: 18px;
color: rgb(255, 255, 255);
font-size: 10px;
border-bottom-left-radius: 18px;
border-top-right-radius: 2px;
background: rgba(0, 0, 0, 0.6);
position: absolute;
top: 1px;
right: 1px;
line-height: 1;
box-sizing: border-box;
padding: 2px 0 0 5px;
transition: background-color 0.2s ease-in-out 0s;
cursor: pointer;
z-index: 2;
//display: flex;
//justify-content: center;
//align-items: center;
}
.image-upload-close:hover {
background-color: var(--red-6);
}
</style>