chore: 构建目录
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
const TokenKey = 'Admin-Token'
|
||||
|
||||
export function getToken() {
|
||||
return localStorage.getItem(TokenKey)
|
||||
}
|
||||
|
||||
export function setToken(token) {
|
||||
return localStorage.setItem(TokenKey, token)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return localStorage.removeItem (TokenKey)
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/**
|
||||
* 根据后缀判断文件类型
|
||||
* @param {string} fileName 文件后缀名
|
||||
* @returns
|
||||
*/
|
||||
export function matchType(fileName) {
|
||||
// 后缀获取
|
||||
let suffix = "";
|
||||
// 获取类型结果
|
||||
let result = "";
|
||||
try {
|
||||
let flieArr = fileName.split(".");
|
||||
suffix = flieArr[flieArr.length - 1];
|
||||
} catch (err) {
|
||||
suffix = "";
|
||||
}
|
||||
// fileName无后缀返回 false
|
||||
if (!suffix) {
|
||||
result = false;
|
||||
return result;
|
||||
}
|
||||
// 图片格式
|
||||
let imglist = ["png", "jpg", "jpeg", "bmp", "gif"];
|
||||
// 进行图片匹配
|
||||
result = imglist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "image";
|
||||
return result;
|
||||
}
|
||||
// 匹配txt
|
||||
let txtlist = ["txt"];
|
||||
result = txtlist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "txt";
|
||||
return result;
|
||||
}
|
||||
// 匹配 excel
|
||||
let excelist = ["xls", "xlsx"];
|
||||
result = excelist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "excel";
|
||||
return result;
|
||||
}
|
||||
// 匹配 word
|
||||
let wordlist = ["doc", "docx"];
|
||||
result = wordlist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "word";
|
||||
return result;
|
||||
}
|
||||
// 匹配 pdf
|
||||
let pdflist = ["pdf"];
|
||||
result = pdflist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "pdf";
|
||||
return result;
|
||||
}
|
||||
// 匹配 ppt
|
||||
let pptlist = ["ppt"];
|
||||
result = pptlist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "ppt";
|
||||
return result;
|
||||
}
|
||||
// 匹配 视频
|
||||
let videolist = ["mp4", "m2v", "mkv"];
|
||||
result = videolist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "video";
|
||||
return result;
|
||||
}
|
||||
// 匹配 音频
|
||||
let radiolist = ["mp3", "wav", "wmv"];
|
||||
result = radiolist.some(function (item) {
|
||||
return item == suffix;
|
||||
});
|
||||
if (result) {
|
||||
result = "radio";
|
||||
return result;
|
||||
}
|
||||
// 其他 文件类型
|
||||
result = "other";
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* url处理
|
||||
* @param {string} path url路径
|
||||
* @returns
|
||||
*/
|
||||
export function convertToUrl(path) {
|
||||
// 替换反斜杠为正斜杠
|
||||
const normalizedPathWithSlashes = path.replace(/\\/g, "/");
|
||||
// 去掉开始的点号和反斜杠
|
||||
const removedDotsAndSlashes = normalizedPathWithSlashes.replace(/^\.\//, "");
|
||||
// 添加斜杠作为根路径
|
||||
const url = `/${removedDotsAndSlashes}`;
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
*
|
||||
* @param {*} path 下载地址/下载请求地址。
|
||||
* @param {string} name 下载文件的名字(考虑到兼容性问题,最好加上后缀名
|
||||
*/
|
||||
export const downLoadFile = (path, name) => {
|
||||
const link = document.createElement("a");
|
||||
link.href = path;
|
||||
link.download = name;
|
||||
|
||||
if (isMobileDevice()) {
|
||||
link.target = "_blank";
|
||||
link.rel = "noopener noreferrer";
|
||||
}
|
||||
|
||||
link.style.display = "none";
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
};
|
||||
|
||||
// 判断是否移动设备
|
||||
export function isMobileDevice() {
|
||||
return /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent);
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
export default {
|
||||
'agate': 1,
|
||||
'androidstudio': 1,
|
||||
'arduino-light': 1,
|
||||
'arta': 1,
|
||||
'ascetic': 1,
|
||||
'atelier-cave-dark': 1,
|
||||
'atelier-cave-light': 1,
|
||||
'atelier-dune-dark': 1,
|
||||
'atelier-dune-light': 1,
|
||||
'atelier-estuary-dark': 1,
|
||||
'atelier-estuary-light': 1,
|
||||
'atelier-forest-dark': 1,
|
||||
'atelier-forest-light': 1,
|
||||
'atelier-heath-dark': 1,
|
||||
'atelier-heath-light': 1,
|
||||
'atelier-lakeside-dark': 1,
|
||||
'atelier-lakeside-light': 1,
|
||||
'atelier-plateau-dark': 1,
|
||||
'atelier-plateau-light': 1,
|
||||
'atelier-savanna-dark': 1,
|
||||
'atelier-savanna-light': 1,
|
||||
'atelier-seaside-dark': 1,
|
||||
'atelier-seaside-light': 1,
|
||||
'atelier-sulphurpool-dark': 1,
|
||||
'atelier-sulphurpool-light': 1,
|
||||
'atom-one-dark': 1,
|
||||
'atom-one-light': 1,
|
||||
'brown-paper': 1,
|
||||
'codepen-embed': 1,
|
||||
'color-brewer': 1,
|
||||
'darcula': 1,
|
||||
'dark': 1,
|
||||
'darkula': 1,
|
||||
'default': 1,
|
||||
'docco': 1,
|
||||
'dracula': 1,
|
||||
'far': 1,
|
||||
'foundation': 1,
|
||||
'github-gist': 1,
|
||||
'github': 1,
|
||||
'googlecode': 1,
|
||||
'grayscale': 1,
|
||||
'gruvbox-dark': 1,
|
||||
'gruvbox-light': 1,
|
||||
'hopscotch': 1,
|
||||
'hybrid': 1,
|
||||
'idea': 1,
|
||||
'ir-black': 1,
|
||||
'kimbie.dark': 1,
|
||||
'kimbie.light': 1,
|
||||
'magula': 1,
|
||||
'mono-blue': 1,
|
||||
'monokai-sublime': 1,
|
||||
'monokai': 1,
|
||||
'obsidian': 1,
|
||||
'ocean': 1,
|
||||
'paraiso-dark': 1,
|
||||
'paraiso-light': 1,
|
||||
'pojoaque': 1,
|
||||
'purebasic': 1,
|
||||
'qtcreator_dark': 1,
|
||||
'qtcreator_light': 1,
|
||||
'railscasts': 1,
|
||||
'rainbow': 1,
|
||||
'routeros': 1,
|
||||
'school-book': 1,
|
||||
'solarized-dark': 1,
|
||||
'solarized-light': 1,
|
||||
'sunburst': 1,
|
||||
'tomorrow-night-blue': 1,
|
||||
'tomorrow-night-bright': 1,
|
||||
'tomorrow-night-eighties': 1,
|
||||
'tomorrow-night': 1,
|
||||
'tomorrow': 1,
|
||||
'vs': 1,
|
||||
'vs2015': 1,
|
||||
'xcode': 1,
|
||||
'xt256': 1,
|
||||
'zenburn': 1
|
||||
};
|
||||
@@ -1,12 +0,0 @@
|
||||
//设置防抖,保证无论拖动窗口大小,只执行一次获取浏览器宽高的方法
|
||||
export const debounce = (fun, delay) => {
|
||||
let timer;
|
||||
return function () {
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
fun();
|
||||
}, delay);
|
||||
};
|
||||
};
|
||||
@@ -1,64 +0,0 @@
|
||||
|
||||
import axios from 'axios';
|
||||
import { getToken } from '@/utils/auth'
|
||||
export let isRelogin = { show: false };
|
||||
// import JsonBig from 'json-bigint'
|
||||
const myaxios = axios.create({
|
||||
baseURL:import.meta.env.VITE_APP_BASEAPI,
|
||||
timeout: 50000,
|
||||
// transformResponse: [data => {
|
||||
// try {
|
||||
// const json = JsonBig({
|
||||
// storeAsString: true
|
||||
// })
|
||||
// return json.parse(data)
|
||||
// } catch (err) {
|
||||
// // 如果转换失败,则包装为统一数据格式并返回
|
||||
// return {
|
||||
// data
|
||||
// }
|
||||
// }
|
||||
// }],
|
||||
})
|
||||
|
||||
|
||||
|
||||
// 请求拦截器
|
||||
myaxios.interceptors.request.use(function (config) {
|
||||
if (getToken()) {
|
||||
config.headers['Authorization'] = 'Bearer ' + getToken() // 让每个请求携带自定义token 请根据实际情况自行修改
|
||||
}
|
||||
|
||||
return config;
|
||||
}, function (error) {
|
||||
return Promise.reject(error);
|
||||
});
|
||||
|
||||
// 响应拦截器
|
||||
myaxios.interceptors.response.use(function (response) {
|
||||
//业务错误
|
||||
if(response.data.statusCode==403)
|
||||
{
|
||||
ElMessage.error(response.data.errors)
|
||||
}
|
||||
return response;
|
||||
}, function (error) {
|
||||
const code = error.response.status;
|
||||
const msg = error.message;
|
||||
//业务异常+应用异常,统一处理
|
||||
switch(code)
|
||||
{
|
||||
case 401:
|
||||
ElMessage.error('登录已过期')
|
||||
break;
|
||||
case 403:
|
||||
ElMessage.error(msg)
|
||||
break;
|
||||
case 500:
|
||||
ElMessage.error(msg)
|
||||
break;
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
});
|
||||
export default myaxios
|
||||
@@ -1,53 +0,0 @@
|
||||
/**
|
||||
* window.localStorage 浏览器永久缓存
|
||||
* @method set 设置永久缓存
|
||||
* @method get 获取永久缓存
|
||||
* @method remove 移除永久缓存
|
||||
* @method clear 移除全部永久缓存
|
||||
*/
|
||||
export const Local = {
|
||||
// 设置永久缓存
|
||||
set(key, val) {
|
||||
window.localStorage.setItem(key, JSON.stringify(val));
|
||||
},
|
||||
// 获取永久缓存
|
||||
get(key) {
|
||||
let json = window.localStorage.getItem(key);
|
||||
return JSON.parse(json);
|
||||
},
|
||||
// 移除永久缓存
|
||||
remove(key) {
|
||||
window.localStorage.removeItem(key);
|
||||
},
|
||||
// 移除全部永久缓存
|
||||
clear() {
|
||||
window.localStorage.clear();
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* window.sessionStorage 浏览器会话临时缓存
|
||||
* @method set 设置临时缓存
|
||||
* @method get 获取临时缓存
|
||||
* @method remove 移除临时缓存
|
||||
* @method clear 移除全部临时缓存
|
||||
*/
|
||||
export const Session = {
|
||||
// 设置临时缓存
|
||||
set(key, val) {
|
||||
window.sessionStorage.setItem(key, JSON.stringify(val));
|
||||
},
|
||||
// 获取临时缓存
|
||||
get(key) {
|
||||
let json = window.sessionStorage.getItem(key);
|
||||
return JSON.parse(json);
|
||||
},
|
||||
// 移除临时缓存
|
||||
remove(key) {
|
||||
window.sessionStorage.removeItem(key);
|
||||
},
|
||||
// 移除全部临时缓存
|
||||
clear() {
|
||||
window.sessionStorage.clear();
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user