index.js
3.22 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
//生成菜单
var menuItem = Vue.extend({
name: 'menu-item',
props:{item:{},index:0},
template:[
'<li :class="{active: (item.type===0 && index === 0)}">',
'<a v-if="item.type === 0" href="javascript:;">',
'<i v-if="item.icon != null" :class="item.icon"></i>',
'<span>{{item.name}}</span>',
'<i class="fa fa-angle-left pull-right"></i>',
'</a>',
'<ul v-if="item.type === 0" class="treeview-menu">',
'<menu-item :item="item" :index="index" v-for="(item, index) in item.list"></menu-item>',
'</ul>',
'<a v-if="item.type === 1" :href="\'#\'+item.url">' +
'<i v-if="item.icon != null" :class="item.icon"></i>' +
'<i v-else class="fa fa-circle-o"></i> {{item.name}}' +
'</a>',
'</li>'
].join('')
});
//iframe自适应
$(window).on('resize', function() {
var $content = $('.content');
$content.height($(this).height() - 120);
$content.find('iframe').each(function() {
$(this).height($content.height());
});
}).resize();
//注册菜单组件
Vue.component('menuItem',menuItem);
var vm = new Vue({
el:'#rrapp',
data:{
user:{},
menuList:{},
main:"main.html",
password:'',
newPassword:'',
navTitle:"欢迎页"
},
methods: {
getMenuList: function () {
$.getJSON(baseURL + "sys/menu/nav", function(r){
vm.menuList = r.menuList;
window.permissions = r.permissions;
//路由
var router = new Router();
routerList(router, vm.menuList);
router.start();
});
},
getUser: function(){
$.getJSON(baseURL + "sys/user/info", function(r){
vm.user = r.user;
});
},
updatePassword: function(){
layer.open({
type: 1,
skin: 'layui-layer-molv',
title: "修改密码",
area: ['550px', '270px'],
shadeClose: false,
content: jQuery("#passwordLayer"),
btn: ['修改','取消'],
btn1: function (index) {
var data = "password="+vm.password+"&newPassword="+vm.newPassword;
$.ajax({
type: "POST",
url: baseURL + "sys/user/password",
data: data,
dataType: "json",
success: function(r){
if(r.code == 0){
layer.close(index);
layer.alert('修改成功', function(){
location.reload();
});
}else{
layer.alert(r.msg);
}
}
});
}
});
},
logout: function () {
//删除本地token
localStorage.removeItem("token");
//跳转到登录页面
location.href = baseURL + 'login.html';
}
},
created: function(){
this.getMenuList();
this.getUser();
}
});
function routerList(router, menuList){
for(var key in menuList){
var menu = menuList[key];
if(menu.type == 0){
routerList(router, menu.list);
}else if(menu.type == 1){
router.add('#'+menu.url, function() {
var url = window.location.hash;
//替换iframe的url
vm.main = url.replace('#', '');
//导航菜单展开
$(".treeview-menu li").removeClass("active");
$(".sidebar-menu li").removeClass("active");
$("a[href='"+url+"']").parents("li").addClass("active");
vm.navTitle = $("a[href='"+url+"']").text();
});
}
}
}