xinyb
2024-07-01 41485264ec9de48ffde1e506b897962e20c8440e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// 生成左侧navList菜单
function createNavListDom(navListData) {
  // console.log('待渲染的菜单navListData',navListData);
  var domStr = '<ul class="group" >';
  var str = '<li class="group-node active">' +
    '<div class="group-node-title">' +
    '<span class="group-node-name">' + navListData.groupName|| '' + '</span><i></i>' +
    '</div>' +
    '<ul class="group-data-ul">';
  navListData.groupData.forEach(function (item) {
    var isShowClassName = item.visible ? 'isHide' : '';
    var isShow = item.visible;
    var isVueGrid = navListData.grid ? 'vue-table ' : 'vue-grid ';
    if (navListData.grid){
      isShowClassName = item.showOnGrid ? 'isHide' : '';
      isShow = item.showOnGrid;
    }
 
    str += '<li class="nav-node '+isVueGrid + isShowClassName +'" draggable="true" data-value="'+ item.value +'" data-id="'+ item.layoutId +'_'+ item.id + '" data-layout-ul-id="'+ navListData.layoutId + '" data-layout-li-id="'+ item.layoutId + '" data-grid-index="'+ item.gridIndex+ '" data-layout-index="'+ item.layoutIndex+ '" data-name="'+ item.name +'" data-visible="'+ isShow +'">' +
      '<div class="nav-node-content text-no-wrap ">' +
      '<span class="nav-node-name ">' + item.name + '</span>' +
      '</div>' +
      '</li>';
  });
  domStr += str + '</ul></li>';
 
  $('.nav-list-container').html(domStr);
  addNavDragInVueGridEvent();
}
 
// 为左侧菜单添加拖拽进入vueGrid组件事件
function addNavDragInVueGridEvent() {
  var navItem = document.querySelectorAll('.nav-node.vue-grid');
 
  for (var i = 0; i < navItem.length; i++) {
    navItem[i].addEventListener('dragstart', function (e) {
      e.target.className = 'nav-node vue-grid dragging';
    });
    navItem[i].addEventListener('drag', throttle(function (e){
      dragToVueGridStart(e);
      // debounce(dragToVueGridStartFn(e),1000)
    },16));
    // navItem[i].addEventListener('drag', function (e){
    //   dragToVueGridStart(e);
    //   // debounce(dragToVueGridStartFn(e),1000)
    // });
    navItem[i].addEventListener('dragend', function (e) {
      // console.log(e.target.dataset.name, e.target.dataset.id);
      dragToVueGridEnd(this,e.target.dataset);
    });
  }
}
 
 
// 防抖函数
function debounce(fn, delay = 1500) {
  let timer = null;
  return function () {
    if (timer) {
      clearTimeout(timer);
    }
 
    timer = setTimeout(()=> {
      // console.log(this); // nodejs global对象、浏览器 window对象
      //fn();
      fn.apply(this,arguments);
      timer = null;
    }, delay)
  }
}
 
// 节流函数
function throttle (fn,delay=100){
  let timer = null
  return ()=>{
    if (timer){return}
    timer = setTimeout(() => {
      fn.apply(this,arguments)
      timer = null
    }, delay);
  }
}
 
function initTab(data){
  layui.use(function(){
    var element = layui.element;
    var $ = layui.$;
    element.render('tab', 'filter-tab');
  });
}
 
