Pu Zhibing
2025-02-18 fcb98e91a1e521b895cb58e8ac424f51dfd4e96a
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
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('用户分配角色')" />
</head>
<body>
    <div class="main-content">
        <form id="form-user-add" class="form-horizontal">
            <input type="hidden" id="userId" name="userId" th:value="${user.userId}">
            <h4 class="form-header h4">基本信息</h4>
            <div class="row">
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">用户名称:</label>
                        <div class="col-sm-8">
                            <input name="userName" class="form-control" type="text" disabled th:value="${user.userName}">
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-4 control-label is-required">登录账号:</label>
                        <div class="col-sm-8">
                            <input name="loginName" class="form-control" type="text" disabled th:value="${user.loginName}">
                        </div>
                    </div>
                </div> 
            </div>
           
            <h4 class="form-header h4">分配角色</h4>
            <div class="row">
                <div class="col-sm-12">
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
      
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "system/user/authRole";
        var roles = [[${roles}]]
        
        $(function() {
            var options = {
                data: roles,
                sidePagination: "client",
                sortName: "roleSort",
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                clickToSelect: true,
                maintainSelected: true,
                columns: [{
                    checkbox: true,
                    formatter:function (value, row, index) {
                        if($.common.isEmpty(value)) {
                            return { checked: row.flag };
                        } else {
                            return { checked: value }
                        }
                    }
                },
                {
                    field: 'roleId',
                    title: '角色编号'
                },
                {
                    field: 'roleSort',
                    title: '排序',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'roleName',
                    title: '角色名称'
                },
                {
                    field: 'roleKey',
                    title: '权限字符',
                    sortable: true
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                }]
            };
            $.table.init(options);
        });
        
        /* 添加角色-提交 */
        function submitHandler(index, layero){
            var roleIds = [];
            var data = $('#bootstrap-table').bootstrapTable('getData');
            for (var i = 0; i < data.length; i++) {
                if (data[i][0] || ($.common.isEmpty(data[i][0]) && data[i].flag)) {
                    roleIds.push(data[i].roleId)
                }
            }
            $.operate.saveTab(prefix + "/insertAuthRole", { "userId": $("#userId").val(), "roleIds": roleIds.join() });
        }
    </script>
</body>
</html>