ai_measure_config.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $("form.edit-form").data("validator-options", {
  5. display: function (elem) {
  6. return $(elem).closest('tr').find("td:first").text();
  7. }
  8. });
  9. Form.api.bindevent($("form.edit-form"));
  10. //不可见的元素不验证
  11. $("form#add-form").data("validator-options", {
  12. ignore: ':hidden',
  13. rules: {
  14. content: function () {
  15. return ['radio', 'checkbox', 'select', 'selects'].indexOf($("#add-form select[name='row[type]']").val()) > -1;
  16. },
  17. extend: function () {
  18. return $("#add-form select[name='row[type]']").val() == 'custom';
  19. }
  20. }
  21. });
  22. Form.api.bindevent($("form#add-form"), function (ret) {
  23. setTimeout(function () {
  24. location.reload();
  25. }, 1500);
  26. });
  27. //切换显示隐藏变量字典列表
  28. $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
  29. $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
  30. });
  31. //删除配置
  32. $(document).on("click", ".btn-delcfg", function () {
  33. var that = this;
  34. Layer.confirm(__('Are you sure you want to delete this item?'), {
  35. icon: 3,
  36. title: '提示'
  37. }, function (index) {
  38. Backend.api.ajax({
  39. url: "general/ai_measure_config/del",
  40. data: {name: $(that).data("name")}
  41. }, function () {
  42. $(that).closest("tr").remove();
  43. Layer.close(index);
  44. });
  45. });
  46. });
  47. // AI测量配置特有的验证逻辑
  48. $(document).on("submit", "form.edit-form", function (e) {
  49. // 检查图片类型的配置项是否有有效的图片URL
  50. var hasError = false;
  51. $(this).find('input[name*="image"], input[name*="picture"]').each(function() {
  52. var value = $(this).val();
  53. if (value && !value.match(/\.(jpg|jpeg|png|gif|webp)$/i)) {
  54. Toastr.error('请上传有效的图片文件');
  55. hasError = true;
  56. return false;
  57. }
  58. });
  59. if (hasError) {
  60. e.preventDefault();
  61. return false;
  62. }
  63. });
  64. // 为特定的AI测量配置项添加提示信息
  65. $(document).ready(function() {
  66. // 为自拍模式配置添加特殊提示
  67. $('#tab-ai_measure_selfie input, #tab-ai_measure_selfie textarea, #tab-ai_measure_selfie select').each(function() {
  68. var name = $(this).attr('name');
  69. if (name && name.indexOf('guide') > -1) {
  70. $(this).attr('data-toggle', 'tooltip');
  71. $(this).attr('title', '引导用户进行自拍的相关配置');
  72. }
  73. });
  74. // 为帮拍模式配置添加特殊提示
  75. $('#tab-ai_measure_helper input, #tab-ai_measure_helper textarea, #tab-ai_measure_helper select').each(function() {
  76. var name = $(this).attr('name');
  77. if (name && name.indexOf('guide') > -1) {
  78. $(this).attr('data-toggle', 'tooltip');
  79. $(this).attr('title', '引导他人协助拍摄的相关配置');
  80. }
  81. });
  82. // 初始化提示信息
  83. $('[data-toggle="tooltip"]').tooltip();
  84. });
  85. // 图片预览功能增强
  86. $(document).on('change', 'input[type="text"][name*="image"], input[type="text"][name*="picture"]', function() {
  87. var $input = $(this);
  88. var imageUrl = $input.val();
  89. var $preview = $input.closest('.form-inline').find('.faupload-preview');
  90. if (!$preview.length) {
  91. $preview = $('<div class="image-preview" style="margin-top: 10px;"></div>');
  92. $input.closest('.form-inline').append($preview);
  93. }
  94. $preview.empty();
  95. if (imageUrl && imageUrl.match(/\.(jpg|jpeg|png|gif|webp)$/i)) {
  96. $preview.html('<img src="' + imageUrl + '" style="max-width: 200px; max-height: 150px; border: 1px solid #ddd; border-radius: 4px;" />');
  97. }
  98. });
  99. // 配置项分组折叠功能
  100. $(document).on('click', '.panel-heading .nav-tabs li a', function() {
  101. var target = $(this).attr('href');
  102. var groupName = target.replace('#tab-', '');
  103. // 记住当前选中的分组
  104. localStorage.setItem('ai_measure_config_active_tab', groupName);
  105. });
  106. // 恢复上次选中的分组
  107. var lastActiveTab = localStorage.getItem('ai_measure_config_active_tab');
  108. if (lastActiveTab) {
  109. $('.nav-tabs li').removeClass('active');
  110. $('.tab-pane').removeClass('active in');
  111. $('.nav-tabs a[href="#tab-' + lastActiveTab + '"]').closest('li').addClass('active');
  112. $('#tab-' + lastActiveTab).addClass('active in');
  113. }
  114. },
  115. add: function () {
  116. Controller.api.bindevent();
  117. },
  118. edit: function () {
  119. Controller.api.bindevent();
  120. },
  121. api: {
  122. bindevent: function () {
  123. Form.api.bindevent($("form[role=form]"));
  124. }
  125. }
  126. };
  127. return Controller;
  128. });