user.js
8.7 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
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
define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'cloudapi/user/index' + location.search,
add_url: 'cloudapi/user/add',
edit_url: 'cloudapi/user/edit',
del_url: 'cloudapi/user/del',
multi_url: 'cloudapi/user/multi',
import_url: 'cloudapi/user/import',
table: 'cloudapi_user',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'id',
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id')},
{field: 'corporate_name', title: __('Corporate_name'), operate: 'LIKE'},
{field: 'admin.username', title: __('Username') ,operate:'LIKE'},
{field: 'admin.nickname', title: __('Nickname') ,operate:'LIKE'},
{field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
{field: 'admin.email', title: __('Email') ,operate:'LIKE'},
{field: 'admin.status', title: __("Status"), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
{field: 'app_id', title: __('App_id'), operate: 'LIKE'},
{field: 'app_secret', title: __('App_secret'), operate: 'LIKE'},
// {field: 'token', title: __('Token'), operate: 'LIKE'},
// {field: 'expire_time', title: __('Expire_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons: [
{
name: 'permission',//按钮name属性
text: 'API访问权限设置',//按钮文本
title: 'API访问权限设置',//窗口title
classname: 'btn btn-xs btn-warning btn-dialog',
icon: 'fa fa-gears',
url: 'cloudapi/user/permission',
//fastadmin js中设置弹窗大小
extend:' data-area=["100%","100%"]',
callback: function (data) {
// Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
},
visible: function (row) {
//返回true时按钮显示,返回false隐藏
return true;
}
}
]
}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
//监听管理员选择
$('#c-admin_id').on('change',function () {
let admin_id = $('#c-admin_id').val()
if (admin_id){
$('#f-groups').hide()
$('#f-username').hide()
$('#f-email').hide()
$('#f-nickname').hide()
$('#f-password').hide()
$('#f-status').hide()
}else{
$('#f-groups').show()
$('#f-username').show()
$('#f-email').show()
$('#f-nickname').show()
$('#f-password').show()
$('#f-status').show()
}
})
Controller.api.bindevent();
},
edit: function () {
//监听管理员选择
$('#c-admin_id').on('change',function () {
let admin_id = $('#c-admin_id').val()
if (parseInt(admin_id) !== parseInt(Config.admin_id)){
$('#f-groups').hide()
$('#f-username').hide()
$('#f-email').hide()
$('#f-nickname').hide()
$('#f-password').hide()
$('#f-status').hide()
}else{
if (parseInt(admin_id) === 1 || parseInt(admin_id) === Config.admin_id){
$('#f-groups').hide()
$('#f-username').hide()
$('#f-email').hide()
$('#f-nickname').hide()
$('#f-password').hide()
$('#f-status').hide()
}else{
$('#f-groups').show()
$('#f-username').show()
$('#f-email').show()
$('#f-nickname').show()
$('#f-password').show()
$('#f-status').show()
}
}
})
Controller.api.bindevent();
},
permission: function () {
//监听水库全选
$('#reservoir_ids-all').on('change',function () {
let checked = $(this).prop('checked');
if (checked){
$('input[name="row[reservoir_ids][]"]').prop('checked',true);
}else{
$('input[name="row[reservoir_ids][]"]').prop('checked',false);
}
});
//监听水库单个勾选
$('input[name="row[reservoir_ids][]"]').on('change',function () {
let checkedAll = true;
$('input[name="row[reservoir_ids][]"]').each(function (index,one) {
let oneChecked = $(one).prop('checked');
if (!oneChecked){
checkedAll = false;
}
});
$('#reservoir_ids-all').prop('checked',checkedAll);
})
//监听API分组全选
$('#group_ids-all').on('change',function () {
let checked = $(this).prop('checked');
if (checked){
$('input[name="row[group_ids][]"]').prop('checked',true);
}else{
$('input[name="row[group_ids][]"]').prop('checked',false);
}
});
//监听API分组单个勾选
$('input[name="row[group_ids][]"]').on('change',function () {
let checkedAll = true;
$('input[name="row[group_ids][]"]').each(function (index,one) {
let oneChecked = $(one).prop('checked');
if (!oneChecked){
checkedAll = false;
}
});
$('#group_ids-all').prop('checked',checkedAll);
})
//监听API全选
$('#api_ids-all').on('change',function () {
let checked = $(this).prop('checked');
if (checked){
$('input[name="row[api_ids][]"]').prop('checked',true);
}else{
$('input[name="row[api_ids][]"]').prop('checked',false);
}
});
//监听API单个勾选
$('input[name="row[api_ids][]"]').on('change',function () {
let checkedAll = true;
$('input[name="row[api_ids][]"]').each(function (index,one) {
let oneChecked = $(one).prop('checked');
if (!oneChecked){
checkedAll = false;
}
});
$('#api_ids-all').prop('checked',checkedAll);
})
Controller.api.bindevent();
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});