update 请求响应对象 与 分页对象 结构修改 适配接口文档配置

This commit is contained in:
疯狂的狮子li 2021-05-20 13:23:12 +08:00
parent 34e7f20f24
commit 39a0e05f87
17 changed files with 496 additions and 495 deletions

View File

@ -19,6 +19,8 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -88,10 +90,10 @@ public class CaptchaController {
code = captcha.getCode(); code = captcha.getCode();
} }
redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); redisCache.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
ajax.put("uuid", uuid); ajax.put("uuid", uuid);
ajax.put("img", captcha.getImageBase64()); ajax.put("img", captcha.getImageBase64());
return ajax; return AjaxResult.success(ajax);
} }
private String getCodeResult(String capStr) { private String getCodeResult(String capStr) {

View File

@ -18,10 +18,12 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;
/** /**
* 通用请求处理 * 通用请求处理
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -34,7 +36,7 @@ public class CommonController
/** /**
* 通用下载请求 * 通用下载请求
* *
* @param fileName 文件名称 * @param fileName 文件名称
* @param delete 是否删除 * @param delete 是否删除
*/ */
@ -77,10 +79,10 @@ public class CommonController
// 上传并返回新文件名称 // 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file); String fileName = FileUploadUtils.upload(filePath, file);
String url = serverConfig.getUrl() + fileName; String url = serverConfig.getUrl() + fileName;
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
ajax.put("fileName", fileName); ajax.put("fileName", fileName);
ajax.put("url", url); ajax.put("url", url);
return ajax; return AjaxResult.success(ajax);
} }
catch (Exception e) catch (Exception e)
{ {

View File

@ -15,12 +15,14 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 部门信息 * 部门信息
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -89,10 +91,10 @@ public class SysDeptController extends BaseController
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
{ {
List<SysDept> depts = deptService.selectDeptList(new SysDept()); List<SysDept> depts = deptService.selectDeptList(new SysDept());
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId)); ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
ajax.put("depts", deptService.buildDeptTreeSelect(depts)); ajax.put("depts", deptService.buildDeptTreeSelect(depts));
return ajax; return AjaxResult.success(ajax);
} }
/** /**

View File

@ -17,12 +17,14 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
* 登录验证 * 登录验证
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -42,24 +44,24 @@ public class SysLoginController
/** /**
* 登录方法 * 登录方法
* *
* @param loginBody 登录信息 * @param loginBody 登录信息
* @return 结果 * @return 结果
*/ */
@PostMapping("/login") @PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody) public AjaxResult login(@RequestBody LoginBody loginBody)
{ {
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
// 生成令牌 // 生成令牌
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
loginBody.getUuid()); loginBody.getUuid());
ajax.put(Constants.TOKEN, token); ajax.put(Constants.TOKEN, token);
return ajax; return AjaxResult.success(ajax);
} }
/** /**
* 获取用户信息 * 获取用户信息
* *
* @return 用户信息 * @return 用户信息
*/ */
@GetMapping("getInfo") @GetMapping("getInfo")
@ -71,16 +73,16 @@ public class SysLoginController
Set<String> roles = permissionService.getRolePermission(user); Set<String> roles = permissionService.getRolePermission(user);
// 权限集合 // 权限集合
Set<String> permissions = permissionService.getMenuPermission(user); Set<String> permissions = permissionService.getMenuPermission(user);
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
ajax.put("user", user); ajax.put("user", user);
ajax.put("roles", roles); ajax.put("roles", roles);
ajax.put("permissions", permissions); ajax.put("permissions", permissions);
return ajax; return AjaxResult.success(ajax);
} }
/** /**
* 获取路由信息 * 获取路由信息
* *
* @return 路由信息 * @return 路由信息
*/ */
@GetMapping("getRouters") @GetMapping("getRouters")

View File

