feat(projects): 添加常用组件、composables函数

This commit is contained in:
Soybean
2021-12-12 17:28:39 +08:00
parent e755caabf2
commit 230a50a4cf
87 changed files with 5424 additions and 2071 deletions

View File

@ -0,0 +1,46 @@
interface BrowserInfo {
type: string;
version: string;
}
/** 获取浏览器版本信息 */
export function getBrowserInfo() {
const explorer = window.navigator.userAgent.toLowerCase();
const info: BrowserInfo = {
type: '',
version: ''
};
function setInfo(data: BrowserInfo) {
Object.assign(info, data);
}
// ie
if (explorer.indexOf('msie') >= 0) {
const [version] = explorer.match(/msie ([\d.]+)/) || [''];
setInfo({ type: 'IE', version });
}
// firefox
if (explorer.indexOf('firefox') >= 0) {
const [version] = explorer.match(/firefox\/([\d.]+)/) || [''];
setInfo({ type: 'Firefox', version });
}
// Chrome
if (explorer.indexOf('chrome') >= 0) {
const [version] = explorer.match(/chrome\/([\d.]+)/) || [''];
setInfo({ type: 'Chrome', version });
if (explorer.indexOf('qqbrowser') >= 0) {
const [version] = explorer.match(/qqbrowser\/([\d.]+)/) || [''];
setInfo({ type: 'QQ浏览器', version });
}
}
// Opera
if (explorer.indexOf('opera') >= 0) {
const [version] = explorer.match(/opera.([\d.]+)/) || [''];
setInfo({ type: 'Opera', version });
}
// Safari
if (explorer.indexOf('Safari') >= 0) {
const [version] = explorer.match(/version\/([\d.]+)/) || [''];
setInfo({ type: 'Safari', version });
}
return info;
}

View File

@ -1,3 +1,6 @@
export * from './typeof';
export * from './color';
export * from './icon';
export * from './browser';
export * from './log';
export * from './number';

5
src/utils/common/log.ts Normal file
View File

@ -0,0 +1,5 @@
/** 打印log */
export function log(data: any) {
// eslint-disable-next-line no-console
console.log(data);
}

View File

@ -0,0 +1,10 @@
/**
* 获取指定整数范围内的随机整数
* @param start - 开始范围
* @param end - 结束范围
*/
export function getRandomInterger(end: number, start: number = 0) {
const range = end - start;
const random = Math.floor(Math.random() * range + start);
return random;
}