2 changed files with 416 additions and 0 deletions
@ -0,0 +1,48 @@ |
|||
import request from '@/utils/request' |
|||
const serviceTitle = '/system'; |
|||
const prefix = '/img/commonImgs'; |
|||
|
|||
// 查询公共素材库图片分页列表
|
|||
export function listCommonImgs(data) { |
|||
return request({ |
|||
url: `${serviceTitle}${prefix}/page`, |
|||
method: 'post', |
|||
data: data |
|||
}) |
|||
} |
|||
|
|||
// 批量新增公共素材库图片
|
|||
export function addCommonImgs(data) { |
|||
return request({ |
|||
url: `${serviceTitle}${prefix}/batchInsert`, |
|||
method: 'post' , |
|||
data: data |
|||
}) |
|||
} |
|||
|
|||
// 删除公共素材库图片
|
|||
export function delCommonImgs(ids) { |
|||
return request({ |
|||
url: `${serviceTitle}${prefix}/delete/` + ids, |
|||
method: 'delete' |
|||
}) |
|||
} |
|||
|
|||
// 批量变更类型显示状态
|
|||
export function changeStatus(data) { |
|||
return request({ |
|||
url: `${serviceTitle}${prefix}/changeStatus`, |
|||
method: 'post' , |
|||
data: data |
|||
}) |
|||
} |
|||
|
|||
// 图片上传
|
|||
export function uploadImg(data) { |
|||
return request({ |
|||
url: '/file/upload', |
|||
method: 'post' , |
|||
data: data |
|||
}) |
|||
} |
|||
|
|||
@ -0,0 +1,368 @@ |
|||
<template> |
|||
<div class="app-container"> |
|||
<el-row :gutter="20"> |
|||
<!--img数据--> |
|||
<el-col :span="20" :xs="24"> |
|||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px"> |
|||
<el-form-item label="图片类型" prop="type" label-width="80px"> |
|||
<el-select v-model="queryParams.type" placeholder="图片类型" clearable> |
|||
<el-option |
|||
v-for="item in type" |
|||
:key="item.value" |
|||
:label="item.label" |
|||
:value="item.value" |
|||
/> |
|||
</el-select> |
|||
</el-form-item> |
|||
<el-form-item label="是否显示" prop="isShow" label-width="80px"> |
|||
<el-select v-model="queryParams.isShow" placeholder="是否显示" clearable> |
|||
<el-option |
|||
v-for="item in isShow" |
|||
:key="item.value" |
|||
:label="item.label" |
|||
:value="item.value" |
|||
/> |
|||
</el-select> |
|||
</el-form-item> |
|||
<el-form-item> |
|||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> |
|||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> |
|||
</el-form-item> |
|||
</el-form> |
|||
|
|||
<el-row :gutter="10" class="mb8"> |
|||
<el-col :span="1.5"> |
|||
<el-button |
|||
type="primary" |
|||
plain |
|||
icon="el-icon-plus" |
|||
size="mini" |
|||
@click="handleAdd" |
|||
v-hasPermi="['img:commonImgs:add']" |
|||
>新增</el-button> |
|||
</el-col> |
|||
<el-col :span="1.5"> |
|||
<el-button |
|||
type="danger" |
|||
plain |
|||
icon="el-icon-delete" |
|||
size="mini" |
|||
@click="handleDelete" |
|||
v-hasPermi="['img:commonImgs:remove']" |
|||
>删除</el-button> |
|||
</el-col> |
|||
<el-col :span="1.5"> |
|||
<el-button |
|||
type="primary" |
|||
plain |
|||
icon="el-icon-add-location" |
|||
size="mini" |
|||
@click="handleChangeStatus('1')" |
|||
v-hasPermi="['img:commonImgs:edit']" |
|||
>显示图片</el-button> |
|||
</el-col> |
|||
<el-col :span="1.5"> |
|||
<el-button |
|||
type="primary" |
|||
plain |
|||
icon="el-icon-delete-location" |
|||
size="mini" |
|||
@click="handleChangeStatus('0')" |
|||
v-hasPermi="['img:commonImgs:edit']" |
|||
>隐藏图片</el-button> |
|||
</el-col> |
|||
</el-row> |
|||
|
|||
<!-- 图片列表 --> |
|||
<div class="images-box"> |
|||
<div class="img-box" v-for="item in commonImgsList" :key="item.id"> |
|||
<el-image style="width: 100px; height: 100px" :src="item.imgUrl" :preview-src-list="bigImgList" @click="getBigImg(item)"></el-image><br/> |
|||
<el-checkbox @change="changeChecked(item.id)">是否选中</el-checkbox> |
|||
</div> |
|||
</div> |
|||
|
|||
<pagination |
|||
v-show="total>0" |
|||
:total="total" |
|||
:page.sync="queryParams.pageNum" |
|||
:limit.sync="queryParams.pageSize" |
|||
@pagination="getList" |
|||
/> |
|||
</el-col> |
|||
</el-row> |
|||
|
|||
<!-- 添加或修改img对话框 --> |
|||
<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body> |
|||
<el-form ref="form" :model="form" :rules="rules" label-width="100px"> |
|||
<el-row> |
|||
<el-col :span="12"> |
|||
<el-form-item label="图片分类" prop="type"> |
|||
<el-select v-model="form.type" placeholder="图片分类" clearable> |
|||
<el-option |
|||
v-for="item in type" |
|||
:key="item.value" |
|||
:label="item.label" |
|||
:value="item.value" |
|||
/> |
|||
</el-select> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
<el-row> |
|||
<el-col :span="12"> |
|||
</el-col> |
|||
<el-col :span="15"> |
|||
<el-form-item label="图片地址" prop="imgUrls"> |
|||
<el-upload |
|||
ref="upload" |
|||
:action="upload.url" |
|||
:limit="9" |
|||
accept=".jpg, .jpeg, .png" |
|||
:headers="upload.headers" |
|||
:disabled="upload.isUploading" |
|||
:on-progress="handleFileUploadProgress" |
|||
:on-success="handleFileSuccess" |
|||
:file-list="fileList" |
|||
:auto-upload="true" |
|||
list-type="picture" |
|||
drag> |
|||
|
|||
<i class="el-icon-upload"></i> |
|||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div> |
|||
<div class="el-upload__tip text-center" slot="tip"> |
|||
<span>仅允许上传jpg,jpeg,png格式图片。</span> |
|||
</div> |
|||
</el-upload> |
|||
</el-form-item> |
|||
</el-col> |
|||
</el-row> |
|||
</el-form> |
|||
<div slot="footer" class="dialog-footer"> |
|||
<el-button type="primary" @click="submitForm">确 定</el-button> |
|||
<el-button @click="cancel">取 消</el-button> |
|||
</div> |
|||
</el-dialog> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { listCommonImgs,addCommonImgs,delCommonImgs,uploadImg, changeStatus } from "@/api/img/commonImgs"; |
|||
import { getToken } from "@/utils/auth"; |
|||
|
|||
export default { |
|||
name: "CommonImgs", |
|||
data() { |
|||
return { |
|||
// 遮罩层 |
|||
loading: true, |
|||
// 选中数组 |
|||
ids: [], |
|||
//图片选中数组 |
|||
checkedArray:[], |
|||
// 非单个禁用 |
|||
single: true, |
|||
// 非多个禁用 |
|||
multiple: true, |
|||
// 显示搜索条件 |
|||
showSearch: true, |
|||
// 总条数 |
|||
total: 0, |
|||
// img列表数据 |
|||
commonImgsList: null, |
|||
// 弹出层标题 |
|||
title: "", |
|||
// 是否显示新增修改弹出层 |
|||
open: false, |
|||
//选中的图片分类 |
|||
selectedTypeName: null, |
|||
// 日期范围 |
|||
dateRange: [], |
|||
//上传图片文件列表 |
|||
fileList:[], |
|||
//大图列表 |
|||
bigImgList:[], |
|||
//分类 |
|||
type:[ |
|||
{ value: '0', label: `头像`}, |
|||
{ value: '1', label: `壁纸`}, |
|||
{ value: '2', label: `插画`} |
|||
], |
|||
//是否显示 |
|||
isShow: [ |
|||
{ value: '0', label: `否`}, |
|||
{ value: '1', label: `是`} |
|||
], |
|||
// 表单参数 |
|||
form: {}, |
|||
// 图片上传参数 |
|||
upload: { |
|||
// 是否显示弹出层 |
|||
open: false, |
|||
// 弹出层标题 |
|||
title: "", |
|||
// 是否禁用上传 |
|||
isUploading: false, |
|||
// 设置上传的请求头部 |
|||
headers: { Authorization: "Bearer " + getToken() }, |
|||
// 上传的地址 |
|||
url: process.env.VUE_APP_BASE_API + "/file/upload" //http://localhost:7010/file/upload |
|||
}, |
|||
// 查询参数 |
|||
queryParams: { |
|||
pageNum: 1, |
|||
pageSize: 100, |
|||
type: undefined, |
|||
isShow: undefined, |
|||
}, |
|||
// 表单校验 |
|||
rules: { |
|||
type: [ |
|||
{ required: true, message: "图片分类不能为空", trigger: "blur" } |
|||
] |
|||
} |
|||
}; |
|||
}, |
|||
created() { |
|||
//加载公共素材库图片列表 |
|||
this.getList(); |
|||
}, |
|||
methods: { |
|||
/** 查询公共素材库列表 */ |
|||
getList() { |
|||
this.loading = true; |
|||
listCommonImgs(this.queryParams).then(response => { |
|||
this.commonImgsList = response.rows; |
|||
this.total = response.total; |
|||
this.loading = false; |
|||
this.checkedArray = []; |
|||
} |
|||
); |
|||
}, |
|||
|
|||
//改变选中状态 |
|||
changeChecked(imgId){ |
|||
console.log('选中的图片id为:',imgId); |
|||
if(!this.checkedArray.includes(imgId)){ |
|||
this.checkedArray.push(imgId); |
|||
}else{ |
|||
this.checkedArray = this.checkedArray.filter(item => item != imgId) |
|||
} |
|||
console.log('选中的图片id数组为:',this.checkedArray) |
|||
}, |
|||
|
|||
//改变公共素材库图片显示状态 |
|||
handleChangeStatus(status){ |
|||
let that = this; |
|||
console.log('图片状态为',status) |
|||
let text = status === "1" ? "显示" : "隐藏"; |
|||
//显示图片 |
|||
that.$modal.confirm('确认要' + text + '这些图片吗?').then(function() { |
|||
const data = { |
|||
ids: that.checkedArray, |
|||
status: status |
|||
} |
|||
return changeStatus(data); |
|||
}).then(() => { |
|||
//变更完清除数组 |
|||
this.checkedArray = []; |
|||
this.resetQuery(); |
|||
|
|||
this.$modal.msgSuccess(text + "成功"); |
|||
}); |
|||
}, |
|||
|
|||
// 取消按钮 |
|||
cancel() { |
|||
this.open = false; |
|||
this.reset(); |
|||
}, |
|||
// 表单重置 |
|||
reset() { |
|||
this.form = { |
|||
type: undefined, |
|||
imgUrl: undefined |
|||
}; |
|||
this.resetForm("form"); |
|||
}, |
|||
/** 搜索按钮操作 */ |
|||
handleQuery() { |
|||
this.queryParams.pageNum = 1; |
|||
this.getList(); |
|||
}, |
|||
/** 重置按钮操作 */ |
|||
resetQuery() { |
|||
this.resetForm("queryForm"); |
|||
this.handleQuery(); |
|||
}, |
|||
/** 查看大图 */ |
|||
getBigImg(row){ |
|||
this.bigImgList.push(row.imgUrl) |
|||
}, |
|||
/** 新增按钮操作 */ |
|||
handleAdd() { |
|||
this.reset(); |
|||
this.open = true; |
|||
this.title = "添加公共素材库图片"; |
|||
this.fileList = [] |
|||
}, |
|||
/** 提交按钮 */ |
|||
submitForm: function() { |
|||
console.log('当前上传文件列表数据为:',this.fileList) |
|||
this.$refs["form"].validate(valid => { |
|||
addCommonImgs(this.form).then(response => { |
|||
if(response.code === 200){ |
|||
this.$modal.msgSuccess("新增成功"); |
|||
this.open = false; |
|||
this.getList(); |
|||
console.log('保存完后上传文件列表数据为:',this.fileList) |
|||
} |
|||
}); |
|||
}); |
|||
}, |
|||
/** 删除按钮操作 */ |
|||
handleDelete() { |
|||
const ids = this.checkedArray; |
|||
this.$modal.confirm('是否确认删除编号为"' + ids + '"的公共素材库图片吗?').then(function() { |
|||
return delCommonImgs(ids); |
|||
}).then(() => { |
|||
this.getList(); |
|||
this.$modal.msgSuccess("删除成功"); |
|||
}).catch(() => {}); |
|||
}, |
|||
// 文件上传中处理 |
|||
handleFileUploadProgress(event, file, fileList) { |
|||
this.upload.isUploading = true; |
|||
}, |
|||
// 文件上传成功处理 |
|||
handleFileSuccess(response, file, fileList) { |
|||
this.fileList.push(response.data); |
|||
console.log('图片上传成功结果为:',this.fileList); |
|||
this.form.imgUrls = this.fileList; |
|||
this.upload.open = false; |
|||
this.upload.isUploading = false; |
|||
} |
|||
} |
|||
}; |
|||
</script> |
|||
<style lang="scss" scoped> |
|||
|
|||
.images-type{ |
|||
margin-left:350px; |
|||
margin-bottom: 35px; |
|||
} |
|||
.images-box { |
|||
width: 2200px; |
|||
display: flex; |
|||
flex-wrap: wrap; |
|||
justify-content: flex-start; |
|||
flex-direction: row; |
|||
margin-left: 35px; |
|||
//margin-right: 20px; |
|||
} |
|||
|
|||
.img-box { |
|||
border-radius: 20px; |
|||
margin-right: 10px; |
|||
|
|||
} |
|||
</style> |
|||
Loading…
Reference in new issue