@ -18,11 +18,13 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 菜单信息 * 菜单信息
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -78,10 +80,10 @@ public class SysMenuController extends BaseController
{ {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId()); List<SysMenu> menus = menuService.selectMenuList(loginUser.getUser().getUserId());
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId)); ajax.put("checkedKeys", menuService.selectMenuListByRoleId(roleId));
ajax.put("menus", menuService.buildMenuTreeSelect(menus)); ajax.put("menus", menuService.buildMenuTreeSelect(menus));
return ajax; return AjaxResult.success(ajax);
} }
/** /**
@ -148,4 +150,4 @@ public class SysMenuController extends BaseController
} }
return toAjax(menuService.deleteMenuById(menuId)); return toAjax(menuService.deleteMenuById(menuId));
} }
} }

View File

@ -19,10 +19,12 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/** /**
* 个人信息 业务处理 * 个人信息 业务处理
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -43,10 +45,11 @@ public class SysProfileController extends BaseController
{ {
LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest()); LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
SysUser user = loginUser.getUser(); SysUser user = loginUser.getUser();
AjaxResult ajax = AjaxResult.success(user); Map<String,Object> ajax = new HashMap<>();
ajax.put("user", user);
ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername())); ajax.put("roleGroup", userService.selectUserRoleGroup(loginUser.getUsername()));
ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername())); ajax.put("postGroup", userService.selectUserPostGroup(loginUser.getUsername()));
return ajax; return AjaxResult.success(ajax);
} }
/** /**
@ -121,12 +124,12 @@ public class SysProfileController extends BaseController
String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file); String avatar = FileUploadUtils.upload(RuoYiConfig.getAvatarPath(), file);
if (userService.updateUserAvatar(loginUser.getUsername(), avatar)) if (userService.updateUserAvatar(loginUser.getUsername(), avatar))
{ {
AjaxResult ajax = AjaxResult.success(); Map<String,Object> ajax = new HashMap<>();
ajax.put("imgUrl", avatar); ajax.put("imgUrl", avatar);
// 更新缓存用户头像 // 更新缓存用户头像
loginUser.getUser().setAvatar(avatar); loginUser.getUser().setAvatar(avatar);
tokenService.setLoginUser(loginUser); tokenService.setLoginUser(loginUser);
return ajax; return AjaxResult.success(ajax);
} }
} }
return AjaxResult.error("上传图片异常,请联系管理员"); return AjaxResult.error("上传图片异常,请联系管理员");

View File

@ -23,12 +23,14 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 用户信息 * 用户信息
* *
* @author ruoyi * @author ruoyi
*/ */
@RestController @RestController
@ -94,17 +96,17 @@ public class SysUserController extends BaseController
@GetMapping(value = { "/", "/{userId}" }) @GetMapping(value = { "/", "/{userId}" })
public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId)
{ {
AjaxResult ajax = AjaxResult.success(); Map<String, Object> ajax = new HashMap<>();
List<SysRole> roles = roleService.selectRoleAll(); List<SysRole> roles = roleService.selectRoleAll();
ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList()));
ajax.put("posts", postService.selectPostAll()); ajax.put("posts", postService.selectPostAll());
if (Validator.isNotNull(userId)) if (Validator.isNotNull(userId))
{ {
ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId)); ajax.put("user", userService.selectUserById(userId));
ajax.put("postIds", postService.selectPostListByUserId(userId)); ajax.put("postIds", postService.selectPostListByUserId(userId));
ajax.put("roleIds", roleService.selectRoleListByUserId(userId)); ajax.put("roleIds", roleService.selectRoleListByUserId(userId));
} }
return ajax; return AjaxResult.success(ajax);
} }
/** /**

View File

@ -1,161 +1,134 @@
package com.ruoyi.common.core.domain; package com.ruoyi.common.core.domain;
import cn.hutool.core.lang.Validator;
import cn.hutool.http.HttpStatus; import cn.hutool.http.HttpStatus;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap; import lombok.experimental.Accessors;
/** /**
* 操作消息提醒 * 操作消息提醒
* *
* @author ruoyi * @author Lion Li
*/ */
public class AjaxResult<T> extends HashMap<String, Object> @Data
{ @NoArgsConstructor
private static final long serialVersionUID = 1L; @AllArgsConstructor
@Accessors(chain = true)
@ApiModel("请求响应对象")
public class AjaxResult<T> {
/** 状态码 */ private static final long serialVersionUID = 1L;
public static final String CODE_TAG = "code";
/** 返回内容 */ /**
public static final String MSG_TAG = "msg"; * 状态码
*/
@ApiModelProperty("消息状态码")
private int code;
/** 数据对象 */ /**
public static final String DATA_TAG = "data"; * 返回内容
*/
@ApiModelProperty("消息内容")
private String msg;
public Integer getCode(){ /**
return (Integer) super.get(CODE_TAG); * 数据对象
} */
@ApiModelProperty("数据对象")
private T data;
public String getMsg(){ /**
return (String) super.get(MSG_TAG); * 初始化一个新创建的 AjaxResult 对象
} *
public T getData(){ * @param code 状态码
return (T) super.get(DATA_TAG); * @param msg 返回内容
} */
public AjaxResult(int code, String msg) {
this.code = code;
this.msg = msg;
}
/** /**
* 初始化一个新创建的 AjaxResult 对象使其表示一个空消息 * 返回成功消息
*/ *
public AjaxResult() * @return 成功消息
{ */
} public static AjaxResult<Void> success() {
return AjaxResult.success("操作成功");
}
/** /**
* 初始化一个新创建的 AjaxResult 对象 * 返回成功数据
* *
* @param code 状态码 * @return 成功消息
* @param msg 返回内容 */
*/ public static <T> AjaxResult<T> success(T data) {
public AjaxResult(int code, String msg) return AjaxResult.success("操作成功", data);
{ }
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
}
/** /**
* 初始化一个新创建的 AjaxResult 对象 * 返回成功消息
* *
* @param code 状态码 * @param msg 返回内容
* @param msg 返回内容 * @return 成功消息
* @param data 数据对象 */
*/ public static AjaxResult<Void> success(String msg) {
public AjaxResult(int code, String msg, T data) return AjaxResult.success(msg, null);
{ }
super.put(CODE_TAG, code);
super.put(MSG_TAG, msg);
if (Validator.isNotNull(data))
{
super.put(DATA_TAG, data);
}
}
/** /**
* 返回成功消息 * 返回成功消息
* *
* @return 成功消息 * @param msg 返回内容
*/ * @param data 数据对象
public static AjaxResult<Void> success() * @return 成功消息
{ */
return AjaxResult.success("操作成功"); public static <T> AjaxResult<T> success(String msg, T data) {
} return new AjaxResult<>(HttpStatus.HTTP_OK, msg, data);
}
/** /**
* 返回成功数据 * 返回错误消息
* *
* @return 成功消息 * @return
*/ */
public static <T> AjaxResult<T> success(T data) public static AjaxResult<Void> error() {
{ return AjaxResult.error("操作失败");
return AjaxResult.success("操作成功", data); }
}
/** /**
* 返回成功消息 * 返回错误消息
* *
* @param msg 返回内容 * @param msg 返回内容
* @return 成功消息 * @return 警告消息
*/ */
public static AjaxResult<Void> success(String msg) public static AjaxResult<Void> error(String msg) {
{ return AjaxResult.error(msg, null);
return AjaxResult.success(msg, null); }
}
/** /**
* 返回成功消息 * 返回错误消息
* *
* @param msg 返回内容 * @param msg 返回内容
* @param data 数据对象 * @param data 数据对象
* @return 成功消息 * @return 警告消息
*/ */
public static <T> AjaxResult<T> success(String msg, T data) public static <T> AjaxResult<T> error(String msg, T data) {
{ return new AjaxResult<>(HttpStatus.HTTP_INTERNAL_ERROR, msg, data);
return new AjaxResult(HttpStatus.HTTP_OK, msg, data); }
}
/** /**
* 返回错误消息 * 返回错误消息
* *
* @return * @param code 状态码
*/ * @param msg 返回内容
public static AjaxResult<Void> error() * @return 警告消息
{ */
return AjaxResult.error("操作失败"); public static AjaxResult<Void> error(int code, String msg) {
} return new AjaxResult<>(code, msg, null);
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult<Void> error(String msg)
{
return AjaxResult.error(msg, null);
}
/**
* 返回错误消息
*
* @param msg 返回内容
* @param data 数据对象
* @return 警告消息
*/
public static <T> AjaxResult<T> error(String msg, T data)
{
return new AjaxResult(HttpStatus.HTTP_INTERNAL_ERROR, msg, data);
}
/**
* 返回错误消息
*
* @param code 状态码
* @param msg 返回内容
* @return 警告消息
*/
public static AjaxResult<Void> error(int code, String msg)
{
return new AjaxResult(code, msg, null);
}
} }

View File

@ -1,5 +1,7 @@
package com.ruoyi.common.core.page; package com.ruoyi.common.core.page;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.Accessors; import lombok.experimental.Accessors;
@ -9,39 +11,50 @@ import java.util.List;
/** /**
* 表格分页数据对象 * 表格分页数据对象
* *
* @author ruoyi * @author Lion Li
*/ */
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@Accessors(chain = true) @Accessors(chain = true)
public class TableDataInfo<T> implements Serializable @ApiModel("分页响应对象")
{ public class TableDataInfo<T> implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/** 总记录数 */ /**
private long total; * 总记录数
*/
@ApiModelProperty("总记录数")
private long total;
/** 列表数据 */ /**
private List<T> rows; * 列表数据
*/
@ApiModelProperty("列表数据")
private List<T> rows;
/** 消息状态码 */ /**
private int code; * 消息状态码
*/
@ApiModelProperty("消息状态码")
private int code;
/** 消息内容 */ /**
private String msg; * 消息内容
*/
@ApiModelProperty("消息内容")
private String msg;
/** /**
* 分页 * 分页
* *
* @param list 列表数据 * @param list 列表数据
* @param total 总记录数 * @param total 总记录数
*/ */
public TableDataInfo(List<T> list, long total) public TableDataInfo(List<T> list, long total) {
{ this.rows = list;
this.rows = list; this.total = total;
this.total = total; }
}
} }

View File

@ -1,179 +1,179 @@
<template> <template>
<div class="upload-file"> <div class="upload-file">
<el-upload <el-upload
:action="uploadFileUrl" :action="uploadFileUrl"
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
:file-list="fileList" :file-list="fileList"
:limit="1" :limit="1"
:on-error="handleUploadError" :on-error="handleUploadError"
:on-exceed="handleExceed" :on-exceed="handleExceed"
:on-success="handleUploadSuccess" :on-success="handleUploadSuccess"
:show-file-list="false" :show-file-list="false"
:headers="headers" :headers="headers"
class="upload-file-uploader" class="upload-file-uploader"
ref="upload" ref="upload"
> >
<!-- 上传按钮 --> <!-- 上传按钮 -->
<el-button size="mini" type="primary">选取文件</el-button> <el-button size="mini" type="primary">选取文件</el-button>
<!-- 上传提示 --> <!-- 上传提示 -->
<div class="el-upload__tip" slot="tip" v-if="showTip"> <div class="el-upload__tip" slot="tip" v-if="showTip">
请上传 请上传
<template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b> </template> <template v-if="fileSize"> 大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b> </template>
<template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template> <template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template>
的文件 的文件
</div> </div>
</el-upload> </el-upload>
<!-- 文件列表 --> <!-- 文件列表 -->
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul"> <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
<li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in list"> <li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in list">
<el-link :href="file.url" :underline="false" target="_blank"> <el-link :href="file.url" :underline="false" target="_blank">
<span class="el-icon-document"> {{ getFileName(file.name) }} </span> <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
</el-link> </el-link>
<div class="ele-upload-list__item-content-action"> <div class="ele-upload-list__item-content-action">
<el-link :underline="false" @click="handleDelete(index)" type="danger">删除</el-link> <el-link :underline="false" @click="handleDelete(index)" type="danger">删除</el-link>
</div> </div>
</li> </li>
</transition-group> </transition-group>
</div> </div>
</template> </template>
<script> <script>
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
export default { export default {
props: { props: {
// //
value: [String, Object, Array], value: [String, Object, Array],
// (MB) // (MB)
fileSize: { fileSize: {
type: Number, type: Number,
default: 5, default: 5,
}, },
// , ['png', 'jpg', 'jpeg'] // , ['png', 'jpg', 'jpeg']
fileType: { fileType: {
type: Array, type: Array,
default: () => ["doc", "xls", "ppt", "txt", "pdf"], default: () => ["doc", "xls", "ppt", "txt", "pdf"],
}, },
// //
isShowTip: { isShowTip: {
type: Boolean, type: Boolean,
default: true default: true
} }
}, },
data() { data() {
return { return {
uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", //
headers: { headers: {
Authorization: "Bearer " + getToken(), Authorization: "Bearer " + getToken(),
}, },
fileList: [], fileList: [],
}; };
}, },
computed: { computed: {
// //
showTip() { showTip() {
return this.isShowTip && (this.fileType || this.fileSize); return this.isShowTip && (this.fileType || this.fileSize);
}, },
// //
list() { list() {
let temp = 1; let temp = 1;
if (this.value) { if (this.value) {
// //
const list = Array.isArray(this.value) ? this.value : [this.value]; const list = Array.isArray(this.value) ? this.value : [this.value];
// //
return list.map((item) => { return list.map((item) => {
if (typeof item === "string") { if (typeof item === "string") {
item = { name: item, url: item }; item = { name: item, url: item };
} }
item.uid = item.uid || new Date().getTime() + temp++; item.uid = item.uid || new Date().getTime() + temp++;
return item; return item;
}); });
} else { } else {
this.fileList = []; this.fileList = [];
return []; return [];
} }
}, },
}, },
methods: { methods: {
// //
handleBeforeUpload(file) { handleBeforeUpload(file) {
// //
if (this.fileType) { if (this.fileType) {
let fileExtension = ""; let fileExtension = "";
if (file.name.lastIndexOf(".") > -1) { if (file.name.lastIndexOf(".") > -1) {
fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1); fileExtension = file.name.slice(file.name.lastIndexOf(".") + 1);
} }
const isTypeOk = this.fileType.some((type) => { const isTypeOk = this.fileType.some((type) => {
if (file.type.indexOf(type) > -1) return true; if (file.type.indexOf(type) > -1) return true;
if (fileExtension && fileExtension.indexOf(type) > -1) return true; if (fileExtension && fileExtension.indexOf(type) > -1) return true;
return false; return false;
}); });
if (!isTypeOk) { if (!isTypeOk) {
this.$message.error(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); this.$message.error(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
return false; return false;
} }
} }
// //
if (this.fileSize) { if (this.fileSize) {
const isLt = file.size / 1024 / 1024 < this.fileSize; const isLt = file.size / 1024 / 1024 < this.fileSize;
if (!isLt) { if (!isLt) {
this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`); this.$message.error(`上传文件大小不能超过 ${this.fileSize} MB!`);
return false; return false;
} }
} }
return true; return true;
}, },
// //
handleExceed() { handleExceed() {
this.$message.error(`只允许上传单个文件`); this.$message.error(`只允许上传单个文件`);
}, },
// //
handleUploadError(err) { handleUploadError(err) {
this.$message.error("上传失败, 请重试"); this.$message.error("上传失败, 请重试");
}, },
// //
handleUploadSuccess(res, file) { handleUploadSuccess(res, file) {
this.$message.success("上传成功"); this.$message.success("上传成功");
this.$emit("input", res.url); this.$emit("input", res.data.url);
}, },
// //
handleDelete(index) { handleDelete(index) {
this.fileList.splice(index, 1); this.fileList.splice(index, 1);
this.$emit("input", ''); this.$emit("input", '');
}, },
// //
getFileName(name) { getFileName(name) {
if (name.lastIndexOf("/") > -1) { if (name.lastIndexOf("/") > -1) {
return name.slice(name.lastIndexOf("/") + 1).toLowerCase(); return name.slice(name.lastIndexOf("/") + 1).toLowerCase();
} else { } else {
return ""; return "";
} }
} }
}, },
created() { created() {
this.fileList = this.list; this.fileList = this.list;
}, },
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.upload-file-uploader { .upload-file-uploader {
margin-bottom: 5px; margin-bottom: 5px;
} }
.upload-file-list .el-upload-list__item { .upload-file-list .el-upload-list__item {
border: 1px solid #e4e7ed; border: 1px solid #e4e7ed;
line-height: 2; line-height: 2;
margin-bottom: 10px; margin-bottom: 10px;
position: relative; position: relative;
} }
.upload-file-list .ele-upload-list__item-content { .upload-file-list .ele-upload-list__item-content {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
color: inherit; color: inherit;
} }
.ele-upload-list__item-content-action .el-link { .ele-upload-list__item-content-action .el-link {
margin-right: 10px; margin-right: 10px;
} }
</style> </style>

View File

@ -1,100 +1,100 @@
<template> <template>
<div class="component-upload-image"> <div class="component-upload-image">
<el-upload <el-upload
:action="uploadImgUrl" :action="uploadImgUrl"
list-type="picture-card" list-type="picture-card"
:on-success="handleUploadSuccess" :on-success="handleUploadSuccess"
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
:on-error="handleUploadError" :on-error="handleUploadError"
name="file" name="file"
:show-file-list="false" :show-file-list="false"
:headers="headers" :headers="headers"
style="display: inline-block; vertical-align: top" style="display: inline-block; vertical-align: top"
> >
<el-image v-if="!value" :src="value"> <el-image v-if="!value" :src="value">
<div slot="error" class="image-slot"> <div slot="error" class="image-slot">
<i class="el-icon-plus" /> <i class="el-icon-plus" />
</div> </div>
</el-image> </el-image>
<div v-else class="image"> <div v-else class="image">
<el-image :src="value" :style="`width:150px;height:150px;`" fit="fill"/> <el-image :src="value" :style="`width:150px;height:150px;`" fit="fill"/>
<div class="mask"> <div class="mask">
<div class="actions"> <div class="actions">
<span title="预览" @click.stop="dialogVisible = true"> <span title="预览" @click.stop="dialogVisible = true">
<i class="el-icon-zoom-in" /> <i class="el-icon-zoom-in" />
</span> </span>
<span title="移除" @click.stop="removeImage"> <span title="移除" @click.stop="removeImage">
<i class="el-icon-delete" /> <i class="el-icon-delete" />
</span> </span>
</div> </div>
</div> </div>
</div> </div>
</el-upload> </el-upload>
<el-dialog :visible.sync="dialogVisible" title="预览" width="800" append-to-body> <el-dialog :visible.sync="dialogVisible" title="预览" width="800" append-to-body>
<img :src="value" style="display: block; max-width: 100%; margin: 0 auto;"> <img :src="value" style="display: block; max-width: 100%; margin: 0 auto;">
</el-dialog> </el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { getToken } from "@/utils/auth"; import { getToken } from "@/utils/auth";
export default { export default {
data() { data() {
return { return {
dialogVisible: false, dialogVisible: false,
uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", // uploadImgUrl: process.env.VUE_APP_BASE_API + "/common/upload", //
headers: { headers: {
Authorization: "Bearer " + getToken(), Authorization: "Bearer " + getToken(),
}, },
}; };
}, },
props: { props: {
value: { value: {
type: String, type: String,
default: "", default: "",
}, },
}, },
methods: { methods: {
removeImage() { removeImage() {
this.$emit("input", ""); this.$emit("input", "");
}, },
handleUploadSuccess(res) { handleUploadSuccess(res) {
this.$emit("input", res.url); this.$emit("input", res.data.url);
this.loading.close(); this.loading.close();
}, },
handleBeforeUpload() { handleBeforeUpload() {
this.loading = this.$loading({ this.loading = this.$loading({
lock: true, lock: true,
text: "上传中", text: "上传中",
background: "rgba(0, 0, 0, 0.7)", background: "rgba(0, 0, 0, 0.7)",
}); });
}, },
handleUploadError() { handleUploadError() {
this.$message({ this.$message({
type: "error", type: "error",
message: "上传失败", message: "上传失败",
}); });
this.loading.close(); this.loading.close();
}, },
}, },
watch: {}, watch: {},
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.image { .image {
position: relative; position: relative;
.mask { .mask {
opacity: 0; opacity: 0;
position: absolute; position: absolute;
top: 0; top: 0;
width: 100%; width: 100%;
background-color: rgba(0, 0, 0, 0.5); background-color: rgba(0, 0, 0, 0.5);
transition: all 0.3s; transition: all 0.3s;
} }
&:hover .mask { &:hover .mask {
opacity: 1; opacity: 1;
} }
} }
</style> </style>

View File

@ -37,8 +37,8 @@ const user = {
const uuid = userInfo.uuid const uuid = userInfo.uuid
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => { login(username, password, code, uuid).then(res => {
setToken(res.token) setToken(res.data.token)
commit('SET_TOKEN', res.token) commit('SET_TOKEN', res.data.token)
resolve() resolve()
}).catch(error => { }).catch(error => {
reject(error) reject(error)
@ -50,11 +50,11 @@ const user = {
GetInfo({ commit, state }) { GetInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
getInfo().then(res => { getInfo().then(res => {
const user = res.user const user = res.data.user
const avatar = user.avatar == "" ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar; const avatar = user.avatar == "" ? require("@/assets/images/profile.jpg") : process.env.VUE_APP_BASE_API + user.avatar;
if (res.roles && res.roles.length > 0) { // 验证返回的roles是否是一个非空数组 if (res.data.roles && res.data.roles.length > 0) { // 验证返回的roles是否是一个非空数组
commit('SET_ROLES', res.roles) commit('SET_ROLES', res.data.roles)
commit('SET_PERMISSIONS', res.permissions) commit('SET_PERMISSIONS', res.data.permissions)
} else { } else {
commit('SET_ROLES', ['ROLE_DEFAULT']) commit('SET_ROLES', ['ROLE_DEFAULT'])
} }

View File

@ -99,8 +99,8 @@ export default {
methods: { methods: {
getCode() { getCode() {
getCodeImg().then(res => { getCodeImg().then(res => {
this.codeUrl = "data:image/gif;base64," + res.img; this.codeUrl = "data:image/gif;base64," + res.data.img;
this.loginForm.uuid = res.uuid; this.loginForm.uuid = res.data.uuid;
}); });
}, },
getCookie() { getCookie() {

View File

@ -390,14 +390,14 @@ export default {
/** 根据角色ID查询菜单树结构 */ /** 根据角色ID查询菜单树结构 */
getRoleMenuTreeselect(roleId) { getRoleMenuTreeselect(roleId) {
return roleMenuTreeselect(roleId).then(response => { return roleMenuTreeselect(roleId).then(response => {
this.menuOptions = response.menus; this.menuOptions = response.data.menus;
return response; return response;
}); });
}, },
/** 根据角色ID查询部门树结构 */ /** 根据角色ID查询部门树结构 */
getRoleDeptTreeselect(roleId) { getRoleDeptTreeselect(roleId) {
return roleDeptTreeselect(roleId).then(response => { return roleDeptTreeselect(roleId).then(response => {
this.deptOptions = response.depts; this.deptOptions = response.data.depts;
return response; return response;
}); });
}, },
@ -513,7 +513,7 @@ export default {
this.open = true; this.open = true;
this.$nextTick(() => { this.$nextTick(() => {
roleMenu.then(res => { roleMenu.then(res => {
let checkedKeys = res.checkedKeys let checkedKeys = res.data.checkedKeys
checkedKeys.forEach((v) => { checkedKeys.forEach((v) => {
this.$nextTick(()=>{ this.$nextTick(()=>{
this.$refs.menu.setChecked(v, true ,false); this.$refs.menu.setChecked(v, true ,false);
@ -539,7 +539,7 @@ export default {
this.openDataScope = true; this.openDataScope = true;
this.$nextTick(() => { this.$nextTick(() => {
roleDeptTreeselect.then(res => { roleDeptTreeselect.then(res => {
this.$refs.dept.setCheckedKeys(res.checkedKeys); this.$refs.dept.setCheckedKeys(res.data.checkedKeys);
}); });
}); });
this.title = "分配数据权限"; this.title = "分配数据权限";
@ -607,4 +607,4 @@ export default {
} }
} }
}; };
</script> </script>

View File

@ -562,8 +562,8 @@ export default {
this.reset(); this.reset();
this.getTreeselect(); this.getTreeselect();
getUser().then(response => { getUser().then(response => {
this.postOptions = response.posts; this.postOptions = response.data.posts;
this.roleOptions = response.roles; this.roleOptions = response.data.roles;
this.open = true; this.open = true;
this.title = "添加用户"; this.title = "添加用户";
this.form.password = this.initPassword; this.form.password = this.initPassword;
@ -575,11 +575,11 @@ export default {
this.getTreeselect(); this.getTreeselect();
const userId = row.userId || this.ids; const userId = row.userId || this.ids;
getUser(userId).then(response => { getUser(userId).then(response => {
this.form = response.data; this.form = response.data.user;
this.postOptions = response.posts; this.postOptions = response.data.posts;
this.roleOptions = response.roles; this.roleOptions = response.data.roles;
this.form.postIds = response.postIds; this.form.postIds = response.data.postIds;
this.form.roleIds = response.roleIds; this.form.roleIds = response.data.roleIds;
this.open = true; this.open = true;
this.title = "修改用户"; this.title = "修改用户";
this.form.password = ""; this.form.password = "";

View File

@ -81,9 +81,9 @@ export default {
methods: { methods: {
getUser() { getUser() {
getUserProfile().then(response => { getUserProfile().then(response => {
this.user = response.data; this.user = response.data.user;
this.roleGroup = response.roleGroup; this.roleGroup = response.data.roleGroup;
this.postGroup = response.postGroup; this.postGroup = response.data.postGroup;
}); });
} }
} }

View File

@ -126,7 +126,7 @@ 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.data.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;