phone-check-test.html
7.18 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>手机号码重复检查测试</title>
<script src="config.js"></script>
<style>
body {
font-family: 'PingFang SC', 'Microsoft YaHei', Arial, sans-serif;
margin: 20px;
background: #f5f5f5;
}
.container {
max-width: 600px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.form-group {
margin: 15px 0;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 5px;
font-size: 16px;
margin-bottom: 10px;
}
.btn {
background: #2196f3;
color: white;
border: none;
padding: 12px 24px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin: 5px;
}
.btn:hover {
background: #1976d2;
}
.result {
margin: 15px 0;
padding: 15px;
border-radius: 8px;
font-family: monospace;
white-space: pre-wrap;
}
.result.success {
background: #e8f5e9;
border: 1px solid #4caf50;
color: #2e7d32;
}
.result.error {
background: #ffebee;
border: 1px solid #f44336;
color: #c62828;
}
.result.info {
background: #e3f2fd;
border: 1px solid #2196f3;
color: #1565c0;
}
</style>
</head>
<body>
<div class="container">
<h1>🔍 手机号码重复检查测试</h1>
<div class="form-group">
<label for="phoneNumber">手机号码:</label>
<input type="tel" id="phoneNumber" placeholder="请输入手机号码" value="18628099313">
</div>
<div class="form-group">
<button class="btn" onclick="testPhoneCheck()">测试手机号码检查</button>
<button class="btn" onclick="clearResult()">清除结果</button>
</div>
<div id="result" class="result info">点击按钮开始测试</div>
</div>
<script>
// 手机号码重复检查函数(复制自expansion.html)
async function checkPhoneNumberDuplicate(phoneNumber) {
if (!phoneNumber) {
return { allowed: false, message: '手机号码不能为空' };
}
try {
const apiBaseUrl = window.APP_CONFIG ? window.APP_CONFIG.getApiBaseUrl() : '';
if (!apiBaseUrl) {
return { allowed: false, message: 'API地址未配置' };
}
console.log('🔍 检查手机号码重复:', phoneNumber);
console.log('🔍 API地址:', apiBaseUrl);
// 调用API检查手机号码
const url = `${apiBaseUrl}/api/Extend/lqtkjlb?dhhm=${encodeURIComponent(phoneNumber)}`;
console.log('🔍 请求URL:', url);
const response = await fetch(url, {
method: 'GET',
headers: {
'Accept': 'application/json'
}
});
console.log('🔍 响应状态:', response.status);
if (response.ok) {
const result = await response.json();
console.log('🔍 API响应:', result);
// 检查响应结构,判断是否有重复记录
if (result && result.code === 200) {
// 检查data.list是否有数据
if (result.data && result.data.list && Array.isArray(result.data.list) && result.data.list.length > 0) {
console.log('❌ 手机号码已存在,找到记录数:', result.data.list.length);
console.log('❌ 重复记录:', result.data.list);
return {
allowed: false,
message: `已有该号码客户,不允许提交。手机号: ${phoneNumber},已存在 ${result.data.list.length} 条记录`
};
}
// 检查data.total是否有总数
if (result.data && result.data.pagination && result.data.pagination.total > 0) {
console.log('❌ 手机号码已存在,总数:', result.data.pagination.total);
return {
allowed: false,
message: `已有该号码客户,不允许提交。手机号: ${phoneNumber},已存在 ${result.data.pagination.total} 条记录`
};
}
// 如果都没有数据,说明可以提交
console.log('✅ 手机号码检查通过,可以提交');
return { allowed: true, message: '手机号码检查通过' };
} else {
console.log('⚠️ API返回非成功状态:', result);
// 如果API返回非成功状态,为了安全起见,允许提交
return { allowed: true, message: 'API检查异常,允许提交' };
}
} else if (response.status === 404) {
// 404表示没有找到记录,可以提交
console.log('✅ 手机号码检查通过(404),可以提交');
return { allowed: true, message: '手机号码检查通过' };
} else {
console.log('⚠️ 手机号码检查异常:', response.status);
// 如果检查失败,为了安全起见,允许提交
return { allowed: true, message: '手机号码检查异常,允许提交' };
}
} catch (error) {
console.error('手机号码检查失败:', error);
// 如果检查失败,为了安全起见,允许提交
return { allowed: true, message: '手机号码检查失败,允许提交' };
}
}
// 测试手机号码检查
async function testPhoneCheck() {
const resultEl = document.getElementById('result');
const phoneNumber = document.getElementById('phoneNumber').value.trim();
if (!phoneNumber) {
resultEl.className = 'result error';
resultEl.textContent = '❌ 请输入手机号码';
return;
}
try {
resultEl.className = 'result info';
resultEl.textContent = '🔄 正在检查手机号码...';
const checkResult = await checkPhoneNumberDuplicate(phoneNumber);
if (checkResult.allowed) {
resultEl.className = 'result success';
resultEl.textContent = `✅ ${checkResult.message}`;
} else {
resultEl.className = 'result error';
resultEl.textContent = `❌ ${checkResult.message}`;
}
} catch (error) {
resultEl.className = 'result error';
resultEl.textContent = `❌ 检查失败: ${error.message}`;
}
}
// 清除结果
function clearResult() {
document.getElementById('result').className = 'result info';
document.getElementById('result').textContent = '点击按钮开始测试';
}
// 页面加载完成后显示配置信息
document.addEventListener('DOMContentLoaded', function() {
if (window.APP_CONFIG) {
const info = `当前环境: ${window.APP_CONFIG.getEnvName()}\nAPI地址: ${window.APP_CONFIG.getApiBaseUrl()}`;
document.getElementById('result').textContent = info;
}
});
</script>
</body>
</html>