init
This commit is contained in:
8
src/utils/components.js
Normal file
8
src/utils/components.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import SvgIcon from "@/components/SvgIcon.vue";
|
||||
|
||||
const initComponents = {
|
||||
install(app) {
|
||||
app.component("SvgIcon", SvgIcon);
|
||||
},
|
||||
};
|
||||
export default initComponents;
|
||||
25
src/utils/enums.js
Normal file
25
src/utils/enums.js
Normal file
@@ -0,0 +1,25 @@
|
||||
export const ENUMS = {
|
||||
// 布局模式
|
||||
layoutModeEnum: {
|
||||
key: ["modeA", "modeB"],
|
||||
value: ["纵向", "分栏"],
|
||||
},
|
||||
// 布局模式
|
||||
navbarModeEnum: {
|
||||
key: ["modeA", "modeB", "modeC"],
|
||||
value: ["圆滑", "卡片", "灵动"],
|
||||
},
|
||||
// 设置配置
|
||||
setColorEnum: {
|
||||
themeColor: "--el-color-primary",
|
||||
menuBGColor: "--el-menu-bg-color",
|
||||
textColor: "--el-menu-text-color",
|
||||
activeTextColor: "--el-menu-active-color",
|
||||
columnBgColor: "--admin-column-bg-color",
|
||||
},
|
||||
// 组件切换
|
||||
componentTransitionEnum: {
|
||||
key: ["mainA", "mainB"],
|
||||
value: ["下至上", "右至左"],
|
||||
},
|
||||
};
|
||||
95
src/utils/index.js
Normal file
95
src/utils/index.js
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* 校验手机号码
|
||||
* @param {*} tel
|
||||
*/
|
||||
export function validPhone(tel) {
|
||||
const reg = /^1[3-9]\d{9}$/;
|
||||
return reg.test(tel);
|
||||
}
|
||||
|
||||
/**
|
||||
* 机构名称
|
||||
*/
|
||||
export const typeNames = {
|
||||
"AG": '代理',
|
||||
"FB": '一级业务员',
|
||||
"FO": '大机构',
|
||||
"MC": '商家',
|
||||
"SB": '二级业务员',
|
||||
"SO": '小机构',
|
||||
"XW": '小微商户',
|
||||
"MG": '平台'
|
||||
}
|
||||
|
||||
/**
|
||||
* 机构列表
|
||||
*/
|
||||
export const organizationList = [
|
||||
{
|
||||
type_code: 'MG',
|
||||
type_name: '平台'
|
||||
},
|
||||
{
|
||||
type_code: 'AG',
|
||||
type_name: '代理'
|
||||
},
|
||||
{
|
||||
type_code: 'FB',
|
||||
type_name: '一级业务员'
|
||||
},
|
||||
{
|
||||
type_code: 'FO',
|
||||
type_name: '大机构'
|
||||
},
|
||||
{
|
||||
type_code: 'MC',
|
||||
type_name: '商家'
|
||||
},
|
||||
{
|
||||
type_code: 'SB',
|
||||
type_name: '二级业务员'
|
||||
},
|
||||
{
|
||||
type_code: 'SO',
|
||||
type_name: '小机构'
|
||||
},
|
||||
{
|
||||
type_code: 'XW',
|
||||
type_name: '小微商户'
|
||||
}
|
||||
]
|
||||
|
||||
/**
|
||||
* 添加事对象下一级类型
|
||||
*/
|
||||
export const addOrganizations = {
|
||||
'MG': 'FO',
|
||||
'FO': 'SO',
|
||||
'SO': 'AG'
|
||||
}
|
||||
|
||||
/**
|
||||
* 去除字符串中除了数字和点以外的其他字符
|
||||
* @param {Object} obj
|
||||
*/
|
||||
export function clearNoNum(obj) {
|
||||
//如果用户第一位输入的是小数点,则重置输入框内容
|
||||
if (obj.value != '' && obj.value.substr(0, 1) == '.') {
|
||||
obj.value = '';
|
||||
}
|
||||
obj.value = obj.value.replace(/^0*(0\.|[1-9])/, '$1'); //粘贴不生效
|
||||
obj.value = obj.value.replace(/[^\d.]/g, ''); //清除“数字”和“.”以外的字符
|
||||
obj.value = obj.value.replace(/\.{2,}/g, '.'); //只保留第一个. 清除多余的
|
||||
obj.value = obj.value
|
||||
.replace('.', '$#$')
|
||||
.replace(/\./g, '')
|
||||
.replace('$#$', '.');
|
||||
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
|
||||
if (obj.value.indexOf('.') < 0 && obj.value != '') {
|
||||
//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
|
||||
if (obj.value.substr(0, 1) == '0' && obj.value.length == 2) {
|
||||
obj.value = obj.value.substr(1, obj.value.length);
|
||||
}
|
||||
}
|
||||
return obj.value;
|
||||
}
|
||||
72
src/utils/request.js
Normal file
72
src/utils/request.js
Normal file
@@ -0,0 +1,72 @@
|
||||
import axios from "axios";
|
||||
import { ElMessage } from "element-plus";
|
||||
import _hook from "@/hooks/index.js";
|
||||
import NProgress from "nprogress";
|
||||
import router from '@/router'
|
||||
|
||||
const service = axios.create({
|
||||
baseURL: import.meta.env.MODE == 'development' ? '/api/' : '/api/admin',
|
||||
// withCredentials: true, // 跨域请求时发送 cookies
|
||||
timeout: 5000, // 请求超时
|
||||
});
|
||||
|
||||
// 请求拦截器
|
||||
service.interceptors.request.use(
|
||||
(config) => {
|
||||
NProgress.start();
|
||||
// 在发送请求之前做些什么 token
|
||||
if (_hook.useLocalStorage.get("token")) {
|
||||
// 让每个请求携带 token
|
||||
// ['X-Token'] 是自定义标题键
|
||||
// 请根据实际情况修改
|
||||
config.headers["token"] = _hook.useLocalStorage.get("token");
|
||||
config.headers["loginName"] = _hook.useLocalStorage.get("userInfo").loginName;
|
||||
config.headers["userId"] = _hook.useLocalStorage.get("userInfo").userId;
|
||||
// config.headers['Content-Type'] = 'application/json'
|
||||
}
|
||||
return config;
|
||||
},
|
||||
(error) => {
|
||||
NProgress.done();
|
||||
// 处理请求错误
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
// 响应拦截器
|
||||
service.interceptors.response.use(
|
||||
(response) => {
|
||||
NProgress.done();
|
||||
// 对响应数据做点什么
|
||||
if (+response.status === 200) {
|
||||
if (+response.data.code == '000000') {
|
||||
return response.data.data;
|
||||
} else if (+response.data.code == '999999') {
|
||||
ElMessage.error('登录已过期,请重新登录')
|
||||
_hook.useLocalStorage.clear()
|
||||
router.replace("/login")
|
||||
return Promise.reject('登录已过期,请重新登录')
|
||||
} else {
|
||||
// 响应错误
|
||||
ElMessage.error(response.data.message)
|
||||
return Promise.reject(response.data.message)
|
||||
}
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
NProgress.done();
|
||||
// 对响应错误做点什么
|
||||
if (error.message.indexOf("timeout") != -1) {
|
||||
ElMessage.error("网络超时");
|
||||
} else if (error.message == "Network Error") {
|
||||
ElMessage.error("网络连接错误");
|
||||
} else {
|
||||
console.log(error);
|
||||
if (error.response.data) ElMessage.error(error.response.statusText);
|
||||
else ElMessage.error("接口路径找不到");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
|
||||
export default service;
|
||||
69
src/utils/watermark.js
Normal file
69
src/utils/watermark.js
Normal file
@@ -0,0 +1,69 @@
|
||||
let id = "uniqueIdProhibitsDuplication",
|
||||
watermarkText = "";
|
||||
|
||||
function createWatermark() {
|
||||
if (document.getElementById(id) !== null) {
|
||||
document.body.removeChild(document.getElementById(id));
|
||||
}
|
||||
// 创建一个画布
|
||||
const can = document.createElement("canvas");
|
||||
// 设置画布的长宽
|
||||
can.width = 250;
|
||||
can.height = 200;
|
||||
const cans = can.getContext("2d");
|
||||
// 旋转角度
|
||||
cans.rotate((-20 * Math.PI) / 180);
|
||||
cans.font = "16px Vedana";
|
||||
// 设置填充绘画的颜色、渐变或者模式
|
||||
cans.fillStyle = "rgba(200, 200, 200, 0.35)";
|
||||
// 设置文本内容的当前对齐方式
|
||||
cans.textAlign = "left";
|
||||
// 设置在绘制文本时使用的当前文本基线
|
||||
cans.textBaseline = "Middle";
|
||||
// 在画布上绘制填色的文本(输出的文本,开始绘制文本的X坐标位置,开始绘制文本的Y坐标位置)
|
||||
cans.fillText(watermarkText, can.width / 8, can.height / 2);
|
||||
const div = document.createElement("div");
|
||||
div.id = id;
|
||||
div.style.pointerEvents = "none"; //禁用鼠标事件
|
||||
div.style.top = "30px";
|
||||
div.style.left = "0px";
|
||||
div.style.position = "fixed";
|
||||
div.style.zIndex = "999999";
|
||||
div.style.width = document.documentElement.clientWidth - 20 + "px";
|
||||
div.style.height = document.documentElement.clientHeight - 20 + "px";
|
||||
div.style.background = "url(" + can.toDataURL("image/png") + ") left top repeat";
|
||||
document.body.appendChild(div);
|
||||
mutationFun();
|
||||
}
|
||||
|
||||
// 添加水印
|
||||
function set(text = "Vue3 ElePlus Admin") {
|
||||
watermarkText = text;
|
||||
createWatermark();
|
||||
window.addEventListener("resize", createWatermark);
|
||||
}
|
||||
|
||||
// 移除水印
|
||||
function remove() {
|
||||
document.body.removeChild(document.getElementById(id));
|
||||
window.removeEventListener("resize", createWatermark);
|
||||
}
|
||||
|
||||
// 监听元素的变化
|
||||
function mutationFun() {
|
||||
const mutation = new MutationObserver((el) => {
|
||||
mutation.disconnect();
|
||||
createWatermark();
|
||||
});
|
||||
const config = {
|
||||
attributes: true,
|
||||
subtree: true,
|
||||
childList: true,
|
||||
};
|
||||
mutation.observe(document.getElementById(id), config);
|
||||
}
|
||||
|
||||
export default {
|
||||
set,
|
||||
remove,
|
||||
};
|
||||
Reference in New Issue
Block a user