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
// import {getStore, setStore} from '@/util/store'
 
// import {getDictionary} from '@/api/system/dict'
let screenSizes = {
  w: window.screen.width,
  h: window.screen.height
};
let innerWH = {
  innerWidth: window.innerWidth,
  innerHeight: window.innerHeight
};
const control = {
  state: {
    clearOtherBut: {
      refreshBtn: false,
      columnBtn: false,
      searchShowBtn: false,
      filterBtn: false,
      // addBtn: false,
      // editBtn: false,
      // viewBtn: false,
      // delBtn: false,
      searchIndex: 6, //收缩展示数量
      searchIcon: true, //搜索是否收缩
      height: window.screen.height //初始高度
    },
    changePageSize: {
      pageSize: 15,
      currentPage: 1,
      total: 0,
      pageSizes: [15, 30, 50, 100]
    },
    windowWidth: innerWH.innerWidth,
    windowHeight: innerWH.innerHeight,
    tableWindowHeight: innerWH.innerHeight,
    heightTimesOut: "",
    table_height: "",
    butState: "",
    oldOpens: "",
    screenSize: screenSizes.w <= 1366 && screenSizes.h <= 768,
    screenHeight: 1000,
 
    searchOpen: {
      searchIndex: 6, //收缩展示数量
      searchIcon: true, //搜索是否收缩
      height: window.screen.height //初始高度
    },
    changeMenuSize: true //是否开启切换菜单
  },
  actions: {
    WHchangeHight({
      state,
      commit
    }, data) {
      if (data.fn) {
        if (!state.heightTimesOut) {
          data.fn(state.windowHeight);
        } else {
          state.heightTimesOut = setTimeout(() => {
            clearTimeout(state.heightTimesOut);
            state.heightTimesOut = "";
            data.fn(state.windowHeight);
          }, 500);
        }
      }
    },
 
    TABLE_CHANGEBUTPOSITION({
      state,
      commit,
      dispatch
    }, data) {
      let table = document.getElementsByClassName("tablesss")[0];
      let heard = table.getElementsByClassName("avue-crud__search")[0]; //获取搜索的长度
      let buts = table.getElementsByClassName("avue-form__menu--center")[0];
      let Open = buts.getElementsByClassName("el-button--text")[0];
      let butsheight = heard.clientHeight;
      let other = data.otherclass || [];
      // buts.style.transition = "all 0.1s";
      if (buts) {
        buts.style.top = butsheight - 3 + "px";
      }
      if (other && state.windowWidth >= 1024) {
        for (let k in other) {
          let otherbuts = document.getElementsByClassName(other[k])[0];
          // otherbuts.style.transition = "all 0.1s";
          if (otherbuts) {
            otherbuts.style.top = butsheight + 26 + "px";
          }
        }
      }
      // Open.style.transition = "all 0.1s";
      // Open.style.top = -(butsheight + 4) + "px";
      // 添加事件
      if (Open) {
        Open.style.top = (state.screenSize ? 125 : 140) + "px";
        Open.onclick = function (e) {
          // changedom(e.srcElement.innerText);
          //固定高度
          //调用改变高度
          if (e.srcElement.innerText == "展 开") {
            state.tableWindowHeight += 1;
          } else {
            state.tableWindowHeight -= 1;
          }
          // commit("setButOpens", e.srcElement.innerText);
        };
      }
    },
    TABLE_CHANGEHEIGHT({
      state,
      commit
    }, data) {
      let h = +state.windowHeight - (+data.searchHeight + +data.flowHeight);
      console.log(h);
      state.table_height = h;
      // commit("settable_height", h);
    },
    changeZoom({
      state,
      commit,
      dispatch
    }, data) {
      if (window.innerWidth <= 1396 && window.innerHeight <= 798) {
        // var devicewidth = document.documentElement.clientWidth; //获取当前分辨率下的可是区域宽度
        // console.log(devicewidth)
        let devicewidth = 1143;
        var scale = devicewidth / 1366; // 分母——设计稿的尺寸
        document.body.style.zoom = scale; //放大缩小相应倍数
        // console.log("应用1366*768")
      } else {
        if (document.body.style.zoom != 1) {
          document.body.style.zoom = 1;
          // console.log("还原缩放")
        }
      }
      // return;
      let usheight = 0;
      //监听可视高度
      Object.defineProperty(state, "tableWindowHeight", {
        set: function (key, value) {
          //   //此处拦截了设置请求
          // window.console.log(key, value, "tableWindowHeight");
          usheight = key;
          let d = {
            fn: function (h) {
              let doit = (height, val) => {
                let table = document.getElementsByClassName("tablesss");
                // console.log(table[0]);
                if (table[0]) {
                  //有需要调整的表格
                  let heard = table[0].getElementsByClassName(
                    "avue-crud__search"
                  );
                  let tip = document.getElementsByClassName("avue-crud__tip")[0];
                  let usNum = state.screenSize ? 125 : 262;
                  if (!tip) {
                    // console.log("没有tip")
                    usNum = usNum - 50;
                  }
                  let pagination = document.getElementsByClassName("avue-crud__pagination")[0];
                  if (!pagination) {
                    // console.log("没有分页")
                    usNum = usNum - 45;
                  }
                  let nav_scroll = document.getElementsByClassName("el-tabs__nav-scroll");
                  if (nav_scroll[1]) {
                    // console.log("有额外标签栏")
                    usNum = usNum + 55;
                  }
                  let smileTableFromSize = document.getElementsByClassName("smileTableFromSize");
                  // console.log(smileTableFromSize)
                  if (smileTableFromSize[0]) {
                    usNum = usNum + (state.screenSize ? 23 : 16);
                  }
                  let tablesssInSmail = document.getElementsByClassName("tablesssInSmail");
                  if (tablesssInSmail[0]) {
                    usNum = usNum + 20;
                  }
                  let hs = height || h;
                  let overHeight = +hs - (+heard[0].clientHeight + +usNum);
                  // console.log(overHeight, heard[0].clientHeight, usNum);
                  let fromDom = document.getElementsByClassName(
                    "el-table--fit"
                  );
                  if (fromDom) {
                    let ifsize = fromDom.length;
                    // console.log("页面表格数量:", ifsize)
                    for (let ifrom = 0; ifrom < ifsize; ifrom++) {
                      // fromDom[ifrom].style.transition = "height 0.1s";
                      fromDom[ifrom].style.maxHeight = overHeight + "px";
                      fromDom[ifrom].style.height = overHeight + "px";
                    }
                  }
                  let d = {
                    otherclass: ["downSFZ"],
                    haveOpen: true
                  };
                  dispatch("TABLE_CHANGEBUTPOSITION", d);
                  //判断是否有左侧选择dom
                  let chouse = document.getElementsByClassName(
                    "changeBoxs"
                  );
                  if (chouse[0]) {
                    let bodys = chouse[0].getElementsByClassName(
                      "el-scrollbar__view"
                    )[1];
 
                    // bodys.style.overflow = "hidden scroll";
                    bodys.style.height = height - (state.screenSize ? 75 : 200) + "px";
                    // height: 500px;
                    // overflow: ;
                  }
                }
                return;
              };
              // if (that.onceTableChange == 1) {
              //   //解决第一次未渲染成功会报错的问题
              //   that.onceTableChange++;
              //   console.log(that.onceTableChange);
              //   commit("checkDomHeight", {
              //     domName: "getElementsByClassName",
              //     name: "el-table--fit",
              //     fn: function() {
              //       that.$nextTick(() => {
              //         setTimeout(() => {
              // doit(window.innerHeight, "once");
              //         }, 200);
              //       });
              //     }
              //   });
              // } else {
              doit(window.innerHeight);
              // }
            }
          };
          dispatch("WHchangeHight", d);
          return
          // tablesss
          // class="tablesss"
          let a = {
            ...this.$store.state.control.changePageSize,
            ...this.$store.state.control.clearOtherBut,
          }
 
          // :class="[
          //   $store.state.control.screenSize == 1366
          //     ? 'smallSize'
          //     : 'normalSize',
          //   $store.state.control.windowWidth >= 1024 ? 'tooRowSearch1' : '',
          // ]"
          $store.state.control.screenSize == 1366 ? 'smallSize' : 'normalSize',
            $store.state.control.windowWidth >= 1024 ? 'tooRowSearch1' : '',
 
            // searchIndex: 6, //收缩展示数量
            // searchIcon: true, //搜索是否收缩
            // ...this.$store.state.control.searchOpen,
            // height: "auto",
            // 初始化位置, 放入mounted, 以及放入onload的获取数据后
            this.$store.commit("setWindowSizeHeightAdd");
          // mounted() {
          //   this.$store.commit("setWindowSizeHeightAdd");
          // },
        },
        get: function () {
          // console.log('get!', usheight);
          return usheight;
        }
      });
    },
    MOUNTED_TABLE_SIZE({
      state,
      commit,
      dispatch
    }, data) {
      let d = {
        otherclass: ["downSFZ"],
        haveOpen: true,
        from: "mounted"
      };
      // 开始就适应高度
      commit("setWindowSizeHeightAdd");
      // dispatch("TABLE_CHANGEBUTPOSITION", d);
    }
  },
  mutations: {
    setWindowSize: (state, data) => {
      state.windowWidth = data.innerWidth;
      state.windowHeight = data.innerHeight;
      // console.log(state.windowWidth, "state.windowHeight")
      // console.log(state.windowHeight, "state.windowHeight")
    },
    setWindowSizeHeight: (state, data) => {
      state.tableWindowHeight = data;
      // console.log(state.tableWindowHeight, "state.tableWindowHeight")
    },
    setWindowSizeHeightAdd: (state, data) => {
      setTimeout(() => {
        state.tableWindowHeight += 1;
      }, 0);
    },
    setButOpens(state, data) {
      state.butState = data;
    },
    setOldOpens(state, data) {
      state.oldOpens = data;
      state.oldOpens = data;
    },
    setScreenSize(state, data) {
      state.screenSize = data.w <= 1366 && data.h <= 768 ? 1366 : false;
      state.screenHeight = data.h;
    },
    checkDomHeight(state, data) {
      //  声明定时器
      var timer = null;
      //  检查dom是否执行完成
      function checkDom() {
        let dom = document[data.domName](data.name);
        console.log(dom[0].style.height, "height");
        if (dom[0].style.height) {
          //  执行dom加载完成后的操作
          //  清除定时器
          if (!timer) {
            clearTimeout(timer);
          }
          if (data.fn) {
            //回调函数
            data.fn(dom);
            return;
          } else {
            return dom;
          }
        } else {
          //  自我调用
          timer = setTimeout(checkDom, 200);
        }
      }
      //  首次执行
      checkDom();
    }
  }
};
 
export default control;