头像和代码生成

This commit is contained in:
20932067@zju.edu.cn 2021-02-22 17:19:16 +08:00
parent f903942925
commit a254eafa8d
14 changed files with 128 additions and 36 deletions

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 查询校验规则列表
export function listRegular(query) {
return request({
url: '/system/regular/list',
url: '/tool/regular/list',
method: 'get',
params: query
})
@ -12,7 +12,7 @@ export function listRegular(query) {
// 查询校验规则详细
export function getRegular(id) {
return request({
url: '/system/regular/' + id,
url: '/tool/regular/' + id,
method: 'get'
})
}
@ -20,7 +20,7 @@ export function getRegular(id) {
// 新增校验规则
export function addRegular(data) {
return request({
url: '/system/regular',
url: '/tool/regular',
method: 'post',
data: data
})
@ -29,7 +29,7 @@ export function addRegular(data) {
// 修改校验规则
export function updateRegular(data) {
return request({
url: '/system/regular',
url: '/tool/regular',
method: 'put',
data: data
})
@ -38,7 +38,7 @@ export function updateRegular(data) {
// 删除校验规则
export function delRegular(id) {
return request({
url: '/system/regular/' + id,
url: '/tool/regular/' + id,
method: 'delete'
})
}
@ -50,4 +50,4 @@ export function exportRegular(query) {
method: 'get',
params: query
})
}
}

View File

@ -51,7 +51,8 @@ const user = {
return new Promise((resolve, reject) => {
getInfo(state.token).then(res => {
const user = res.user
const avatar = user.avatar == "" ? require("@/assets/image/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
// const avatar = user.avatar == "" ? require("@/assets/image/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
const avatar = user.avatar == "" ? require("@/assets/image/profile.jpg") : user.avatar;
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions)
@ -66,7 +67,7 @@ const user = {
})
})
},
// 退出系统
LogOut({ commit, state }) {
return new Promise((resolve, reject) => {

View File

@ -22,7 +22,7 @@ export function uploadFile(data) {
}
}).then(res => {
if (res.data.code === 200) {
return res.data
return res.data.data
} else {
Message({
message: res.data.msg,

View File

@ -126,7 +126,9 @@ export default {
formData.append("avatarfile", data);
uploadAvatar(formData).then(response => {
this.open = false;
this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
// this.options.img = process.env.VUE_APP_BASE_API + response.imgUrl;
this.options.img = response.imgUrl;
store.commit('SET_AVATAR', this.options.img);
this.msgSuccess("修改成功");
this.visible = false;
@ -139,4 +141,4 @@ export default {
}
}
};
</script>
</script>

View File

@ -1,18 +1,18 @@
<template>
<div>
F:{{ value }}
<download ref="download" v-model="value" :v-data="true" :v-public="true"/>
<UploadFile ref="download" :v-data="false" :union-id="5" v-model="value" :v-public="true"/>
<el-button @click="submitForm"> </el-button>
</div>
</template>
<script>
import download from './download'
import UploadFile from '../utils/uploadFile'
export default {
name: "downloadtest",
components: {
download
UploadFile
},
data() {
return {

View File

@ -29,18 +29,18 @@
</el-select>
</el-form-item>
</div>
<el-form-item label="文件类型">
<el-form-item v-if="this.fileType === null" label="文件类型">
<el-switch
v-model="fileType"
v-model="fileTypeShow"
active-text="文件"
inactive-color="#1890ff"
inactive-text="图片" @change="fileTypeChange">
</el-switch>
</el-form-item>
<el-form-item label="图片上传" v-show="!fileType">
<el-form-item label="图片上传" v-show="!fileTypeShow">
<ImageUpload v-model="staticUrl" v-on:change="changeAddress"/>
</el-form-item>
<el-form-item label="文件上传" v-show="fileType">
<el-form-item label="文件上传" v-show="fileTypeShow">
<FileUpload v-model="staticUrl" v-on:change="changeAddress"/>
</el-form-item>
</el-form>
@ -48,13 +48,13 @@
</template>
<script>
import {getRoleAll, getFolder, updateFile, addFile} from "@/api/system/file";
import {getRoleAll, getFolder} from "@/api/system/file";
import {uploadFile} from '@/utils/fileUtils'
import ImageUpload from '@/components/ImageUpload'
import FileUpload from '@/components/FileUpload'
export default {
name: "download",
name: "uploadFile",
components: {
ImageUpload,
FileUpload
@ -64,18 +64,31 @@ export default {
// type: String,
// default: "",
// },
/**
* 文件类型 图片:image 文件:file
*/
fileType: {
type: String,
default: null
},
unionId: {
type: Number,
default: null
},
/**
* 返回数据(true)或者已经上传到云端返回连接(false)
*/
vData: {
type: Boolean,
default: true
},
/**
* 是否公开 公开:true 保护:false 手动选择:父级组件不设置
*/
vPublic: {
type: Boolean,
default: null
},
vId:{
type: String,
default:null
}
},
data() {
const checkRoleIds = (rule, value, callback) => {
@ -95,7 +108,7 @@ export default {
roleIds: [],
isPublic: (this.vPublic === null) ? "1" : (this.vPublic === true) ? "1" : "2",
fileAddr: "",
uuid: this.vId,
unionId: this.unionId,
},
staticUrl: "",
//
@ -103,7 +116,7 @@ export default {
//
roleOptions: [],
isPublicShow: (this.vPublic === null) ? true : this.vPublic,
fileType: false,
fileTypeShow: this.fileType === null ? false : this.fileType !== "image",
rules: {
roleIds: [
{required: true, validator: checkRoleIds, trigger: 'change'},

View File

@ -4,6 +4,7 @@ import java.util.List;
import java.util.Set;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.system.utils.FtpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -67,6 +68,9 @@ public class LoginController {
public AjaxResult getInfo() {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
User user = loginUser.getUser();
String avatar = FtpUtils.getResources() + user.getAvatar();
user.setAvatar(avatar);
// 角色集合
Set<String> roles = permissionService.getRolePermission(user);
// 权限集合

View File

@ -3,6 +3,7 @@ package com.hchyun.web.controller.system;
import java.io.IOException;
import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.system.utils.FtpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -105,12 +106,13 @@ public class ProfileController extends BaseController {
public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
if (!file.isEmpty()) {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
String avatar = FileUploadUtils.upload(HchYunConfig.getAvatarPath(), file);
file.getName();
String avatar = FtpUtils.uploadFtp(file);
if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
AjaxResult ajax = AjaxResult.success();
ajax.put("imgUrl", avatar);
// 更新缓存用户头像
loginUser.getUser().setAvatar(avatar);
ajax.put("imgUrl", FtpUtils.getResources() + avatar);
// 更新缓存用户头像
tokenService.setLoginUser(loginUser);
return ajax;
}

View File

@ -26,7 +26,7 @@ ftp:
# 字符集编码
encoding: UTF-8
# 资源域名末尾以/结尾
resources: http://download.hchyun.com/
resources: http://download.hchyun.com
# 公开目录
pubfiles: pubfiles
# 保护目录

View File

@ -26,6 +26,10 @@ public class SysFile extends BaseEntity {
*/
@ApiModelProperty("文件夹id")
private Long pId;
@ApiModelProperty("上级id")
private Long unionId;
/**
* 角色id
*/
@ -72,6 +76,13 @@ public class SysFile extends BaseEntity {
@ApiModelProperty("是否公开")
private String isPublic;
public Long getUnionId() {
return unionId;
}
public void setUnionId(Long unionId) {
this.unionId = unionId;
}
public String getInherit() {
return inherit;

View File

@ -130,6 +130,9 @@ public class FileServiceImpl implements FileService {
@Override
public ServerResult<Integer> updateFile(SysFile sysFile) {
try {
if (sysFile.getIsPublic().equals("1")){
return new ServerResult<>(false,"此文件不可修改!");
}
if (sysFile.getpId() != null || sysFile.getpId() > 0) {
SysFile folder = fileDao.selectFileById(sysFile.getpId());
sysFile.setInherit(folder.getRoleIds());
@ -177,6 +180,12 @@ public class FileServiceImpl implements FileService {
}
}
/**
* 下载文件
* @param fileId
* @param loginUser
* @return
*/
@Override
public ServerResult<SysFile> downloadFile(Long fileId, LoginUser loginUser) {
try {

View File

@ -14,6 +14,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
import java.util.List;
@ -30,11 +31,13 @@ public class FtpUtils {
private static Logger logger = LoggerFactory.getLogger(FtpUtils.class);
private static String baseDir = "/profile";
private static String ftpDir = "/profile/upload";
/**
* 公开目录
*/
private static String pubfiles;
/**
* 保护目录
*/
private static String prifiles;
public static String getPubfiles() {
@ -55,6 +58,10 @@ public class FtpUtils {
private static String resources;
public static String getAvatarDir() {
return pubfiles + "avatar";
}
public void setPubfiles(String pubfiles) {
FtpUtils.pubfiles = pubfiles + "/";
}
@ -91,6 +98,45 @@ public class FtpUtils {
FtpUtils.encoding = encoding;
}
/**
* 头像上传
* @param file
* @return
*/
public static String uploadFtp(MultipartFile file) {
String avatarDir = getAvatarDir();
String avatarName = IdUtils.fastUUID();
InputStream inputStream = null;
try {
inputStream = file.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
FTPClient ftpClient = linkFtp();
if (ftpClient == null) {
return null;
}
try {
String[] basePathList = avatarDir.split("/");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
for (String path : basePathList) {
if (!ftpClient.changeWorkingDirectory(path)) {
ftpClient.makeDirectory(path);
ftpClient.changeWorkingDirectory(path);
}
}
ftpClient.enterLocalPassiveMode();
ftpClient.storeFile(avatarName, inputStream);
inputStream.close();
ftpClient.logout();
} catch (IOException e) {
logger.error(e.getMessage());
return null;
}
return "/avatar/" + avatarName;
}
/**
* 上传文件
*
@ -99,7 +145,7 @@ public class FtpUtils {
*/
public static SysFile uploadFtp(SysFile sysFile) {
String dir = HchYunConfig.getProfile() + sysFile.getFileAddr().substring(baseDir.length());
String ftpdir = "";
String ftpdir = "/";
if (sysFile.getIsPublic().equals("1")) {
ftpdir += pubfiles;
} else {
@ -137,6 +183,7 @@ public class FtpUtils {
ftpClient.logout();
} catch (IOException e) {
e.printStackTrace();
return null;
}
if (!FileUtils.deleteFile(dir)) {

View File

@ -7,6 +7,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<resultMap type="com.hchyun.system.entity.SysFile" id="FileResult">
<result property="fileId" column="file_id" />
<result property="pId" column="p_id" />
<result property="unionId" column="union_id" />
<result property="roleIds" column="role_ids" />
<result property="fileName" column="file_name" />
<result property="mapping" column="mapping" />
@ -21,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectFileVo">
select file_id, p_id, role_ids,inherit, file_name, mapping, file_addr, file_type, file_size, is_public, create_by, create_time, update_by, update_time from sys_file
select file_id, p_id, union_id, role_ids,inherit, file_name, mapping, file_addr, file_type, file_size, is_public, create_by, create_time, update_by, update_time from sys_file
</sql>
<select id="selectFileList" parameterType="SysFile" resultMap="FileResult">
<include refid="selectFileVo"/>
@ -49,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into sys_file
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="pId != null">p_id,</if>
<if test="unionId != null">union_id,</if>
<if test="roleIds != null">role_ids,</if>
<if test="inherit != null">inherit,</if>
<if test="fileName != null">file_name,</if>
@ -62,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="pId != null">#{pId},</if>
<if test="unionId != null">#{unionId},</if>
<if test="roleIds != null">#{roleIds},</if>
<if test="inherit != null">#{inherit},</if>
<if test="fileName != null">#{fileName},</if>