修改了对象存储
This commit is contained in:
parent
241de49166
commit
ec74a2d3de
@ -33,6 +33,8 @@
|
||||
<version>${wx-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -64,14 +64,14 @@ public class WineryGoodsController extends BaseController {
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodsSpec())){
|
||||
lqw.eq(WineryGoods::getGoodsSpec ,wineryGoods.getGoodsSpec());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodDesc())){
|
||||
lqw.eq(WineryGoods::getGoodDesc ,wineryGoods.getGoodDesc());
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodsDesc())){
|
||||
lqw.eq(WineryGoods::getGoodsDesc ,wineryGoods.getGoodsDesc());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodFaceImg())){
|
||||
lqw.eq(WineryGoods::getGoodFaceImg ,wineryGoods.getGoodFaceImg());
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodsFaceImg())){
|
||||
lqw.eq(WineryGoods::getGoodsFaceImg ,wineryGoods.getGoodsFaceImg());
|
||||
}
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodImg())){
|
||||
lqw.eq(WineryGoods::getGoodImg ,wineryGoods.getGoodImg());
|
||||
if (StringUtils.isNotBlank(wineryGoods.getGoodsImg())){
|
||||
lqw.eq(WineryGoods::getGoodsImg ,wineryGoods.getGoodsImg());
|
||||
}
|
||||
List<WineryGoods> list = iWineryGoodsService.list(lqw);
|
||||
return getDataTable(list);
|
||||
|
@ -58,15 +58,15 @@ private static final long serialVersionUID=1L;
|
||||
|
||||
/** 商品说明 */
|
||||
@Excel(name = "商品说明")
|
||||
private String goodDesc;
|
||||
private String goodsDesc;
|
||||
|
||||
/** 商品封面 */
|
||||
@Excel(name = "商品封面")
|
||||
private String goodFaceImg;
|
||||
private String goodsFaceImg;
|
||||
|
||||
/** 商品图片 */
|
||||
@Excel(name = "商品图片")
|
||||
private String goodImg;
|
||||
private String goodsImg;
|
||||
|
||||
/** 创建者 */
|
||||
private String createBy;
|
||||
|
1
pom.xml
1
pom.xml
@ -35,6 +35,7 @@
|
||||
<mybatis-plus.version>3.4.1</mybatis-plus.version>
|
||||
<hutool.version>5.4.0</hutool.version>
|
||||
<wx-java.version>4.0.0</wx-java.version>
|
||||
<cos-java.version>5.6.34</cos-java.version>
|
||||
</properties>
|
||||
|
||||
<!-- 依赖声明 -->
|
||||
|
@ -2,12 +2,15 @@ package com.ruoyi.web.controller.common;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.common.utils.file.CosUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.ruoyi.common.config.RuoYiConfig;
|
||||
@ -20,30 +23,30 @@ import com.ruoyi.framework.config.ServerConfig;
|
||||
|
||||
/**
|
||||
* 通用请求处理
|
||||
*
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
public class CommonController
|
||||
{
|
||||
public class CommonController {
|
||||
private static final Logger log = LoggerFactory.getLogger(CommonController.class);
|
||||
|
||||
@Autowired
|
||||
private ServerConfig serverConfig;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CosUtils cosUtils;
|
||||
|
||||
/**
|
||||
* 通用下载请求
|
||||
*
|
||||
*
|
||||
* @param fileName 文件名称
|
||||
* @param delete 是否删除
|
||||
* @param delete 是否删除
|
||||
*/
|
||||
@GetMapping("common/download")
|
||||
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!FileUtils.checkAllowDownload(fileName))
|
||||
{
|
||||
public void fileDownload(String fileName, Boolean delete, HttpServletResponse response, HttpServletRequest request) {
|
||||
try {
|
||||
if (!FileUtils.checkAllowDownload(fileName)) {
|
||||
throw new Exception(StringUtils.format("文件名称({})非法,不允许下载。 ", fileName));
|
||||
}
|
||||
String realFileName = System.currentTimeMillis() + fileName.substring(fileName.indexOf("_") + 1);
|
||||
@ -52,13 +55,10 @@ public class CommonController
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, realFileName);
|
||||
FileUtils.writeBytes(filePath, response.getOutputStream());
|
||||
if (delete)
|
||||
{
|
||||
if (delete) {
|
||||
FileUtils.deleteFile(filePath);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
@ -67,37 +67,44 @@ public class CommonController
|
||||
* 通用上传请求
|
||||
*/
|
||||
@PostMapping("/common/upload")
|
||||
public AjaxResult uploadFile(MultipartFile file) throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
public AjaxResult uploadFile(MultipartFile file) throws Exception {
|
||||
try {
|
||||
|
||||
// 上传文件路径
|
||||
String filePath = RuoYiConfig.getUploadPath();
|
||||
// String filePath = RuoYiConfig.getUploadPath();
|
||||
// 上传并返回新文件名称
|
||||
String fileName = FileUploadUtils.upload(filePath, file);
|
||||
String url = serverConfig.getUrl() + fileName;
|
||||
// String fileName = FileUploadUtils.upload(filePath, file);
|
||||
|
||||
|
||||
String fileName = cosUtils.upload(file);
|
||||
String url = serverConfig.getUrl() + "/common/file?fileName=" + fileName;
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
ajax.put("fileName", fileName);
|
||||
ajax.put("url", url);
|
||||
return ajax;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通用文件获取请求
|
||||
*/
|
||||
@GetMapping("/common/file")
|
||||
public void uploadFile(@RequestParam(required = true) String fileName, HttpServletResponse response) throws Exception {
|
||||
|
||||
cosUtils.getFile(fileName, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地资源通用下载
|
||||
*/
|
||||
@GetMapping("/common/download/resource")
|
||||
public void resourceDownload(String resource, HttpServletRequest request, HttpServletResponse response)
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!FileUtils.checkAllowDownload(resource))
|
||||
{
|
||||
throws Exception {
|
||||
try {
|
||||
if (!FileUtils.checkAllowDownload(resource)) {
|
||||
throw new Exception(StringUtils.format("资源文件({})非法,不允许下载。 ", resource));
|
||||
}
|
||||
// 本地资源路径
|
||||
@ -109,9 +116,7 @@ public class CommonController
|
||||
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
|
||||
FileUtils.setAttachmentResponseHeader(response, downloadName);
|
||||
FileUtils.writeBytes(downloadPath, response.getOutputStream());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
log.error("下载文件失败", e);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
package com.ruoyi.web.controller.system;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ruoyi.common.utils.file.CosUtils;
|
||||
import com.ruoyi.framework.config.ServerConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -38,6 +41,13 @@ public class SysProfileController extends BaseController
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
|
||||
@Autowired
|
||||
private CosUtils cosUtils;
|
||||
|
||||
@Autowired
|
||||
private ServerConfig serverConfig;
|
||||
|
||||
/**
|
||||
* 个人信息
|
||||
*/
|
||||
@ -111,7 +121,11 @@ public class SysProfileController extends BaseController
|
||||
if (!file.isEmpty())
|
||||
{
|
||||
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
|
||||
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
||||
|
||||
String fileName = cosUtils.upload(file);
|
||||
String avatar = "/common/file?fileName=" + fileName;
|
||||
|
||||
// String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
|
||||
if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
|
||||
{
|
||||
AjaxResult ajax = AjaxResult.success();
|
||||
|
@ -78,8 +78,9 @@ token:
|
||||
# 令牌密钥
|
||||
secret: abcdefghijklmnopqrstuvwxyz
|
||||
# 令牌有效期(默认30分钟)
|
||||
expireTime: 30
|
||||
|
||||
# expireTime: 30
|
||||
expireTime: 300
|
||||
|
||||
# MyBatis配置
|
||||
# https://baomidou.com/config/
|
||||
mybatis-plus:
|
||||
|
@ -136,6 +136,14 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 对象存储 -->
|
||||
<dependency>
|
||||
<groupId>com.qcloud</groupId>
|
||||
<artifactId>cos_api</artifactId>
|
||||
<version>${cos-java.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,39 @@
|
||||
package com.ruoyi.common.config;
|
||||
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.BasicCOSCredentials;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.region.Region;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author tottimctj
|
||||
* @since 2020-12-28
|
||||
*/
|
||||
@Configuration
|
||||
public class CosConfig {
|
||||
|
||||
|
||||
@Bean(name = "cosCredentials")
|
||||
public COSCredentials cosCredentials() {
|
||||
// 1 初始化用户身份信息(secretId, secretKey)。
|
||||
String secretId = "AKIDovztW8x0DpQnunSw2uXUDhw3IH0fQC75";
|
||||
String secretKey = "rCH8tOfjX5XjegYBXfkZWc2E75nJq9Dx";
|
||||
COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
|
||||
return cred;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Bean(name = "cosClientConfig")
|
||||
public ClientConfig cosClientConfig() {
|
||||
// 2 设置 bucket 的区域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224
|
||||
// clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。
|
||||
Region region = new Region("ap-beijing");
|
||||
ClientConfig clientConfig = new ClientConfig(region);
|
||||
return clientConfig;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.ruoyi.common.utils.file;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.qcloud.cos.COSClient;
|
||||
import com.qcloud.cos.ClientConfig;
|
||||
import com.qcloud.cos.auth.COSCredentials;
|
||||
import com.qcloud.cos.model.*;
|
||||
import com.qcloud.cos.transfer.Download;
|
||||
import com.ruoyi.common.utils.uuid.UUID;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
import static cn.hutool.core.util.IdUtil.fastSimpleUUID;
|
||||
|
||||
/**
|
||||
* @author tottimctj
|
||||
* @since 2020-12-28
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class CosUtils {
|
||||
|
||||
|
||||
@Autowired
|
||||
COSCredentials cosCredentials;
|
||||
|
||||
@Autowired
|
||||
ClientConfig clientConfig;
|
||||
|
||||
|
||||
// 指定要上传到的存储桶
|
||||
|
||||
final String bucketName = "winery-1257413599";
|
||||
String SPECIAL_CHARACTERS = "[`~! @#$%^&*()+=|{}':;',//[//]<>/?~!@#¥%……&*()_——+|{}【】‘;:”“’。,、?]";
|
||||
|
||||
public String upload(MultipartFile file) {
|
||||
|
||||
|
||||
// 指定要上传到 COS 上对象键
|
||||
String key = ReUtil.replaceAll(StrUtil.trim(fastSimpleUUID() + Optional.of(file.getOriginalFilename()).orElse(StrUtil.EMPTY)), SPECIAL_CHARACTERS, StrUtil.EMPTY);
|
||||
// 生成 cos 客户端。
|
||||
COSClient cosClient = new COSClient(cosCredentials, clientConfig);
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentType(file.getContentType());
|
||||
metadata.setContentLength(file.getSize());
|
||||
file.getContentType();
|
||||
try {
|
||||
PutObjectResult putObjectResult = cosClient.putObject(bucketName, key, file.getInputStream(), metadata);
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
cosClient.shutdown();
|
||||
}
|
||||
return key;
|
||||
|
||||
}
|
||||
|
||||
public void getFile(String fileName, HttpServletResponse response) {
|
||||
|
||||
COSClient cosClient = new COSClient(cosCredentials, clientConfig);
|
||||
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, fileName);
|
||||
// 限流使用的单位是bit/s, 这里设置下载带宽限制为 10MB/s
|
||||
getObjectRequest.setTrafficLimit(80 * 1024 * 1024);
|
||||
|
||||
COSObject cosObject = cosClient.getObject(getObjectRequest);
|
||||
|
||||
response.setContentType(cosObject.getObjectMetadata().getContentType());
|
||||
response.setContentLengthLong(cosObject.getObjectMetadata().getContentLength());
|
||||
OutputStream os = null;
|
||||
try {
|
||||
os = response.getOutputStream();
|
||||
while (true) {
|
||||
int line = cosObject.getObjectContent().read();
|
||||
if (line == -1) {
|
||||
break;
|
||||
} else {
|
||||
os.write(line);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭输入流
|
||||
cosClient.shutdown();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -19,15 +19,15 @@
|
||||
|
||||
<!-- BEGIN 如果想使用 Tomcat 注释掉以下代码 -->
|
||||
<!-- SpringBoot Web容器 -->
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- web 容器使用 undertow 性能更强 -->
|
||||
<dependency>
|
||||
@ -37,10 +37,10 @@
|
||||
<!-- END -->
|
||||
|
||||
<!-- BEGIN 如果想使用 Tomcat 解除以下代码注释 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-web</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- END -->
|
||||
|
||||
<!-- SpringBoot 拦截器 -->
|
||||
@ -79,6 +79,7 @@
|
||||
<artifactId>ruoyi-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -107,6 +107,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
|
||||
).permitAll()
|
||||
.antMatchers("/profile/**").anonymous()
|
||||
.antMatchers("/common/download**").anonymous()
|
||||
.antMatchers("/common/file**").anonymous()
|
||||
.antMatchers("/common/download/resource**").anonymous()
|
||||
.antMatchers("/swagger-ui.html").anonymous()
|
||||
.antMatchers("/swagger-resources/**").anonymous()
|
||||
|
@ -1,68 +1,74 @@
|
||||
<template>
|
||||
<div class="component-upload-image">
|
||||
<el-upload
|
||||
:action="uploadImgUrl"
|
||||
list-type="picture-card"
|
||||
:on-success="handleUploadSuccess"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-error="handleUploadError"
|
||||
name="file"
|
||||
:show-file-list="false"
|
||||
:headers="headers"
|
||||
style="display: inline-block; vertical-align: top"
|
||||
>
|
||||
<img v-if="value" :src="value" class="avatar" />
|
||||
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
||||
</el-upload>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getToken } from "@/utils/auth";
|
||||
|
||||
export default {
|
||||
components: {},
|
||||
data() {
|
||||
return {
|
||||
uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
|
||||
headers: {
|
||||
Authorization: "Bearer " + getToken(),
|
||||
},
|
||||
};
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleUploadSuccess(res) {
|
||||
this.$emit("input", res.url);
|
||||
this.loading.close();
|
||||
},
|
||||
handleBeforeUpload() {
|
||||
this.loading = this.$loading({
|
||||
lock: true,
|
||||
text: "上传中",
|
||||
background: "rgba(0, 0, 0, 0.7)",
|
||||
});
|
||||
},
|
||||
handleUploadError() {
|
||||
this.$message({
|
||||
type: "error",
|
||||
message: "上传失败",
|
||||
});
|
||||
this.loading.close();
|
||||
},
|
||||
},
|
||||
watch: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.avatar {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
<template>
|
||||
<div class="component-upload-image">
|
||||
<el-upload
|
||||
:action="uploadImgUrl"
|
||||
accept="image/*"
|
||||
list-type="picture-card"
|
||||
:on-success="handleUploadSuccess"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-error="handleUploadError"
|
||||
:on-remove="handleRemove"
|
||||
name="file"
|
||||
:show-file-list="false"
|
||||
:headers="headers"
|
||||
style="display: inline-block; vertical-align: top"
|
||||
>
|
||||
<img v-if="value" :src="value" class="avatar" />
|
||||
<i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
||||
</el-upload>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getToken } from "@/utils/auth";
|
||||
|
||||
export default {
|
||||
components: {},
|
||||
data() {
|
||||
return {
|
||||
uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
|
||||
headers: {
|
||||
Authorization: "Bearer " + getToken(),
|
||||
},
|
||||
};
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleUploadSuccess(res) {
|
||||
this.$emit("input", res.url);
|
||||
this.loading.close();
|
||||
},
|
||||
handleBeforeUpload() {
|
||||
this.loading = this.$loading({
|
||||
lock: true,
|
||||
text: "上传中",
|
||||
background: "rgba(0, 0, 0, 0.7)",
|
||||
});
|
||||
},
|
||||
handleUploadError() {
|
||||
this.$message({
|
||||
type: "error",
|
||||
message: "上传失败",
|
||||
});
|
||||
this.loading.close();
|
||||
},
|
||||
handleRemove(file, fileList) {
|
||||
console.log(file, fileList);
|
||||
this.$emit("input", '');
|
||||
},
|
||||
},
|
||||
watch: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.avatar {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
|
105
ruoyi-ui/src/components/UploadImageMultiple/index.vue
Normal file
105
ruoyi-ui/src/components/UploadImageMultiple/index.vue
Normal file
@ -0,0 +1,105 @@
|
||||
<template>
|
||||
<div class="component-upload-image">
|
||||
<!-- <el-upload-->
|
||||
<!-- :action="uploadImgUrl"-->
|
||||
<!-- list-type="picture-card"-->
|
||||
<!-- :on-success="handleUploadSuccess"-->
|
||||
<!-- :before-upload="handleBeforeUpload"-->
|
||||
<!-- :on-error="handleUploadError"-->
|
||||
<!-- name="file"-->
|
||||
<!-- :show-file-list="false"-->
|
||||
<!-- :headers="headers"-->
|
||||
<!-- style="display: inline-block; vertical-align: top"-->
|
||||
<!-- >-->
|
||||
<!-- <img v-if="value" :src="value| image" class="avatar"/>-->
|
||||
<!-- <i v-else class="el-icon-plus avatar-uploader-icon"></i>-->
|
||||
<!-- </el-upload>-->
|
||||
|
||||
<el-upload
|
||||
class="upload-demo"
|
||||
accept="image/*"
|
||||
:action="uploadImgUrl"
|
||||
:headers="headers"
|
||||
:on-success="handleUploadSuccess"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-error="handleUploadError"
|
||||
:on-preview="handlePreview"
|
||||
:on-remove="handleRemove"
|
||||
name="file"
|
||||
:file-list="fileList"
|
||||
list-type="picture">
|
||||
<el-button size="small" type="primary">点击上传</el-button>
|
||||
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
|
||||
</el-upload>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {getToken} from "@/utils/auth";
|
||||
|
||||
export default {
|
||||
components: {},
|
||||
data() {
|
||||
return {
|
||||
uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址
|
||||
headers: {
|
||||
Authorization: "Bearer " + getToken(),
|
||||
},
|
||||
};
|
||||
},
|
||||
props: {
|
||||
value: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
},
|
||||
filters: {
|
||||
image(value) {
|
||||
return process.env.VUE_APP_BASE_API + "/common/file?fileName=" + value
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
fileList() {
|
||||
|
||||
return this.value.split(',').map(x => {
|
||||
|
||||
return process.env.VUE_APP_BASE_API + "/common/file?fileName=" + x
|
||||
})
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
handleUploadSuccess(res) {
|
||||
this.$emit("input", res.fileName);
|
||||
this.loading.close();
|
||||
},
|
||||
handleBeforeUpload() {
|
||||
this.loading = this.$loading({
|
||||
lock: true,
|
||||
text: "上传中",
|
||||
background: "rgba(0, 0, 0, 0.7)",
|
||||
});
|
||||
},
|
||||
handleUploadError() {
|
||||
this.$message({
|
||||
type: "error",
|
||||
message: "上传失败",
|
||||
});
|
||||
this.loading.close();
|
||||
},
|
||||
handleRemove(file, fileList) {
|
||||
console.log(file, fileList);
|
||||
},
|
||||
handlePreview(file) {
|
||||
console.log(file);
|
||||
}
|
||||
},
|
||||
watch: {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.avatar {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
@ -98,7 +98,8 @@ export function selectDictLabels(datas, value, separator) {
|
||||
|
||||
// 通用下载方法
|
||||
export function download(fileName) {
|
||||
window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
|
||||
// window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
|
||||
window.location.href = baseURL + "/common/file?fileName=" + encodeURI(fileName)
|
||||
}
|
||||
|
||||
// 字符串格式化(%s )
|
||||
|
@ -21,21 +21,21 @@
|
||||
</el-form-item>
|
||||
<el-form-item label="商品类型" prop="goodsType">
|
||||
<el-select v-model="queryParams.goodsType" placeholder="请选择商品类型" clearable size="small">
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
<el-option label="请选择字典生成" value=""/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品说明" prop="goodDesc">
|
||||
<el-form-item label="商品说明" prop="goodsDesc">
|
||||
<el-input
|
||||
v-model="queryParams.goodDesc"
|
||||
v-model="queryParams.goodsDesc"
|
||||
placeholder="请输入商品说明"
|
||||
clearable
|
||||
size="small"
|
||||
@keyup.enter.native="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品封面" prop="goodFaceImg">
|
||||
<el-form-item label="商品封面" prop="goodsFaceImg">
|
||||
<el-input
|
||||
v-model="queryParams.goodFaceImg"
|
||||
v-model="queryParams.goodsFaceImg"
|
||||
placeholder="请输入商品封面"
|
||||
clearable
|
||||
size="small"
|
||||
@ -56,7 +56,8 @@
|
||||
size="mini"
|
||||
@click="handleAdd"
|
||||
v-hasPermi="['winery:winery_goods:add']"
|
||||
>新增</el-button>
|
||||
>新增
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@ -66,7 +67,8 @@
|
||||
:disabled="single"
|
||||
@click="handleUpdate"
|
||||
v-hasPermi="['winery:winery_goods:edit']"
|
||||
>修改</el-button>
|
||||
>修改
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@ -76,7 +78,8 @@
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['winery:winery_goods:remove']"
|
||||
>删除</el-button>
|
||||
>删除
|
||||
</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button
|
||||
@ -85,22 +88,23 @@
|
||||
size="mini"
|
||||
@click="handleExport"
|
||||
v-hasPermi="['winery:winery_goods:export']"
|
||||
>导出</el-button>
|
||||
>导出
|
||||
</el-button>
|
||||
</el-col>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="winery_goodsList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55" align="center" />
|
||||
<el-table-column type="selection" width="55" align="center"/>
|
||||
<el-table-column label="商品ID" align="center" prop="id" v-if="false"/>
|
||||
<el-table-column label="商品名称" align="center" prop="goodsName" />
|
||||
<el-table-column label="商品简称" align="center" prop="goodsAlias" />
|
||||
<el-table-column label="商品类型" align="center" prop="goodsType" />
|
||||
<el-table-column label="关联规格" align="center" prop="goodsSpec" />
|
||||
<el-table-column label="商品说明" align="center" prop="goodDesc" />
|
||||
<el-table-column label="商品封面" align="center" prop="goodFaceImg" />
|
||||
<el-table-column label="商品图片" align="center" prop="goodImg" />
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
<el-table-column label="商品名称" align="center" prop="goodsName"/>
|
||||
<el-table-column label="商品简称" align="center" prop="goodsAlias"/>
|
||||
<el-table-column label="商品类型" align="center" prop="goodsType"/>
|
||||
<el-table-column label="关联规格" align="center" prop="goodsSpec"/>
|
||||
<el-table-column label="商品说明" align="center" prop="goodsDesc"/>
|
||||
<el-table-column label="商品封面" align="center" prop="goodsFaceImg"/>
|
||||
<el-table-column label="商品图片" align="center" prop="goodsImg"/>
|
||||
<el-table-column label="备注" align="center" prop="remark"/>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
@ -109,14 +113,16 @@
|
||||
icon="el-icon-edit"
|
||||
@click="handleUpdate(scope.row)"
|
||||
v-hasPermi="['winery:winery_goods:edit']"
|
||||
>修改</el-button>
|
||||
>修改
|
||||
</el-button>
|
||||
<el-button
|
||||
size="mini"
|
||||
type="text"
|
||||
icon="el-icon-delete"
|
||||
@click="handleDelete(scope.row)"
|
||||
v-hasPermi="['winery:winery_goods:remove']"
|
||||
>删除</el-button>
|
||||
>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
@ -134,30 +140,34 @@
|
||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
||||
|
||||
<el-form-item label="商品名称" prop="goodsName">
|
||||
<el-input v-model="form.goodsName" placeholder="请输入商品名称" />
|
||||
<el-input v-model="form.goodsName" placeholder="请输入商品名称"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品简称" prop="goodsAlias">
|
||||
<el-input v-model="form.goodsAlias" placeholder="请输入商品简称" />
|
||||
<el-input v-model="form.goodsAlias" placeholder="请输入商品简称"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品类型" prop="goodsType">
|
||||
<el-select v-model="form.goodsType" placeholder="请选择商品类型">
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
<el-option label="请选择字典生成" value=""/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="关联规格" prop="goodsSpec">
|
||||
<el-input v-model="form.goodsSpec" type="textarea" placeholder="请输入内容" />
|
||||
<el-input v-model="form.goodsSpec" type="textarea" placeholder="请输入内容"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品说明" prop="goodDesc">
|
||||
<el-input v-model="form.goodDesc" placeholder="请输入商品说明" />
|
||||
<el-form-item label="商品说明" prop="goodsDesc">
|
||||
<el-input v-model="form.goodsDesc" placeholder="请输入商品说明"/>
|
||||
</el-form-item>
|
||||
<el-form-item label="商品封面" prop="goodFaceImg">
|
||||
<el-input v-model="form.goodFaceImg" placeholder="请输入商品封面" />
|
||||
<el-form-item label="商品封面" prop="goodsFaceImg">
|
||||
|
||||
|
||||
<upload-image :value="form.goodsFaceImg" @input="inputGoodsFaceImg"/>
|
||||
<!-- <el-input v-model="form.goodsFaceImg" placeholder="请输入商品封面" />-->
|
||||
</el-form-item>
|
||||
<el-form-item label="商品图片" prop="goodImg">
|
||||
<el-input v-model="form.goodImg" placeholder="请输入商品图片" />
|
||||
<el-form-item label="商品图片" prop="goodsImg">
|
||||
<upload-image-multiple :value="form.goodsImg" @input="inputGoodsImg"/>
|
||||
<!-- <el-input v-model="form.goodsImg" placeholder="请输入商品图片"/>-->
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
@ -169,12 +179,24 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { listWinery_goods, getWinery_goods, delWinery_goods, addWinery_goods, updateWinery_goods, exportWinery_goods } from "@/api/winery/winery_goods";
|
||||
import {
|
||||
listWinery_goods,
|
||||
getWinery_goods,
|
||||
delWinery_goods,
|
||||
addWinery_goods,
|
||||
updateWinery_goods,
|
||||
exportWinery_goods
|
||||
} from "@/api/winery/winery_goods";
|
||||
import UploadImage from '@/components/UploadImage/index'
|
||||
import UploadImageMultiple from '@/components/UploadImageMultiple/index'
|
||||
|
||||
export default {
|
||||
name: "Winery_goods",
|
||||
components: {
|
||||
UploadImage,
|
||||
UploadImageMultiple,
|
||||
},
|
||||
computed: {},
|
||||
data() {
|
||||
return {
|
||||
// 遮罩层
|
||||
@ -203,21 +225,27 @@ export default {
|
||||
goodsAlias: undefined,
|
||||
goodsType: undefined,
|
||||
goodsSpec: undefined,
|
||||
goodDesc: undefined,
|
||||
goodFaceImg: undefined,
|
||||
goodImg: undefined,
|
||||
goodsDesc: undefined,
|
||||
goodsFaceImg: undefined,
|
||||
goodsImg: undefined,
|
||||
},
|
||||
// 表单参数
|
||||
form: {},
|
||||
// 表单校验
|
||||
rules: {
|
||||
}
|
||||
rules: {}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.getList();
|
||||
},
|
||||
methods: {
|
||||
inputGoodsFaceImg(fileName) {
|
||||
this.form.goodsFaceImg = fileName
|
||||
},
|
||||
|
||||
inputGoodsImg(fileName) {
|
||||
this.form.goodsImg = fileName
|
||||
},
|
||||
/** 查询商品信息列表 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
@ -240,9 +268,9 @@ export default {
|
||||
goodsAlias: undefined,
|
||||
goodsType: undefined,
|
||||
goodsSpec: undefined,
|
||||
goodDesc: undefined,
|
||||
goodFaceImg: undefined,
|
||||
goodImg: undefined,
|
||||
goodsDesc: undefined,
|
||||
goodsFaceImg: undefined,
|
||||
goodsImg: undefined,
|
||||
createBy: undefined,
|
||||
createTime: undefined,
|
||||
updateBy: undefined,
|
||||
@ -264,7 +292,7 @@ export default {
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.id)
|
||||
this.single = selection.length!==1
|
||||
this.single = selection.length !== 1
|
||||
this.multiple = !selection.length
|
||||
},
|
||||
/** 新增按钮操作 */
|
||||
@ -307,28 +335,28 @@ export default {
|
||||
handleDelete(row) {
|
||||
const ids = row.id || this.ids;
|
||||
this.$confirm('是否确认删除商品信息编号为"' + ids + '"的数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function() {
|
||||
return delWinery_goods(ids);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.msgSuccess("删除成功");
|
||||
})
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function () {
|
||||
return delWinery_goods(ids);
|
||||
}).then(() => {
|
||||
this.getList();
|
||||
this.msgSuccess("删除成功");
|
||||
})
|
||||
},
|
||||
/** 导出按钮操作 */
|
||||
handleExport() {
|
||||
const queryParams = this.queryParams;
|
||||
this.$confirm('是否确认导出所有商品信息数据项?', "警告", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function() {
|
||||
return exportWinery_goods(queryParams);
|
||||
}).then(response => {
|
||||
this.download(response.msg);
|
||||
})
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(function () {
|
||||
return exportWinery_goods(queryParams);
|
||||
}).then(response => {
|
||||
this.download(response.msg);
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user