<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="在线用户列表" libs=["table"]/>
<div class="container-div" id="_app">
<div class="row">
<@table id="bootstrap-table">
	<@shiro.hasPermission name="sys:online:forceLogout">
		<a class="btn btn-danger multiple disabled" onclick="javascript:batchForceLogout()">
			<i class="fa fa-sign-out"></i> 强退
		</a>
	</@shiro.hasPermission>
</@table>
</div>
</div>
<@footer>
	<script>
		var forceFlag = "${permission.hasPermi('sys:online:forceLogout')}";
		var prefix = baseURL + "sys/online";

		$(function() {
		    var options = {
		    	uniqueId: "sid",
		        url: prefix + "/list",
		        sortName: "userId",
		         /* sortOrder: "a", */
		        showExport: true,
		        escape: true,
		        columns: [
					{checkbox: true},
					{title: $.i18n.prop("序号"), formatter: function (value, row, index) {
                 	    return $.table.serialNumber(index);}
                    },
					{field: 'sid', title: '会话编号'},
					{field: 'name', title: '姓名'},
					{field: 'username', title: '登录名称'},
					{field: 'compName',	title: '所属公司'},
					{field: 'loginIp', title: '主机'},
					{field: 'loginLocation', title: '登陆地点'},
					{
		            field: 'loginStatus',
		            title: '会话状态',
		            align: 'center',
		            formatter: function(value, row, index) {
		                if (value == '1') {
		                    return '<span class="badge badge-primary">在线</span>';
		                }if (value == '-1') {
							return '<span class="badge badge-warning">锁屏</span>';
						}if (value == '-9') {
							return '<span class="badge badge-warning">已踢,等待下线</span>';
						}else{
		                    return '<span class="badge badge-danger">离线</span>';
		                }
		            }},
					{field: 'loginTime', title: '登录时间'},
					{title:"<@ctx.i18n text = "操作"/>", align: 'center', formatter: function(value, row, index) {
		                var msg = '<a class="btn btn-danger btn-xs ' + forceFlag + '" href="javascript:void(0)" onclick="forceLogout(\'' + row.sid + '\')"><i class="fa fa-sign-out"></i>强退</a> ';
		                return msg;}
					}]
		    };
		    $.table.init(options);
		});

		/* 单条强退 */
		function forceLogout(sessionId) {
		    opt.modal.confirm("确定要强制选中用户下线吗？", function() {
		    	var data = { "ids": sessionId };
		        opt.operate.post(prefix + "/batchForceLogout", data);
		    })
		}

		/* 批量强退 */
		function batchForceLogout() {
		    var rows = $.table.selectColumns("sid");
		    if (rows.length == 0) {
		        opt.modal.alertWarning("请选择要强退的用户");
		        return;
		    }
		    opt.modal.confirm("确认要强退选中的" + rows.length + "条数据吗?", function() {
		        var url = prefix + "/batchForceLogout";
		        var data = { "ids": rows.join() };
		        opt.operate.post(url, data);
		    });
		}
	</script>
</@footer>
</@pageTheme>