/
search_result.html
422 lines (408 loc) · 19.4 KB
/
search_result.html
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
{% load static %}
{% load i18n %}
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta http-equiv="Cache-Control" content="max-age=7200" />
<meta name="keywords" content="{% if site_keywords != None %}{{site_keywords}}{% endif %}"/>
<meta name="description" content="{% if site_desc != None %}{{site_desc}}{% endif %}" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>{{ kw }} - {% trans "觅思搜索" %} - {% if site_name != None and site_name != '' %}{{ site_name }}{% endif %}</title>
<link href="{% static 'layui/css/layui.css' %}" rel="stylesheet">
<link href="{% static 'mrdoc/mrdoc.css' %}?version={{mrdoc_version}}" rel="stylesheet">
<link href="{% static 'mrdoc/mrdoc-search-result.css' %}?version={{mrdoc_version}}" rel="stylesheet">
<link rel="icon" href="{% static 'search/mrdoc_logo_300.png' %}" sizes="192x192" />
<style>
.layui-form-switch{
margin-top: 0px !important;
}
</style>
</head>
<body class="layui-container">
<!-- 页头 -->
<div class="layui-header layui-fluid">
<div class="" style="display:flex;flex-direction:row;justify-content:space-between;">
<!-- LOGO -->
<div class="">
<a class="logo" href="{% url 'search' %}">
<img src="{% static 'search/mrdoc_search_logo_2.svg' %}" style="height: 32px;width: auto;">
</a>
</div>
<!-- 搜索框 -->
<div style="margin:12px;" class="layui-hide-xs">
<form method="get" action="">
<div class="layui-input-inline">
<input class="layui-input mrdoc-search-input"
placeholder="搜索文集或文档" name="kw" style="width: 500px;border-radius:5px" value="{{kw}}"/>
<input name="type" value="{{search_type}}" hidden>
<button type="submit"
style="position: absolute;top:12px;right: 8px;border: none;background-color: white;">
<i class="layui-icon layui-icon-search" ></i>
</button>
</div>
</form>
</div>
<!-- 用户菜单 -->
<div class="">
<ul class="layui-nav layui-layout-right">
{% if request.user.is_authenticated %}
<li class="layui-nav-item">
<a href="javascript:void(0);">
<i class="layui-icon layui-icon-friends"></i>
<span class="layui-hide-xs">{% if request.user.first_name != '' %}{{request.user.first_name}}{% else %}{{request.user.username}}{% endif %}</span>
</a>
<dl class="layui-nav-child">
<!-- <dd><a href="">基本资料</a></dd> -->
{% if request.user.is_superuser %}
<dd>
<a href="{% url 'pro_list' %}">
<i class="layui-icon layui-icon-console layui-hide-md"></i>
<span class="layui-hide-xs">{% trans "返回首页" %}</span>
</a>
</dd>
{% endif %}
<dd class="layui-hide-md">
<a href="{% url 'create_doc' %}">
<i class="layui-icon layui-icon-add-1 layui-hide-md"></i>
</a>
</dd>
<dd>
<a href="{% url 'user_center' %}">
<i class="layui-icon layui-icon-app layui-hide-md"></i>
<span class="layui-hide-xs">{% trans "个人中心" %}</span>
</a>
</dd>
<dd>
<a href="javascript:void(0);" onclick="changePwd('{{ request.user.id }}','{{ request.user.username }}' )">
<i class="layui-icon layui-icon-password layui-hide-md"></i>
<span class="layui-hide-xs">{% trans "修改密码" %}</span>
</a>
</dd>
<dd>
<a href="javascript:void(0)" title="退出登录" onclick="Logout()">
<i class="layui-icon layui-icon-release layui-hide-md"></i>
<span class="layui-hide-xs">{% trans "退出登录" %}</span>
</a>
</dd>
</dl>
</li>
{% else %}
<li class="layui-nav-item">
<a href="javascript:void(0);">
<i class="layui-icon layui-icon-username"></i> {% trans "游客" %}
</a>
<dl class="layui-nav-child">
<!-- <dd><a href="">基本资料</a></dd> -->
{% if close_register == 'on' %}
<dd><a href="{% url 'login' %}">{% trans "登录" %}</a></dd>
{% else %}
<dd><a href="{% url 'register' %}">{% trans "注册" %}</a></dd>
<dd><a href="{% url 'login' %}">{% trans "登录" %}</a></dd>
{% endif %}
</dl>
</li>
{% endif %}
</ul>
</div>
</div>
</div>
<!-- 页头结束 -->
<!-- 小屏下的搜索框 -->
<div class="" style="margin-top:10px;padding-left:15px;">
<!-- 搜索框 -->
<div style="margin:12px 0 12px 0;" class="layui-hide-md layui-hide-lg layui-hide-sm">
<form method="get" action="">
<div class="layui-inline">
<div class="layui-input-inline">
<input class="layui-input mrdoc-search-input"
placeholder="搜索文集或文档" name="kw" style="border-radius:5px" value="{{kw}}"/>
<input name="type" value="{{search_type}}" hidden>
</div>
<div class="layui-input-inline">
<button type="submit" class="layui-btn layui-btn-sm layui-btn-normal">
<i class="layui-icon layui-icon-search" ></i>
</button>
</div>
</div>
</form>
</div>
</div>
<!-- 筛选栏 -->
<div class="layui-container" style="margin-top: 10px;">
<!-- 表单风格开始 -->
<div class="layui-row">
<form class="index-control layui-form" lay-filter="filter-time-form">
<div class="layui-form-item">
<!-- 筛选开始 -->
<div class="layui-inline">
<!-- 文档搜索 -->
<div class="layui-input-inline" style="width: inherit;">
<a href="{% url 'doc_search' %}?q={{kw}}&d_range={{d_range}}" class="search_type" id="search_doc"><i class="layui-icon layui-icon-search"></i>{% trans "文档" %}</a>
<a href="{% url 'search' %}?kw={{kw}}&type=pro&d_range={{d_range}}" class="search_type" id="search_project"><i class="layui-icon layui-icon-list"></i>{% trans "文集" %}</a>
<a href="{% url 'search' %}?kw={{kw}}&type=tag&d_range={{d_range}}" class="search_type" id="search_tag"><i class="layui-icon layui-icon-note"></i>{% trans "标签" %}</a>
</div>
</div>
<!-- 筛选结束 -->
<div class="layui-input-inline" style="float: right;display: flex;">
<div class="layui-input-inline">
<input type="checkbox" name="switch" lay-filter="search_match" lay-skin="switch" lay-text="精准搜索|全文搜索">
</div>
<select name="d_range" lay-verify="sel_recent" id="sel_recent">
<option value="">{% trans "时间筛选" %}</option>
<option value="all">{% trans "全部时间" %}</option>
<option value="recent1">{% trans "近1天" %}</option>
<option value="recent7">{% trans "近7天" %}</option>
<option value="recent30">{% trans "近30天" %}</option>
<option value="recent365">{% trans "近1年" %}</option>
</select>
</div>
</div>
</form>
</div>
<!-- 表单风格结束 -->
</div>
<!-- 搜索结果提示 -->
{% if kw != '' %}
<div style="padding: 0 15px;margin-top: 10px;margin-bottom: 10px;color: #999;">
{% trans "觅思文档在" %}
{% if date_range == 'recent1' %}
{% trans "近1天内" %}
{% elif date_range == 'recent7' %}
{% trans "近7天内" %}
{% elif date_range == 'recent30' %}
{% trans "近30天内" %}
{% elif date_range == 'recent365' %}
{% trans "近一年内" %}
{% else %}
{% trans "全部时间内" %}
{% endif %}
{% trans "搜索到" %} {{ data_list.count }} {% trans "条结果" %}
</div>
{% endif %}
<!-- 主体 -->
<div class="layui-container search_result" id="search_result" style="padding: 0 20px;">
<!-- 遍历搜索结果列表 -->
<!-- 文档搜索结果 -->
{% if search_type == 'doc' %}
{% load doc_filter %}
{% for result in datas %}
<div style="margin-bottom: 18px;">
<!-- 标题 -->
<h3>
<a href="{% url 'doc' pro_id=result.top_doc doc_id=result.id %}" target="_blank" class="search_result_title">{{ result.name }}</a>
</h3>
<!-- 简介 -->
<div class="search_result_pre">{{ result.pre_content|get_key_context:kw }}</div>
<!-- 所属文集 -->
<p class="search_result_info">
<a href="{% url 'pro_index' pro_id=result.top_doc %}" target="_blank">{{ result.top_doc | get_doc_top }}</a> - <span style="font-size: 14px;color: #999;">{{result.modify_time}}</span></p>
</div>
{% endfor %}
<!-- 文集搜索结果 -->
{% elif search_type == 'pro' %}
{% load project_filter %}
{% for result in datas %}
<div style="margin-bottom: 18px;">
<!-- 标题 -->
<h3>
<a href="{% url 'pro_index' pro_id=result.id %}" target="_blank" class="search_result_title">{{ result.name }}</a>
</h3>
<!-- 简介 -->
<div class="search_result_pre">{{ result.intro|get_key_context:kw }}</div>
<!-- 所属文集 -->
<p class="search_result_info">
<a>{% if result.create_user.first_name != '' %}{{ result.create_user.first_name }}{% else %}{{result.create_user}}{% endif %}</a> - <span style="font-size: 14px;color: #999;">{{result.modify_time}}</span></p>
</div>
{% endfor %}
<!-- 标签搜索结果 -->
{% elif search_type == 'tag' %}
{% load doc_filter %}
{% for result in datas %}
<div style="margin-bottom: 18px;">
<!-- 标题 -->
<h3>
<a href="{% url 'doc' pro_id=result.top_doc doc_id=result.id %}" target="_blank" class="search_result_title">{{ result.name }}</a>
</h3>
<!-- 简介 -->
<div class="search_result_pre">{{ result.pre_content|get_key_context:kw }}</div>
<!-- 所属文集 -->
<p class="search_result_info">
<a href="{% url 'pro_index' pro_id=result.top_doc %}" target="_blank">{{ result.top_doc | get_doc_top }}</a> - <span style="font-size: 14px;color: #999;">{{result.modify_time}}</span></p>
</div>
{% endfor %}
{% endif %}
</div>
<!-- 主体结束 -->
<!-- 分页 -->
<div class="layui-row project-list-page" style="text-align: center;">
<div class="layui-box layui-laypage layui-laypage-default">
<!-- 上一页 -->
{% if datas.has_previous %}
<a href="?page={{ datas.previous_page_number }}&kw={{kw}}&type={{search_type}}&d_range={{date_range}}" class="layui-btn layui-btn-xs layui-btn-normal">{% trans "上一页" %}</a>
{% else %}
<a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-disabled">{% trans "上一页" %}</a>
{% endif %}
<!-- 当前页 -->
<span class="layui-laypage-curr">
<em class="layui-laypage-em"></em>
<em>{{ datas.number }}/{{ datas.paginator.num_pages }}</em>
</span>
<!-- 下一页 -->
{% if datas.has_next %}
<a href="?page={{ datas.next_page_number }}&kw={{kw}}&type={{search_type}}&d_range={{date_range}}" class="layui-btn layui-btn-xs layui-btn-normal">{% trans "下一页" %}</a>
{% else %}
<a class="layui-btn layui-btn-xs layui-btn-disabled">{% trans "下一页" %}</a>
{% endif %}
</div>
</div>
<!-- 分页结束 -->
<!-- 页脚 -->
{% include 'app_doc/foot_base.html' %}
<!-- 页脚结束 -->
<script src="{% static 'jquery/3.1.1/jquery.min.js' %}"></script>
<script src="{% static 'layui/layui.js' %}"></script>
{% block custom_script %}
<script>
$.ajaxSetup({
data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
});
var layer = layui.layer;
var form = layui.form;
function positionFooter() {
// 获取页脚的高度
footerHeight = $(".layui-footer").height();
// 获取页脚的高度
// scrollTop() 设置或获取位于对象最顶端和窗口中可见内容的最顶端之间的距离
footerTop = ($(window).scrollTop() + $(window).height() - footerHeight - 35)+"px";
//如果页面内容高度小于屏幕高度,div#footer将绝对定位到屏幕底部,否则div#footer保留它的正常静态定位
if(($(".layui-header").height() + $(".index-control").height() + $(".project-list-content").height() + $(".project-list-page").height() + 16) < $(window).height()) {
console.log("页脚置底")
$(".layui-footer").css({ position: "absolute",left:"0" }).stop().css({top:footerTop});
}else{
$(".layui-footer").css({ position: ""})
}
};
$(window).bind("load", function() {
// 设置页脚位置
var footerHeight = 0;
var footerTop = 0;
positionFooter();
//$(window).scroll(positionFooter).resize(positionFooter);
//设置条件栏选中值
var url = layui.url();
console.log(url)
$("#sel-role").val(url.search.role);
$("#sel-sort").val(url.search.sort);
layui.form.render('select');
});
// 搜索词高亮
function keyLight(id, key, bgColor){
var oDiv = document.getElementById(id),
sText = oDiv.innerHTML,
bgColor = bgColor || "#c00",
sKey = "<span name='addSpan' style='color: "+bgColor+";'>"+key+"</span>",
num = -1,
rStr = new RegExp(key, "ig"),
rHtml = new RegExp("\<.*?\>","ig"), //匹配html元素
aHtml = sText.match(rHtml); //存放html元素的数组
sText = sText.replace(rHtml, '{~}'); //替换html标签
// sText = sText.replace(rStr,sKey); //替换key
sText = sText.replace(rStr,function(text){
return "<span name='addSpan' style='color: "+bgColor+";'>"+text+"</span>"
}); //替换key
sText = sText.replace(/{~}/g,function(){ //恢复html标签
num++;
return aHtml[num];
});
oDiv.innerHTML = sText;
};
keyLight('search_result',"{{kw}}")
// 侦听Select下拉框的选择事件
form.on('select()', function(data){
var filter_data = form.val("filter-time-form");
// console.log(filter_data)
window.location.href = '{% url "search" %}?kw={{kw}}&type={{search_type}}' + '&d_range=' + filter_data['d_range']
});
// 切换到匹配搜索
form.on('switch(search_match)', function(data){
window.location.href = "{% url 'doc_search' %}?q={{kw}}&d_range={{d_range}}";
});
// 当前搜索类型动态设置
tagCurrentSearchType = function(){
if('{{ search_type }}' == 'doc'){
$('#search_doc').addClass('current_search_type')
$('#search_project').removeClass('current_search_type')
$('#search_tag').removeClass('current_search_type')
}else if('{{ search_type }}' == 'pro'){
$('#search_project').addClass('current_search_type')
$('#search_doc').removeClass('current_search_type')
$('#search_tag').removeClass('current_search_type')
}else if('{{ search_type }}' == 'tag'){
$('#search_tag').addClass('current_search_type')
$('#search_doc').removeClass('current_search_type')
$('#search_project').removeClass('current_search_type')
}
}
tagCurrentSearchType();
</script>
<script>
//修改用户密码
changePwd = function(uid,username){
layer.open({
type:1,
title:'修改密码',
area:'300px;',
id:'changePwd',
content:'<div style="padding:10px 0 0 20px;">修改用户[' + username + ']的密码:</div><div style="padding: 20px;"><input class="layui-input" type="password" id="newPwd1" style="margin-bottom:10px;" placeholder="输入新密码" required lay-verify="required"><input class="layui-input" type="password" id="newPwd2" placeholder="再次确认新密码" required lay-verify="required"></div>',
btn:['确认修改','取消'],
yes:function (index,layero) {
layer.load(1);
data = {
'password':$("#newPwd1").val(),
'password2':$("#newPwd2").val(),
}
$.post("{% url 'modify_pwd' %}",data,function(r){
layer.closeAll("loading");
if(r.status){
//修改成功
window.location.reload();
//layer.close(index)
}else{
//修改失败,提示
//console.log(r)
layer.msg(r.data)
}
})
},
})
};
function Logout(){
$.ajax({
url:"{% url 'logout' %}",
method:'post',
success:function(r){
if(r.status){
window.location.href = r.data
}else{
layer.msg("注销失败")
}
},
error:function(){
layer.msg("注销失败")
}
})
}
</script>
<!-- 统计代码开始 -->
{% if debug %}
{% else %}
{{ static_code | safe }}
{% endif %}
<!-- 统计代码结束 -->
{% endblock %}
</body>
</html>