增加轮播图配置

This commit is contained in:
BianLzhaoMin 2025-01-15 13:16:34 +08:00
parent 28b58646c2
commit 546f1f4ea1
2 changed files with 118 additions and 39 deletions

View File

@ -0,0 +1,23 @@
import request from "@/utils/request";
// 新增上传首页轮播图
export const addHomeSwiperApi = () => {
return request({
url: "/auth/getConfig",
method: "get",
});
};
// 修改轮播图状态
export const editHomeSwiperTypeApi = () => {
return request({
url: "/auth/getConfig",
method: "get",
});
};
// 删除轮播图
export const deleteHomeSwiperApi = () => {
return request({
url: "/auth/getConfig",
method: "get",
});
};

View File

@ -18,18 +18,29 @@
<el-table-column label="序号" align="center" width="100" type="index" /> <el-table-column label="序号" align="center" width="100" type="index" />
<el-table-column prop="imgSrc" label="图片链接" align="center" /> <el-table-column prop="imgSrc" label="图片链接" align="center" />
<el-table-column prop="isShow" label="是否禁用" align="center"> <el-table-column prop="isShow" label="是否禁用" align="center">
<template> <template slot-scope="{ row }">
<el-switch active-text="激活" inactive-text="禁用" v-model="value2" /> <el-switch
active-text="激活"
inactive-text="禁用"
v-model="row.isShow"
/>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column prop="outLink" label="外部链接" align="center" /> <el-table-column prop="outLink" label="外部链接" align="center" />
<el-table-column label="操作" align="center">
<template>
<el-button size="mini" type="danger" @click="onClickDelete">
删除
</el-button>
</template>
</el-table-column>
</el-table> </el-table>
<el-dialog <el-dialog
width="50%"
append-to-body
title="新增轮播图" title="新增轮播图"
:visible.sync="addSwiperVisible" :visible.sync="addSwiperVisible"
width="40%"
append-to-body
> >
<el-form <el-form
ref="addSwiperFormRef" ref="addSwiperFormRef"
@ -56,16 +67,16 @@
<el-form-item label="轮播图上传:"> <el-form-item label="轮播图上传:">
<el-upload <el-upload
:limit="1" :limit="1"
:headers="headers"
:show-file-list="true"
:action="uploadFileUrl" :action="uploadFileUrl"
list-type="picture-card" list-type="picture-card"
:file-list="addOrEditForm.fileList" :on-exceed="handleExceed"
:headers="headers"
:on-remove="handleRemove" :on-remove="handleRemove"
:on-preview="handlePreview" :on-preview="handlePreview"
:on-success="handleSuccess" :on-success="handleSuccess"
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
:show-file-list="true" :file-list="addSwiperForm.fileList"
:on-exceed="handleExceed"
> >
<i class="el-icon-plus"></i> <i class="el-icon-plus"></i>
</el-upload> </el-upload>
@ -77,19 +88,50 @@
<el-button type="primary" @click="submitForm"> </el-button> <el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button> <el-button @click="cancel"> </el-button>
</div> </div>
<el-dialog
width="30%"
append-to-body
:before-close="
() => {
dialogInnerVisible = false;
}
"
:visible.sync="dialogInnerVisible"
>
<img
:src="previewUrl"
style="display: block; max-width: 100%; margin: 0 auto"
/>
</el-dialog>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { getToken } from "@/utils/auth";
import {
addHomeSwiperApi,
deleteHomeSwiperApi,
editHomeSwiperTypeApi,
} from "@/api/swiper-manage/index.js";
export default { export default {
data() { data() {
return { return {
uploadFileUrl: process.env.VUE_APP_BASE_API + "/file/upload",
dialogInnerVisible: false,
fileType: ["png", "jpg", "jpeg"],
previewUrl: "",
addSwiperVisible: false, addSwiperVisible: false,
value1: true, value1: true,
value2: true, value2: true,
uploadFileUrl: "", addSwiperFormRules: {},
headers: {}, addSwiperForm: {
fileList: [],
},
headers: {
Authorization: "Bearer " + getToken(),
},
noticeList: [ noticeList: [
{ {
imgSrc: "xxxx", imgSrc: "xxxx",
@ -121,44 +163,58 @@ export default {
}, },
// //
handleBeforeUpload(file) { handleBeforeUpload(file) {
// const isSvg = this.fileType.some((e) => file.type.includes(e)); const isSvg = this.fileType.some((e) => file.type.includes(e));
// if (!isSvg) { if (!isSvg) {
// this.$modal.msgError( this.$modal.msgError(
// `, ${this.fileType.join("")}!` `文件格式不正确, 请上传${this.fileType.join("、")}格式的文件!`
// ); );
// return false; return false;
// } }
// const isLt = file.size / 1024 / 1024 < 3; const isLt = file.size / 1024 / 1024 < 10;
// if (!isLt) { if (!isLt) {
// this.$modal.msgError(`LOGO 3 MB`); this.$modal.msgError(`图片大小不能超过 10 MB`);
// return false; return false;
// } }
// this.$modal.loading("..."); this.$modal.loading("图片正在上传,请稍候...");
}, },
// //
handleRemove(file) { handleRemove(file) {
// this.addOrEditForm.fileList = this.addOrEditForm.fileList.filter( this.addSwiperFormRules.fileList =
// (item) => item.uid !== file.uid this.addSwiperFormRules.fileList.filter(
// ); (item) => item.uid !== file.uid
// this.addOrEditForm.logo = ""; );
this.addSwiperFormRules.logo = "";
}, },
// LOGO //
handlePreview(file) { handlePreview(file) {
// this.dialogInnerVisible = true; this.dialogInnerVisible = true;
// this.previewUrl = file.url; this.previewUrl = file.url;
},
//
handleExceed() {
this.$modal.msgError(`上传的图片数量不能超过 1 个`);
}, },
// //
handleSuccess(res) { handleSuccess(res) {
// if (res.code === 200) { if (res.code === 200) {
// this.addOrEditForm.logo = res.data.url; this.addSwiperFormRules.logo = res.data.url;
// } else { } else {
// this.addOrEditForm.fileList = []; this.addSwiperFormRules.fileList = [];
// this.addOrEditForm.logo = ""; this.addSwiperFormRules.logo = "";
// } }
// this.$modal.closeLoading(); this.$modal.closeLoading();
},
onClickDelete() {
this.$confirm("确定删除该轮播图吗?", "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning",
})
.then(() => {})
.catch(() => {});
}, },
}, },
}; };
</script> </script>
<style></style>