357 lines
10 KiB
JavaScript
357 lines
10 KiB
JavaScript
import Vue from 'vue'
|
||
|
||
import Cookies from 'js-cookie'
|
||
import 'normalize.css/normalize.css' // a modern alternative to CSS resets
|
||
|
||
import './assets/css/iconfont/iconfont.css'
|
||
|
||
import Element from 'element-ui'
|
||
import './styles/element-variables.scss'
|
||
import 'xterm/css/xterm.css'
|
||
// import enLang from 'element-ui/lib/locale/lang/en'// 如果使用中文语言包请默认支持,无需额外引入,请删除该依赖
|
||
// import 'lib-flexible/flexible'
|
||
|
||
import '@/styles/index.scss' // global css
|
||
|
||
import globalMixin from '@/mixin/globalMixin'; // 替换为实际的文件路径
|
||
|
||
// 全局混入
|
||
Vue.mixin(globalMixin);
|
||
|
||
let ploady={
|
||
reseller_orgid:'',
|
||
start_date:'',
|
||
end_date:''
|
||
}
|
||
// reqSaleMoneyList(ploady)
|
||
// import {saveApprovalInfo} from "@/api/finance/approvalList";
|
||
// saveApprovalInfo(JSON.stringify({
|
||
// "flag":"update",
|
||
// "id": "GUwHSPn7oKC-LZoqFfdJ9",
|
||
// "user_id": "11",
|
||
// "orgid": "x",
|
||
// "send_dd_user_id": "11",
|
||
// "source": "sssss",
|
||
// "app_key": "aaa",
|
||
// "app_secret": "app_secret",
|
||
// "http_aes_key": "http_aes_key",
|
||
// "http_token": "http_token",
|
||
// "process_code": "PROC-B2DAA076-6A9F-4740-80AB-0D5D4410F7AC",
|
||
// "process_name": "process_name",
|
||
// "update_time": "2023-08-25 16:15:18"
|
||
// }))
|
||
// bpmn 工作流绘图工具的样式
|
||
// import "bpmn-js/dist/assets/diagram-js.css" // 左边工具栏以及编辑节点的样式
|
||
// import "bpmn-js/dist/assets/bpmn-font/css/bpmn.css"
|
||
// import "bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css"
|
||
// import "bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css"
|
||
// import 'bpmn-js-properties-panel/dist/assets/properties-panel.css' // 右边工具栏样式
|
||
|
||
|
||
import App from './App'
|
||
import store from './store'
|
||
import router from './router'
|
||
// import 'default-passive-events'
|
||
import './icons' // icon
|
||
import './permission' // permission control
|
||
// import './utils/error-log' // error log
|
||
import index from '@/styles/index.css'
|
||
import { v4 as uuidv4 } from 'uuid';//引入uuid
|
||
// uuidv4();
|
||
|
||
sessionStorage.setItem('client_uuid', uuidv4())
|
||
// console.log(uuidv4());
|
||
|
||
// 引入form-create 表单生成器
|
||
import formCreate from "@form-create/element-ui"
|
||
|
||
Vue.use(formCreate);
|
||
|
||
import * as filters from './filters' // global filters
|
||
|
||
import HappyScroll from 'vue-happy-scroll'
|
||
// 引入css
|
||
import 'vue-happy-scroll/docs/happy-scroll.css'
|
||
import {reqSaleMoneyList} from "@/api/sales/distributorMangement";
|
||
Vue.use(HappyScroll)
|
||
// Vue.use(axios)
|
||
// Vue.prototype.axios=axios
|
||
|
||
/**
|
||
* If you don't want to use mock-server
|
||
* you want to use MockJs for mock api
|
||
* you can execute: mockXHR()
|
||
*
|
||
* Currently MockJs will be used in the production environment,
|
||
* please remove it before going online ! ! !
|
||
*/
|
||
// if (process.env.NODE_ENV === 'production') {
|
||
// const { mockXHR } = require('../mock')
|
||
// mockXHR()
|
||
// }
|
||
|
||
// ==================== 防 F12 和右键检查功能开始 ====================
|
||
// 只在生产环境启用防调试功能
|
||
if (process.env.NODE_ENV === 'production') {
|
||
// 禁止右键菜单
|
||
document.addEventListener('contextmenu', function(e) {
|
||
e.preventDefault();
|
||
return false;
|
||
});
|
||
|
||
// 禁止F12和开发者工具快捷键
|
||
document.addEventListener('keydown', function(e) {
|
||
// 禁止F12
|
||
if (e.key === 'F12') {
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
|
||
// 禁止Ctrl+Shift+I (Chrome, Edge)
|
||
if (e.ctrlKey && e.shiftKey && e.key === 'I') {
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
|
||
// 禁止Ctrl+Shift+J (Chrome)
|
||
if (e.ctrlKey && e.shiftKey && e.key === 'J') {
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
|
||
// 禁止Ctrl+U (查看源代码)
|
||
if (e.ctrlKey && e.key === 'u') {
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
|
||
// 禁止Ctrl+Shift+C (开发者工具检查元素)
|
||
if (e.ctrlKey && e.shiftKey && e.key === 'C') {
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
|
||
// 禁止Ctrl+Shift+J (Firefox)
|
||
if (e.ctrlKey && e.shiftKey && e.key === 'K') {
|
||
e.preventDefault();
|
||
return false;
|
||
}
|
||
});
|
||
|
||
// 更准确的开发者工具检测
|
||
let isDevToolsOpened = false;
|
||
|
||
// 方法1: 检查开发者工具宽度
|
||
function checkDevToolsByWidth() {
|
||
const threshold = 160; // 开发者工具通常至少160px宽
|
||
const widthThreshold = window.outerWidth - window.innerWidth > threshold;
|
||
const heightThreshold = window.outerHeight - window.innerHeight > threshold;
|
||
|
||
return widthThreshold || heightThreshold;
|
||
}
|
||
|
||
// 方法2: 检查debugger执行时间(更宽松的阈值)
|
||
function checkDevToolsByDebugger() {
|
||
return new Promise((resolve) => {
|
||
const start = performance.now();
|
||
debugger;
|
||
const end = performance.now();
|
||
// 使用更宽松的阈值,避免误报
|
||
resolve(end - start > 200);
|
||
});
|
||
}
|
||
|
||
// 方法3: 检查控制台是否打开
|
||
function checkDevToolsByConsole() {
|
||
const element = new Image();
|
||
Object.defineProperty(element, 'id', {
|
||
get: function() {
|
||
isDevToolsOpened = true;
|
||
}
|
||
});
|
||
|
||
console.log(element);
|
||
console.clear(); // 清除测试日志
|
||
}
|
||
|
||
// 方法4: 检查Eruda等移动端调试工具
|
||
function checkMobileDevTools() {
|
||
return !!(window.eruda || window.__eruda || window.vConsole);
|
||
}
|
||
|
||
// 处理检测到调试器的情况
|
||
function handleDebuggerDetected() {
|
||
if (!isDevToolsOpened) {
|
||
isDevToolsOpened = true;
|
||
|
||
// 可以选择以下一种或多种处理方式
|
||
// 1. 显示警告信息(推荐)
|
||
alert('检测到开发者工具已打开,为了系统安全,请关闭开发者工具。');
|
||
|
||
// 2. 跳转到关于页面或其他安全页面
|
||
// window.location.href = '/about';
|
||
|
||
// 3. 清空敏感数据
|
||
// sessionStorage.clear();
|
||
// localStorage.clear();
|
||
|
||
// 4. 关闭窗口(慎用)
|
||
// window.close();
|
||
|
||
// 5. 禁用页面交互
|
||
// document.body.innerHTML = '<h1>请关闭开发者工具后刷新页面</h1>';
|
||
}
|
||
}
|
||
|
||
// 定期检查(使用更宽松的间隔)
|
||
const checkInterval = setInterval(async function() {
|
||
// 如果已经检测到开发工具打开,停止检查
|
||
if (isDevToolsOpened) {
|
||
clearInterval(checkInterval);
|
||
return;
|
||
}
|
||
|
||
// 检查移动端调试工具
|
||
if (checkMobileDevTools()) {
|
||
handleDebuggerDetected();
|
||
return;
|
||
}
|
||
|
||
// 检查窗口大小
|
||
if (checkDevToolsByWidth()) {
|
||
handleDebuggerDetected();
|
||
return;
|
||
}
|
||
|
||
// 检查debugger(异步)
|
||
const isDebugging = await checkDevToolsByDebugger();
|
||
if (isDebugging) {
|
||
handleDebuggerDetected();
|
||
return;
|
||
}
|
||
|
||
// 偶尔检查控制台(不要太频繁)
|
||
if (Math.random() < 0.1) { // 10%的概率检查
|
||
checkDevToolsByConsole();
|
||
}
|
||
}, 2000); // 每2秒检查一次,减少性能影响
|
||
|
||
// 监听窗口大小变化(添加去抖)
|
||
let resizeTimer;
|
||
window.addEventListener('resize', function() {
|
||
clearTimeout(resizeTimer);
|
||
resizeTimer = setTimeout(function() {
|
||
if (checkDevToolsByWidth() && !isDevToolsOpened) {
|
||
handleDebuggerDetected();
|
||
}
|
||
}, 500);
|
||
});
|
||
|
||
// 禁用控制台输出(可选,根据需求开启)
|
||
// 注意:这会影响你自己的console.log调试,建议只在生产环境使用
|
||
if (typeof console !== 'undefined') {
|
||
const noop = () => {};
|
||
const methods = ['log', 'debug', 'info', 'warn', 'error', 'table', 'dir', 'trace'];
|
||
methods.forEach(method => {
|
||
console[method] = noop;
|
||
});
|
||
|
||
// 防止重写console被绕过
|
||
Object.defineProperty(window, 'console', {
|
||
get: function() {
|
||
return {
|
||
log: noop, debug: noop, info: noop, warn: noop, error: noop,
|
||
table: noop, dir: noop, trace: noop
|
||
};
|
||
},
|
||
set: function() {}
|
||
});
|
||
}
|
||
|
||
console.log('防调试保护已启用');
|
||
}
|
||
// ==================== 防 F12 和右键检查功能结束 ====================
|
||
|
||
Vue.use(Element, {
|
||
size: Cookies.get('size') || 'medium' // set element-ui default size
|
||
// locale: enLang // 如果使用中文,无需设置,请删除
|
||
})
|
||
|
||
// 解决bug:页面/路由跳转后,滚动条消失,页面无法滚动
|
||
//设置跳转页面时给页面的body属性设置滚动条
|
||
var onOverflow = ["/shoppingManagement", "/supplierManagement"];
|
||
|
||
// 修复:在路由守卫中恢复用户状态和重新生成路由
|
||
router.beforeEach(async (to, from, next) => {
|
||
// 清空面包屑状态的代码
|
||
// store.commit('tagsView/resetBreadcrumbState');
|
||
|
||
// 新增:如果已登录且有token,但Vuex状态丢失,从sessionStorage恢复
|
||
if (store.getters.token && (!store.getters.user || !store.getters.userType)) {
|
||
console.log("检测到状态丢失,从sessionStorage恢复用户状态");
|
||
|
||
const user = sessionStorage.getItem('user');
|
||
const auths = sessionStorage.getItem('auths');
|
||
const userType = sessionStorage.getItem('userType');
|
||
const orgType = sessionStorage.getItem('orgType');
|
||
|
||
if (user) {
|
||
store.commit('user/SET_USER', user);
|
||
}
|
||
if (auths) {
|
||
store.commit('user/SET_AUTHS', JSON.parse(auths));
|
||
}
|
||
if (userType) {
|
||
store.commit('user/SET_USER_TYPE', userType);
|
||
}
|
||
if (orgType) {
|
||
store.commit('user/SET_ORG_TYPE', parseInt(orgType));
|
||
}
|
||
|
||
// 重新生成路由
|
||
try {
|
||
const accessRoutes = await store.dispatch('permission/generateRoutes', {
|
||
user: store.getters.user,
|
||
auths: store.getters.auths,
|
||
userType: store.getters.userType,
|
||
orgType: store.getters.orgType
|
||
});
|
||
|
||
// 重新添加路由
|
||
router.addRoutes(accessRoutes);
|
||
|
||
// 重定向到当前路由以确保路由更新
|
||
next({ ...to, replace: true });
|
||
return;
|
||
} catch (error) {
|
||
console.error('重新生成路由失败:', error);
|
||
}
|
||
}
|
||
|
||
onOverflow.forEach(element => {
|
||
if (to.path == element) {
|
||
document.querySelector("body").setAttribute("style", "overflow: auto !important;")
|
||
}
|
||
});
|
||
|
||
next();
|
||
});
|
||
|
||
window.addEventListener('beforeunload', function () {
|
||
// 清空面包屑状态的代码
|
||
store.commit('tagsView/resetBreadcrumbState');
|
||
});
|
||
|
||
Object.keys(filters).forEach(key => {
|
||
Vue.filter(key, filters[key])
|
||
})
|
||
|
||
Vue.config.productionTip = false
|
||
|
||
new Vue({
|
||
el: '#app',
|
||
router,
|
||
store,
|
||
render: h => h(App)
|
||
})
|