Commit c5690c87 by 前端

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

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