Compare commits

..

4 Commits
master ... new

Author SHA1 Message Date
1
5aed5a6177 6.6 2025-06-06 06:31:05 +08:00
8cc5a7bcdd 5.30 2025-05-30 16:25:17 +08:00
328e470c27 5.27 2025-05-27 15:23:19 +08:00
afdda263e6 5.22 2025-05-22 15:34:21 +08:00
12 changed files with 446 additions and 240 deletions

28
package-lock.json generated
View File

@ -27,6 +27,7 @@
"lamejs": "^1.2.1", "lamejs": "^1.2.1",
"mqtt": "^2.18.8", "mqtt": "^2.18.8",
"nipplejs": "^0.10.2", "nipplejs": "^0.10.2",
"qiankun": "^2.10.16",
"vant": "^4.9.5", "vant": "^4.9.5",
"vconsole": "^3.15.1", "vconsole": "^3.15.1",
"vue": "^3.2.13", "vue": "^3.2.13",
@ -8199,6 +8200,15 @@
"url": "https://github.com/sponsors/sindresorhus" "url": "https://github.com/sponsors/sindresorhus"
} }
}, },
"node_modules/import-html-entry": {
"version": "1.17.0",
"resolved": "https://registry.npmmirror.com/import-html-entry/-/import-html-entry-1.17.0.tgz",
"integrity": "sha512-2SDsRlGlE8bqdnGqsOyiDPEWlzJR0jNW4LWopnZl5QE1Yd0nJ7fykWo2GaKUF7Jq7pR0g3dElhuJHyamTt1gPQ==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.7.2"
}
},
"node_modules/imurmurhash": { "node_modules/imurmurhash": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmmirror.com/imurmurhash/-/imurmurhash-0.1.4.tgz", "resolved": "https://registry.npmmirror.com/imurmurhash/-/imurmurhash-0.1.4.tgz",
@ -11277,6 +11287,18 @@
"node": ">=6" "node": ">=6"
} }
}, },
"node_modules/qiankun": {
"version": "2.10.16",
"resolved": "https://registry.npmmirror.com/qiankun/-/qiankun-2.10.16.tgz",
"integrity": "sha512-Q3tSVUrPnzx8ckEOKIoPnhb5LE28FPKyan/r6jEuGJGqTbIy+3rp6E2/KfU82ZI4yZpef9LFTrnxdj49jAEsmw==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.10.5",
"import-html-entry": "^1.15.1",
"lodash": "^4.17.11",
"single-spa": "^5.9.2"
}
},
"node_modules/qs": { "node_modules/qs": {
"version": "6.13.0", "version": "6.13.0",
"resolved": "https://registry.npmmirror.com/qs/-/qs-6.13.0.tgz", "resolved": "https://registry.npmmirror.com/qs/-/qs-6.13.0.tgz",
@ -12015,6 +12037,12 @@
"url": "https://github.com/sponsors/isaacs" "url": "https://github.com/sponsors/isaacs"
} }
}, },
"node_modules/single-spa": {
"version": "5.9.5",
"resolved": "https://registry.npmmirror.com/single-spa/-/single-spa-5.9.5.tgz",
"integrity": "sha512-9SQdmsyz4HSP+3gs6PJzhkaMEg+6zTlu9oxIghnwUX3eq+ajq4ft5egl0iyR55LAmO/UwvU8NgIWs/ZyQMa6dw==",
"license": "MIT"
},
"node_modules/sirv": { "node_modules/sirv": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmmirror.com/sirv/-/sirv-2.0.4.tgz", "resolved": "https://registry.npmmirror.com/sirv/-/sirv-2.0.4.tgz",

View File

@ -27,6 +27,7 @@
"lamejs": "^1.2.1", "lamejs": "^1.2.1",
"mqtt": "^2.18.8", "mqtt": "^2.18.8",
"nipplejs": "^0.10.2", "nipplejs": "^0.10.2",
"qiankun": "^2.10.16",
"vant": "^4.9.5", "vant": "^4.9.5",
"vconsole": "^3.15.1", "vconsole": "^3.15.1",
"vue": "^3.2.13", "vue": "^3.2.13",

View File

@ -7,6 +7,7 @@
<link rel="icon" href="<%= BASE_URL %>favicon.ico"> <link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title> <title><%= htmlWebpackPlugin.options.title %></title>
<script src="./web/js/webView.js"></script> <script src="./web/js/webView.js"></script>
<script src="./uni.webview.1.5.6.js"></script>
</head> </head>
<body> <body>
<noscript> <noscript>

View File

@ -6,7 +6,7 @@
* @LastEditors: Andy * @LastEditors: Andy
* @LastEditTime: 2024-03-11 11:07:00 * @LastEditTime: 2024-03-11 11:07:00
*/ */
var MQTT_MODE = 0; var MQTT_MODE = 1;
function pageName() { function pageName() {
var a = location.href; var a = location.href;
@ -25,10 +25,10 @@ function MQTT_send(string) {
json_id = 0; json_id = 0;
} }
localStorage.setItem("json_id", json_id); localStorage.setItem("json_id", json_id);
let send_string = "{\"JSON_id\":" + json_id + ",\"board_id\":102"+",\"led_protocol\":" + string + "}"; let send_string = "JSON_id\":" + json_id + ",\"board_id\":102" + ",\"led_protocol\":" + string ;
console.log("MQTT 发送:" + send_string); console.log("MQTT 发送:" + send_string);
if (/xazn/.test(navigator.userAgent)||/uni-app/.test(navigator.userAgent)) { if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) {
uni.postMessage({ uni.postMessage({
data: { data: {
str: send_string str: send_string
@ -37,7 +37,7 @@ function MQTT_send(string) {
} else { } else {
//这里需要将string发送出去 //这里需要将string发送出去
window.parent.postMessage({ window.parent.postMessage({
str: send_string data: send_string
}, "*"); // 替换为Vue应用的URL }, "*"); // 替换为Vue应用的URL
} }
@ -51,16 +51,16 @@ function MQTT_json_send(string, protocol) {
} }
let send_string; let send_string;
localStorage.setItem("json_id", json_id); localStorage.setItem("json_id", json_id);
if(protocol=="sound_card"){ if (protocol == "sound_card") {
send_string = "{\"JSON_id\":" + json_id + ",\"board_id\":103"+ ",\"" + protocol + "\":" + string + "}"; send_string = "{\"JSON_id\":" + json_id + ",\"board_id\":103" + ",\"" + protocol + "\":" + string + "}";
}else{ } else {
send_string = "{\"JSON_id\":" + json_id + ",\"" + protocol + "\":" + string + "}"; send_string = "{\"JSON_id\":" + json_id + ",\"" + protocol + "\":" + string + "}";
} }
console.log("MQTT 发送:" + send_string); console.log("MQTT 发送:" + send_string);
if (/xazn/.test(navigator.userAgent)||/uni-app/.test(navigator.userAgent)) { if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) {
uni.postMessage({ uni.postMessage({
data: { data: {
str: send_string str: send_string
@ -69,7 +69,7 @@ function MQTT_json_send(string, protocol) {
} else { } else {
//这里需要将string发送出去 //这里需要将string发送出去
window.parent.postMessage({ window.parent.postMessage({
str: send_string data: send_string
}, "*"); // 替换为Vue应用的URL }, "*"); // 替换为Vue应用的URL
} }
} }
@ -109,3 +109,9 @@ function MQTT_recv(string) {
voice_reply_parse_fun(string); voice_reply_parse_fun(string);
} }
} }
window.addEventListener('message', function (event) {
console.log("接受的原始数据", JSON.stringify(event.data))
if (event.data) {
MQTT_recv(JSON.stringify(event.data)); // 保持与原 MQTT_recv 兼容
}
});

View File

@ -4,10 +4,12 @@ import App from './App.vue';
import router from './router'; import router from './router';
import store from './store'; import store from './store';
import '@vant/touch-emulator'; import '@vant/touch-emulator';
import '../public/uni.webview.1.5.6.js';
// import '../../set-vue/src/assets/icon/iconfont.js'; // import '../../set-vue/src/assets/icon/iconfont.js';
import '../src/assets/icon/iconfont' import '../src/assets/icon/iconfont'
// const VConsole = require('vconsole'); // import '../public/jweixin-1.3.2'
// new VConsole(); // 初始化vConsole const VConsole = require('vconsole');
new VConsole(); // 初始化vConsole
if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) { if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) {
// 在App中 // 在App中
console.log("UniAppJSBridgeReady 事件已触发"); console.log("UniAppJSBridgeReady 事件已触发");
@ -73,3 +75,53 @@ app.use(store).use(router).mount('#app');
window.VueRouter = router; // 这里立即暴露 router window.VueRouter = router; // 这里立即暴露 router
console.log("VueRouter 已暴露到全局"); console.log("VueRouter 已暴露到全局");
// main.js
if (window.uni && uni.postMessage) {
console.log('WebView SDK 已加载');
}
// 示例:监听 UniApp 原生事件
document.addEventListener('UniAppJSBridgeReady', () => {
uni.postMessage({
data: '子页面已准备好'
});
});
if (uni.getEnv().plus) {
console.log('运行在 UniApp WebView 中');
}
// qiankun
// let instance = null;
// function render(props = {}) {
// const { container } = props;
// instance = new Vue({
// render: (h) => h(App),
// }).$mount(container ? container.querySelector('#app') : '#app');
// }
// // 独立运行(非 Qiankun 环境)
// if (!window.__POWERED_BY_QIANKUN__) {
// render();
// }
// // Qiankun 生命周期
// export async function bootstrap() {
// console.log('[subapp] bootstrap');
// }
// export async function mount(props) {
// console.log('[subapp] mount', props);
// render(props);
// }
// export async function unmount() {
// console.log('[subapp] unmount');
// instance.$destroy();
// instance = null;
// }

View File

@ -246,9 +246,9 @@ export default {
const sendLightStatusCommand = (value) => { const sendLightStatusCommand = (value) => {
const lightStatusCommand = { const lightStatusCommand = {
board_id: 50, board_id: 106,
JSON_id: 1, JSON_id: 1,
cones: { cones_card: {
traffic_cone: { traffic_cone: {
lamplight: value lamplight: value
} }
@ -274,9 +274,9 @@ export default {
const onDefenseChange = (value) => { const onDefenseChange = (value) => {
const defenseCommand = { const defenseCommand = {
board_id: 50, board_id: 106,
JSON_id: 1, JSON_id: 1,
cones: { cones_card: {
traffic_cone: { traffic_cone: {
mode: value ? 1 : 0 mode: value ? 1 : 0
} }
@ -343,7 +343,7 @@ export default {
const powerValue = powerOptions.find(option => option.text === power.value)?.value || 0; const powerValue = powerOptions.find(option => option.text === power.value)?.value || 0;
const configData = { const configData = {
"board_id": 50, "board_id": 1,
"JSON_id": jsonId.value, "JSON_id": jsonId.value,
"gateway": { "gateway": {
"LoRa_cfg": { "LoRa_cfg": {
@ -383,9 +383,9 @@ export default {
const sendCommand = (command) => { const sendCommand = (command) => {
if (command === 'clearAlarm') { if (command === 'clearAlarm') {
const clearAlarmCommand = { const clearAlarmCommand = {
board_id: 50, board_id: 106,
JSON_id: 1, JSON_id: 1,
cones: { cones_card: {
traffic_cone: { traffic_cone: {
alarm: 0 alarm: 0
} }
@ -418,9 +418,9 @@ export default {
// //
const configData = { const configData = {
board_id: 50, board_id: 106,
JSON_id: 1, JSON_id: 1,
cones: { cones_card: {
LoRa_cfg: { LoRa_cfg: {
mesh_id: [ mesh_id: [
parseInt(networkId.value.slice(0, 2), 16), parseInt(networkId.value.slice(0, 2), 16),
@ -456,14 +456,14 @@ export default {
const updateStateFromResponse = (data) => { const updateStateFromResponse = (data) => {
// //
if (!data || !data.cones) { if (!data || !data.cones_card) {
console.error('Invalid response data structure'); console.error('Invalid response data structure');
return; return;
} }
// LoRa // LoRa
if (data.cones.LoRa_cfg) { if (data.cones_card.LoRa_cfg) {
const loraConfig = data.cones.LoRa_cfg; const loraConfig = data.cones_card.LoRa_cfg;
firmwareVersion.value = loraConfig.versions; firmwareVersion.value = loraConfig.versions;
macAddress.value = loraConfig.mac_addr.join(':'); macAddress.value = loraConfig.mac_addr.join(':');
networkId.value = loraConfig.mesh_id.map(num => num.toString(16).padStart(2, '0').toUpperCase()).join(''); networkId.value = loraConfig.mesh_id.map(num => num.toString(16).padStart(2, '0').toUpperCase()).join('');
@ -480,8 +480,8 @@ export default {
} }
// //
if (data.cones.traffic_cone) { if (data.cones_card.traffic_cone) {
const trafficCone = data.cones.traffic_cone; const trafficCone = data.cones_card.traffic_cone;
// //
alarmStatus.value = trafficCone.alarm === 1 ? '报警' : '正常'; alarmStatus.value = trafficCone.alarm === 1 ? '报警' : '正常';
@ -498,9 +498,9 @@ export default {
const onRefresh = () => { const onRefresh = () => {
const refreshCommand = { const refreshCommand = {
board_id: 50, board_id: 106,
JSON_id: 1, JSON_id: 1,
cones: { cones_card: {
get_traffic_cone: 1, get_traffic_cone: 1,
get_LoRa_cfg: 1 get_LoRa_cfg: 1
}, },

View File

@ -331,17 +331,14 @@ export default {
} }
} }
const MQTT_send = (send_string) => { const MQTT_send = (send_string) => {
console.log("MQTT 发送:" + JSON.stringify(send_string)); console.log(" 向父页面发送消息:", JSON.stringify(send_string));
jsonId.value++; // 使 postMessage
if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) { window.parent.postMessage(
uni.postMessage({ {
data: { data: send_string
str: JSON.stringify(send_string) },
} '*' // origin
}); );
} else {
window.parent.postMessage({ str: JSON.stringify(send_string) }, "*");
}
}; };
const MQTT_recv = (string) => { const MQTT_recv = (string) => {
@ -371,8 +368,15 @@ export default {
onMounted(async () => { onMounted(async () => {
await checkEnvironment(); await checkEnvironment();
console.log(isLocal.value); console.log(isLocal.value);
window.MQTT_recv = MQTT_recv; // window.MQTT_recv = MQTT_recv;
window.addEventListener('message', function (event) {
// console.log("message",JSON.stringify(message))
//
console.log("接受的原始数据", JSON.stringify(event.data))
if (event.data) {
MQTT_recv(JSON.stringify(event.data)); // MQTT_recv
}
});
onRefresh(); onRefresh();
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {

View File

@ -6,22 +6,14 @@
<van-notice-bar class="notice" scrollable text="下滑刷新页面" color="black" /> <van-notice-bar class="notice" scrollable text="下滑刷新页面" color="black" />
<van-swipe class="my-swipe" :autoplay="3000" indicator-color="white"> <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
<van-swipe-item>信安智能</van-swipe-item> <van-swipe-item>信安智能</van-swipe-item>
<!-- <van-swipe-item>2</van-swipe-item> -->
<!-- <van-swipe-item>3</van-swipe-item> -->
</van-swipe> </van-swipe>
<div class="item-content"> <div class="item-content">
<van-cell-group inset> <van-cell-group inset>
<van-cell size="large" class="custom-cell" title="显示设置" icon="photo-o" is-link value="显示" @click="navigateTo('web/screen_main.html')" /> <!-- 全部改为动态渲染的菜单项 -->
<van-cell size="large" class="custom-cell" title="声卡设置" icon="volume-o" is-link value="语音" @click="goto('voiceset')" /> <template v-for="(item, index) in filteredMenuItems" :key="index">
<van-cell size="large" class="custom-cell" title="车牌识别" icon="search" is-link value="识别" @click="goto('recognition')" /> <van-cell size="large" class="custom-cell" :title="item.title" :icon="item.icon" is-link
<van-cell size="large" class="custom-cell" title="预警设置" icon="warning-o" is-link value="预警" @click="goto('warning')" /> :value="item.value" @click="item.action" />
<van-cell size="large" class="custom-cell" title="远程喊话" icon="bullhorn-o" is-link value="喊话" @click="navigateTo('web/voice_copy.html')" /> </template>
<van-cell size="large" class="custom-cell" title="小车控制" icon="logistics" is-link value="控制" @click="goto('CarControl')" />
<!-- <van-cell size="large" class="custom-cell" title="小车控制" icon="car" is-link value="控制" @click="goto('TEST')" /> -->
<!-- <van-cell size="large" class="custom-cell" title="小车控制" icon="car" is-link value="控制" @click="goto('AudioPlay')" /> -->
<van-cell size="large" class="custom-cell" title="网关设置" icon="desktop-o" is-link value="控制" @click="goto('GatewaySetting')" />
<van-cell size="large" class="custom-cell" title="路锥控制" icon="warning-o" is-link value="控制" @click="goto('ConeControl')" />
<van-cell size="large" class="custom-cell" title="翻转屏遥控" icon="warning-o" is-link value="控制" @click="goto('flipScreen')" />
</van-cell-group> </van-cell-group>
</div> </div>
</div> </div>
@ -31,55 +23,104 @@
</template> </template>
<script> <script>
import { ref, onMounted } from 'vue'; import { ref, onMounted, computed, onBeforeUnmount } from 'vue';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
import axios from 'axios';
import Header from "../../components/Header.vue"; import Header from "../../components/Header.vue";
import Footer from "../../components/Footer.vue"; import Footer from "../../components/Footer.vue";
export default { export default {
components: { components: { Header, Footer },
Header,
Footer
},
setup() { setup() {
const currentTitle = ref('系统设置'); const currentTitle = ref('系统设置');
const loading = ref(false); const loading = ref(false);
const router = useRouter(); const router = useRouter();
// // 88
const allMenuItems = ref([
{ title: "显示设置", icon: "photo-o", value: "显示", action: () => navigateTo('web/screen_main.html') },
{ title: "声卡设置", icon: "volume-o", value: "语音", action: () => goto('voiceset') },
{ title: "车牌识别", icon: "search", value: "识别", action: () => goto('recognition') },
{ title: "预警设置", icon: "warning-o", value: "预警", action: () => goto('warning') },
{ title: "远程喊话", icon: "bullhorn-o", value: "喊话", action: () => navigateTo('web/voice_copy.html') },
{ title: "网关设置", icon: "desktop-o", value: "控制", action: () => goto('GatewaySetting') },
{ title: "路锥控制", icon: "warning-o", value: "控制", action: () => goto('ConeControl') },
{ title: "翻转屏遥控", icon: "warning-o", value: "控制", action: () => goto('flipScreen') }
]);
// 8
// const permissionString = ref('00000000'); //
const permissionString = ref('11111111');
//
const filteredMenuItems = computed(() => {
return allMenuItems.value.filter((_, index) => {
return permissionString.value[index] === '1';
});
});
//
const updateMenuVisibility = (binaryStr) => {
allMenuItems.value.forEach((item, index) => {
item.isVisible = binaryStr[index] === '1';
});
};
//
onMounted(() => {
const messageHandler = (event) => {
console.log(' 收到父页面消息:', event);
console.log(' 收到父页面消息:', event.data);
// XXXXXXXX/XXX
if (typeof event.data === 'string') {
permissionString.value = event.data.substring(0, 8);
if (/^[01]{8}$/.test(permissionString.value)) {
updateMenuVisibility(permissionString.value);
}
} else {
console.error(' 无效的权限字符串:', event.data);
}
};
window.addEventListener('message', messageHandler);
//
onBeforeUnmount(() => {
window.removeEventListener('message', messageHandler);
console.log('移除事件监听器');
});
});
//
const navigateTo = (path) => {
window.location.href = path;
};
const goto = (name) => {
router.push({ name });
};
const onRefresh = () => { const onRefresh = () => {
setTimeout(() => { setTimeout(() => {
loading.value = false; loading.value = false;
}, 1000); }, 1000);
}; };
//
const navigateTo = (path) => {
window.location.href = path;
};
// 使 router
const goto = (name) => {
router.push({ name });
};
onMounted(() => {
});
return { return {
currentTitle, currentTitle,
loading, loading,
filteredMenuItems,
onRefresh, onRefresh,
navigateTo, navigateTo,
goto, goto,
updateMenuVisibility
}; };
} }
}; };
</script> </script>
<style scoped> <style scoped>
/* 原有样式保持不变 */
.page-container { .page-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -99,7 +140,6 @@ export default {
.item-content { .item-content {
margin-top: 20px; margin-top: 20px;
} }
van-pull-refresh { van-pull-refresh {
@ -128,7 +168,7 @@ van-pull-refresh {
.custom-cell .van-cell__label, .custom-cell .van-cell__label,
.custom-cell .van-cell__value, .custom-cell .van-cell__value,
.custom-cell .van-icon { .custom-cell .van-icon {
font-size: 20px; /* Adjust the font size as needed */ font-size: 20px;
} }
.custom-cell .van-cell__title { .custom-cell .van-cell__title {
@ -136,7 +176,6 @@ van-pull-refresh {
} }
.custom-cell .van-cell__value { .custom-cell .van-cell__value {
color: #666; /* Customize the value text color if needed */ color: #666;
} }
</style> </style>

View File

@ -643,17 +643,14 @@ export default {
} }
}; };
const MQTT_send = (send_string) => { const MQTT_send = (send_string) => {
console.log("MQTT 发送:" + JSON.stringify(send_string)); console.log(" 向父页面发送消息:", JSON.stringify(send_string));
jsonId.value++; // 使 postMessage
if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) { window.parent.postMessage(
uni.postMessage({ {
data: { data: send_string
str: JSON.stringify(send_string) },
} '*' // origin
}); );
} else {
window.parent.postMessage({ str: JSON.stringify(send_string) }, "*");
}
}; };
const MQTT_recv = (string) => { const MQTT_recv = (string) => {
@ -667,7 +664,12 @@ export default {
onMounted(async () => { onMounted(async () => {
await checkEnvironment(); await checkEnvironment();
console.log(isLocal.value); console.log(isLocal.value);
window.MQTT_recv = MQTT_recv; window.addEventListener('message', function (event) {
console.log("接受的原始数据", JSON.stringify(event.data))
if (event.data) {
MQTT_recv(JSON.stringify(event.data)); // MQTT_recv
}
});
onRefresh(); onRefresh();
}); });

View File

@ -112,21 +112,60 @@ export default {
// //
const isLocal = window.location.hostname === '192.168.4.1'; const isLocal = window.location.hostname === '192.168.4.1';
const MQTT_send = (send_string) => { // const MQTT_send = (send_string) => {
console.log("MQTT 发送:" + JSON.stringify(send_string)); // console.log(" :", JSON.stringify(send_string));
if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) { // // 使 postMessage
// window.parent.postMessage(
// {
// data: send_string
// },
// '*' // origin
// );
// };
// const MQTT_send = (send_string) => {
// console.log(":", JSON.stringify(send_string));
// //
// if (typeof uni !== 'undefined' && uni.postMessage) {
// // /APP使uni.postMessage
// uni.postMessage({
// data: {
// type: 'mqtt_data',
// payload: send_string,
// timestamp: Date.now()
// }
// });
// } else {
// // H5使window.parent.postMessage
// window.parent.postMessage(
// {
// data: send_string
// },
// '*' // origin
// );
// }
// };
const MQTT_send = (send_string) => {
console.log("向父页面发送消息:", JSON.stringify(send_string));
// 使uni.postMessage
uni.postMessage({ uni.postMessage({
data: { data: {
str: JSON.stringify(send_string) type: 'mqtt_data',
payload: send_string,
timestamp: Date.now()
} }
}); });
} else { };
window.parent.postMessage({ str: JSON.stringify(send_string) }, "*");
}
};
const handleMQTTMessage = (string) => { const handleMQTTMessage = (string) => {
console.log("MQTT 接收:" + string); // console.log("MQTT :" + string);
const data = JSON.parse(string); const data = JSON.parse(string);
// console.log("MQTT :", JSON.stringify(data, null, 2)); // JSON // console.log("MQTT :", JSON.stringify(data, null, 2)); // JSON
@ -247,8 +286,13 @@ export default {
// MQTT // MQTT
const MQTT_recv = (string) => { const MQTT_recv = (string) => {
console.log("MQTT 接收的json:" + string); // console.log("MQTT json:" + string);
handleMQTTMessage(string); // JSON
const parsedString = JSON.parse(string);
//
const data = typeof parsedString === 'string' ? JSON.parse(parsedString) : parsedString;
// console.log("MQTTRECV json:" + JSON.stringify(data));
handleMQTTMessage(JSON.stringify(data));
}; };
// //
const onRefresh = async () => { const onRefresh = async () => {
@ -280,9 +324,21 @@ export default {
// MQTT // MQTT
onMounted(() => { onMounted(() => {
console.log(isLocal); console.log(isLocal);
onRefresh(); const messageHandler = function (event) {
window.MQTT_recv = MQTT_recv; console.log("111接受的原始数据", JSON.stringify(event.data))
if (event.data) {
MQTT_recv(JSON.stringify(event.data)); // MQTT_recv
}
};
window.addEventListener('message', messageHandler);
// onRefresh();
//
onBeforeUnmount(() => {
window.removeEventListener('message', messageHandler);
console.log('移除事件监听器');
});
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {

View File

@ -225,6 +225,8 @@ export default {
const runningtime = ref("1"); const runningtime = ref("1");
const pauseduration = ref("1"); const pauseduration = ref("1");
const playlist = ref([]); // const playlist = ref([]); //
const eventplaylist = ref([]); // const eventplaylist = ref([]); //
const showOptionsDialog = ref(false); // Dialog const showOptionsDialog = ref(false); // Dialog
const selectedOption = ref(""); // const selectedOption = ref(""); //
@ -400,8 +402,14 @@ export default {
}; };
// //
onMounted(async () => { onMounted(async () => {
window.addEventListener('message', function (event) {
console.log("接受的原始数据",JSON.stringify(event.data))
if (event.data) {
MQTT_recv(JSON.stringify(event.data)); // MQTT_recv
}
});
// showToast("success") // showToast("success")
window.MQTT_recv = MQTT_recv; // window.MQTT_recv = MQTT_recv;
await checkEnvironment(); await checkEnvironment();
getallinfo(); getallinfo();
// fetchAudioData(); // // fetchAudioData(); //
@ -449,16 +457,14 @@ export default {
const MQTT_send = (send_string) => { const MQTT_send = (send_string) => {
console.log("MQTT 发送:" + JSON.stringify(send_string)); console.log(" 向父页面发送消息:", JSON.stringify(send_string));
if (/xazn/.test(navigator.userAgent) || /uni-app/.test(navigator.userAgent)) { // 使 postMessage
uni.postMessage({ window.parent.postMessage(
data: { {
str: JSON.stringify(send_string) data: send_string
} },
}); '*' // origin
} else { );
window.parent.postMessage({ str: JSON.stringify(send_string) }, "*");
}
}; };
// MQTT // MQTT
const MQTT_recv = (string) => { const MQTT_recv = (string) => {
@ -1177,7 +1183,7 @@ export default {
} }
console.log('combinedList:', JSON.stringify(combinedList.value)); console.log('combinedList:', JSON.stringify(combinedList.value));
} }

View File

@ -26,7 +26,10 @@ module.exports = defineConfig({
devServer: { devServer: {
open: true, open: true,
hot: true,//自动保存 hot: true,//自动保存
port:80 port: 80,
headers: {
'Access-Control-Allow-Origin': '*', // 允许跨域
},
}, },
chainWebpack: (config) => { chainWebpack: (config) => {
config.plugin('code-inspector-plugin').use( config.plugin('code-inspector-plugin').use(
@ -36,16 +39,24 @@ module.exports = defineConfig({
); );
}, },
configureWebpack: { configureWebpack: {
//qiankun
output: {
library: `subapp-[name]`, // 必须唯一
libraryTarget: 'umd', // 必须使用 UMD 格式
chunkLoadingGlobal: `webpackJsonp_subapp`, // 避免全局 JSONP 冲突
},
plugins: [ plugins: [
// 当 unplugin-vue-components 版本小于 0.26.0 时,使用以下写法 // 当 unplugin-vue-components 版本小于 0.26.0 时,使用以下写法
// AutoImport({ resolvers: [VantResolver()] }), // AutoImport({ resolvers: [VantResolver()] }),
// Components({ resolvers: [VantResolver()] }), // Components({ resolvers: [VantResolver()] }),
//当大于等于 0.26.0 时,使用以下写法 //当大于等于 0.26.0 时,使用以下写法
AutoImport.default({ AutoImport.default({
resolvers: [VantResolver(),ElementPlusResolver()], resolvers: [VantResolver(), ElementPlusResolver()],
}), }),
Components.default({ resolvers: [VantResolver(),ElementPlusResolver()] }), Components.default({ resolvers: [VantResolver(), ElementPlusResolver()] }),
// new CompressionWebpackPlugin({ // new CompressionWebpackPlugin({
// algorithm: 'gzip', // 使用gzip压缩 // algorithm: 'gzip', // 使用gzip压缩
// test: /\.js$|\.html$|\.css$/, // 匹配文件名 // test: /\.js$|\.html$|\.css$/, // 匹配文件名