| | |
| | | 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') |
| | | }) |
| | | } |
| | | 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
|
| | | } |