define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
var Controller = {
index: function () {
// 初始化表格参数配置
Table.api.init({
extend: {
index_url: 'user/user/index',
add_url: 'user/user/add',
edit_url: 'user/user/edit',
del_url: 'user/user/del',
multi_url: 'user/user/multi',
table: 'user',
}
});
var table = $("#table");
// 初始化表格
table.bootstrapTable({
url: $.fn.bootstrapTable.defaults.extend.index_url,
pk: 'id',
sortName: 'user.id',
fixedColumns: true,
fixedRightNumber: 1,
columns: [
[
{checkbox: true},
{field: 'id', title: __('Id'), sortable: true},
{field: 'group.name', title: __('Group')},
// {field: 'username', title: __('Username'), operate: 'LIKE'},
{
field: 'user.username',
title: '用户信息',
operate: 'LIKE',
formatter: function (value, row, index) {
// 显示用户头像和用户名
var avatar = row && row.avatar ? row.avatar : '/assets/img/avatar.png';
var username = row && row.username ? row.username : '游客';
var userId = row.id || '';
// 处理头像URL
var avatarUrl = avatar;
if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
}
return '
' +
'

' +
'
' +
'
' + username + '
' +
'
ID: ' + userId + '
' +
'
' +
'
';
}
},
// {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
{field: 'email', title: __('Email'), operate: 'LIKE'},
{field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
// {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
//{field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
{field: 'gender', title: __('Gender'), visible: false, searchList: Controller.api.parseConfigJson('genderList')},
// {field: 'score', title: __('Score'), operate: 'BETWEEN', sortable: true},
// {field: 'successions', title: __('Successions'), visible: false, operate: 'BETWEEN', sortable: true},
// {field: 'maxsuccessions', title: __('Maxsuccessions'), visible: false, operate: 'BETWEEN', sortable: true},
// {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
// {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
// {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
// {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
{field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: Controller.api.parseConfigJson('statusList')},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
]
]
});
// 为表格绑定事件
Table.api.bindevent(table);
},
add: function () {
Controller.api.bindevent();
},
edit: function () {
// 为第三方信息卡片添加样式
$(document).ready(function(){
// 添加第三方信息卡片样式
$('.third-info-card').each(function(){
$(this).hover(
function(){
$(this).css({
'box-shadow': '0 4px 8px rgba(0,0,0,0.1)',
'transform': 'translateY(-2px)',
'transition': 'all 0.3s ease'
});
},
function(){
$(this).css({
'box-shadow': '0 1px 3px rgba(0,0,0,0.1)',
'transform': 'translateY(0)',
'transition': 'all 0.3s ease'
});
}
);
});
// 为登录信息面板添加样式
$('.login-info .form-control-static').each(function(){
$(this).css({
'background-color': '#f8f9fa',
'padding': '8px 12px',
'border-radius': '4px',
'border': '1px solid #e9ecef',
'margin': '0'
});
});
// 为第三方平台标签添加图标
$('.third-platform-label').each(function(){
var platform = $(this).text().toLowerCase().trim();
var icon = '';
switch(platform) {
case 'wechat':
icon = ' ';
break;
case 'qq':
icon = ' ';
break;
case 'weibo':
icon = ' ';
break;
default:
icon = ' ';
}
$(this).html(icon + $(this).text());
});
// 为第三方信息卡片添加响应式处理
function adjustThirdInfoCards() {
if ($(window).width() < 768) {
$('.third-info-card').parent().removeClass('col-md-6').addClass('col-md-12');
} else {
$('.third-info-card').parent().removeClass('col-md-12').addClass('col-md-6');
}
}
// 初始调整
adjustThirdInfoCards();
// 窗口大小改变时调整
$(window).resize(function() {
adjustThirdInfoCards();
});
});
Controller.api.bindevent();
},
api: {
// 解析Config中的JSON字符串的辅助函数
parseConfigJson: function(configKey, defaultValue) {
var configValue = Config[configKey] || defaultValue || {};
// 如果是字符串,尝试解析JSON
if (typeof configValue === 'string') {
try {
return JSON.parse(configValue);
} catch (e) {
return defaultValue || {};
}
}
return configValue;
},
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
}
}
};
return Controller;
});