6
jinlin
2023-11-30 ae68db0801b89aa31c4a4d4e506a68c641da97b3
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
import http from '../../packages/utils/request'
 
function getShowColumns(pageUrl, pageCode, table, showColList, defaultShowConfig) {
  http.get(`defaultShowConfig/getDefaultShowConfig?pageName=${pageUrl}&pageCode=${pageCode}`)
    .then(res => {
        let userShowConfig = res.data
        console.log(userShowConfig, 'userShowConfig userShowConfig')
        // 页面名字  pagecode 用户Id 列名 中文名 是否显示
        table.forEach(obj => {
          if (obj.label !== undefined && obj.prop !== undefined) {
            let itemDefaultShow = eval('defaultShowConfig.' + obj.prop)
            itemDefaultShow = itemDefaultShow === undefined ? true : itemDefaultShow
            let showField = itemDefaultShow
            if (showField && userShowConfig !== undefined) {
              let dbStatus = eval('userShowConfig.' + obj.prop)
              if (dbStatus === false) {
                showField = false
              }
            }
            if (itemDefaultShow == 'debugging') {
              showField = true
            }
            showColList.push({label: obj.label, prop: obj.prop, isShow: showField, solidShow: itemDefaultShow})
          }
        })
        console.log(showColList, 'showColList showColList')
      }
    )
}
 
const S4 = function () {
  return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
}
 
function guid() {
  return (S4() + S4() + '-' + S4() + '-' + S4() + '-' + S4() + '-' + S4() + S4() + S4());
}
 
function getCurrentSkin() {
  let skin = 'light'
  let aaa = document.querySelectorAll('.zt')
  for (let i = 0; i < aaa.length; i++) {
    if (aaa[i].classList.contains('high')) {
      skin = 'high'
      break
    }
  }
  return skin;
}
 
export function isStringContain(all, searchs) {
  return isArrContain(all.split(','), searchs.split(','));
}
 
function isArrContain(all, searchs) {
  let result = false
  searchs.forEach((item) => {
    if (all.indexOf(item) > -1) {
      result = true;
      return
    }
  })
  return result;
}
 
function isJSON(str) {
  if (typeof str == 'string') {
    try {
      var obj = JSON.parse(str);
      if (typeof obj == 'object' && obj) {
        return true;
      } else {
        return false;
      }
 
    } catch (e) {
      console.log('error:' + str + '!!!' + e);
      return false;
    }
  }
  console.log('It is not a string!')
}
 
function removeCurrentTabHandle(that) {
  removeTabHandle(that)
}
 
function formatDate(value) {
  var date = new Date(value);
  var y = date.getFullYear(),
    m = date.getMonth() + 1,
    d = date.getDate(),
    h = date.getHours(),
    i = date.getMinutes(),
    s = date.getSeconds();
  if (m < 10) {
    m = '0' + m;
  }
  if (d < 10) {
    d = '0' + d;
  }
  if (h < 10) {
    h = '0' + h;
  }
  if (i < 10) {
    i = '0' + i;
  }
  if (s < 10) {
    s = '0' + s;
  }
  var t = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
  return t;
}
 
function getYearMonDay(date){
  const dateObject = new Date(date);
  let year = dateObject.getFullYear();
  let month = dateObject.getMonth() + 1;
  let day = dateObject.getDate();
  return {year,month,day}
}
// tabs, 删除tab
function removeTabHandle(that) {
  let tabName = that.$route.name
  if (tabName === 'home') {
    return false
  }
  that.$store.state.contentTabs = that.$store.state.contentTabs.filter(item => item.name !== tabName)
  if (that.$store.state.contentTabs.length <= 0) {
    that.$store.state.sidebarMenuActiveName = that.$store.state.contentTabsActiveName = 'home'
    return false
  }
  // 当前选中tab被删除
  if (tabName === that.$store.state.contentTabsActiveName) {
    let tab = that.$store.state.contentTabs[that.$store.state.contentTabs.length - 1]
    that.$router.push({
      name: tab.name,
      params: {...tab.params},
      query: {...tab.query}
    })
  }
}
 
function formatDate2(date, fmt) {
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
  }
  let o = {
    'M+': date.getMonth() + 1,
    'd+': date.getDate(),
    'h+': date.getHours(),
    'm+': date.getMinutes(),
    's+': date.getSeconds()
  };
  for (let k in o) {
    if (new RegExp(`(${k})`).test(fmt)) {
      let str = o[k] + '';
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str));
    }
  }
  return fmt;
}
 
function padLeftZero(str) {
  return ('00' + str).substr(str.length);
}
 
function setHartBeat(intervalm, timeoutm) {
  if (intervalm == null) {
    intervalm = 10
  }
  let timer = window.setInterval(getHartBeat, intervalm * 60 * 1000)
  if (timeoutm != null) {
    window.setTimeout(function () {
      window.clearInterval(timer)
    }, timeoutm * 60 * 1000);
  }
  return timer;
}
 
function getHartBeat() {
  http.get(`sys/common/heartBeat`)
  if (res.success) {
  }
}
 
export {
  guid,
  getCurrentSkin,
  isJSON,
  removeCurrentTabHandle,
  formatDate,
  formatDate2,
  getShowColumns,
  setHartBeat,
  getYearMonDay
}