user.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. $('.third-info-card').each(function(){
  81. $(this).hover(
  82. function(){
  83. $(this).css({
  84. 'box-shadow': '0 4px 8px rgba(0,0,0,0.1)',
  85. 'transform': 'translateY(-2px)',
  86. 'transition': 'all 0.3s ease'
  87. });
  88. },
  89. function(){
  90. $(this).css({
  91. 'box-shadow': '0 1px 3px rgba(0,0,0,0.1)',
  92. 'transform': 'translateY(0)',
  93. 'transition': 'all 0.3s ease'
  94. });
  95. }
  96. );
  97. });
  98. // 为登录信息面板添加样式
  99. $('.login-info .form-control-static').each(function(){
  100. $(this).css({
  101. 'background-color': '#f8f9fa',
  102. 'padding': '8px 12px',
  103. 'border-radius': '4px',
  104. 'border': '1px solid #e9ecef',
  105. 'margin': '0'
  106. });
  107. });
  108. // 为第三方平台标签添加图标
  109. $('.third-platform-label').each(function(){
  110. var platform = $(this).text().toLowerCase().trim();
  111. var icon = '';
  112. switch(platform) {
  113. case 'wechat':
  114. icon = '<i class="fa fa-wechat"></i> ';
  115. break;
  116. case 'qq':
  117. icon = '<i class="fa fa-qq"></i> ';
  118. break;
  119. case 'weibo':
  120. icon = '<i class="fa fa-weibo"></i> ';
  121. break;
  122. default:
  123. icon = '<i class="fa fa-link"></i> ';
  124. }
  125. $(this).html(icon + $(this).text());
  126. });
  127. // 为第三方信息卡片添加响应式处理
  128. function adjustThirdInfoCards() {
  129. if ($(window).width() < 768) {
  130. $('.third-info-card').parent().removeClass('col-md-6').addClass('col-md-12');
  131. } else {
  132. $('.third-info-card').parent().removeClass('col-md-12').addClass('col-md-6');
  133. }
  134. }
  135. // 初始调整
  136. adjustThirdInfoCards();
  137. // 窗口大小改变时调整
  138. $(window).resize(function() {
  139. adjustThirdInfoCards();
  140. });
  141. });
  142. Controller.api.bindevent();
  143. },
  144. api: {
  145. // 解析Config中的JSON字符串的辅助函数
  146. parseConfigJson: function(configKey, defaultValue) {
  147. var configValue = Config[configKey] || defaultValue || {};
  148. // 如果是字符串,尝试解析JSON
  149. if (typeof configValue === 'string') {
  150. try {
  151. return JSON.parse(configValue);
  152. } catch (e) {
  153. return defaultValue || {};
  154. }
  155. }
  156. return configValue;
  157. },
  158. bindevent: function () {
  159. Form.api.bindevent($("form[role=form]"));
  160. }
  161. }
  162. };
  163. return Controller;
  164. });