Commit db904f679ed589af623b481f6b747b9609e487fd

Authored by 若依
Committed by Gitee
2 parents 98982515 d78f6422

!57 若干 ruoyi-ui 前端公共工具函数优化

Merge pull request !57 from FungLeo/master
.gitignore
... ... @@ -37,7 +37,8 @@ nbdist/
37 37 # Others
38 38 *.log
39 39 *.xml.versionsBackup
  40 +*.swp
40 41  
41 42 !*/build/*.java
42 43 !*/build/*.html
43   -!*/build/*.xml
44 44 \ No newline at end of file
  45 +!*/build/*.xml
... ...
ruoyi-ui/src/utils/ruoyi.js
... ... @@ -54,42 +54,29 @@ export function resetForm(refName) {
54 54 }
55 55  
56 56 // 添加日期范围
57   -export function addDateRange(params, dateRange) {
58   - var search = params;
59   - search.beginTime = "";
60   - search.endTime = "";
61   - if (null != dateRange && '' != dateRange) {
62   - search.beginTime = this.dateRange[0];
63   - search.endTime = this.dateRange[1];
64   - }
65   - return search;
  57 +export function addDateRange (params = {}, dateRange) {
  58 + if (dateRange != null && dateRange !== '') {
  59 + params.beginTime = this.dateRange[0]
  60 + params.endTime = this.dateRange[1]
  61 + }
  62 + return params
66 63 }
67 64  
68 65 // 回显数据字典
69   -export function selectDictLabel(datas, value) {
70   - var actions = [];
71   - Object.keys(datas).some((key) => {
72   - if (datas[key].dictValue == ('' + value)) {
73   - actions.push(datas[key].dictLabel);
74   - return true;
75   - }
76   - })
77   - return actions.join('');
  66 +export function selectDictLabel(datas = [], value = '') {
  67 + if (!value) return '-';
  68 + const dataArr = datas.filter(item => item.dictValue === value.toString());
  69 + return dataArr.length ? dataArr[0].dictLabel : 'Error Dict';
78 70 }
79 71  
80 72 // 回显数据字典(字符串数组)
81   -export function selectDictLabels(datas, value, separator) {
82   - var actions = [];
83   - var currentSeparator = undefined === separator ? "," : separator;
84   - var temp = value.split(currentSeparator);
85   - Object.keys(value.split(currentSeparator)).some((val) => {
86   - Object.keys(datas).some((key) => {
87   - if (datas[key].dictValue == ('' + temp[val])) {
88   - actions.push(datas[key].dictLabel + currentSeparator);
89   - }
90   - })
91   - })
92   - return actions.join('').substring(0, actions.join('').length - 1);
  73 +export function selectDictLabels(datas = [], value = '', separator = ',') {
  74 + const actions = [];
  75 + const temp = value.split(separator).filter(item => item);
  76 + temp.forEach((_, index) => {
  77 + actions.push(selectDictLabel(datas, temp[index]));
  78 + })
  79 + return actions.join(separator);
93 80 }
94 81  
95 82 // 通用下载方法
... ... @@ -127,23 +114,19 @@ export function praseStrEmpty(str) {
127 114 * @param {*} children 孩子节点字段 默认 'children'
128 115 * @param {*} rootId 根Id 默认 0
129 116 */
130   -export function handleTree(data, id, parentId, children, rootId) {
131   - id = id || 'id'
132   - parentId = parentId || 'parentId'
133   - children = children || 'children'
134   - rootId = rootId || 0
  117 +export function handleTree(data = [], id = 'id', parentId = 'parentId', children = 'children', rootId = 0) {
135 118 //对源数据深度克隆
136 119 const cloneData = JSON.parse(JSON.stringify(data))
137 120 //循环所有项
138 121 const treeData = cloneData.filter(father => {
139   - let branchArr = cloneData.filter(child => {
  122 + const branchArr = cloneData.filter(child => {
140 123 //返回每一项的子级数组
141 124 return father[id] === child[parentId]
142 125 });
143   - branchArr.length > 0 ? father.children = branchArr : '';
  126 + branchArr.length && (father.children = branchArr);
144 127 //返回第一层
145 128 return father[parentId] === rootId;
146 129 });
147   - return treeData != '' ? treeData : data;
  130 + return treeData !== '' ? treeData : data;
148 131 }
149 132  
... ...