platform.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 平台列表页面逻辑
  5. this.bindPlatformEvents();
  6. },
  7. // 绑定平台相关事件
  8. bindPlatformEvents: function () {
  9. // 平台配置按钮点击事件
  10. $(document).on('click', '.platform-btn', function (e) {
  11. e.preventDefault();
  12. var url = $(this).data('url');
  13. var title = $(this).data('title');
  14. if (url) {
  15. // 打开配置弹窗
  16. Fast.api.open(url, title, {
  17. area: ['80%', '80%'],
  18. callback: function(data) {
  19. // 配置保存成功后刷新状态
  20. Controller.loadPlatformStatus();
  21. }
  22. });
  23. }
  24. });
  25. Form.api.bindevent($("form[role=form]"), function (data, ret) {
  26. Layer.alert(data.data);
  27. });
  28. },
  29. // 更新平台状态显示
  30. updatePlatformStatus: function (statusData) {
  31. $.each(statusData, function (platform, status) {
  32. var $card = $('[data-platform="' + platform + '"]');
  33. if ($card.length > 0) {
  34. var $badge = $card.find('.status-badge');
  35. var $btn = $card.find('.platform-btn');
  36. if (status) {
  37. $card.addClass('platform-enabled');
  38. $badge.removeClass('status-disabled').addClass('status-enabled').text('已启用');
  39. $btn.removeClass('btn-default').addClass('btn-success');
  40. } else {
  41. $card.removeClass('platform-enabled');
  42. $badge.removeClass('status-enabled').addClass('status-disabled').text('未启用');
  43. $btn.removeClass('btn-success').addClass('btn-default');
  44. }
  45. }
  46. });
  47. },
  48. // 平台配置页面逻辑
  49. edit: function () {
  50. $(document).on('click', '.btn-success', function () {
  51. Form.api.submit($("form[role=form]"));
  52. setTimeout(refresh, 1500)
  53. })
  54. // 然后绑定其他事件
  55. Controller.bindVisibilityEvents();
  56. // 延迟初始化,确保DOM完全加载
  57. // 初始化支付配置的显示状态
  58. Controller.initializePaymentConfig();
  59. // 初始化分享配置的显示状态
  60. Controller.initializeShareConfig();
  61. // 在所有初始化完成后绑定表单事件
  62. Controller.api.bindevent();
  63. },
  64. // 初始化支付配置显示状态
  65. initializePaymentConfig: function() {
  66. Controller.updatePaymentConfigVisibility();
  67. },
  68. // 初始化分享配置显示状态
  69. initializeShareConfig: function() {
  70. Controller.updateShareConfigVisibility();
  71. },
  72. // 绑定显示隐藏事件
  73. bindVisibilityEvents: function () {
  74. // 支付方式选择事件
  75. $(document).on('change', 'input[name="row[payment][methods][]"]', function () {
  76. Controller.updatePaymentConfigVisibility();
  77. });
  78. // 分享方式选择事件
  79. $(document).on('change', 'input[name="row[share][methods][]"]', function () {
  80. Controller.updateShareConfigVisibility();
  81. });
  82. // 状态切换事件
  83. $(document).on('change', 'input[name="row[status]"]', function () {
  84. var status = $(this).val();
  85. if (status == '1') {
  86. $('.config-section').show();
  87. } else {
  88. $('.config-section').hide();
  89. }
  90. });
  91. },
  92. // 更新支付配置显示状态
  93. updatePaymentConfigVisibility: function() {
  94. var selectedMethods = [];
  95. $('input[name="row[payment][methods][]"]:checked').each(function () {
  96. selectedMethods.push($(this).val());
  97. });
  98. // 显示隐藏对应的配置项
  99. $('.payment-config').hide();
  100. // 遍历所有payment-config元素,检查是否应该显示
  101. $('.payment-config').each(function() {
  102. var $this = $(this);
  103. var showMethods = $this.data('show');
  104. if (showMethods) {
  105. // 将字符串转换为数组(支持逗号分隔)
  106. var methodsArray = showMethods.toString().split(',');
  107. // 检查选中的方法是否与当前元素的显示条件匹配
  108. var shouldShow = false;
  109. $.each(methodsArray, function(index, method) {
  110. if (selectedMethods.indexOf(method.trim()) !== -1) {
  111. shouldShow = true;
  112. return false; // 跳出循环
  113. }
  114. });
  115. if (shouldShow) {
  116. $this.show();
  117. }
  118. }
  119. });
  120. },
  121. // 更新分享配置显示状态
  122. updateShareConfigVisibility: function() {
  123. var selectedMethods = [];
  124. $('input[name="row[share][methods][]"]:checked').each(function () {
  125. selectedMethods.push($(this).val());
  126. });
  127. // 显示隐藏对应的配置项
  128. $('.share-config').hide();
  129. // 遍历所有share-config元素,检查是否应该显示
  130. $('.share-config').each(function() {
  131. var $this = $(this);
  132. var showMethods = $this.data('show');
  133. if (showMethods) {
  134. // 将字符串转换为数组(支持逗号分隔)
  135. var methodsArray = showMethods.toString().split(',');
  136. // 检查选中的方法是否与当前元素的显示条件匹配
  137. var shouldShow = false;
  138. $.each(methodsArray, function(index, method) {
  139. if (selectedMethods.indexOf(method.trim()) !== -1) {
  140. shouldShow = true;
  141. return false; // 跳出循环
  142. }
  143. });
  144. if (shouldShow) {
  145. $this.show();
  146. }
  147. }
  148. });
  149. },
  150. api: {
  151. bindevent: function () {
  152. Form.api.bindevent($("form[role=form]"));
  153. },
  154. }
  155. };
  156. return Controller;
  157. });