mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 添加常用组件、composables函数
This commit is contained in:
46
src/utils/common/browser.ts
Normal file
46
src/utils/common/browser.ts
Normal 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;
|
||||
}
|
@ -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
5
src/utils/common/log.ts
Normal file
@ -0,0 +1,5 @@
|
||||
/** 打印log */
|
||||
export function log(data: any) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(data);
|
||||
}
|
10
src/utils/common/number.ts
Normal file
10
src/utils/common/number.ts
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user