Commit 959d9b39 by Sixong.Zhu

u

parent 70752c4d
Showing with 13 additions and 3 deletions
/* eslint-disable */ /* eslint-disable */
export function throttle(time: number = 100) { export function throttle(time: number = 100) {
let pending = false let pending = false
return function (target: any, name: string): any { return function(target: any, name: string): any {
const originFunc = target[name] const originFunc = target[name]
const newFunc = function (this: Vue, ...params: any[]) { const newFunc = function(this: Vue, ...params: any[]) {
if (pending) { if (pending) {
return return
} }
...@@ -22,7 +22,7 @@ export function throttle(time: number = 100) { ...@@ -22,7 +22,7 @@ export function throttle(time: number = 100) {
} }
export function unique<T>(arr: T[], existed: (item: T, all: T[]) => number) { export function unique<T>(arr: T[], existed: (item: T, all: T[]) => number) {
return arr.filter(function (item, index, arr) { return arr.filter(function(item, index, arr) {
return index === existed(item, arr) return index === existed(item, arr)
}) })
} }
...@@ -62,10 +62,20 @@ const URL_REGEX = ...@@ -62,10 +62,20 @@ const URL_REGEX =
const LINE_URL_REGEX = const LINE_URL_REGEX =
/((?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/i /((?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#\/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#\/%=~_|$?!:,.]*\)|[A-Z0-9+&@#\/%=~_|$]))/i
const mobile_reg = /(1[0-9_]{8,14})/ig
export function replaceText2Link(text: string) { export function replaceText2Link(text: string) {
return text.replace(URL_REGEX, '<a href="$1" target="_blank">$1</a>') return text.replace(URL_REGEX, '<a href="$1" target="_blank">$1</a>')
} }
export function replaceText2Dom(text: string, className: string) {
return text.replace(URL_REGEX, `<span class="${className}">$1</span>`)
}
export function replacePhone2Dom(text: string, className: string) {
return text.replace(mobile_reg, `<a href="tel:$1" class="${className}">$1</a>`)
}
export function isUrl(text: string) { export function isUrl(text: string) {
return LINE_URL_REGEX.test(text) return LINE_URL_REGEX.test(text)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment