/** * 获取顶部地址栏地址 */ export const getTopUrl = () => { return window.location.href.split("/#/")[0]; } // 解析参数 export const bjectToQueryString = (obj) => { return Object.keys(obj) .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`) .join('&'); } export const isVideo = (fileName) => { const videoExtensions = ['mp4', 'webm', 'ogg']; return videoExtensions.includes(fileName.split('.').pop().toLowerCase()); } export const isImage = (fileName) => { const imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'svg']; return imageExtensions.includes(fileName.split('.').pop().toLowerCase()); } export const dateFormat = (fmt, date) => { let ret; const opt = { "y+": date.getFullYear().toString(), // 年 "M+": (date.getMonth() + 1).toString(), // 月 "d+": date.getDate().toString(), // 日 "h+": date.getHours().toString(), // 时 "m+": date.getMinutes().toString(), // 分 "s+": date.getSeconds().toString(), // 秒 // 有其他格式化字符需求可以继续添加,必须转化成字符串 }; for (const k in opt) { ret = new RegExp("(" + k + ")").exec(fmt); if (ret) { fmt = fmt.replace( ret[1], ret[1].length === 1 ? opt[k] : opt[k].padStart(ret[1].length, "0") ); } } return fmt; }