From 489397fee3aa5937d6017f16a464bc3acbb7ab74 Mon Sep 17 00:00:00 2001 From: zhanglipeng <chinazhanglipeng@qq.com> Date: Fri, 6 Aug 2021 18:05:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/api/benyi/files.js | 9 ++ .../src/views/benyi/filelibrary/index.vue | 4 +- ruoyi-ui/src/views/benyi/files/index.vue | 133 ++++++++++++++++-- ruoyi-ui/src/views/system/user/index.vue | 10 +- .../benyi/controller/ByFilesController.java | 39 ++++- .../ruoyi/project/benyi/domain/ByFiles.java | 26 ++++ .../service/impl/ByFilesServiceImpl.java | 7 + .../resources/mybatis/benyi/ByFilesMapper.xml | 14 +- 8 files changed, 218 insertions(+), 24 deletions(-) diff --git a/ruoyi-ui/src/api/benyi/files.js b/ruoyi-ui/src/api/benyi/files.js index 8697496f9..79424aeba 100644 --- a/ruoyi-ui/src/api/benyi/files.js +++ b/ruoyi-ui/src/api/benyi/files.js @@ -9,6 +9,15 @@ export function listFiles(query) { }) } +// 查询文件管理列表 +export function listFilesByRole(query) { + return request({ + url: '/benyi/files/listbyrole', + method: 'get', + params: query + }) +} + // 查询文件管理详细 export function getFiles(id) { return request({ diff --git a/ruoyi-ui/src/views/benyi/filelibrary/index.vue b/ruoyi-ui/src/views/benyi/filelibrary/index.vue index 590b9c62b..65812604a 100644 --- a/ruoyi-ui/src/views/benyi/filelibrary/index.vue +++ b/ruoyi-ui/src/views/benyi/filelibrary/index.vue @@ -84,7 +84,7 @@ </template> <script> -import { listFiles, getFiles } from "@/api/benyi/files"; +import { listFilesByRole, getFiles } from "@/api/benyi/files"; import { getToken } from "@/utils/auth"; @@ -142,7 +142,7 @@ export default { /** 查询文件管理列表 */ getList() { this.loading = true; - listFiles(this.queryParams).then((response) => { + listFilesByRole(this.queryParams).then((response) => { this.filesList = response.rows; this.total = response.total; this.loading = false; diff --git a/ruoyi-ui/src/views/benyi/files/index.vue b/ruoyi-ui/src/views/benyi/files/index.vue index 40a5ae898..04cb0fc8a 100644 --- a/ruoyi-ui/src/views/benyi/files/index.vue +++ b/ruoyi-ui/src/views/benyi/files/index.vue @@ -1,6 +1,11 @@ <template> <div class="app-container"> - <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"> + <el-form + :model="queryParams" + ref="queryForm" + :inline="true" + label-width="68px" + > <el-form-item label="文件名称" prop="name"> <el-input v-model="queryParams.name" @@ -11,7 +16,12 @@ /> </el-form-item> <el-form-item label="所属类型" prop="type"> - <el-select v-model="queryParams.type" placeholder="请选择文件所属类型" clearable size="small"> + <el-select + v-model="queryParams.type" + placeholder="请选择文件所属类型" + clearable + size="small" + > <el-option v-for="dict in typeOptions" :key="dict.dictValue" @@ -21,8 +31,16 @@ </el-select> </el-form-item> <el-form-item> - <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> - <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> + <el-button + type="primary" + icon="el-icon-search" + size="mini" + @click="handleQuery" + >搜索</el-button + > + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" + >重置</el-button + > </el-form-item> </el-form> @@ -34,7 +52,8 @@ size="mini" @click="handleAdd" v-hasPermi="['benyi:files:add']" - >新增</el-button> + >新增</el-button + > </el-col> <el-col :span="1.5"> <el-button @@ -44,7 +63,8 @@ :disabled="single" @click="handleUpdate" v-hasPermi="['benyi:files:edit']" - >修改</el-button> + >修改</el-button + > </el-col> <el-col :span="1.5"> <el-button @@ -54,17 +74,37 @@ :disabled="multiple" @click="handleDelete" v-hasPermi="['benyi:files:remove']" - >删除</el-button> + >删除</el-button + > </el-col> </el-row> - <el-table v-loading="loading" :data="filesList" @selection-change="handleSelectionChange"> + <el-table + v-loading="loading" + :data="filesList" + @selection-change="handleSelectionChange" + > <el-table-column type="selection" width="55" align="center" /> <el-table-column label="编号" align="center" prop="id" /> <el-table-column label="文件名称" align="center" prop="name" /> <el-table-column label="文件类型" align="center" prop="filetype" /> - <el-table-column label="文件所属类型" align="center" prop="type" :formatter="typeFormat" /> - <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> + <el-table-column + label="文件所属类型" + align="center" + prop="type" + :formatter="typeFormat" + /> + <el-table-column + label="适用角色" + align="center" + :formatter="rolesFormat" + prop="roles" + /> + <el-table-column + label="操作" + align="center" + class-name="small-padding fixed-width" + > <template slot-scope="scope"> <el-button size="mini" @@ -72,20 +112,22 @@ icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['benyi:files:edit']" - >修改</el-button> + >修改</el-button + > <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['benyi:files:remove']" - >删除</el-button> + >删除</el-button + > </template> </el-table-column> </el-table> <pagination - v-show="total>0" + v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @@ -125,6 +167,21 @@ <el-button size="small" type="primary">选择文件</el-button> </el-upload> </el-form-item> + <el-form-item label="适用角色" prop="roles"> + <el-select + v-model="form.roles" + multiple + placeholder="请选择适用角色" + clearable + > + <el-option + v-for="dict in rolesOptions" + :key="dict.roleId" + :label="dict.roleName" + :value="dict.roleId" + /> + </el-select> + </el-form-item> </el-form> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="submitForm">确 定</el-button> @@ -142,6 +199,7 @@ import { addFiles, updateFiles, } from "@/api/benyi/files"; +import { listRole } from "@/api/system/role"; import { getToken } from "@/utils/auth"; @@ -162,6 +220,8 @@ export default { // 文件管理表格数据 filesList: [], fileList: [], + //角色 + rolesOptions: [], //文件类型 typeOptions: [], uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // 上传的图片服务器地址 @@ -182,6 +242,9 @@ export default { fileurl: undefined, createuserid: undefined, }, + queryParams_roles: { + roleKey: "school", + }, // 表单参数 form: {}, // 表单校验 @@ -203,6 +266,39 @@ export default { }); }, methods: { + getRoles() { + listRole(this.queryParams_roles).then((response) => { + this.rolesOptions = response.rows; + }); + }, + // 适用role--字典状态字典翻译 + rolesFormat(row, column) { + //alert(row.scope.split(';').length); + if (row.roles == null) { + return ""; + } + var ilength = row.roles.split(";").length; + var names = ""; + for (var i = 0; i < ilength - 1; i++) { + names = + names + + this.selectRolesLabel(this.rolesOptions, row.roles.split(";")[i]) + + ";"; + } + //this.selectDictLabel(this.scopeOptions, row.xnxq); + return names; + }, + // 回显数据字典 + selectRolesLabel(datas, value) { + var actions = []; + Object.keys(datas).map((key) => { + if (datas[key].roleId == "" + value) { + actions.push(datas[key].roleName); + return false; + } + }); + return actions.join(""); + }, handleAvatarSuccess(res, file) { //console.log(res); if (res.code == "200") { @@ -243,6 +339,7 @@ export default { this.total = response.total; this.loading = false; }); + this.getRoles(); }, // 取消按钮 cancel() { @@ -290,7 +387,15 @@ export default { this.reset(); const id = row.id || this.ids; getFiles(id).then((response) => { + console.log(response); this.form = response.data; + var roleArr = []; + if (response.roles != null) { + response.roles.forEach((element) => { + roleArr.push(parseInt(element)); + }); + } + this.form.roles = roleArr; this.open = true; this.title = "修改文件管理"; this.fileList.push({ @@ -303,6 +408,8 @@ export default { submitForm: function () { this.$refs["form"].validate((valid) => { if (valid) { + var arrscope = this.form.roles; + this.form.roles = arrscope.join(";") + ";"; if (this.form.id != undefined) { updateFiles(this.form).then((response) => { if (response.code === 200) { diff --git a/ruoyi-ui/src/views/system/user/index.vue b/ruoyi-ui/src/views/system/user/index.vue index 55b09337e..f0cde0972 100644 --- a/ruoyi-ui/src/views/system/user/index.vue +++ b/ruoyi-ui/src/views/system/user/index.vue @@ -141,7 +141,7 @@ </div> <el-table - border + border v-loading="loading" :data="userList" @selection-change="handleSelectionChange" @@ -149,7 +149,7 @@ <el-table-column type="selection" width="40" align="center" /> <!-- <el-table-column label="用户编号" align="center" prop="userId" /> --> <el-table-column - fixed + fixed label="登录账号" align="center" prop="userName" @@ -188,7 +188,7 @@ </template> </el-table-column> <el-table-column - fixed="right" + fixed="right" label="操作" align="center" width="60" @@ -289,8 +289,8 @@ </el-col> <el-col :span="12"> <el-form-item label="状态"> - <el-select v-model="form.status" placeholder="请选择"> - <el-option + <el-select v-model="form.status" placeholder="请选择"> + <el-option v-for="dict in statusOptions" :key="dict.dictValue" :label="dict.dictLabel" diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByFilesController.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByFilesController.java index 62fb60f84..a3b5fbd36 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByFilesController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/controller/ByFilesController.java @@ -3,6 +3,8 @@ package com.ruoyi.project.benyi.controller; import java.util.List; import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.project.common.SchoolCommon; +import com.ruoyi.project.system.domain.SysRole; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; @@ -33,14 +35,37 @@ import com.ruoyi.framework.web.page.TableDataInfo; public class ByFilesController extends BaseController { @Autowired private IByFilesService byFilesService; + @Autowired + private SchoolCommon schoolCommon; + + /** + * 查询文件管理列表 + */ + @PreAuthorize("@ss.hasPermi('benyi:files:list')") + @GetMapping("/list") + public TableDataInfo list(ByFiles byFiles) { + startPage(); + List<ByFiles> list = byFilesService.selectByFilesList(byFiles); + return getDataTable(list); + } /** * 查询文件管理列表 */ @PreAuthorize("@ss.hasPermi('benyi:files:list')") @Log(title = "查询文件", businessType = BusinessType.QUERY) - @GetMapping("/list") - public TableDataInfo list(ByFiles byFiles) { + @GetMapping("/listbyrole") + public TableDataInfo listbyrole(ByFiles byFiles) { + + String strRoles = ""; + List<SysRole> roles = SecurityUtils.getLoginUser().getUser().getRoles(); + System.out.println(roles.size()); + if (roles != null && roles.size() > 0) { + for (int i = 0; i < roles.size(); i++) { + strRoles = strRoles + roles.get(i).getRoleId() + ";"; + } + } + byFiles.setRoles(strRoles); startPage(); List<ByFiles> list = byFilesService.selectByFilesList(byFiles); return getDataTable(list); @@ -64,7 +89,15 @@ public class ByFilesController extends BaseController { @PreAuthorize("@ss.hasPermi('benyi:files:query')") @GetMapping(value = "/{id}") public AjaxResult getInfo(@PathVariable("id") Long id) { - return AjaxResult.success(byFilesService.selectByFilesById(id)); + AjaxResult ajax = AjaxResult.success(); + ByFiles byFiles = byFilesService.selectByFilesById(id); + ajax.put(AjaxResult.DATA_TAG, byFiles); + if (!schoolCommon.isStringEmpty(byFiles.getRoles())) { + ajax.put("roles", byFiles.getRoles().split(";")); + } else { + ajax.put("roles", null); + } + return ajax; } /** diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByFiles.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByFiles.java index 533a4c89c..ecb1c21c2 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByFiles.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/domain/ByFiles.java @@ -49,6 +49,22 @@ public class ByFiles extends BaseEntity { @Excel(name = "创建人") private Long createuserid; + /** + * 适用角色 + */ + @Excel(name = "适用角色") + private String roles; + + public String[] getRoleArr() { + return roleArr; + } + + public void setRoleArr(String[] roleArr) { + this.roleArr = roleArr; + } + + private String[] roleArr; + public void setId(Long id) { this.id = id; } @@ -97,6 +113,14 @@ public class ByFiles extends BaseEntity { return createuserid; } + public void setRoles(String roles) { + this.roles = roles; + } + + public String getRoles() { + return roles; + } + @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) @@ -107,6 +131,8 @@ public class ByFiles extends BaseEntity { .append("fileurl", getFileurl()) .append("createuserid", getCreateuserid()) .append("createTime", getCreateTime()) + .append("roles", getRoles()) + .append("roleArr", getRoleArr()) .toString(); } } diff --git a/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByFilesServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByFilesServiceImpl.java index 8192e91e6..f0ae54f18 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByFilesServiceImpl.java +++ b/ruoyi/src/main/java/com/ruoyi/project/benyi/service/impl/ByFilesServiceImpl.java @@ -39,6 +39,13 @@ public class ByFilesServiceImpl implements IByFilesService { */ @Override public List<ByFiles> selectByFilesList(ByFiles byFiles) { + if (byFiles.getRoles() == null || "".equals(byFiles.getRoles())) { + + } else { + String strArr = byFiles.getRoles(); + byFiles.setRoleArr(strArr.split(";")); + } + return byFilesMapper.selectByFilesList(byFiles); } diff --git a/ruoyi/src/main/resources/mybatis/benyi/ByFilesMapper.xml b/ruoyi/src/main/resources/mybatis/benyi/ByFilesMapper.xml index 20f3b1764..34b7d6dbd 100644 --- a/ruoyi/src/main/resources/mybatis/benyi/ByFilesMapper.xml +++ b/ruoyi/src/main/resources/mybatis/benyi/ByFilesMapper.xml @@ -12,20 +12,29 @@ <result property="fileurl" column="fileurl"/> <result property="createuserid" column="createuserid"/> <result property="createTime" column="create_time"/> + <result property="roles" column="roles"/> </resultMap> <sql id="selectByFilesVo"> - select id, name, filetype, type, fileurl, createuserid, create_time from by_files + select id, name, filetype, type, fileurl, createuserid, create_time, roles from by_files </sql> <select id="selectByFilesList" parameterType="ByFiles" resultMap="ByFilesResult"> <include refid="selectByFilesVo"/> <where> + and 1=1 <if test="name != null and name != ''">and name like concat('%', #{name}, '%')</if> <if test="filetype != null and filetype != ''">and filetype = #{filetype}</if> <if test="type != null and type != ''">and type = #{type}</if> <if test="fileurl != null and fileurl != ''">and fileurl = #{fileurl}</if> <if test="createuserid != null ">and createuserid = #{createuserid}</if> + <if test="roles != null and roles != ''"> + and ( + <foreach collection="roleArr" item="item" index="index" separator=" or "> + roles like concat('%', #{item}, '%') + </foreach> + ) + </if> </where> order by type </select> @@ -44,6 +53,7 @@ <if test="fileurl != null and fileurl != ''">fileurl,</if> <if test="createuserid != null ">createuserid,</if> <if test="createTime != null ">create_time,</if> + <if test="roles != null and roles != ''">roles,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="name != null and name != ''">#{name},</if> @@ -52,6 +62,7 @@ <if test="fileurl != null and fileurl != ''">#{fileurl},</if> <if test="createuserid != null ">#{createuserid},</if> <if test="createTime != null ">#{createTime},</if> + <if test="roles != null and roles != ''">#{roles},</if> </trim> </insert> @@ -64,6 +75,7 @@ <if test="fileurl != null and fileurl != ''">fileurl = #{fileurl},</if> <if test="createuserid != null ">createuserid = #{createuserid},</if> <if test="createTime != null ">create_time = #{createTime},</if> + <if test="roles != null and roles != ''">roles = #{roles},</if> </trim> where id = #{id} </update>