Browse Source

feature:新增公共素材库页面和方法

master
Penny 3 years ago
parent
commit
5b8b5ad99a
  1. 48
      src/api/img/commonImgs.js
  2. 368
      src/views/img/commonImgs/index.vue

48
src/api/img/commonImgs.js

@ -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
})
}

368
src/views/img/commonImgs/index.vue

@ -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…
Cancel
Save