oil-station/fuintAdmin_zt/src/views/setting/banner/index.vue
2024-10-10 19:49:45 +08:00

499 lines
16 KiB
Vue

<template>
<div class="app-container">
<div class="card-change">
<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>
<!-- <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>
</el-form-item>
</el-form>
<!-- </el-card>-->
<!-- &lt;!&ndash; 列表信息&ndash;&gt;-->
<!-- <el-card style="margin-top: 20px" >-->
<div style="height: 70vh;overflow: auto">
<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>
</div>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.page"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
<el-dialog :title="title" :close-on-click-modal="false" :visible.sync="open" width="55%" append-to-body>
<el-form ref="form" :model="deviceInfo" label-width="80px" :rules="rules">
<el-form :model="deviceInfo" ref="deviceForm" label-width="120px" :rules="rules">
<el-form-item label="banner名称" prop="bannerName">
<el-input v-model="deviceInfo.bannerName" style="width: 300px"></el-input>
</el-form-item>
<el-form-item label="图片" prop="uploadAction">
<el-upload
ref="uploadRef"
accept=".jpg, .jpeg, .png, .gif"
:class="{hide:hideUpload}"
:headers="uploadHeader"
: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>
</el-upload>
<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>-->
</el-form-item>
<el-form-item label="系统位置" prop="systemPosition">
<el-select v-model="deviceInfo.systemPosition" placeholder="系统位置" style="width: 300px">
<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="sortOrder">
<el-input v-model="deviceInfo.sortOrder" style="width: 300px"></el-input>
</el-form-item>
<el-form-item label="Banner链接" prop="bannerLink">
<el-input v-model="deviceInfo.bannerLink" style="width: 300px"></el-input>
</el-form-item>
<el-form-item label="Banner状态" prop="bannerStatus">
<el-switch
v-model="deviceInfo.bannerStatus"
active-color="#13ce66"
inactive-color="#ff4949"
>
</el-switch>
</el-form-item>
<el-form-item label="备注" prop="note">
<el-input v-model="deviceInfo.note" style="width: 300px"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('deviceForm')">提交</el-button>
</el-form-item>
</el-form>
</el-form>
</el-dialog>
</div>
</template>
<script>
import { deleteBannerApi, getBannerListApi, saveBannerApi, updateBannerApi } from '@/api/sys/banner'
import { getToken } from '@/utils/auth'
export default {
name: 'printIndex',
data() {
return {
dialogImageUrl: '',
dialogVisible: false,
disabled: false,
tableData: [],
deviceInfo: {
id: null, // 自增id
bannerName: '', // Banner名称
productImage: '', // 商品图片
systemPosition: '', // 系统位置
sortOrder: null, // 排序号
bannerLink: '', // Banner链接
bannerStatus: false, // Banner状态
note: '', // 备注
createByName: '' //
},
systemPositionList: [{
value: '系统首页',
label: '系统首页'
}],
// 是否显示弹出层
open: false,
title: '',
total: 0,
// 查询参数
queryParams: {
page: 1,
pageSize: 10,
bannerName: '',
systemPosition: '系统首页',
bannerStatus: ''
},
rules: {
bannerName: [
{ required: true, message: '请填写banner名称', trigger: 'blur' }
],
systemPosition: [
{ required: true, message: '请填写系统位置', trigger: '' }
],
sortOrder: [
{ required: true, message: '请填写排序号', trigger: 'blur' }
],
bannerLink: [
{ required: true, message: '请填写链接', trigger: 'blur' }
],
note: [
{ required: true, message: '请选择备注', trigger: 'blur' }
]
},
// 上传地址
uploadAction: process.env.VUE_APP_BASE_API + 'backendApi/file/upload',
uploadHeader: { 'Access-Token': getToken() }, // 上传文件列表
uploadFiles: [],
// 图片根目录
imagePath: process.env.VUE_APP_BASE_API,
// 隐藏上传
hideUpload: false
}
},
created() {
this.getList()
},
watch: {
// 监听上传图片列表
uploadFiles(newValue) {
// 判断上传文件数量
if (newValue.length >= 1) {
// 隐藏上传按钮
this.hideUpload = true
} else {
// 显示上传按钮
this.hideUpload = false
}
}
},
methods: {
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
this.total = res.data.total
})
},
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
// 表单验证通过,可以提交数据
this.submitDeviceInfo()
} else {
// 表单验证失败,不执行任何操作
return false
}
})
},
submitDeviceInfo() {
// 在这里调用接口提交设备信息数据
console.log('提交设备信息数据:', this.deviceInfo)
if (this.deviceInfo.id) {
updateBannerApi(this.deviceInfo).then(res => {
if (res.code === 200) {
this.getList()
this.open = false
}
})
} else {
saveBannerApi(this.deviceInfo).then(res => {
if (res.code === 200) {
this.getList()
this.open = false
}
})
}
},
changeStatus(data) {
updateBannerApi(data).then(res => {
if (res.code === 200) {
this.$message({
type: 'success',
message: '修改状态成功!'
})
this.getList()
}
})
},
handleQuery() {
this.getList()
},
resetQuery() {
this.queryParams = {
page: 1,
pageSize: 10,
deviceName: '',
systemPosition: '系统首页'
},
this.getList()
},
handleAdd(e) {
this.clean()
this.open = true
this.title = '新增banner图'
},
edit(e) {
this.clean()
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)
}
},
del(e) {
this.$confirm('此操作将永久删除该banner图, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deleteBannerApi(e.id).then(res => {
if (res.code == 200) {
this.$message({
type: 'success',
message: '删除成功!'
})
this.getList()
}
})
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
})
})
},
clean() {
this.deviceInfo = {
id: null, // 自增id
bannerName: '', // Banner名称
productImage: '', // 商品图片
systemPosition: '', // 系统位置
sortOrder: null, // 排序号
bannerLink: '', // Banner链接
bannerStatus: false, // Banner状态
note: '', // 备注
createByName: '' //
}
this.uploadFiles = []
}
}
}
</script>
<style lang="scss" scoped>
.common-dialog > > > .el-upload--picture-card {
width: 60px;
height: 50px;
line-height: 60px;
}
::v-deep.hide .el-upload--picture-card {
display: none;
}
.d-dialog > > > .el-upload--picture-card {
width: 100px;
height: 100px;
line-height: 100px;
}
.d-dialog > > > .avatar-uploader .el-upload {
width: 100px;
height: 100px;
}
.d-dialog > > > .el-upload-list--picture-card .el-upload-list__item {
width: 100px;
height: 100px;
}
.list-img {
width: 98px;
height: 98px;
}
</style>