unknown
2023-10-23 5672f352d0ba114e2ae96c8cefad6c74ae6d2934
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
import axios from 'axios'
import Vue from 'vue'
/**
 * 防抖函数
 */
 export const debounce = (fun, time) => {
    let timer = null
    return function() {
        if(timer) {
            clearTimeout(timer)
        }
        let args = arguments
        timer = setTimeout(() => {
            fun.apply(this, args)
        }, time)
    }
}
 
/**
 * 节流函数
 */
export const throttle = (fun, time) => {
    let strTime = 0
    return function() {
        let endTime = new Date()
        let args = arguments
        if(endTime - strTime > time) {
            strTime = endTime
            fun.apply(this, args)
        }
    }
}
 
/**
 * 动态切换组件尺寸
*/
export const changeSize = () => {
  // let size = ""
  // let viewWidth = document.documentElement.clientWidth
  // switch(true) {
  //   case viewWidth <= 1024:
  //     size = "mini"
  //     break;
  //   case viewWidth <= 1280:
  //     size = "small"
  //     break;
  //   case viewWidth <= 1600:
  //     size = "medium"
  //     break;
  //   default:
  //     size = ""
  // }
  // return size
    return 'small'
}
 
/**
 * 存入/更新cookie信息
 * name: cookie 名称
 * values: cookie 值
 * times: 过期时间
*/
export const setCookie = (name, values, times) => {
    let date = new Date();
    let params = JSON.stringify(values)
    date.setTime(date.getTime() + (times * 24 * 60 * 60 * 1000));
    document.cookie = `${name}=${params};expires=${date.toGMTString()}`;
}
 
/**
 * 获取cookie信息
 * name: 存入的cookie名
*/
export const getCookie = (name) => {
    let data = "";
    let list = document.cookie.split(';');
    list.forEach(item => {
        item = item.split('=')
        if(item[0].replace(/^\s+|\s+$/g,"") === name) {
            data = JSON.parse(item[item.length - 1])
        }
    })
    return data
}
 
/**
 * 处理时间戳
*/
export const changeTime = (time) => {
    const date = new Date(time);
    console.log(date,'---');
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    month = month > 9 ? month : `0${month}`;
    let day = date.getDate() > 9 ? date.getDate() : `0${date.getDate()}`;
    let hours = date.getHours() > 9 ? date.getHours() : `0${date.getHours()}`;
    let min = date.getMinutes() > 9 ? date.getMinutes() : `0${date.getMinutes()}`;
    let sec = date.getSeconds() > 9 ? date.getSeconds() : `0${date.getSeconds()}`;
    return `${year}-${month}-${day} ${hours}:${min}:${sec}`
}
 
/**
 * 下载文件公共方法
*/
 
export const downLoadFile = (data, url) => {
    let link = document.createElement("a")
    link.style.display = "none";
    link.href = `${process.env.VUE_APP_BASE_URL}${url}?authcode=${data}`;
    document.body.appendChild(link)
    link.click();
    URL.revokeObjectURL(link.href) // 释放URL 对象
}
 
export const downFiles = (data, fileName = 'downLoad', fileType) => {
    let url = URL.createObjectURL(new Blob([data]))
    let link = document.createElement("a")
    link.style.display = "none";
    link.href = url;
    link.setAttribute("download", `${fileName}.${fileType}`)
    document.body.appendChild(link)
    link.click();
    URL.revokeObjectURL(link.href) // 释放URL 对象
}
 
/**
 * 转二维码(blob流转地址)
 */
export const tranQr = (val) => {
    let imageUrl = '';
    Vue.prototype.$api.Print.getPrintPhone({num:val}).then(res=>{
        imageUrl = URL.createObjectURL(new Blob([res.data]));
    })
    return imageUrl
}
 
 
export const downLoadQR = (data, url) => {
    axios({
        method: 'get',
        url: `${process.env.VUE_APP_BASE_URL}${url}?num=${data}`,
        responseType: 'blob'
    }).then((res) => {
        downFiles(res.data, '二维码图片','png')
    })
    // let link = document.createElement("a")
    // link.style.display = "none";
    // link.href = ;
    // document.body.appendChild(link)
    // link.click();
    // URL.revokeObjectURL(link.href) // 释放URL 对象
 
    // link.href = `${process.env.VUE_APP_BASE_URL}${url}?num=${data}`;
    // link.setAttribute("download", '二维码图片.png')
    // document.body.appendChild(link)
    // link.click();
}
//通过扫描二维码跳转详情页面
export const downLoadQRDetails = (data,id,typePage, url) => {
    axios({
        method: 'get',
        url: `${process.env.VUE_APP_BASE_URL}${url}?num=${data}&bigDeviceId=${id}&type=${typePage}`,
        responseType: 'blob'
    }).then((res) => {
        downFiles(res.data, '二维码图片','png')
    })
}
 
/* Date原型添加format方法 */
Date.prototype.format = function (fmt) {
  fmt = fmt || 'yyyy-MM-dd'
  var o = {
    'M+': this.getMonth() + 1, //月份
    'd+': this.getDate(), //日
    'h+': this.getHours(), //小时
    'm+': this.getMinutes(), //分
    's+': this.getSeconds(), //秒
    'q+': Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds() //毫秒
  }
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(
      RegExp.$1,
      (this.getFullYear() + '').substr(4 - RegExp.$1.length)
    )
  }
  for (var k in o) {
    if (new RegExp('(' + k + ')').test(fmt)) {
      fmt = fmt.replace(
        RegExp.$1,
        RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
      )
    }
  }
  return fmt
}