define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { var Controller = { index: function () { $("form.edit-form").data("validator-options", { display: function (elem) { return $(elem).closest('tr').find("td:first").text(); } }); Form.api.bindevent($("form.edit-form")); //不可见的元素不验证 $("form#add-form").data("validator-options", { ignore: ':hidden', rules: { content: function () { return ['radio', 'checkbox', 'select', 'selects'].indexOf($("#add-form select[name='row[type]']").val()) > -1; }, extend: function () { return $("#add-form select[name='row[type]']").val() == 'custom'; } } }); Form.api.bindevent($("form#add-form"), function (ret) { setTimeout(function () { location.reload(); }, 1500); }); //切换显示隐藏变量字典列表 $(document).on("change", "form#add-form select[name='row[type]']", function (e) { $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true); }); //删除配置 $(document).on("click", ".btn-delcfg", function () { var that = this; Layer.confirm(__('Are you sure you want to delete this item?'), { icon: 3, title: '提示' }, function (index) { Backend.api.ajax({ url: "general/ai_measure_config/del", data: {name: $(that).data("name")} }, function () { $(that).closest("tr").remove(); Layer.close(index); }); }); }); // AI测量配置特有的验证逻辑 $(document).on("submit", "form.edit-form", function (e) { // 检查图片类型的配置项是否有有效的图片URL var hasError = false; $(this).find('input[name*="image"], input[name*="picture"]').each(function() { var value = $(this).val(); if (value && !value.match(/\.(jpg|jpeg|png|gif|webp)$/i)) { Toastr.error('请上传有效的图片文件'); hasError = true; return false; } }); if (hasError) { e.preventDefault(); return false; } }); // 为特定的AI测量配置项添加提示信息 $(document).ready(function() { // 为自拍模式配置添加特殊提示 $('#tab-ai_measure_selfie input, #tab-ai_measure_selfie textarea, #tab-ai_measure_selfie select').each(function() { var name = $(this).attr('name'); if (name && name.indexOf('guide') > -1) { $(this).attr('data-toggle', 'tooltip'); $(this).attr('title', '引导用户进行自拍的相关配置'); } }); // 为帮拍模式配置添加特殊提示 $('#tab-ai_measure_helper input, #tab-ai_measure_helper textarea, #tab-ai_measure_helper select').each(function() { var name = $(this).attr('name'); if (name && name.indexOf('guide') > -1) { $(this).attr('data-toggle', 'tooltip'); $(this).attr('title', '引导他人协助拍摄的相关配置'); } }); // 初始化提示信息 $('[data-toggle="tooltip"]').tooltip(); }); // 图片预览功能增强 $(document).on('change', 'input[type="text"][name*="image"], input[type="text"][name*="picture"]', function() { var $input = $(this); var imageUrl = $input.val(); var $preview = $input.closest('.form-inline').find('.faupload-preview'); if (!$preview.length) { $preview = $('
'); $input.closest('.form-inline').append($preview); } $preview.empty(); if (imageUrl && imageUrl.match(/\.(jpg|jpeg|png|gif|webp)$/i)) { $preview.html('