头像和代码生成

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) { export function listRegular(query) {
return request({ return request({
url: '/system/regular/list', url: '/tool/regular/list',
method: 'get', method: 'get',
params: query params: query
}) })
@ -12,7 +12,7 @@ export function listRegular(query) {
// 查询校验规则详细 // 查询校验规则详细
export function getRegular(id) { export function getRegular(id) {
return request({ return request({
url: '/system/regular/' + id, url: '/tool/regular/' + id,
method: 'get' method: 'get'
}) })
} }
@ -20,7 +20,7 @@ export function getRegular(id) {
// 新增校验规则 // 新增校验规则
export function addRegular(data) { export function addRegular(data) {
return request({ return request({
url: '/system/regular', url: '/tool/regular',
method: 'post', method: 'post',
data: data data: data
}) })
@ -29,7 +29,7 @@ export function addRegular(data) {
// 修改校验规则 // 修改校验规则
export function updateRegular(data) { export function updateRegular(data) {
return request({ return request({
url: '/system/regular', url: '/tool/regular',
method: 'put', method: 'put',
data: data data: data
}) })
@ -38,7 +38,7 @@ export function updateRegular(data) {
// 删除校验规则 // 删除校验规则
export function delRegular(id) { export function delRegular(id) {
return request({ return request({
url: '/system/regular/' + id, url: '/tool/regular/' + id,
method: 'delete' method: 'delete'
}) })
} }

View File

@ -51,7 +51,8 @@ const user = {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo(state.token).then(res => { getInfo(state.token).then(res => {
const user = res.user 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是否是一个非空数组 if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles) commit('SET_ROLES', res.roles)
commit('SET_PERMISSIONS', res.permissions) commit('SET_PERMISSIONS', res.permissions)

View File

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

View File

@ -126,7 +126,9 @@ export default {
formData.append("avatarfile", data); formData.append("avatarfile", data);
uploadAvatar(formData).then(response => { uploadAvatar(formData).then(response => {
this.open = false; 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); store.commit('SET_AVATAR', this.options.img);
this.msgSuccess("修改成功"); this.msgSuccess("修改成功");
this.visible = false; this.visible = false;

View File

@ -1,18 +1,18 @@
<template> <template>
<div> <div>
F:{{ value }} 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> <el-button @click="submitForm"> </el-button>
</div> </div>
</template> </template>
<script> <script>
import download from './download' import UploadFile from '../utils/uploadFile'
export default { export default {
name: "downloadtest", name: "downloadtest",
components: { components: {
download UploadFile
}, },
data() { data() {
return { return {

View File

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

View File

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

View File

@ -3,6 +3,7 @@ package com.hchyun.web.controller.system;
import java.io.IOException; import java.io.IOException;
import com.hchyun.common.constant.ReturnConstants; import com.hchyun.common.constant.ReturnConstants;
import com.hchyun.system.utils.FtpUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; 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 { public AjaxResult avatar(@RequestParam("avatarfile") MultipartFile file) throws IOException {
if (!file.isEmpty()) { if (!file.isEmpty()) {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); 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)) { if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) {
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
ajax.put("imgUrl", avatar);
// 更新缓存用户头像
loginUser.getUser().setAvatar(avatar); loginUser.getUser().setAvatar(avatar);
ajax.put("imgUrl", FtpUtils.getResources() + avatar);
// 更新缓存用户头像
tokenService.setLoginUser(loginUser); tokenService.setLoginUser(loginUser);
return ajax; return ajax;
} }

View File

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

View File

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

View File

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

View File

@ -14,6 +14,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.util.List; import java.util.List;
@ -30,11 +31,13 @@ public class FtpUtils {
private static Logger logger = LoggerFactory.getLogger(FtpUtils.class); private static Logger logger = LoggerFactory.getLogger(FtpUtils.class);
private static String baseDir = "/profile"; private static String baseDir = "/profile";
/**
private static String ftpDir = "/profile/upload"; * 公开目录
*/
private static String pubfiles; private static String pubfiles;
/**
* 保护目录
*/
private static String prifiles; private static String prifiles;
public static String getPubfiles() { public static String getPubfiles() {
@ -55,6 +58,10 @@ public class FtpUtils {
private static String resources; private static String resources;
public static String getAvatarDir() {
return pubfiles + "avatar";
}
public void setPubfiles(String pubfiles) { public void setPubfiles(String pubfiles) {
FtpUtils.pubfiles = pubfiles + "/"; FtpUtils.pubfiles = pubfiles + "/";
} }
@ -91,6 +98,45 @@ public class FtpUtils {
FtpUtils.encoding = encoding; 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) { public static SysFile uploadFtp(SysFile sysFile) {
String dir = HchYunConfig.getProfile() + sysFile.getFileAddr().substring(baseDir.length()); String dir = HchYunConfig.getProfile() + sysFile.getFileAddr().substring(baseDir.length());
String ftpdir = ""; String ftpdir = "/";
if (sysFile.getIsPublic().equals("1")) { if (sysFile.getIsPublic().equals("1")) {
ftpdir += pubfiles; ftpdir += pubfiles;
} else { } else {
@ -137,6 +183,7 @@ public class FtpUtils {
ftpClient.logout(); ftpClient.logout();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return null;
} }
if (!FileUtils.deleteFile(dir)) { 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"> <resultMap type="com.hchyun.system.entity.SysFile" id="FileResult">
<result property="fileId" column="file_id" /> <result property="fileId" column="file_id" />
<result property="pId" column="p_id" /> <result property="pId" column="p_id" />
<result property="unionId" column="union_id" />
<result property="roleIds" column="role_ids" /> <result property="roleIds" column="role_ids" />
<result property="fileName" column="file_name" /> <result property="fileName" column="file_name" />
<result property="mapping" column="mapping" /> <result property="mapping" column="mapping" />
@ -21,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectFileVo"> <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> </sql>
<select id="selectFileList" parameterType="SysFile" resultMap="FileResult"> <select id="selectFileList" parameterType="SysFile" resultMap="FileResult">
<include refid="selectFileVo"/> <include refid="selectFileVo"/>
@ -49,6 +50,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
insert into sys_file insert into sys_file
<trim prefix="(" suffix=")" suffixOverrides=","> <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="pId != null">p_id,</if> <if test="pId != null">p_id,</if>
<if test="unionId != null">union_id,</if>
<if test="roleIds != null">role_ids,</if> <if test="roleIds != null">role_ids,</if>
<if test="inherit != null">inherit,</if> <if test="inherit != null">inherit,</if>
<if test="fileName != null">file_name,</if> <if test="fileName != null">file_name,</if>
@ -62,6 +64,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides=","> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="pId != null">#{pId},</if> <if test="pId != null">#{pId},</if>
<if test="unionId != null">#{unionId},</if>
<if test="roleIds != null">#{roleIds},</if> <if test="roleIds != null">#{roleIds},</if>
<if test="inherit != null">#{inherit},</if> <if test="inherit != null">#{inherit},</if>
<if test="fileName != null">#{fileName},</if> <if test="fileName != null">#{fileName},</if>