Commit c5690c87 by 前端

下载公共方法加上时间戳参数

1 parent 61f9a48b
// import Vue from 'vue'
import { Message, MessageBox, Loading } from "element-ui"
import { Message, MessageBox, Loading } from 'element-ui'
// import moment from 'moment'
import dayjs from "dayjs"
let loadingInstance = ""
import dayjs from 'dayjs'
let loadingInstance = ''
export const Util = {
/**
......@@ -16,20 +16,20 @@ export const Util = {
* confirmButtonColor 确认按钮颜色
* cancelButtonColor 取消按钮颜色
*/
msg: function (options) {
msg: function(options) {
MessageBox({
title: options.title || "",
type: options.type || "error",
message: options.message || "",
className: options.className || "",
title: options.title || '',
type: options.type || 'error',
message: options.message || '',
className: options.className || '',
showCancelButton: options.showCancelButton || false,
confirmButtonText: options.confirmButtonText || "确认",
cancelButtonText: options.cancelButtonText || "取消",
confirmButtonColor: options.confirmButtonColor || "#1989fa",
cancelButtonColor: options.cancelButtonColor || "#000",
confirmButtonText: options.confirmButtonText || '确认',
cancelButtonText: options.cancelButtonText || '取消',
confirmButtonColor: options.confirmButtonColor || '#1989fa',
cancelButtonColor: options.cancelButtonColor || '#000',
dangerouslyUseHTMLString: true,
callback: function (action, done) {
if (action == "confirm") {
callback: function(action, done) {
if (action == 'confirm') {
if (options.success) {
options.success(done)
}
......@@ -55,56 +55,55 @@ export const Util = {
/**
* 提示框
*/
Info: function (options) {
Info: function(options) {
Message({
message: options.message || "提示",
type: options.type || "error",
message: options.message || '提示',
type: options.type || 'error',
duration: options.time || 2000,
onClose: options.onClose || ""
onClose: options.onClose || ''
})
},
/**
* 轻提示
*/
Tips: function (options) {
Tips: function(options) {
Message({
message: options.message || "提示",
message: options.message || '提示',
duration: options.duration || 3000,
type: options.type || "text",
icon: options.icon || ""
type: options.type || 'text',
icon: options.icon || ''
})
},
/**
* loading
*/
loading: function (message) {
loading: function(message) {
loadingInstance = Loading.service({
text: message || "加载中..."
text: message || '加载中...'
})
},
/**
* 关闭loading
*/
closeLoading: function () {
closeLoading: function() {
loadingInstance.close()
},
/**
* 校验手机号码格式
*/
checkPhone: function (mobile) {
const myreg =
/^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
checkPhone: function(mobile) {
const myreg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/
return myreg.test(mobile)
},
/**
* 校验固定电话
*/
validationTel: function (tel) {
validationTel: function(tel) {
const reg = /^0[\d]{2,3}-[\d]{7,8}$/
return reg.test(tel)
},
......@@ -112,17 +111,15 @@ export const Util = {
/**
* 是否特殊字符
*/
isSpecialLetter: function (str) {
const reg = new RegExp(
"[`~!@#$^&*=|{}':;',\\[\\]<>?~!@#¥……&*——|{}【】‘;:”“'。,、? ]"
)
isSpecialLetter: function(str) {
const reg = new RegExp("[`~!@#$^&*=|{}':;',\\[\\]<>?~!@#¥……&*——|{}【】‘;:”“'。,、? ]")
return reg.test(str)
},
/**
* 只能输入英文字母和数字,不能输入中文
*/
validationInput: function (str) {
validationInput: function(str) {
const reg = /[^\w\.\/]/gi // eslint-disable-line
return reg.test(str)
},
......@@ -130,29 +127,27 @@ export const Util = {
/**
* 获取当前时间
*/
getCurrentDate: function () {
getCurrentDate: function() {
const time = new Date()
const y = time.getFullYear()
const m = time.getMonth() + 1
const d = time.getDate()
return {
date: y + "/" + m + "/" + d
date: y + '/' + m + '/' + d
}
},
/**
* 获取浏览器参数
*/
getUrlParams: function (name) {
getUrlParams: function(name) {
const vars = []
let hash
const oParams = {}
const hashes = window.location.href
.slice(window.location.href.indexOf("?") + 1)
.split("&")
const hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')
for (let i = 0; i < hashes.length; i++) {
hash = hashes[i].split("=")
hash = hashes[i].split('=')
vars.push(hash[0])
oParams[hash[0]] = hash[1]
}
......@@ -167,7 +162,7 @@ export const Util = {
/**
* 根据当前时间,计算往后30天的日期
*/
getAfterDate: function (day) {
getAfterDate: function(day) {
const date1 = new Date()
const date2 = new Date(date1)
let time = 30
......@@ -176,8 +171,7 @@ export const Util = {
}
date2.setDate(date1.getDate() + time)
const _date =
date2.getFullYear() + "-" + (date2.getMonth() + 1) + "-" + date2.getDate()
const _date = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate()
return {
date: _date,
......@@ -190,8 +184,8 @@ export const Util = {
/**
* 日期格式转换
*/
dateFormate: function (str, type) {
let txt = "YYYY-MM-DD"
dateFormate: function(str, type) {
let txt = 'YYYY-MM-DD'
if (type) {
txt = type
}
......@@ -202,9 +196,9 @@ export const Util = {
/**
* 字段截取
*/
cutStr: function (str, num) {
cutStr: function(str, num) {
if (!str) {
return ""
return ''
}
let m = 10
......@@ -213,7 +207,7 @@ export const Util = {
m = num
}
if (str.length > m) {
n = str.slice(0, m) + "..."
n = str.slice(0, m) + '...'
}
return n
......@@ -225,8 +219,8 @@ export const Util = {
// * console.log(bar===foo) false
// * @param {*} obj
// */
deepClone: function (obj) {
const clone = require("rfdc")({ proto: false, circles: false })
deepClone: function(obj) {
const clone = require('rfdc')({ proto: false, circles: false })
return clone(obj)
},
// deepClone: function (obj) {
......@@ -257,12 +251,12 @@ export const Util = {
* url下载文件
*
*/
downLoadFile: function (url) {
downLoadFile: function(url) {
// console.log(row)
// return
const Temp = document.createElement("a")
const Temp = document.createElement('a')
// Temp.href = process.env.VUE_APP_BASE_URL + '/article/export.do?articleId=' + row.id
Temp.href = url
Temp.href = url + '?timestamp=' + new Date().getTime()
// console.log(url)
// console.log(Temp.href)
document.body.append(Temp)
......@@ -275,8 +269,8 @@ export const Util = {
* @param {Object} type: 默认不传 ==>全部小写;传1 ==>全部大写;传2 ==>首字母大写
* 将json的key值进行大小写转换
*/
jsonKeysToCase: function (json, type) {
if (typeof json == "object") {
jsonKeysToCase: function(json, type) {
if (typeof json == 'object') {
var tempJson = JSON.parse(JSON.stringify(json))
toCase(tempJson)
return tempJson
......@@ -285,15 +279,15 @@ export const Util = {
}
function toCase(json) {
if (typeof json == "object") {
if (typeof json == 'object') {
if (Array.isArray(json)) {
json.forEach(function (item) {
json.forEach(function(item) {
toCase(item)
})
} else {
for (var key in json) {
var item = json[key]
if (typeof item == "object") {
if (typeof item == 'object') {
toCase(item)
}
delete json[key]
......@@ -304,10 +298,7 @@ export const Util = {
break
case 2:
// key值首字母大写,其余小写
json[
key.substring(0, 1).toLocaleUpperCase() +
key.substring(1).toLocaleLowerCase()
] = item
json[key.substring(0, 1).toLocaleUpperCase() + key.substring(1).toLocaleLowerCase()] = item
break
default:
// 默认key值全部小写
......@@ -321,21 +312,21 @@ export const Util = {
},
// 判断字段为空时显示
fieldShow: function (field, show) {
fieldShow: function(field, show) {
return field || show
},
// 整数补零显示两位小数
returnFloat: function (num) {
returnFloat: function(num) {
num = num.toString()
if (num.indexOf(".") != -1) {
let newVal = num.split(".")
if (num.indexOf('.') != -1) {
let newVal = num.split('.')
if (newVal[1].length == 1) {
newVal = newVal.join(".")
newVal += "0"
newVal = newVal.join('.')
newVal += '0'
num = newVal
}
} else {
num += ".00"
num += '.00'
}
return num
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!