// function getResultData(layoutsData){
//   let resultList = [];
//   layoutsData.map((item,index)=>{
//     item.map((item2,index2)=>{
//       item2.map((item3,index3)=>{
//         item3.data.map((item4,index4)=>{
//           if (!item4.userCode||!item4.formId) return;
//           resultList.push({
//             "userCode": item4.userCode,
//             "formId": item4.formId,
//             "formType": item4.formType,
//             "headFlag": item4.headFlag,
//             "fieldId": item4.id,
//             "statisId": (index4+1)*10,
//             "fieldName": item4.name,
//             "dataType": item4.dataType,
//             "dataTypeLength": item4.dataTypeLength,
//             "showOnGrid": item4.showOnGrid,
//             "gridCaption": item4.gridCaption,
//             "visible": item4.visible,
//             "hideLabel": item4.hideLabel,
//             "colNo": item4.x<=0?1:item4.x+1,
//             "rowNo": item4.y<=0?1:item4.y+1,
//             "lengthNum": item4.w,
//             "heightNum": item4.h,
//             "masterFieldShowLocation": item4.masterFieldShowLocation,
//           })
//         })
//       })
//     })
//   })
//   return resultList;
// }
function getResultData(layoutsData){
  console.log('layoutsData原始',layoutsData);
  let resultList = [];
  layoutsData.map((item,index)=>{
    item.map((item2,index2)=>{
      item2.map((item3,index3)=>{
        if (item3.filedName==='master'||item3.filedName==='master1'){
          // 对item3.data进行遍历,按item4的x,y顺序,按从小到大排列顺序
          item3.data.sort((a,b)=>{
            // 首先比较y值,如果相等则比较x值
            if(a.y>b.y) return 1;
            if(a.y<b.y) return -1;
            if (a.x>b.x) return 1;
            if (a.x<b.x) return -1;
            // 相等则返回0
            return 0;
          })
          // console.log('排列后',item3.data);
          // console.table(JSON.parse(JSON.stringify(item3.data)));
        }
        item3.data.map((item4,index4)=>{
          if (!item4.userCode||!item4.formId) return;
          resultList.push({
            "userCode": item4.userCode,
            "formId": item4.formId,
            "formType": item4.formType,
            "headFlag": item4.headFlag,
            "fieldId": item4.id,
            "statisId": (index4+1)*10,
            "fieldName": item4.name,
            "dataType": item4.dataType,
            "dataTypeLength": item4.dataTypeLength,
            "showOnGrid": item4.showOnGrid,
            "gridCaption": item4.gridCaption,
            "visible": item4.visible,
            "hideLabel": item4.hideLabel,
            "colNo": item4.x<=0?1:item4.x+1,
            "rowNo": item4.y<=0?1:item4.y+1,
            "lengthNum": item4.w,
            "heightNum": item4.h,
            "masterFieldShowLocation": item4.masterFieldShowLocation,
          })
        })
      })
    })
  })
  return resultList;
}
 
