This commit is contained in:
JayJiaJun 2025-05-27 15:23:19 +08:00
parent afdda263e6
commit 328e470c27
2 changed files with 103 additions and 72 deletions

View File

@ -6,31 +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')" /> <template v-for="(item, index) in filteredMenuItems" :key="index">
<van-cell size="large" class="custom-cell" title="声卡设置" icon="volume-o" is-link value="语音" <van-cell size="large" class="custom-cell" :title="item.title" :icon="item.icon" is-link
@click="goto('voiceset')" /> :value="item.value" @click="item.action" />
<van-cell size="large" class="custom-cell" title="车牌识别" icon="search" is-link value="识别" </template>
@click="goto('recognition')" />
<van-cell size="large" class="custom-cell" title="预警设置" icon="warning-o" is-link value="预警"
@click="goto('warning')" />
<van-cell size="large" class="custom-cell" title="远程喊话" icon="bullhorn-o" is-link value="喊话"
@click="navigateTo('web/voice_copy.html')" />
<!-- <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>
@ -40,64 +23,102 @@
</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 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.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(() => {
// window.addEventListener('message', function (event) {
// // console.log("message",JSON.stringify(message))
// //
// if (event.data ) {
// const thingsModels = event.data.data;
// console.log('Received thingsModels:', thingsModels);
// // thingsModels 使
// }
// });
});
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;
@ -117,7 +138,6 @@ export default {
.item-content { .item-content {
margin-top: 20px; margin-top: 20px;
} }
van-pull-refresh { van-pull-refresh {
@ -147,7 +167,6 @@ van-pull-refresh {
.custom-cell .van-cell__value, .custom-cell .van-cell__value,
.custom-cell .van-icon { .custom-cell .van-icon {
font-size: 20px; font-size: 20px;
/* Adjust the font size as needed */
} }
.custom-cell .van-cell__title { .custom-cell .van-cell__title {
@ -156,6 +175,5 @@ van-pull-refresh {
.custom-cell .van-cell__value { .custom-cell .van-cell__value {
color: #666; color: #666;
/* Customize the value text color if needed */
} }
</style> </style>

View File

@ -112,16 +112,16 @@ 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(" 向父页面发送消息:", JSON.stringify(send_string)); console.log(" 向父页面发送消息:", JSON.stringify(send_string));
// 使 postMessage // 使 postMessage
window.parent.postMessage( window.parent.postMessage(
{ {
data: send_string data: send_string
}, },
'*' // origin '*' // origin
); );
}; };
const handleMQTTMessage = (string) => { const handleMQTTMessage = (string) => {
console.log("MQTT 接收:" + string); console.log("MQTT 接收:" + string);
@ -245,8 +245,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 () => {
@ -278,12 +283,20 @@ export default {
// MQTT // MQTT
onMounted(() => { onMounted(() => {
console.log(isLocal); console.log(isLocal);
onRefresh(); const messageHandler = function (event) {
window.addEventListener('message', function (event) { console.log("111接受的原始数据", JSON.stringify(event.data))
console.log("接受的原始数据", JSON.stringify(event.data))
if (event.data) { if (event.data) {
MQTT_recv(JSON.stringify(event.data)); // MQTT_recv MQTT_recv(JSON.stringify(event.data)); // MQTT_recv
} }
};
window.addEventListener('message', messageHandler);
// onRefresh();
//
onBeforeUnmount(() => {
window.removeEventListener('message', messageHandler);
console.log('移除事件监听器');
}); });
}); });