X 4 anni fa
parent
commit
fff859c858
4 ha cambiato i file con 126 aggiunte e 0 eliminazioni
  1. +32
    -0
      src/utils/clipboard.js
  2. +19
    -0
      src/utils/data.js
  3. +29
    -0
      src/utils/time.js
  4. +46
    -0
      src/utils/validate.js

+ 32
- 0
src/utils/clipboard.js Vedi File

@@ -0,0 +1,32 @@
import Vue from 'vue'
import Clipboard from 'clipboard'

function clipboardSuccess() {
Vue.prototype.$message({
message: 'Copy successfully',
type: 'success',
duration: 1500
})
}

function clipboardError() {
Vue.prototype.$message({
message: 'Copy failed',
type: 'error'
})
}

export default function handleClipboard(text, event) {
const clipboard = new Clipboard(event.target, {
text: () => text
})
clipboard.on('success', () => {
clipboardSuccess()
clipboard.destroy()
})
clipboard.on('error', () => {
clipboardError()
clipboard.destroy()
})
clipboard.onClick(event)
}

+ 19
- 0
src/utils/data.js Vedi File

@@ -0,0 +1,19 @@
/**
* post写法get传参
* @param obj
* @returns {string}
*/
export function postConvertGet(obj) {
let params = ''
if (obj === undefined) {
return params
} else if (JSON.stringify(obj) === '{}') {
return params
} else {
for (const [key, value] of Object.entries(obj)) {
params += `${key}=${value}&`
}
params = `?${params.slice(0, -1)}`
return params
}
}

+ 29
- 0
src/utils/time.js Vedi File

@@ -0,0 +1,29 @@

/**
* 时间戳格式化
* @param date
* @returns {string}
*/
export function timestamp2std(date) {
const addZero = num => num > 9 ? num : ('0' + num)
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()} ${addZero(date.getHours())}:${addZero(date.getMinutes())}:${addZero(date.getSeconds())}`
}

/**
* 时间戳格式化
* @param strtime
* @returns {number}
*/
export function Time2MSec(strtime) {
return (new Date(strtime)).getTime();
}

/**
* 时间戳格式化
* @param t
* @returns {number}
*/
export function Time2Sec(t) {
return Date.parse(new Date(t)) / 1000;
}


+ 46
- 0
src/utils/validate.js Vedi File

@@ -0,0 +1,46 @@
/*过滤数据*/


export function validPhone(str) {
return /^1[3456789]\d{9}$/.test(str)
}

/**
* @param {string} url
* @returns {Boolean}
*/
export function validURL(url) {
const reg = /^(https?|ftp):\/\/([a-zA-Z0-9.-]+(:[a-zA-Z0-9.&%$-]+)*@)*((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3}|([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(:[0-9]+)*(\/($|[a-zA-Z0-9.,?'\\+&%$#=~_-]+))*$/
return reg.test(url)
}

/**
* @param {string} email
* @returns {Boolean}
*/
export function validEmail(email) {
const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
return reg.test(email)
}

/**
* @param {string} str
* @returns {Boolean}
*/
export function isString(str) {
if (typeof str === 'string' || str instanceof String) {
return true
}
return false
}

/**
* @param {Array} arg
* @returns {Boolean}
*/
export function isArray(arg) {
if (typeof Array.isArray === 'undefined') {
return Object.prototype.toString.call(arg) === '[object Array]'
}
return Array.isArray(arg)
}

Caricamento…
Annulla
Salva