function getResultFormId(layoutsData){
  let array=[];
  let json = {};
  layoutsData.map((item, index) => {
    item.map((item2, index2) => {
      item2.map((item3, index3) => {
        item3.data.map((item4, index4) => {
          if (!item4.userCode || !item4.formId) return;
          // if (formIds.indexOf(item4.formId) === -1) {
            json.formId=item4.formId;
            json.formType=item4.formType;
            array.push(json);
          // }
        })
      })
    })
  })
  return array;
}
function handleResData(resData,navListData) {
  // 布局内容数据
  var layoutData = [];
 
  var resItemArr = [];
 
  for (const resItem in resData){
    if (resData.hasOwnProperty(resItem)){
      resItemArr.push(resData[resItem]);
      tabsIndex.push(0);
    }
  }
  // console.log('resItemArr',resItemArr);
  var gridSum = -1; // 网格布局总数
  var layoutSum = -1; // 布局总数
  resItemArr.forEach(function (resItem,resIndex) {
    // console.log('resItem',resItem);
    var navItem = {};
    var layoutItem = {};
    var navItemData = [];
    var layoutItemData = [];
    var layoutRows = [];
    var navRows = [];
    var layoutId1 = resIndex; // 定位第一层0,20,30,40,50
    var layoutId2 = ''; // 定位第二层tab标签
    var layoutId3 = ''; // 定位第三层master,slave,master1
    var layoutId4 = ''; // 定位第四层data数据
    // var gridSum = 0; // 
 
    // 遍历0,20,30,40,50这些数据
    resItem.forEach(function (formItem,formIndex) {
      layoutId2 = layoutId1+'_'+formIndex;
 
      layoutItemData = [];
      navItemData = [];
      var formListFiledName = ['master','slave','master1'];
      // 遍历master,slave,master1这些数据
      var filedIndex1 = 0;
      formListFiledName.forEach(function (filedName,filedIndex) {
        // layoutId2 = layoutId1+'_'+filedIndex;
 
        navItem = {
          groupName: formItem.formName,
          filedName: '',
          groupData:[]
        }
        layoutItem = {
          name: formItem.formName,
          filedName: '',
          data:[]
        }
        // 
        var masterList = formItem[filedName].list;
        var masterData = formItem[filedName].data;
        // console.log('masterData',masterData);
        // console.log('masterData',masterData);
        // navItem.filedName = filedName;
        // navItem[filedName] = [];
        if (masterList.length<=0) {
          return;
        };
        layoutId3 = layoutId2+'_'+filedName+','+filedIndex1+','+filedIndex;
        filedIndex1++;
        // console.log('------masterList.length',masterList.length);
        navItem.filedName = filedName;
        navItem.layoutId = layoutId3;
        navItem.grid = formItem[filedName].grid;
 
        layoutItem.filedName = filedName;
        layoutItem.grid = formItem[filedName].grid;
        if (!layoutItem.grid){
          gridSum ++;
        }
        layoutSum++;
        layoutItem.gridIndex=gridSum;
        navItem.gridIndex=gridSum;
        layoutItem.layoutIndex=layoutSum;
        navItem.layoutIndex=layoutSum;
        // console.log('<<<<>>>>layoutItem.gridIndex',layoutItem.gridIndex);
        layoutItem.layoutId = layoutId3;
 
        //  遍历masterList
        masterList.forEach(function (masterItem,index) {
          // console.log('<<<<<masterItem.fieldId',masterItem.fieldId); 
          // console.log('>>>>data',masterData[masterItem.fieldId]);
          var fieldId = '';
          if (masterItem.fieldId!==''&&masterData&&masterData[masterItem.fieldId]!==''){
 
            fieldId = masterData[masterItem.fieldId];
            // console.log('<<<<<fieldId',index,masterItem.fieldId);
          }
          layoutId4 = layoutId3 + '_'+index;
 
          navItem.groupData.push({
            // fieldId: masterItem.fieldId,
            id: masterItem.fieldId,
            name: masterItem.fieldName,
            // x: masterItem.colNo<=0?0:masterItem.colNo-1,
            // y: masterItem.rowNo<=0?0:masterItem.rowNo-1,
            x: masterItem.visible?(masterItem.colNo<=0?0:masterItem.colNo-1):-100,
            y: masterItem.visible?(masterItem.rowNo<=0?0:masterItem.rowNo-1):-100,
            w: masterItem.lengthNum,
            h: masterItem.heightNum,
            i: layoutId4 + '_'+ masterItem.fieldId,
            isCheckbox: (masterItem.controlType===30||masterItem.controlType===32),
            value: fieldId,
            visible: masterItem.visible,
            showOnGrid: masterItem.showOnGrid,
            layoutId: layoutId4,
            gridIndex:gridSum,
            layoutIndex:layoutSum
          })
          layoutItem.data.push({
            id: masterItem.fieldId,
            name: masterItem.fieldName,
            // x: masterItem.colNo<=0?0:masterItem.colNo-1,
            // y: masterItem.rowNo<=0?0:masterItem.rowNo-1,
            x: masterItem.visible?(masterItem.colNo<=0?0:masterItem.colNo-1):-100,
            y: masterItem.visible?(masterItem.rowNo<=0?0:masterItem.rowNo-1):-100,
            w: masterItem.lengthNum,
            h: masterItem.heightNum,
            i: layoutId4 + '_'+ masterItem.fieldId,
            isCheckbox: (masterItem.controlType===30||masterItem.controlType===32),
            value:fieldId,
            visible: masterItem.visible,
            showOnGrid: masterItem.showOnGrid,
            layoutId: layoutId4,
            gridIndex:gridSum,
            layoutIndex:layoutSum,
            userCode: masterItem.userCode,
            formId: masterItem.formId,
            formType: masterItem.formType,
            headFlag: masterItem.headFlag,
            statisId: masterItem.statisId,
            dataType: masterItem.dataType,
            dataTypeLength: masterItem.dataTypeLength,
            gridCaption: masterItem.gridCaption,
            hideLabel: masterItem.hideLabel,
            masterFieldShowLocation: masterItem.masterFieldShowLocation,
          })
 
        })
        // navListData.push(navItem);
        navItemData.push(navItem);
        layoutItemData.push(layoutItem);
 
      })
      layoutRows.push(layoutItemData);
      navRows.push(navItemData);
 
    })
 
    navListData.push(navRows);
    layoutData.push(layoutRows);
  })
  // console.log('navListData',navListData);
  // console.log('layoutData',layoutData);
  return layoutData;
}
 
function getCurrentNavDataBackup(){
  // return JSON.parse(JSON.stringify(navListDataBackup[currentIndexGroup.tabLayoutIndex][currentIndexGroup.tabsIndex][currentIndexGroup.groupIndex]));
  return JSON.parse(JSON.stringify(navListDataBackup[currentIndexGroup.tabLayoutIndex][currentIndexGroup.tabsIndex][currentIndexGroup.groupIndex]));
}
function getCurrentLayoutDataBackup(){
  return JSON.parse(JSON.stringify(layoutsDataBackup[currentIndexGroup.tabLayoutIndex][currentIndexGroup.tabsIndex][currentIndexGroup.groupIndex]));
  // return layoutsDataBackup[currentIndexGroup.tabLayoutIndex][currentIndexGroup.tabsIndex][currentIndexGroup.groupIndex];
}