123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- 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 = $('<div class="image-preview" style="margin-top: 10px;"></div>');
- $input.closest('.form-inline').append($preview);
- }
-
- $preview.empty();
-
- if (imageUrl && imageUrl.match(/\.(jpg|jpeg|png|gif|webp)$/i)) {
- $preview.html('<img src="' + imageUrl + '" style="max-width: 200px; max-height: 150px; border: 1px solid #ddd; border-radius: 4px;" />');
- }
- });
- // 配置项分组折叠功能
- $(document).on('click', '.panel-heading .nav-tabs li a', function() {
- var target = $(this).attr('href');
- var groupName = target.replace('#tab-', '');
-
- // 记住当前选中的分组
- localStorage.setItem('ai_measure_config_active_tab', groupName);
- });
- // 恢复上次选中的分组
- var lastActiveTab = localStorage.getItem('ai_measure_config_active_tab');
- if (lastActiveTab) {
- $('.nav-tabs li').removeClass('active');
- $('.tab-pane').removeClass('active in');
-
- $('.nav-tabs a[href="#tab-' + lastActiveTab + '"]').closest('li').addClass('active');
- $('#tab-' + lastActiveTab).addClass('active in');
- }
- },
- add: function () {
- Controller.api.bindevent();
- },
- edit: function () {
- Controller.api.bindevent();
- },
- api: {
- bindevent: function () {
- Form.api.bindevent($("form[role=form]"));
- }
- }
- };
- return Controller;
- });
|