**
/* 合法uri */
**
export function validateURL(textval) {
const urlregex = /^(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 urlregex.test(textval)
}
* 获取文件相对于浏览器的地址
- @param {[type]} file [文件流]
- @return {[url]} [相对于浏览器的安全加密地址]
*/
export const getblobUrl = (file) => {
let url = ''
if (window.createObjcectURL !== undefined) {
url = window.createOjcectURL(file)
} else if (window.URL !== undefined) {
url = window.URL.createObjectURL(file)
} else if (window.webkitURL !== undefined) {
url = window.webkitURL.createObjectURL(file)
}
return url
}
* 格式化时间
- @param {[type]} time [description]
- @return {[type]} [description]
*/
export const formatDateTimeList = time => {
time = new Date(time)
let _hour = time.getHours()
let _minute = time.getMinutes()
let _second = time.getSeconds()
let _year = time.getFullYear()
let _month = time.getMonth()
let _date = time.getDate()
if (_hour < 10) {
_hour = '0' + _hour
}
if (_minute < 10) {
_minute = '0' + _minute
}
if (_second < 10) {
_second = '0' + _second
}
_month = _month + 1
if (_month < 10) {
_month = '0' + _month
}
if (_date < 10) {
_date = '0' + _date
}
return (
_year +
'-' +
_month +
'-' +
_date
)
}
* 截取时间
- @param {[type]} time [description]
- @return {[type]} [description]
*/
export const getViewTime = time => {
if(time){
return time.split(' ')[0]
}
return ''
}
*Android
function isAndroid() {
return /(?:android)/.test(window.navigator.userAgent.toLowerCase());
}
*移动端
function isWap() {
return !!window.navigator.userAgent
.toLowerCase()
.match(
/(phone|pad|pod|iphone|ipod|ios|ipad|android|mobile|blackberry|iemobile|mqqbrowser|juc|fennec|wosbrowser|browserng|webos|symbian|windows phone)/i
);
}
*app
function isApp() {
return !!window.navigator.userAgent
.toLowerCase()
.match(
/(csdn)/i
);
}
*拼接url
function setParamsList(params, isFirst = true) {
var paramsData = "";
for (var Key in params) {
if (typeof params[Key] != "function") {
paramsData += Key + "=" + (params[Key]||"") + "&";
}
}
paramsData = paramsData.substr(0, paramsData.length - 1);
return `${isFirst ? "?" : "&"}${paramsData}`;
}
|