oil-station/fuintAdmin_zt/src/views/setting/banner/index.vue

507 lines
17 KiB
Vue
Raw Normal View History

2024-08-16 18:26:19 +08:00
<template>
<div class="app-container">
2024-10-10 19:49:45 +08:00
<div class="card-change">
2024-08-16 18:26:19 +08:00
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
<el-form-item label="" prop="name">
<el-input
v-model="queryParams.bannerName"
placeholder="请输入banner图名称"
clearable
style="width: 240px;"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
2024-10-10 19:49:45 +08:00
<!-- <el-form-item style="float: right">-->
<!-- <el-form-item label="" prop="bannerName">-->
<!-- <el-select v-model="queryParams.systemPosition" placeholder="请选择系统位置">-->
<!-- <el-option-->
<!-- v-for="item in systemPositionList"-->
<!-- :key="item.value"-->
<!-- :label="item.label"-->
<!-- :value="item.value">-->
<!-- </el-option>-->
<!-- </el-select>-->
<!-- </el-form-item>-->
<el-form-item label="" prop="bannerName">
<el-select v-model="queryParams.bannerStatus" placeholder="请选择banner图状态">
<el-option label="停用" value="0"></el-option>
<el-option label="启用" value="1"></el-option>
<!-- <el-option-->
<!-- v-for="item in systemPositionList"-->
<!-- :key="item.value"-->
<!-- :label="item.label"-->
<!-- :value="item.value">-->
<!-- </el-option>-->
</el-select>
</el-form-item>
<el-form-item style="float: right">
<el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
<el-button
type="primary"
icon="el-icon-plus"
@click="handleAdd"
v-hasPermi="['setting:banner:add']"
>新增banner图
</el-button>
2024-08-16 18:26:19 +08:00
</el-form-item>
</el-form>
2024-10-10 19:49:45 +08:00
<!-- </el-card>-->
2024-08-16 18:26:19 +08:00
2024-10-10 19:49:45 +08:00
<!-- &lt;!&ndash; 列表信息&ndash;&gt;-->
<!-- <el-card style="margin-top: 20px" >-->
2024-08-16 18:26:19 +08:00
<div style="height: 70vh;overflow: auto">
2024-10-10 19:49:45 +08:00
<el-table :data="tableData" style="width: 100%;" border>
<el-table-column type="index" label="序号"></el-table-column>
<el-table-column prop="bannerName" label="banner名称"></el-table-column>
<el-table-column prop="productImage" label="图片">
<template slot-scope="scope">
<el-image
v-if="scope.row.productImage"
style="width: 50px; height: 50px"
:src="imagePath+scope.row.productImage"
:preview-src-list="[imagePath + scope.row.productImage]"
fit="cover"
>
</el-image>
</template>
</el-table-column>
<el-table-column prop="systemPosition" label="系统位置"></el-table-column>
<el-table-column prop="sortOrder" label="排序号"></el-table-column>
<el-table-column prop="bannerLink" label="banner图链接"></el-table-column>
<el-table-column prop="note" label="备注"></el-table-column>
<el-table-column prop="bannerStatus" label="banner图状态">
<template slot-scope="scope">
<el-switch
v-model="scope.row.bannerStatus"
active-color="#13ce66"
inactive-color="#ff4949"
@change="changeStatus(scope.row)"
>
</el-switch>
</template>
</el-table-column>
<el-table-column prop="createByName" label="创建人"></el-table-column>
<el-table-column prop="createTime" label="创建时间"></el-table-column>
<el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-view"
@click="edit(scope.row)"
v-hasPermi="['setting:banner:edit']"
>编辑
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="del(scope.row)"
v-hasPermi="['setting:banner:delete']"
>删除
</el-button>
</template>
</el-table-column>
</el-table>
2024-08-16 18:26:19 +08:00
</div>
2024-10-10 19:49:45 +08:00
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.page"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
2024-08-16 18:26:19 +08:00
</div>
2024-10-26 18:08:58 +08:00
<el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="35%" append-to-body>
<el-form ref="form" :model="deviceInfo" label-width="80px" :rules="rules">
2024-08-16 18:26:19 +08:00
<el-form :model="deviceInfo" ref="deviceForm" label-width="120px" :rules="rules">
<el-form-item label="banner名称" prop="bannerName">
2024-10-26 18:08:58 +08:00
<el-input v-model="deviceInfo.bannerName" style="width: 100%" placeholder="请输入banner名称"></el-input>
2024-08-16 18:26:19 +08:00
</el-form-item>
<el-form-item label="图片" prop="uploadAction">
2024-10-10 19:49:45 +08:00
2024-08-16 18:26:19 +08:00
<el-upload
2024-10-10 19:49:45 +08:00
ref="uploadRef"
accept=".jpg, .jpeg, .png, .gif"
2024-08-16 18:26:19 +08:00
:class="{hide:hideUpload}"
:headers="uploadHeader"
2024-10-10 19:49:45 +08:00
:action="uploadAction"
:on-success="handleSuccess"
:on-error="handleError"
:file-list="uploadFiles"
list-type="picture-card"
:disable-transition="true"
>
<i slot="default" class="el-icon-plus"></i>
<div slot="file" slot-scope="{file}">
<img
class="el-upload-list__item-thumbnail"
:src="file.url" alt=""
>
<!-- 按钮容器 -->
<span class="el-upload-list__item-actions">
<!-- 放大 -->
<span
class="el-upload-list__item-preview"
@click="handlePictureCardPreview(file)"
>
<i class="el-icon-zoom-in"></i>
</span>
<!-- 删除-->
<span
v-if="!disabled"
class="el-upload-list__item-delete"
@click="handleRemove(file)"
>
<i class="el-icon-delete"></i>
</span>
</span>
</div>
2024-08-16 18:26:19 +08:00
</el-upload>
2024-10-10 19:49:45 +08:00
<el-dialog :visible.sync="dialogVisible" :append-to-body="true">
<img width="100%" :src="dialogImageUrl" alt="">
</el-dialog>
<!-- <el-upload-->
<!-- :action="uploadAction"-->
<!-- list-type="picture-card"-->
<!-- :class="{hide:hideUpload}"-->
<!-- :file-list="uploadFiles"-->
<!-- :auto-upload="true"-->
<!-- :show-file-list="false"-->
<!-- :headers="uploadHeader"-->
<!-- :on-success="handleUploadSuccessCover">-->
<!-- <img-->
<!-- v-if="this.deviceInfo.productImage"-->
<!-- :src="imagePath + this.deviceInfo.productImage"-->
<!-- class="list-img"-->
<!-- style="width: 750px; height: 100%"-->
<!-- />-->
<!-- <i v-if="!this.deviceInfo.productImage" class="el-icon-plus"></i>-->
<!-- </el-upload>-->
2024-08-16 18:26:19 +08:00
</el-form-item>
<el-form-item label="系统位置" prop="systemPosition">
2024-10-26 18:08:58 +08:00
<el-select v-model="deviceInfo.systemPosition" placeholder="请选择系统位置" style="width: 100%">
2024-08-16 18:26:19 +08:00
<el-option
v-for="item in systemPositionList"
:key="item.value"
:label="item.label"
2024-10-10 19:49:45 +08:00
:value="item.value"
>
2024-08-16 18:26:19 +08:00
</el-option>
</el-select>
</el-form-item>
<el-form-item label="排序号" prop="sortOrder">
2024-10-26 18:08:58 +08:00
<el-input v-model="deviceInfo.sortOrder" placeholder="请选择排序号" style="width: 100%"></el-input>
2024-08-16 18:26:19 +08:00
</el-form-item>
2024-10-26 18:08:58 +08:00
<el-form-item label="banner图链接" prop="bannerLink">
<el-input v-model="deviceInfo.bannerLink" placeholder="请输入banner图链接地址" style="width: 100%"></el-input>
2024-08-16 18:26:19 +08:00
</el-form-item>
2024-10-26 18:08:58 +08:00
<el-form-item label="banner图状态" prop="bannerStatus">
2024-08-16 18:26:19 +08:00
<el-switch
v-model="deviceInfo.bannerStatus"
active-color="#13ce66"
2024-10-10 19:49:45 +08:00
inactive-color="#ff4949"
>
2024-08-16 18:26:19 +08:00
</el-switch>
</el-form-item>
<el-form-item label="备注" prop="note">
2024-10-26 18:08:58 +08:00
<el-input type="textarea" v-model="deviceInfo.note" style="width: 100%" placeholder="请输入banner图的备注信息" :rows="5" ></el-input>
2024-08-16 18:26:19 +08:00
</el-form-item>
</el-form>
</el-form>
2024-10-26 18:08:58 +08:00
<div style="text-align: center; margin-top: 50px;">
<el-button style="margin-right: 20px;" @click="handleReset"> </el-button>
<el-button type="primary" @click="submitForm('deviceForm')"> </el-button>
</div>
2024-08-16 18:26:19 +08:00
</el-dialog>
</div>
</template>
<script>
2024-10-10 19:49:45 +08:00
import { deleteBannerApi, getBannerListApi, saveBannerApi, updateBannerApi } from '@/api/sys/banner'
2024-08-16 18:26:19 +08:00
import { getToken } from '@/utils/auth'
export default {
2024-10-10 19:49:45 +08:00
name: 'printIndex',
2024-08-16 18:26:19 +08:00
data() {
return {
2024-10-10 19:49:45 +08:00
dialogImageUrl: '',
dialogVisible: false,
disabled: false,
2024-08-16 18:26:19 +08:00
tableData: [],
deviceInfo: {
id: null, // 自增id
bannerName: '', // Banner名称
productImage: '', // 商品图片
systemPosition: '', // 系统位置
sortOrder: null, // 排序号
bannerLink: '', // Banner链接
bannerStatus: false, // Banner状态
note: '', // 备注
2024-10-10 19:49:45 +08:00
createByName: '' //
2024-08-16 18:26:19 +08:00
},
2024-10-10 19:49:45 +08:00
systemPositionList: [{
2024-08-16 18:26:19 +08:00
value: '系统首页',
label: '系统首页'
2024-10-10 19:49:45 +08:00
}],
2024-08-16 18:26:19 +08:00
// 是否显示弹出层
open: false,
2024-10-10 19:49:45 +08:00
title: '',
total: 0,
2024-08-16 18:26:19 +08:00
// 查询参数
queryParams: {
page: 1,
pageSize: 10,
2024-10-10 19:49:45 +08:00
bannerName: '',
systemPosition: '系统首页',
bannerStatus: ''
2024-08-16 18:26:19 +08:00
},
rules: {
2024-10-10 19:49:45 +08:00
bannerName: [
{ required: true, message: '请填写banner名称', trigger: 'blur' }
2024-08-16 18:26:19 +08:00
],
2024-10-26 18:08:58 +08:00
uploadAction: [
{ required: true, message: '请上传banner图', trigger: 'blur' }
],
2024-10-10 19:49:45 +08:00
systemPosition: [
2024-10-17 17:53:02 +08:00
{ required: true, message: '请填写系统位置', trigger: 'blur' }
2024-08-16 18:26:19 +08:00
],
2024-10-10 19:49:45 +08:00
sortOrder: [
{ required: true, message: '请填写排序号', trigger: 'blur' }
2024-08-16 18:26:19 +08:00
],
2024-10-10 19:49:45 +08:00
bannerLink: [
{ required: true, message: '请填写链接', trigger: 'blur' }
2024-08-16 18:26:19 +08:00
],
2024-10-26 18:08:58 +08:00
bannerStatus: [
{ required: true, message: '请选择banner图状态', trigger: 'blur' }
2024-10-10 19:49:45 +08:00
]
2024-08-16 18:26:19 +08:00
},
// 上传地址
uploadAction: process.env.VUE_APP_BASE_API + 'backendApi/file/upload',
2024-10-10 19:49:45 +08:00
uploadHeader: { 'Access-Token': getToken() }, // 上传文件列表
uploadFiles: [],
2024-08-16 18:26:19 +08:00
// 图片根目录
imagePath: process.env.VUE_APP_BASE_API,
// 隐藏上传
2024-10-10 19:49:45 +08:00
hideUpload: false
}
2024-08-16 18:26:19 +08:00
},
created() {
this.getList()
},
2024-10-10 19:49:45 +08:00
watch: {
// 监听上传图片列表
uploadFiles(newValue) {
// 判断上传文件数量
if (newValue.length >= 1) {
// 隐藏上传按钮
this.hideUpload = true
} else {
// 显示上传按钮
this.hideUpload = false
}
}
},
2024-08-16 18:26:19 +08:00
methods: {
2024-10-10 19:49:45 +08:00
handleRemove(file) {
console.log('删除文件', file)
console.log('删除文件', this.uploadFiles)
},
handlePictureCardPreview(file) {
this.dialogImageUrl = file.url
this.dialogVisible = true
},
handleSuccess(response, file, fileList) {
//Element UI 的 el-upload 组件会自动管理文件列表,并更新 fileList 属性 但是这里需要根据 上传文件数量控制 隐藏上传框 需要手动
console.log('上传成功', response, file)
this.uploadFiles = fileList
// 路径存入当前表单
this.deviceInfo.productImage = response.data.title
},
handleError(error, file, fileList) {
console.error('上传失败', error, file, fileList)
},
getList() {
getBannerListApi(this.queryParams).then(res => {
this.tableData = res.data.records
2024-08-16 18:26:19 +08:00
this.total = res.data.total
})
},
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
// 表单验证通过,可以提交数据
2024-10-10 19:49:45 +08:00
this.submitDeviceInfo()
2024-08-16 18:26:19 +08:00
} else {
// 表单验证失败,不执行任何操作
2024-10-10 19:49:45 +08:00
return false
2024-08-16 18:26:19 +08:00
}
2024-10-10 19:49:45 +08:00
})
2024-08-16 18:26:19 +08:00
},
submitDeviceInfo() {
// 在这里调用接口提交设备信息数据
2024-10-10 19:49:45 +08:00
console.log('提交设备信息数据:', this.deviceInfo)
2024-08-16 18:26:19 +08:00
if (this.deviceInfo.id) {
2024-10-10 19:49:45 +08:00
updateBannerApi(this.deviceInfo).then(res => {
if (res.code === 200) {
2024-08-16 18:26:19 +08:00
this.getList()
this.open = false
}
})
2024-10-10 19:49:45 +08:00
} else {
saveBannerApi(this.deviceInfo).then(res => {
if (res.code === 200) {
2024-08-16 18:26:19 +08:00
this.getList()
this.open = false
}
})
}
},
2024-10-10 19:49:45 +08:00
changeStatus(data) {
updateBannerApi(data).then(res => {
if (res.code === 200) {
2024-08-16 18:26:19 +08:00
this.$message({
type: 'success',
message: '修改状态成功!'
2024-10-10 19:49:45 +08:00
})
2024-08-16 18:26:19 +08:00
this.getList()
}
})
},
2024-10-10 19:49:45 +08:00
handleQuery() {
2024-08-16 18:26:19 +08:00
this.getList()
},
2024-10-10 19:49:45 +08:00
resetQuery() {
2024-08-16 18:26:19 +08:00
this.queryParams = {
page: 1,
pageSize: 10,
2024-10-10 19:49:45 +08:00
deviceName: '',
systemPosition: '系统首页'
2024-10-17 17:53:02 +08:00
}
2024-10-10 19:49:45 +08:00
this.getList()
2024-08-16 18:26:19 +08:00
},
handleAdd(e) {
this.clean()
2024-10-10 19:49:45 +08:00
this.open = true
this.title = '新增banner图'
2024-08-16 18:26:19 +08:00
},
2024-10-17 12:50:55 +08:00
handleReset() {
this.open = false
},
2024-08-16 18:26:19 +08:00
edit(e) {
this.clean()
2024-10-10 19:49:45 +08:00
this.open = true
this.title = '修改banner图'
// 用深拷贝写
this.deviceInfo = JSON.parse(JSON.stringify(e));
console.log('编辑',e)
// 图片回显
if (e.productImage && e.productImage != ''){
this.uploadFiles=[
{
url: this.imagePath + e.productImage,
name: e.productImage
}
]
console.log('图片回显',this.uploadFiles)
}
2024-08-16 18:26:19 +08:00
},
del(e) {
this.$confirm('此操作将永久删除该banner图, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
2024-10-10 19:49:45 +08:00
deleteBannerApi(e.id).then(res => {
2024-08-16 18:26:19 +08:00
if (res.code == 200) {
this.$message({
type: 'success',
message: '删除成功!'
2024-10-10 19:49:45 +08:00
})
2024-08-16 18:26:19 +08:00
this.getList()
}
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
2024-10-10 19:49:45 +08:00
})
})
2024-08-16 18:26:19 +08:00
},
clean() {
2024-10-10 19:49:45 +08:00
this.deviceInfo = {
2024-08-16 18:26:19 +08:00
id: null, // 自增id
bannerName: '', // Banner名称
productImage: '', // 商品图片
systemPosition: '', // 系统位置
sortOrder: null, // 排序号
bannerLink: '', // Banner链接
bannerStatus: false, // Banner状态
note: '', // 备注
2024-10-10 19:49:45 +08:00
createByName: '' //
2024-10-17 17:53:02 +08:00
};
2024-10-10 19:49:45 +08:00
this.uploadFiles = []
2024-10-17 17:53:02 +08:00
if (this.$refs.deviceForm) {
this.$refs.deviceForm.resetFields();
}
2024-10-10 19:49:45 +08:00
}
2024-08-16 18:26:19 +08:00
}
2024-10-10 19:49:45 +08:00
}
2024-08-16 18:26:19 +08:00
</script>
<style lang="scss" scoped>
2024-10-10 19:49:45 +08:00
.common-dialog > > > .el-upload--picture-card {
2024-08-16 18:26:19 +08:00
width: 60px;
height: 50px;
line-height: 60px;
}
2024-10-10 19:49:45 +08:00
::v-deep.hide .el-upload--picture-card {
display: none;
}
.d-dialog > > > .el-upload--picture-card {
2024-08-16 18:26:19 +08:00
width: 100px;
height: 100px;
line-height: 100px;
}
2024-10-10 19:49:45 +08:00
.d-dialog > > > .avatar-uploader .el-upload {
2024-08-16 18:26:19 +08:00
width: 100px;
height: 100px;
}
2024-10-10 19:49:45 +08:00
.d-dialog > > > .el-upload-list--picture-card .el-upload-list__item {
2024-08-16 18:26:19 +08:00
width: 100px;
height: 100px;
}
2024-10-10 19:49:45 +08:00
.list-img {
2024-08-16 18:26:19 +08:00
width: 98px;
height: 98px;
}
</style>