弹窗双开关控制台存储
This commit is contained in:
parent
a8266b78eb
commit
b8dfc49d55
|
@ -1,14 +1,20 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="settings-container">
|
<div class="settings-container">
|
||||||
|
|
||||||
<el-row class="popup-row">
|
<el-row class="popup-row">
|
||||||
<el-checkbox v-model="isPopupEnabled" @change="handleCheckboxChange" style="color: aliceblue;">
|
<el-col :sm="24" :md="24">弹窗设置</el-col>
|
||||||
开启弹窗
|
<el-col :sm="24" :md="24">
|
||||||
</el-checkbox>
|
<el-checkbox v-model="isInteractivePopupEnabled" @change="handleInteractiveChange" style="color: aliceblue;">
|
||||||
|
开启交互式弹窗
|
||||||
|
</el-checkbox>
|
||||||
|
</el-col>
|
||||||
|
<el-col :sm="24" :md="24">
|
||||||
|
<el-checkbox v-model="isResponsivePopupEnabled" @change="handleResponsiveChange" style="color: aliceblue;">
|
||||||
|
开启响应式弹窗
|
||||||
|
</el-checkbox>
|
||||||
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-row class="channel-row">
|
<el-row class="channel-row">
|
||||||
<Channel/>
|
<Channel />
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -16,51 +22,114 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, inject, onMounted } from 'vue';
|
import { ref, inject, onMounted } from 'vue';
|
||||||
import { ElMessageBox, ElMessage } from 'element-plus';
|
import { ElMessageBox, ElMessage } from 'element-plus';
|
||||||
import type { GlobalWebSocket } from '../utils/useGlobalWebSocket';
|
import type { GlobalWebSocket } from '@/utils/useGlobalWebSocket';
|
||||||
import Channel from '@/components/Channel.vue';
|
import Channel from '@/components/Channel.vue';
|
||||||
|
|
||||||
const isPopupEnabled = ref(false); // 控制弹窗状态
|
const isInteractivePopupEnabled = ref(false); // 交互式弹窗状态
|
||||||
const globalWebSocket = inject<GlobalWebSocket>('globalWebSocket'); // 指定类型
|
const isResponsivePopupEnabled = ref(false); // 响应式弹窗状态
|
||||||
|
const globalWebSocket = inject<GlobalWebSocket>('globalWebSocket');
|
||||||
|
|
||||||
// 确保 globalWebSocket 已经注入成功
|
|
||||||
if (!globalWebSocket) {
|
if (!globalWebSocket) {
|
||||||
throw new Error('globalWebSocket 注入失败');
|
throw new Error('globalWebSocket 注入失败');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从 localStorage 中读取勾选状态
|
// 初始化时加载弹窗模式状态
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const storedState = localStorage.getItem('isPopupEnabled');
|
isInteractivePopupEnabled.value = localStorage.getItem('isInteractivePopupEnabled') === 'true';
|
||||||
isPopupEnabled.value = storedState === 'true';
|
isResponsivePopupEnabled.value = localStorage.getItem('isResponsivePopupEnabled') === 'true';
|
||||||
|
updateWebSocketConnection();
|
||||||
// 如果已经勾选且 WebSocket 还未连接,则连接 WebSocket
|
|
||||||
if (isPopupEnabled.value && !globalWebSocket.isWebSocketConnected.value) {
|
|
||||||
globalWebSocket.connectWebSocket();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 当用户勾选或取消勾选时触发的函数
|
// const handleInteractiveChange = () => {
|
||||||
const handleCheckboxChange = () => {
|
// if (isInteractivePopupEnabled.value) {
|
||||||
if (isPopupEnabled.value) {
|
// isResponsivePopupEnabled.value = false;
|
||||||
// 如果复选框被勾选,弹出确认对话框
|
// localStorage.setItem('isResponsivePopupEnabled', 'false');
|
||||||
ElMessageBox.confirm('是否开启弹窗提示?', '提示', {
|
// }
|
||||||
|
// localStorage.setItem('isInteractivePopupEnabled', String(isInteractivePopupEnabled.value));
|
||||||
|
// updateWebSocketConnection();
|
||||||
|
// };
|
||||||
|
|
||||||
|
// const handleResponsiveChange = () => {
|
||||||
|
// if (isResponsivePopupEnabled.value) {
|
||||||
|
// isInteractivePopupEnabled.value = false;
|
||||||
|
// localStorage.setItem('isInteractivePopupEnabled', 'false');
|
||||||
|
// }
|
||||||
|
// localStorage.setItem('isResponsivePopupEnabled', String(isResponsivePopupEnabled.value));
|
||||||
|
// updateWebSocketConnection();
|
||||||
|
// };
|
||||||
|
|
||||||
|
const handleInteractiveChange = () => {
|
||||||
|
if (isInteractivePopupEnabled.value) {
|
||||||
|
ElMessageBox.confirm('是否开启交互式弹窗提示?', '确认提示', {
|
||||||
confirmButtonText: '是',
|
confirmButtonText: '是',
|
||||||
cancelButtonText: '否',
|
cancelButtonText: '否',
|
||||||
type: 'warning',
|
type: 'warning',
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// 用户点击确认,开启 WebSocket 并保存状态
|
isResponsivePopupEnabled.value = false;
|
||||||
localStorage.setItem('isPopupEnabled', 'true');
|
localStorage.setItem('isResponsivePopupEnabled', 'false');
|
||||||
globalWebSocket.connectWebSocket();
|
|
||||||
|
localStorage.setItem('isInteractivePopupEnabled', 'true');
|
||||||
|
updateWebSocketConnection();
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
// 用户取消勾选,重置状态
|
isInteractivePopupEnabled.value = false;
|
||||||
isPopupEnabled.value = false;
|
|
||||||
localStorage.setItem('isPopupEnabled', 'false');
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// 如果复选框未勾选,关闭 WebSocket
|
ElMessageBox.confirm('是否关闭交互式弹窗?', '确认提示', {
|
||||||
|
confirmButtonText: '是',
|
||||||
|
cancelButtonText: '否',
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
localStorage.setItem('isInteractivePopupEnabled', 'false');
|
||||||
|
updateWebSocketConnection();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
isInteractivePopupEnabled.value = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleResponsiveChange = () => {
|
||||||
|
if (isResponsivePopupEnabled.value) {
|
||||||
|
ElMessageBox.confirm('是否开启响应式弹窗提示?', '确认提示', {
|
||||||
|
confirmButtonText: '是',
|
||||||
|
cancelButtonText: '否',
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
isInteractivePopupEnabled.value = false;
|
||||||
|
localStorage.setItem('isInteractivePopupEnabled', 'false');
|
||||||
|
localStorage.setItem('isResponsivePopupEnabled', 'true');
|
||||||
|
updateWebSocketConnection();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
isResponsivePopupEnabled.value = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ElMessageBox.confirm('是否关闭响应式弹窗?', '确认提示', {
|
||||||
|
confirmButtonText: '是',
|
||||||
|
cancelButtonText: '否',
|
||||||
|
type: 'warning',
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
localStorage.setItem('isResponsivePopupEnabled', 'false');
|
||||||
|
updateWebSocketConnection();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
isResponsivePopupEnabled.value = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 根据开关状态更新 WebSocket 连接
|
||||||
|
const updateWebSocketConnection = () => {
|
||||||
|
if (isInteractivePopupEnabled.value || isResponsivePopupEnabled.value) {
|
||||||
|
globalWebSocket.connectWebSocket();
|
||||||
|
} else {
|
||||||
globalWebSocket.closeWebSocket();
|
globalWebSocket.closeWebSocket();
|
||||||
localStorage.setItem('isPopupEnabled', 'false');
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -69,11 +138,11 @@ const handleCheckboxChange = () => {
|
||||||
.settings-container {
|
.settings-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
background-color: #ffffff;
|
background-color: #F1F1F1;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.popup-row {
|
.popup-row {
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
height: 20vh;
|
height: 20vh;
|
||||||
|
@ -85,12 +154,11 @@ const handleCheckboxChange = () => {
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
.channel-row{
|
.channel-row {
|
||||||
margin: 1vh 2vw;
|
margin: 1vh 2vw;
|
||||||
width: 80vw;
|
width: 80vw;
|
||||||
height: 70vh;
|
height: 70vh;
|
||||||
background-color: #001529;
|
background-color: #001529;
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue