summaryrefslogtreecommitdiff
path: root/nezha-admin/src/main/resources/templates/js/index.js
blob: 64bfc86d1051e7f8ddcd399f34330d88dbc1e143 (plain)
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
<script>
//生成菜单
var menuItem = Vue.extend({
    name: 'menu-item',
    props:{item:{}},
    template:[
        '<li>',
        '	<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" v-for="item in item.list"></menu-item>',
        '	</ul>',

        '	<a v-if="item.type === 1 && item.parentId === 0" :href="\'#\'+item.url">',
        '		<i v-if="item.icon != null" :class="item.icon"></i>',
        '		<span>{{item.name}}</span>',
        '	</a>',

        '	<a v-if="item.type === 1 && item.parentId != 0" :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() - 154);
	$content.find('iframe').each(function() {
		$(this).height($content.height());
		$(this).contents().find('.ui-jqgrid-bdiv').height($content.height()-130);
	});
}).resize();

//注册菜单组件
Vue.component('menuItem',menuItem);

var vm = new Vue({
	el:'#rrapp',
	data:{
		user:{},
		menuList:{},
		currSystem: {}, //当前业务系统
		systems:{}, //用户可切换的业务系统列表
		main:"main.html",
		password:'',
		newPassword:'',
        navTitle:"控制台",
        changeSystemShow: false, //是否显示业务系统列表
        changeLangShow: false, //是否显示语言列表
        systemBoxWidth: null, //业务系统列表dom的宽度
        langList: [],
        currLang: {}
	},
	methods: {
		getMenuList: function (event) {
			$.getJSON("sys/menu/nav?_"+$.now(), function(r){
				vm.menuList = r.menuList;
			});
		},
		getUser: function(){
			$.getJSON("sys/user/info?_"+$.now(), function(r){
				vm.user = r.user;
			});
		},
		getCurrSystem: function() {
			$.getJSON("system/detail", function(r){
				vm.currSystem = r.data;
			});
		},
		getSystems: function() {
			$.getJSON("system/listByUser?_"+$.now(), function(r){
				vm.systems = r.data;
			});
		},
		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: "sys/user/password",
					    data: data,
					    dataType: "json",
					    success: function(result){
							if(result.code == 200){
								layer.close(index);
								layer.alert('修改成功', function(index){
									location.reload();
								});
							}else{
								layer.alert(result.msg);
							}
						}
					});
	            }
			});
		},
		toChangeSystem: function(event) {
			vm.changeSystemShow = !(vm.changeSystemShow); 
			vm.changeLangShow = false;
		},
		toChangeLang: function() {
			vm.changeLangShow = !(vm.changeLangShow); 
			vm.changeSystemShow = false;
		},
		getLangList: function(event) { //查字典获取语言种类
			$.getJSON("sys/i18n/getLangList2", function(r){
				vm.langList = r.data;
			});
		},
		changeSystem: function(systemId) {
			$.getJSON("system/changeSystem?id=" + systemId, function(r){
				if (r.code == '200') {
					location.reload();
				} else {
					alert(r.msg);
				}
			});
		},
		changeLang: function(lang) {
			location.href = "?_lang=" + lang;
		},
		getCurrLang: function() {
			$.getJSON("sys/i18n/getCurrLang", function(r){
				if (r.code == '200') {
					vm.currLang = r.data;
				}
			});
		},
        donate: function() {
            layer.open({
                type: 2,
                title: false,
                area: ['806px', '467px'],
                closeBtn: 1,
                shadeClose: false,
                content: ['http://cdn.nezha.io/donate.jpg', 'no']
            });
        },
        logout: function() {
        	$.get("${request.contextPath}/logout");
        	location.reload();
        }
	},
	created: function(){
		this.getMenuList();
		this.getUser();
		this.getSystems();
		this.getCurrSystem();
		this.getLangList();
		this.getCurrLang();
	},
	updated: function(){
		//路由
		var router = new Router();
		routerList(router, vm.menuList);
		router.start();
	}
});



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('#', '');
				goNext(url.replace('#', ''));
			    
			    //导航菜单展开
			    $(".treeview-menu li").removeClass("active");
			    $("a[href='"+url+"']").parents("li").addClass("active");
			    
			    vm.navTitle = $("a[href='"+url+"']").text();
			    
			    window.location.hash = url + "?_" + new Date().getTime();
			});
		}
	}
}

function goNext(url) {
    vm.main = url;
    $("#childIframe")[0].contentWindow.location.reload(true);
}
</script>