From ad5eb5aa483d86d3c94d1642eb15911593fdff88 Mon Sep 17 00:00:00 2001 From: Guo XIn <371864209@qq.com> Date: Thu, 31 Aug 2023 10:08:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=EF=BC=9A=E7=BB=BC=E5=90=88?= =?UTF-8?q?=E6=B5=8F=E8=A7=88=E7=B3=BB=E7=BB=9F=E8=B5=84=E6=BA=90=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E9=A1=B5=E9=9D=A2=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E8=A1=A8=E8=A1=A8=E5=A4=B4=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E5=92=8C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BrowserIndexController.java | 14 +-- .../src/main/resources/static/js/browser.js | 112 +++++++++++++++++- .../src/main/resources/view/browser.html | 57 ++++++--- .../controller/SysTheadConfigController.java | 42 +++++++ .../shandan/system/entity/SysTheadConfig.java | 65 ++++++++++ .../system/mapper/SysTheadConfigMapper.java | 15 +++ .../system/service/SysTheadConfigService.java | 16 +++ .../impl/SysTheadConfigServiceImpl.java | 78 ++++++++++++ .../static/js/sys/form/formConfig.js | 5 + 9 files changed, 375 insertions(+), 29 deletions(-) create mode 100644 shandan-system/src/main/java/com/keyware/shandan/system/controller/SysTheadConfigController.java create mode 100644 shandan-system/src/main/java/com/keyware/shandan/system/entity/SysTheadConfig.java create mode 100644 shandan-system/src/main/java/com/keyware/shandan/system/mapper/SysTheadConfigMapper.java create mode 100644 shandan-system/src/main/java/com/keyware/shandan/system/service/SysTheadConfigService.java create mode 100644 shandan-system/src/main/java/com/keyware/shandan/system/service/impl/SysTheadConfigServiceImpl.java diff --git a/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/BrowserIndexController.java b/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/BrowserIndexController.java index 7c105f5..1f2d5b6 100644 --- a/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/BrowserIndexController.java +++ b/shandan-browser/src/main/java/com/keyware/shandan/browser/controller/BrowserIndexController.java @@ -4,7 +4,6 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.keyware.shandan.bianmu.entity.MetadataBasicVo; import com.keyware.shandan.bianmu.service.DirPermissionService; -import com.keyware.shandan.bianmu.service.DirectoryService; import com.keyware.shandan.bianmu.service.MetadataService; import com.keyware.shandan.common.enums.SystemTypes; import com.keyware.shandan.common.util.RsaUtil; @@ -13,11 +12,12 @@ import com.keyware.shandan.datasource.entity.DBTableColumnVo; import com.keyware.shandan.frame.config.security.SecurityUtil; import com.keyware.shandan.system.entity.SysSetting; import com.keyware.shandan.system.entity.SysUser; -import com.keyware.shandan.system.service.SysFileService; +import com.keyware.shandan.system.service.SysTheadConfigService; import com.keyware.shandan.system.service.SysUserService; import com.keyware.shandan.system.utils.SysSettingUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -39,9 +39,6 @@ import java.util.List; @RequestMapping("/") public class BrowserIndexController { - @Autowired - private DirectoryService directoryService; - @Autowired private MetadataService metadataService; @@ -49,10 +46,10 @@ public class BrowserIndexController { private SysUserService sysUserService; @Autowired - private SysFileService sysFileService; + private DirPermissionService permissionService; @Autowired - private DirPermissionService permissionService; + private SysTheadConfigService theadConfigService; @Value("${project.cors-lib-search:#}") private String corsLibSearchUrl; @@ -90,10 +87,11 @@ public class BrowserIndexController { } @GetMapping("/browser") - public ModelAndView browser(ModelAndView mov) { + public ModelAndView browser(ModelAndView mov, Authentication auth) { mov.setViewName("browser"); SysSetting bianmuSetting = SysSettingUtil.getSysSetting(SystemTypes.BIANMU.name()); mov.addObject("bianmuServer", bianmuSetting.getSysAddress()); + mov.addObject("theadConfig", theadConfigService.listByCreateUser(auth.getName())); return mov; } diff --git a/shandan-browser/src/main/resources/static/js/browser.js b/shandan-browser/src/main/resources/static/js/browser.js index 6d46f0c..51a9108 100644 --- a/shandan-browser/src/main/resources/static/js/browser.js +++ b/shandan-browser/src/main/resources/static/js/browser.js @@ -135,11 +135,10 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop height: 'full-110', method: 'post', autoSort: false, - defaultToolbar: [{ - title: '导出' //标题 - , layEvent: 'export' //事件名,用于 toolbar 事件中使用 - , icon: 'layui-icon-export' //图标类名 - }], + defaultToolbar: [ + {title: '导出', layEvent: 'export', icon: 'layui-icon-export'}, + {title: '列表配置', layEvent: 'theadSet', icon: 'layui-icon-cols'} + ], request: {pageName: 'page', limitName: 'size'}, limit: 30, cols: [[ @@ -218,6 +217,8 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop openMaxLayerWithURL(`${ctx}/search/meta/${obj.id}`) } }) + + new THeadSetLayer(metaListTable, layui); } function initFileSearchTable(id) { @@ -230,6 +231,9 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop url: `${ctx}/search/full/file?metaId=${id}`, height: 'full-110', request: {pageName: 'page', limitName: 'size'}, + defaultToolbar: [ + {title: '列表配置', layEvent: 'theadSet', icon: 'layui-icon-cols'} + ], autoSort: false, limit: 30, method: 'get', @@ -285,6 +289,8 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop dirFileTable.addTableRowEvent('details-file', function (obj) { openMaxLayerWithURL(`${ctx}/sys/file/view?fileId=${obj.id}`) }) + + new THeadSetLayer(dirFileTable, layui); } /** @@ -508,4 +514,98 @@ layui.use(['layer', 'listPage', 'globalTree', 'gtable', 'form', 'element', 'drop closeBtn: 1 }); } -}) \ No newline at end of file +}) + +/** + * 表格表头配置组件 + */ +class THeadSetLayer { + constructor(pageTable, lay) { + this.layer = lay.layer; + this.form = lay.form; + this.gtable = lay.gtable; + this.pageTable = pageTable; + this.id = pageTable.id + 'Set'; + this.pageTable.addTableRowEvent('theadSet', () => this.show()) + } + + show() { + const {layer, pageTable, id} = this; + layer.open({ + id: id + 'Layer', + title: '数据列表配置', + type: 1, + area: ['1000px', '700px'], + shadeClose: true, + maxmin: false, + anim: 0, + content: `
`, + btn: ['保存', '取消'], + success: () => { + this._renderInnerTable(); + }, + yes: (layerIndex) => { + this._saveTheadSet().then(() => { + pageTable.reloadTable(); + layer.close(layerIndex); + }) + } + }); + } + + _renderInnerTable() { + const {gtable, form, id} = this; + gtable.init({ + id, + data: [...sourceTableConfigMap.values()], + method: 'get', + toolbar: false, + height: 'full-310', + page: false, + cols: [[ + {field: 'id', hide: true}, + {field: 'colName', title: '列名'}, + {field: 'colTitle', title: '列标题', edit: 'text'}, + {field: 'colSort', title: '列顺序', edit: 'text'}, + {field: 'colWidth', title: '列宽度', edit: 'text'}, + { + field: 'isSort', + title: '是否允许排序', + templet: (data) => renderSwitch('isSort', data) + }, + { + field: 'isShow', + title: '是否显示', + templet: (data) => renderSwitch('isShow', data) + } + ]], + }); + gtable.on(`edit(${id})`, ({field, value, data}) => { + sourceTableConfigMap.get(data.id)[field] = value; + }) + // 监听switch按钮 + form.on(`switch(${id}-switch)`, ({elem}) => { + const id = $(elem).attr('id'), name = $(elem).attr('name'); + const value = sourceTableConfigMap.get(id)[name]; + sourceTableConfigMap.get(id)[name] = !value; + }); + + function renderSwitch(colName, data) { + const dataId = data.id, value = data[colName]; + return `` + } + } + + _saveTheadSet() { + return new Promise(resolve => { + Util.post(`/sys/thead/config/api/save`, {params: JSON.stringify([...sourceTableConfigMap.values()])}).then(res=>{ + if(res.flag){ + showOkMsg('保存成功') + }else{ + showErrorMsg2('保存失败:'+res.msg) + } + }) + resolve(); + }) + } +} \ No newline at end of file diff --git a/shandan-browser/src/main/resources/view/browser.html b/shandan-browser/src/main/resources/view/browser.html index 3c069da..5d8c1da 100644 --- a/shandan-browser/src/main/resources/view/browser.html +++ b/shandan-browser/src/main/resources/view/browser.html @@ -11,6 +11,18 @@ @@ -79,18 +91,23 @@
当前位置:
diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysTheadConfigController.java b/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysTheadConfigController.java new file mode 100644 index 0000000..cc2e3e6 --- /dev/null +++ b/shandan-system/src/main/java/com/keyware/shandan/system/controller/SysTheadConfigController.java @@ -0,0 +1,42 @@ +package com.keyware.shandan.system.controller; + +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONUtil; +import com.keyware.shandan.common.entity.Result; +import com.keyware.shandan.common.util.StringUtils; +import com.keyware.shandan.system.entity.SysTheadConfig; +import com.keyware.shandan.system.service.SysTheadConfigService; +import org.springframework.security.core.Authentication; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * 前端数据表格表头配置前端控制器 + * + * @author GuoXin + * @date 2023/8/30 + */ +@RestController +@RequestMapping("/sys/thead/config") +public class SysTheadConfigController { + private final SysTheadConfigService theadConfigService; + + public SysTheadConfigController(SysTheadConfigService theadConfigService) { + this.theadConfigService = theadConfigService; + } + + @PostMapping(value = "/api/save") + public Result save(String params, Authentication auth) { + JSONArray jsonArray = JSONUtil.parseArray(params); + List list = jsonArray.toList(SysTheadConfig.class); + list.forEach(item->{ + if(!StringUtils.hasText(item.getId())){ + item.genId(auth.getName()); + } + }); + return Result.of(theadConfigService.saveOrUpdateBatch(list)); + } +} diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/entity/SysTheadConfig.java b/shandan-system/src/main/java/com/keyware/shandan/system/entity/SysTheadConfig.java new file mode 100644 index 0000000..ae2e581 --- /dev/null +++ b/shandan-system/src/main/java/com/keyware/shandan/system/entity/SysTheadConfig.java @@ -0,0 +1,65 @@ +package com.keyware.shandan.system.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.OrderBy; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.keyware.shandan.common.entity.BaseEntity; +import com.keyware.shandan.common.util.MD5Util; +import lombok.Builder; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 前端数据表格表头配置实体类 + * + * @author GuoXin + * @date 2023/8/30 + */ +@Data +@Builder +@EqualsAndHashCode(callSuper = true) +@TableName("SYS_THEAD_CONFIG") +public class SysTheadConfig extends BaseEntity { + + private static final long serialVersionUID = 1480474706145625172L; + /** + * 主键 + */ + @TableId(type = IdType.INPUT) + private String id; + /** + * 数据表ID,对应前端页面上的layui中table组件的id + */ + private String tableId; + /** + * 列名 + */ + private String colName; + /** + * 列标题 + */ + private String colTitle; + /** + * 列顺序 + */ + @OrderBy(isDesc = false, sort = 2) + private Integer colSort; + /** + * 列宽度 + */ + private String colWidth; + /** + * 是否显示 + */ + @OrderBy(sort = 1) + private Boolean isShow; + /** + * 是否允许排序 + */ + private Boolean isSort; + + public void genId(String userName) { + this.id = MD5Util.getMD5(tableId + colName + userName); + } +} diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/mapper/SysTheadConfigMapper.java b/shandan-system/src/main/java/com/keyware/shandan/system/mapper/SysTheadConfigMapper.java new file mode 100644 index 0000000..8a7a15e --- /dev/null +++ b/shandan-system/src/main/java/com/keyware/shandan/system/mapper/SysTheadConfigMapper.java @@ -0,0 +1,15 @@ +package com.keyware.shandan.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.keyware.shandan.system.entity.SysTheadConfig; +import org.apache.ibatis.annotations.Mapper; + +/** + * 前端数据表格表头配置数据库操作映射接口 + * + * @author GuoXin + * @date 2023/8/30 + */ +@Mapper +public interface SysTheadConfigMapper extends BaseMapper { +} diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/service/SysTheadConfigService.java b/shandan-system/src/main/java/com/keyware/shandan/system/service/SysTheadConfigService.java new file mode 100644 index 0000000..77ec5c5 --- /dev/null +++ b/shandan-system/src/main/java/com/keyware/shandan/system/service/SysTheadConfigService.java @@ -0,0 +1,16 @@ +package com.keyware.shandan.system.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.keyware.shandan.system.entity.SysTheadConfig; + +import java.util.List; + +/** + * 前端数据表格表头配置数据库操作接口 + * + * @author GuoXin + * @date 2023/8/30 + */ +public interface SysTheadConfigService extends IService { + List listByCreateUser(String userId); +} diff --git a/shandan-system/src/main/java/com/keyware/shandan/system/service/impl/SysTheadConfigServiceImpl.java b/shandan-system/src/main/java/com/keyware/shandan/system/service/impl/SysTheadConfigServiceImpl.java new file mode 100644 index 0000000..0676e04 --- /dev/null +++ b/shandan-system/src/main/java/com/keyware/shandan/system/service/impl/SysTheadConfigServiceImpl.java @@ -0,0 +1,78 @@ +package com.keyware.shandan.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.keyware.shandan.common.util.StringUtils; +import com.keyware.shandan.system.entity.SysTheadConfig; +import com.keyware.shandan.system.mapper.SysTheadConfigMapper; +import com.keyware.shandan.system.service.SysTheadConfigService; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * 前端数据表格表头配置数据库操作接口实现类 + * + * @author GuoXin + * @date 2023/8/30 + */ +@Service +public class SysTheadConfigServiceImpl extends ServiceImpl implements SysTheadConfigService { + static final String resourceTableId = "browser_resource_table", fileTableId = "browser_file_table"; + static List defaultConfig = new ArrayList<>(); + + static { + SysTheadConfig.SysTheadConfigBuilder builder = SysTheadConfig.builder(); + // 初始化综合浏览系统资源查询数据表表头默认配置 + defaultConfig.add(builder.tableId(resourceTableId).colName("resourceName").colTitle("资源名称").colSort(1).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("resourceComment").colTitle("资源注释").colSort(2).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("directoryPath").colTitle("目录路径").colSort(3).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("themeTask").colTitle("主题任务").colSort(4).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("dataSource").colTitle("数据来源").colSort(5).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("taskTime").colTitle("任务时间").colSort(6).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("dataType").colTitle("数据类型").colSort(7).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("secretLevel").colTitle("数据密级").colSort(8).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(resourceTableId).colName("resourceType").colTitle("资源类型").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + // 初始化综合浏览系统文件全文检索数据表表头默认配置 + defaultConfig.add(builder.tableId(fileTableId).colName("fileName").colTitle("文件名称").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("fileType").colTitle("文件类型").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("fileSize").colTitle("文件大小").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("remark").colTitle("文件描述").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("exerciseData").colTitle("是否演训数据").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("entryStaff").colTitle("录入人员").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("equipmentModel").colTitle("装备型号").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("inputDate").colTitle("任务时间").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("source").colTitle("文件来源").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("taskCode").colTitle("任务代号").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("taskNature").colTitle("任务性质").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("troopCode").colTitle("部队代号").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("targetNumber").colTitle("目标/靶标类型").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("missileNumber").colTitle("导弹编号").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("themeTask").colTitle("主题任务").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + defaultConfig.add(builder.tableId(fileTableId).colName("secretLevel").colTitle("文件密级").colSort(9).colWidth("100").isShow(true).isSort(false).build()); + } + + @Override + public List listByCreateUser(String userId) { + if (StringUtils.hasText(userId)) { + LambdaQueryWrapper query = new LambdaQueryWrapper<>(); + query.eq(SysTheadConfig::getCreateUser, userId); + List list = list(query); + if (list.size() == 0) { + // 为默认数据生成包含用户主键的ID + defaultConfig.forEach(conf -> conf.genId(userId)); + return defaultConfig; + } + return list; + } + return Collections.emptyList(); + } + + @Override + public boolean saveOrUpdateBatch(Collection entityList, int batchSize) { + return super.saveOrUpdateBatch(entityList, batchSize); + } +} diff --git a/shandan-system/src/main/resources/static/js/sys/form/formConfig.js b/shandan-system/src/main/resources/static/js/sys/form/formConfig.js index 0eb040b..9badef6 100644 --- a/shandan-system/src/main/resources/static/js/sys/form/formConfig.js +++ b/shandan-system/src/main/resources/static/js/sys/form/formConfig.js @@ -53,7 +53,12 @@ class FormConfigComponent { }) } } + }); + + gtable.on(`edit(${elemId})`, ({field, value, data}) => { + this.dataMap.get(data.id)[field] = value; }) + // 监听switch按钮 form.on(`switch(${elemId}-switch)`, (data) => this.switchChangeListen(data));