PageSourceSearch

https://hnls.gov.cn/js/newRobot.js

js hnls.gov.cn collected 2026-10-07 14:42:34 UTC 16,232 bytes, 418 lines download raw bytes

1    document.addEventListener('DOMContentLoaded', function () {
2        loadHistoryFromStorage();
3    });
4
5
6    document.querySelectorAll('.common-questions li').forEach(item => {
7        item.addEventListener('click', function () {
8            const question = this.getAttribute('data-question');
9            document.getElementById('message-input').value = question;
10            sendMessage();
11        });
12    });
13
14    document.getElementById('expand-toggle').addEventListener('click', function () {
15        const container = document.querySelector('.common-questions-container');
16        const icon = this.querySelector('i');
17        const text = this.querySelector('.expand-text');
18        const serviceCard = document.querySelector('.sidebar .card:nth-child(1)'); 
19        const historyCard = document.querySelector('.sidebar .card:nth-child(3)'); 
20        container.classList.toggle('expanded');
21        this.classList.toggle('expanded');
22        if (container.classList.contains('expanded')) {
23            text.textContent = '收起内容';
24            serviceCard.classList.add('sidebar-card-hidden');
25            historyCard.classList.add('sidebar-card-hidden');
26        } else {
27            text.textContent = '展开更多';
28            serviceCard.classList.remove('sidebar-card-hidden');
29            historyCard.classList.remove('sidebar-card-hidden');
30        }
31    });
32
33    document.querySelectorAll('.history-tag').forEach(tag => {
34        tag.addEventListener('click', function () {
35            const historyQuery = this.getAttribute('data-query');
36            document.getElementById('message-input').value = historyQuery;
37            document.getElementById('message-input').focus();
38        });
39    });
40
41    document.getElementById('send-btn').addEventListener('click', function () {
42        sendMessage();
43    });
44     function escapeHtml(text) {
45        const map = {
46            '&': '&',
47            '<': '&lt;',
48            '>': '&gt;',
49            '"': '&quot;',
50            "'": '&#039;',
51            '/': '&#x2F;'
52        };
53        
54        return String(text).replace(/[&<>"'\/]/g, function (s) {
55            return map[s];
56        });
57    }
58
59    function getZwfw(word ,callback) {
60        $.ajax({
61                type: "get",
62                url: "https://search.hnzwfw.gov.cn/search/matters",
63                dataType: "json",
64                data: {
65                    pageNum: 1,
66                    pageSize: 6,
67                    areaCode: '410400000000',
68                    q: word
69                },
70                success: function(data){
71                    if(data && data.result && data.result.records.length > 0){
72                        var services = data.result.records;
73                        var service='';
74                        for(var i=0; i < services.length; i++){
75                            var deal_url = 'https://www.hnzwfw.gov.cn/portal/guide/' + services[i].unid + '?region=410400000000';
76                            service +='<li><a href="' + deal_url + '" target="_blank"><img src="https://www.pds.gov.cn/images/linkqarobot.png">' + services[i].serviceName + '</a></li><em>' + services[i].deptName + '</em>';
77                        }
78                      
79
80                    } else {
81                        // var service = '<a href="javascript:void(0);"><span>抱歉,您的问题我暂时答不上来。</span></a>';
82                        var service = '';
83                    }
84                    callback(null, service);
85
86                },
87                error: function(xhr, status, error) {
88                    console.log('请求失败:', error);
89                    callback(error, '');
90                }
91            });
92           
93    }
94
95    function postService(keywords,callback) { 
96        $.ajax({
97            type: "post",
98            url: "https://user.pds.gov.cn/api/User/Smart?word=" + keywords+"&siteId=10206",
99            dataType: "json",
100            success: function(data){
101                var responses='';
102                if (data.length > 1) {
103
104                        if(data.length > 6){
105                            for(var i=0; i < 6; i++){
106                                responses+=`<li class="contText">${data[i].Title}</li>`
107                            }
108                            responses+=`<div style="border-top: 1px solid #ccc;margin: 10px 0;"></div>`;
109                        }else{
110                            for(var i=0; i < data.length; i++){
111                                responses+=`<li class="contText">${data[i].Title}</li>`
112                            }
113                            responses+=`<div style="border-top: 1px solid #ccc;margin: 10px 0;"></div>`;
114                        }
115
116                    } else if (data.length == 1) {
117                        responses=data[0].Title;
118                        responses=`<ul><li>${responses}</li></ul>`
119                        responses+=`<div style="border-top: 1px solid #ccc;margin: 10px 0;"></div>`
120                    } else {
121                        // var responses = '<li>抱歉!没有能够帮到您。</li>';
122                        var responses = '';
123
124                    }
125                
126               callback(null, responses);
127            },
128             error: function(xhr, status, error) {
129                console.log('请求失败:', error);
130                callback(error, '');
131                resolve(''); 
132            }
133        });
134           
135}
136
137    function sendMessage() {
138
139        const input = document.getElementById('message-input');
140        const message = input.value.trim();
141        const sendBtn = document.getElementById('send-btn');
142         if (sendBtn.disabled || !message) {
143                return;
144            }
145
146        const escapedMessage = escapeHtml(message);
147
148        sendBtn.disabled = true;
149        sendBtn.style.opacity = '0.6';
150        sendBtn.style.cursor = 'not-allowed';
151
152        if (message) {
153            saveToHistory(message);
154            addMessage(escapedMessage, 'user');
155
156            input.value = '';
157
158            var weathers=new Map([
159                ['天气', '<iframe allowtransparency="true" frameborder="0" width="410" height="98" scrolling="no" src="//tianqi.2345.com/plugin/widget/index.htm?s=1&z=1&t=1&v=0&d=2&bd=0&k=&f=&ltf=009944&htf=cc0000&q=1&e=1&a=0&c=70280&w=410&h=98&align=center"></iframe>'],
160                ['景区', '<li><a href="https://wglj.pds.gov.cn/channels/12520.html" target="_blank"><img src="https://pds.gov.cn/images/linkqarobot.png">文旅资源-旅游景区</a></li>'],
161                ['美食', '<li><a href="https://wglj.pds.gov.cn/channels/12525.html" target="_blank"><img src="https://pds.gov.cn/images/linkqarobot.png">文旅资源-旅游美食</a></li>'],
162                ['文化场馆', '<li><a href="https://wglj.pds.gov.cn/channels/12528.html" target="_blank"><img src="https://pds.gov.cn/images/linkqarobot.png"> 文旅资源-文化场馆</a></li>'],
163
164            ]);
165            var weather =weathers.get(escapedMessage);
166            if(weather){
167                addMessage(weather, 'assistant', false);
168                sendBtn.disabled = false;
169                sendBtn.style.opacity = '';
170                sendBtn.style.cursor = '';
171                return ;
172            }
173
174        let completed = 0;
175        let results = { zwfw: '', postService: '' };
176        
177        function checkComplete() {
178            completed++;
179            if (completed === 2) {
180                let finalResponse = '';
181               
182                if (results.postService) {
183                    finalResponse +='<li>您好,为您找到以下相关信息:</li>';
184                    finalResponse += results.postService;
185                }else if(results.zwfw){
186                    finalResponse +='<li>您好,为您找到以下相关信息:</li>';
187                }
188                 if (results.zwfw) {
189                    finalResponse += results.zwfw;
190                }
191             
192                
193                if (!finalResponse) {
194                    finalResponse = '抱歉,暂时没有找到相关的信息。';
195                }
196
197                addMessage(finalResponse, 'assistant', false);
198                
199                sendBtn.disabled = false;
200                sendBtn.style.opacity = '';
201                sendBtn.style.cursor = '';
202            }
203        }
204        
205        getZwfw(escapedMessage, function(error, result) {
206            if (!error) {
207                results.zwfw = result;
208            }
209            checkComplete();
210        });
211        postService(escapedMessage, function(error, result) {
212            if (!error) {
213                results.postService = result;
214            }
215
216            checkComplete();
217        });
218
219
220        }
221    }
222
223    function addMessage(text, sender, feedback = false) {
224        const messagesContainer = document.querySelector('.chat-messages');
225        const now = new Date();
226        const timeString = `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
227
228        const messageDiv = document.createElement('div');
229        messageDiv.className = `message ${sender === 'user' ? 'user-message' : ''}`;
230
231        const avatarIcon = sender === 'user' ? 'fa-user' : 'fa-robot';
232        const avatarClass = sender === 'user' ? 'user-avatar-small' : 'assistant-avatar-small';
233
234        let feedbackHtml = '';
235        if (feedback) {
236            feedbackHtml = `
237            <div class="feedback-buttons">
238                <button class="feedback-btn resolved" data-message-id="${Date.now()}">已解决</button>
239                <button class="feedback-btn unresolved" data-message-id="${Date.now()}">未解决</button>
240            </div>
241        `;
242        }
243
244        messageDiv.innerHTML = `
245        <div class="message-avatar ${avatarClass}">
246            <i class="fas ${avatarIcon}"></i>
247        </div>
248        <div class="message-content">
249            <div class="message-bubble ${sender === 'user' ? 'user-bubble' : 'assistant-bubble'}">
250                ${text}
251                ${feedbackHtml}
252            </div>
253        </div>
254    `;
255        messagesContainer.appendChild(messageDiv);
256        messagesContainer.scrollTop = messagesContainer.scrollHeight;
257
258        if (feedback) {
259            const resolvedBtn = messageDiv.querySelector('.resolved');
260            const unresolvedBtn = messageDiv.querySelector('.unresolved');
261
262            resolvedBtn.addEventListener('click', function () {
263                handleFeedback(this, 'resolved');
264            });
265
266            unresolvedBtn.addEventListener('click', function () {
267                handleFeedback(this, 'unresolved');
268            });
269        }
270    }
271
272    function handleFeedback(button, type) {
273        const buttonGroup = button.parentElement;
274        const resolvedBtn = buttonGroup.querySelector('.resolved');
275        const unresolvedBtn = buttonGroup.querySelector('.unresolved');
276
277        resolvedBtn.disabled = true;
278        unresolvedBtn.disabled = true;
279
280        button.classList.add('selected');
281
282        const messageBubble = button.closest('.message-bubble');
283        const feedbackResult = document.createElement('div');
284        feedbackResult.style.marginTop = '8px';
285        feedbackResult.style.fontSize = '12px';
286        feedbackResult.style.color = type === 'resolved' ? '#27ae60' : '#e74c3c';
287        feedbackResult.textContent = type === 'resolved' ? '感谢您的反馈!' : 'æ
287ˆ‘们会继续改进服务质量。';
288
289        messageBubble.appendChild(feedbackResult);
290
291        console.log(`用户反馈: ${type}`);
292    }
293
294    document.getElementById('message-input').addEventListener('keydown', function (e) {
295        if (e.key === 'Enter' && !e.shiftKey) {
296            e.preventDefault();
297            sendMessage();
298        }
299    });
300
301    function saveToHistory(query) {
302        let history = JSON.parse(localStorage.getItem('searchHistory')) || [];
303
304        history = history.filter(item => item !== query);
305
306        history.unshift(query);
307
308        if (history.length > 10) {
309            history = history.slice(0, 10);
310        }
311
312        localStorage.setItem('searchHistory', JSON.stringify(history));
313
314        updateHistoryDisplay(history);
315    }
316
317    function loadHistoryFromStorage() {
318        const history = JSON.parse(localStorage.getItem('searchHistory')) || [];
319        updateHistoryDisplay(history);
320    }
321
322    function updateHistoryDisplay(history) {
323        const historyContainer = document.querySelector('.history-items');
324        if (!historyContainer) return;
325
326        historyContainer.innerHTML = '';
327
328        history.forEach(item => {
329            const tag = document.createElement('div');
330            tag.className = 'history-tag';
331            tag.setAttribute('data-query', item);
332            tag.textContent = item;
333            tag.addEventListener('click', function () {
334                document.getElementById('message-input').value = item;
335                document.getElementById('message-input').focus();
336            });
337            historyContainer.appendChild(tag);
338        });
339    }
340
341    document.querySelectorAll('.quick-action-btn').forEach(button => {
342        button.addEventListener('click', function () {
343            const query = this.getAttribute('data-query');
344            document.getElementById('message-input').value = query;
345            sendMessage();
346        });
347    });
348
349
350    document.getElementById('clear-history').addEventListener('click', function () {
351        this.classList.add('clearing');
352        this.textContent = '清除中...';
353
354        setTimeout(() => {
355            localStorage.removeItem('searchHistory');
356
357            updateHistoryDisplay([]);
358
359            this.classList.remove('clearing');
360            this.textContent = '清除历史记录';
361        }, 500);
362    });
363
364
365    document.addEventListener('DOMContentLoaded', function () {
366        loadHistoryFromStorage();
367        addGreetingMessage();
368    });
369
370    function addGreetingMessage() {
371        const now = new Date();
372        const hour = now.getHours();
373        const timeString = `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
374
375        let greeting = "";
376        if (hour >= 6 && hour < 9) {
377            greeting = "早上好";
378        } else if (hour >= 9 && hour < 12) {
379            greeting = "上午好";
380        } else if (hour >= 12 && hour < 14) {
381            greeting = "中午好";
382        } else if (hour >= 14 && hour < 18) {
383            greeting = "下午好";
384        } else if (hour >= 18 && hour < 22) {
385            greeting = "晚上好";
386        } else {
387            greeting = "夜深了";
388        }
389
390        const dateStr = `${now.getFullYear()}年${(now.getMonth() + 1)}月${now.getDate()}日`;
391        const dayStr = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'][now.getDay()];
392
393        const greetingMessage = `
394        ${greeting}!欢迎使用鲁山县人民政府智能问答平台。<br>
395        今天是${dateStr},${dayStr}。<br>
396        我是您的智能助手"小鹰",有什么我可以帮您的吗?
397    `;
398        const messagesContainer = document.querySelector('.chat-messages');
399
400        const messageDiv = document.createElement('div');
401        messageDiv.className = 'message';
402
403        messageDiv.innerHTML = `
404        <div class="message-avatar assistant-avatar-small">
405        </div>
406        <div class="message-content">
407            <div class="message-bubble assistant-bubble">
408                ${greetingMessage}
409                <div class="message-time">${timeString}</div>
410            </div>
411        </div>
412    `;
413
414        const firstMessage = messagesContainer.firstChild;
415        messagesContainer.insertBefore(messageDiv, firstMessage.nextSibling);
416
417        messagesContainer.scrollTop = messagesContainer.scrollHeight;
418    }

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.