2024-11-13 11:26:59 +08:00
|
|
|
import 'amfe-flexible';
|
|
|
|
import { createApp } from 'vue';
|
|
|
|
import App from './App.vue';
|
|
|
|
import router from './router';
|
|
|
|
import store from './store';
|
|
|
|
import '@vant/touch-emulator';
|
2024-12-09 14:45:59 +08:00
|
|
|
// import '../../set-vue/src/assets/icon/iconfont.js';
|
|
|
|
import '../src/assets/icon/iconfont'
|
2024-11-13 11:26:59 +08:00
|
|
|
// const VConsole = require('vconsole');
|
|
|
|
// new VConsole(); // 初始化vConsole
|
|
|
|
if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) {
|
|
|
|
// 在App中
|
|
|
|
console.log("UniAppJSBridgeReady 事件已触发");
|
|
|
|
document.addEventListener("UniAppJSBridgeReady", function () {
|
|
|
|
console.log("ok");
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
window.MQTT_recv = MQTT_recv;
|
|
|
|
|
|
|
|
//在收到数据后需要调用这个函数
|
|
|
|
function MQTT_recv(string) {
|
|
|
|
console.log("MQTT 接收:" + string);
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkEnvironment() {
|
|
|
|
if (window.location.hostname === '192.168.4.1') {
|
|
|
|
console.log('in local');
|
|
|
|
// 本地开发环境,需要登录
|
|
|
|
requireLogin();
|
|
|
|
} else {
|
|
|
|
// 生产环境,不需要登录
|
|
|
|
bypassLogin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function requireLogin() {
|
|
|
|
if (!store.state.isAuthenticated) {
|
|
|
|
router.push('/login');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 获取 URL 中的 token 参数
|
|
|
|
function getQueryString(name) {
|
|
|
|
const urlParams = new URLSearchParams(window.location.search);
|
|
|
|
return urlParams.get(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 在页面加载时,获取 token 并存储到 localStorage
|
|
|
|
const token = getQueryString('token');
|
|
|
|
if (token) {
|
|
|
|
localStorage.setItem('token', token);
|
|
|
|
console.log('Token stored:', token);
|
|
|
|
} else {
|
|
|
|
console.log('No token found in URL');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function bypassLogin() {
|
|
|
|
// 假设在服务器环境中已经有登录信息,可以直接跳过登录逻辑
|
|
|
|
store.commit('setAuthenticated', true);
|
|
|
|
}
|
|
|
|
|
|
|
|
const app = createApp(App);
|
|
|
|
|
|
|
|
checkEnvironment(); // 检查环境并执行相应的逻辑
|
|
|
|
const isAuthenticated = JSON.parse(localStorage.getItem('isAuthenticated'));
|
|
|
|
if (isAuthenticated) {
|
|
|
|
store.commit('setAuthenticated', true);
|
|
|
|
}
|
|
|
|
app.use(store).use(router).mount('#app');
|
|
|
|
|
|
|
|
|
|
|
|
window.VueRouter = router; // 这里立即暴露 router
|
|
|
|
console.log("VueRouter 已暴露到全局");
|