debug-dialog.html
5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>弹框状态调试工具</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.container {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
}
.status-section {
margin: 20px 0;
padding: 15px;
background: #f8f9fa;
border-radius: 5px;
border-left: 4px solid #007bff;
}
.button-group {
display: flex;
gap: 10px;
margin: 20px 0;
flex-wrap: wrap;
}
button {
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
transition: background-color 0.3s;
}
.btn-primary {
background-color: #007bff;
color: white;
}
.btn-primary:hover {
background-color: #0056b3;
}
.btn-warning {
background-color: #ffc107;
color: #212529;
}
.btn-warning:hover {
background-color: #e0a800;
}
.btn-danger {
background-color: #dc3545;
color: white;
}
.btn-danger:hover {
background-color: #c82333;
}
.alert {
padding: 10px;
margin: 10px 0;
border-radius: 5px;
}
.alert-success {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.alert-info {
background-color: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
</style>
</head>
<body>
<div class="container">
<h1>未完成表单弹框调试工具</h1>
<div class="alert alert-info">
<strong>说明:</strong>此工具用于调试"您还未完成的表单"弹框的显示状态。如果弹框不显示,可能是因为已经显示过或者表单代码发生了变化。
</div>
<div class="status-section">
<h3>当前状态</h3>
<div id="status"></div>
</div>
<div class="status-section">
<div id="cookies"></div>
</div>
<div class="button-group">
<button class="btn-primary" onclick="checkStatus()">刷新状态</button>
<button class="btn-warning" onclick="resetDialogState()">重置弹框状态</button>
<button class="btn-danger" onclick="clearAllData()">清除所有数据</button>
</div>
<div id="message"></div>
</div>
<script>
function checkStatus() {
const dialogShown = sessionStorage.getItem('unfinished_form_dialog_shown');
const dialogCode = sessionStorage.getItem('unfinished_form_dialog_code');
const statusDiv = document.getElementById('status');
statusDiv.innerHTML = `
<p><strong>弹框状态:</strong> ${dialogShown === 'true' ? '已显示过' : '未显示'}</p>
<p><strong>记录的表单Code:</strong> ${dialogCode || '无'}</p>
<p><strong>SessionStorage弹框值:</strong> ${dialogShown || '无'}</p>
<p><strong>SessionStorage代码值:</strong> ${dialogCode || '无'}</p>
`;
// 检查Cookie状态
const cookies = document.cookie.split(';');
const cookieDiv = document.getElementById('cookies');
let cookieInfo = '<h3>相关Cookie信息:</h3>';
if (cookies.length === 1 && cookies[0] === '') {
cookieInfo += '<p>无Cookie数据</p>';
} else {
cookies.forEach(cookie => {
const [name, value] = cookie.trim().split('=');
if (name && value) {
cookieInfo += `<p><strong>${name}:</strong> ${decodeURIComponent(value)}</p>`;
}
});
}
cookieDiv.innerHTML = cookieInfo;
}
function resetDialogState() {
sessionStorage.removeItem('unfinished_form_dialog_shown');
sessionStorage.removeItem('unfinished_form_dialog_code');
showMessage('弹框状态已重置!现在可以重新显示弹框了。', 'success');
checkStatus();
}
function clearAllData() {
// 清除所有sessionStorage
sessionStorage.clear();
// 清除所有cookies(注意:只能清除当前域名下的cookies)
const cookies = document.cookie.split(';');
cookies.forEach(cookie => {
const eqPos = cookie.indexOf('=');
const name = eqPos > -1 ? cookie.substr(0, eqPos).trim() : cookie.trim();
if (name) {
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/';
}
});
showMessage('所有数据已清除!包括SessionStorage和Cookies。', 'success');
checkStatus();
}
function showMessage(text, type) {
const messageDiv = document.getElementById('message');
messageDiv.innerHTML = `<div class="alert alert-${type}">${text}</div>`;
setTimeout(() => {
messageDiv.innerHTML = '';
}, 3000);
}
// 页面加载时自动检查状态
window.onload = function() {
checkStatus();
};
</script>
</body>
</html>