Skip to content

Commit

Permalink
* 导航模块优化
Browse files Browse the repository at this point in the history
1、添加导航排序功能
2、链接转化文字功能
3、显示隐藏功能
4、打开方式配置
  • Loading branch information
hwm committed Feb 8, 2017
1 parent 759400c commit d5986da
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 39 deletions.
65 changes: 34 additions & 31 deletions liblog.sql

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/common/config/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
port: '3306',
database: 'liblog',
user: 'root',
password: 'root',
password: '',
prefix: 'li_',
encoding: 'utf8'
},
Expand Down
2 changes: 1 addition & 1 deletion src/doc/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class extends think.controller.base {
this.assign('tagList', tagList);

//获取导航链接
let navList = await this.model("doc").findAll('menu');
let navList = await this.model("doc").getOrderList('menu', { appear: 1 });
this.assign("navList", navList);

//获取友情链接
Expand Down
2 changes: 1 addition & 1 deletion src/home/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class extends think.controller.base {
this.assign('tagList', tagList);

//获取导航链接
let navList = await this.model("home").findAll('menu');
let navList = await this.model("home").getOrderList('menu', { appear: 1 });
this.assign("navList", navList);

//获取友情链接
Expand Down
2 changes: 1 addition & 1 deletion src/personal/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class extends think.controller.base {
//是否登陆

//获取导航链接
let navList = await this.model('personal').findAll('menu');
let navList = await this.model('personal').getOrderList('menu', { appear: 1 });
this.assign("navList", navList);

// 设置主题地址
Expand Down
2 changes: 1 addition & 1 deletion src/topic/controller/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class extends think.controller.base {
this.assign('tagList', tagList);

//获取导航链接
let navList = await this.model("topic").findAll('menu');
let navList = await this.model("topic").getOrderList('menu', { appear: 1 });
this.assign("navList", navList);

//获取友情链接
Expand Down
23 changes: 23 additions & 0 deletions view/admin/menu_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<th width="80" class="sorting_desc" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-sort="descending" aria-label="ID: 升序排列" style="width: 80px;">ID</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 247px;">导航名</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 247px;">导航链接</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 100px;">是否显示</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 100px;">显示顺序</th>
<th class="sorting" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="标题: 升序排列" style="width: 100px;">打开方式</th>
<th width="120" class="sorting_disabled" rowspan="1" colspan="1" aria-label="操作" style="width: 120px;">操作</th>
</tr>
</thead>
Expand All @@ -30,7 +33,27 @@
<td>{{item.id}}</td>
<td>{{item.menuname}}</td>
<td>{{item.url}}</td>
<td class="td-status">
{% if item.appear==1 %}
<span class="label label-success radius">显示</span> {%else%}
<span class="label label-defaunt radius">隐藏</span> {%endif%}
</td>
<td>{{item.orders}}</td>
<td>
{% if item.target==0 %}
默认 {%else%}
新窗口 {%endif%}
</td>
<td class="f-14 td-manage">
{% if item.appear==1 %}
<a style="text-decoration:none" class="ml-5 edit isappear" href="javascript:void(0);" menu-id="{{item.id}}" menu-val="0" title="隐藏">
<i class="Hui-iconfont"></i>
</a>
{%else%}
<a style="text-decoration:none" class="ml-5 edit isappear" href="javascript:void(0);" menu-id="{{item.id}}" menu-val="1" title="显示">
<i class="Hui-iconfont"></i>
</a>
{%endif%}
<a style="text-decoration:none" class="ml-5 edit" href="/admin/{{action}}/item/{{item.id}}" title="编辑">
<i class="Hui-iconfont"></i>
</a>
Expand Down
43 changes: 42 additions & 1 deletion view/admin/menu_item.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,53 @@
</div>
</div>
<div class="row cl">
<input type="hidden" value="{{item.id}}" id="tid" />
<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>导航链接:</label>
<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
<select name="" class="select" id="linkselect" data-val={{item.url}}>
<option value="" selected>请选择</option>
<option value="/" {%if item.url=="/" %}selected{%endif%}>首页</option>
<option value="/doc.html" {%if item.url=="/doc.html" %}selected{%endif%}>文档</option>
<option value="/download.html" {%if item.url=="/download.html" %}selected{%endif%}>资源下载</option>
<option value="/activity.html" {%if item.url=="/activity.html" %}selected{%endif%}>活动</option>
<option value="/topic.html" {%if item.url=="/topic.html" %}selected{%endif%}>社区</option>
<option value="/topic/job.html" {%if item.url=="/topic/job.html" %}selected{%endif%}>招聘</option>
<option value="/donate.html" {%if item.url=="/donate.html" %}selected{%endif%}>捐赠</option>
<option value="custom">自定义</option>
</select>
</span> </div>
</div>
<div class="row cl customlink" style="display: none;">
<label class="form-label col-xs-4 col-sm-2"></label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text url" value="{{item.url}}" placeholder="" id="" name="">
</div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>是否显示:</label>
<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
<select name="" class="select" id="menuselect">
<option value="" selected>请选择</option>
<option value="1" {%if item.appear==1 %}selected{%endif%}>显示</option>
<option value="0" {%if item.appear==0 %}selected{%endif%}>隐藏</option>
</select>
</span> </div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>打开方式:</label>
<div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
<select name="" class="select" id="targetselect">
<option value="" selected>请选择</option>
<option value="1" {%if item.target==1 %}selected{%endif%}>新窗口</option>
<option value="0" {%if item.target==0 %}selected{%endif%}>默认</option>
</select>
</span> </div>
</div>
<div class="row cl">
<label class="form-label col-xs-4 col-sm-2"><span class="c-red"></span>显示顺序:</label>
<div class="formControls col-xs-8 col-sm-9">
<input type="text" class="input-text orders" value="{{item.orders}}" placeholder="请输入整数,默认为0" id="" name="">
</div>
</div>
<div class="row cl">
<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
<button class="btn btn-secondary radius" id="savemenu" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
Expand Down
49 changes: 48 additions & 1 deletion www/static/admin/js/admin/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,34 @@
* Created by livi on 16/4/20.
*/
$(function(){

//若导航链接为自定义,锁定自定义项
var linkselectData = $('#linkselect').data('val');
if( linkselectData != ''){
if(linkselectData!='/' && linkselectData!='/doc.html' && linkselectData!='/download.html' && linkselectData!='/activity.html' && linkselectData!='/topic.html' && linkselectData!='/topic/job.html' && linkselectData!='/donate.html'){
$('#linkselect').val('custom');
$('.customlink').show();
}
}

//导航链接选择与自定义切换事件
$('#linkselect').change(function(){
var val = $(this).find('option:selected').val();
val=='custom' ? $('.customlink').show() : $('.customlink').hide();$('.url').val('');
})

$("#savemenu").click(function(){
var linkselect = $("#linkselect").val();
if($('.url').val() != ''){
linkselect = $('.url').val();
}
var newData={
id:$("#tid").val(),
menuname:$(".menuname").val(),
url:$(".url").val(),
appear: $("#menuselect").val(),
target: $("#targetselect").val(),
orders: $(".orders").val(),
url:linkselect,
__CSRF__:G_csrf
}
$.ajax({
Expand Down Expand Up @@ -75,3 +98,27 @@ $(function(){
return false
}
}

//显示/隐藏标签
$(".isappear").on('click', function() {
var mid = $(this).attr('menu-id');
var menuVal = $(this).attr('menu-val');
var newData = {
id: mid,
appear: menuVal,
__CSRF__: G_csrf
}
$.ajax({
url: '/admin/menu/save',
data: newData,
type: 'POST',
success: function(json) {
if (json.errno === 0) {
alert("操作成功!");
window.location.href = '/admin/menu/index';
} else {
alert(json.errmsg)
}
}
})
})
2 changes: 1 addition & 1 deletion www/static/theme/liblog/modules_src/common/inc/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<ul class="site-nav site-navbar">
{% for item in navList %}
<li class="item">
<a href="{{ item.url }}">{{ item.menuname }}</a>
<a href="{{ item.url }}" target="{%if(item.target=='0') %}_self{%else%}_blank{% endif %}">{{ item.menuname }}</a>
{% if (item.menuname=="社区") %}
<i class="newicon"></i>
{% endif %}
Expand Down

0 comments on commit d5986da

Please sign in to comment.