user.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'user/user/index',
  8. add_url: 'user/user/add',
  9. edit_url: 'user/user/edit',
  10. del_url: 'user/user/del',
  11. multi_url: 'user/user/multi',
  12. table: 'user',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'user.id',
  21. fixedColumns: true,
  22. fixedRightNumber: 1,
  23. columns: [
  24. [
  25. {checkbox: true},
  26. {field: 'id', title: __('Id'), sortable: true},
  27. // {field: 'group.name', title: __('Group')},
  28. // {field: 'username', title: __('Username'), operate: 'LIKE'},
  29. {
  30. field: 'user.username',
  31. title: '用户信息',
  32. operate: 'LIKE',
  33. formatter: function (value, row, index) {
  34. // 显示用户头像和用户名
  35. var avatar = row && row.avatar ? row.avatar : '/assets/img/avatar.png';
  36. var username = row && row.username ? row.username : '游客';
  37. var userId = row.id || '';
  38. // 处理头像URL
  39. var avatarUrl = avatar;
  40. if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
  41. avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
  42. }
  43. return '<div style="display:flex;align-items:center;">' +
  44. '<img src="' + avatarUrl + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
  45. '<div>' +
  46. '<div style="color:#337ab7;font-weight:bold;">' + username + '</div>' +
  47. '<div style="color:#999;font-size:12px;">ID: ' + userId + '</div>' +
  48. '</div>' +
  49. '</div>';
  50. }
  51. },
  52. // {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
  53. // {field: 'email', title: __('Email'), operate: 'LIKE'},
  54. {field: 'mobile', title: __('Mobile'), operate: 'LIKE'},
  55. // {field: 'avatar', title: __('Avatar'), events: Table.api.events.image, formatter: Table.api.formatter.image, operate: false},
  56. //{field: 'level', title: __('Level'), operate: 'BETWEEN', sortable: true},
  57. {field: 'gender', title: __('Gender'), visible: false, searchList: Controller.api.parseConfigJson('genderList')},
  58. // {field: 'score', title: __('Score'), operate: 'BETWEEN', sortable: true},
  59. // {field: 'successions', title: __('Successions'), visible: false, operate: 'BETWEEN', sortable: true},
  60. // {field: 'maxsuccessions', title: __('Maxsuccessions'), visible: false, operate: 'BETWEEN', sortable: true},
  61. // {field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  62. // {field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
  63. // {field: 'jointime', title: __('Jointime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  64. // {field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
  65. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: Controller.api.parseConfigJson('statusList')},
  66. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  67. ]
  68. ]
  69. });
  70. // 为表格绑定事件
  71. Table.api.bindevent(table);
  72. },
  73. add: function () {
  74. Controller.api.bindevent();
  75. },
  76. edit: function () {
  77. // 双列布局样式优化
  78. $(document).ready(function(){
  79. // 为登录信息面板添加样式
  80. $('.login-info .form-control-static').each(function(){
  81. $(this).css({
  82. 'background-color': '#f8f9fa',
  83. 'padding': '8px 12px',
  84. 'border-radius': '4px',
  85. 'border': '1px solid #e9ecef',
  86. 'margin': '0'
  87. });
  88. });
  89. // 为第三方平台标签添加图标
  90. $('.third-platform-label').each(function(){
  91. var platform = $(this).text().toLowerCase().trim();
  92. var icon = '';
  93. switch(platform) {
  94. case 'wechat':
  95. icon = '<i class="fa fa-wechat"></i> ';
  96. break;
  97. case 'qq':
  98. icon = '<i class="fa fa-qq"></i> ';
  99. break;
  100. case 'weibo':
  101. icon = '<i class="fa fa-weibo"></i> ';
  102. break;
  103. default:
  104. icon = '<i class="fa fa-link"></i> ';
  105. }
  106. $(this).html(icon + $(this).text());
  107. });
  108. // 添加第三方信息表格样式
  109. $('.third-info-table').each(function(){
  110. $(this).addClass('table-hover');
  111. });
  112. // 双列布局响应式处理
  113. function adjustDualColumnLayout() {
  114. if ($(window).width() < 768) {
  115. // 小屏幕时保持双列但调整比例
  116. $('.form-horizontal .col-md-6').each(function(){
  117. $(this).addClass('col-xs-12').removeClass('col-md-6');
  118. });
  119. // 调整label和input的比例
  120. $('.form-horizontal .col-sm-4').each(function(){
  121. $(this).removeClass('col-sm-4').addClass('col-sm-3');
  122. });
  123. $('.form-horizontal .col-sm-8').each(function(){
  124. $(this).removeClass('col-sm-8').addClass('col-sm-9');
  125. });
  126. } else {
  127. // 大屏幕时恢复双列布局
  128. $('.form-horizontal .col-xs-12').each(function(){
  129. if (!$(this).hasClass('col-md-12')) {
  130. $(this).addClass('col-md-6').removeClass('col-xs-12');
  131. }
  132. });
  133. // 恢复label和input的比例
  134. $('.form-horizontal .col-sm-3').each(function(){
  135. $(this).removeClass('col-sm-3').addClass('col-sm-4');
  136. });
  137. $('.form-horizontal .col-sm-9').each(function(){
  138. $(this).removeClass('col-sm-9').addClass('col-sm-8');
  139. });
  140. }
  141. }
  142. // 初始调整
  143. adjustDualColumnLayout();
  144. // 窗口大小改变时调整
  145. $(window).resize(function() {
  146. adjustDualColumnLayout();
  147. });
  148. // 为面板添加间距
  149. $('.panel').not(':last-child').css('margin-bottom', '20px');
  150. // 为双列布局添加分隔线(可选)
  151. $('.panel-body .row .col-md-6:first-child').css({
  152. 'border-right': '1px solid #eee',
  153. 'padding-right': '20px'
  154. });
  155. $('.panel-body .row .col-md-6:last-child').css({
  156. 'padding-left': '20px'
  157. });
  158. });
  159. Controller.api.bindevent();
  160. },
  161. api: {
  162. // 解析Config中的JSON字符串的辅助函数
  163. parseConfigJson: function(configKey, defaultValue) {
  164. var configValue = Config[configKey] || defaultValue || {};
  165. // 如果是字符串,尝试解析JSON
  166. if (typeof configValue === 'string') {
  167. try {
  168. return JSON.parse(configValue);
  169. } catch (e) {
  170. return defaultValue || {};
  171. }
  172. }
  173. return configValue;
  174. },
  175. bindevent: function () {
  176. Form.api.bindevent($("form[role=form]"));
  177. }
  178. }
  179. };
  180. return Controller;
  181. });