From 14207687b44b6d9688f0a3aa3201f1ada837cb19 Mon Sep 17 00:00:00 2001 From: Karson Date: Thu, 18 Dec 2025 15:08:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96switch=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=9C=AA=E7=9F=A5=E7=8A=B6=E6=80=81=E5=B1=95=E7=A4=BA=E5=92=8C?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Crud.php | 4 ++-- application/admin/lang/zh-cn.php | 4 ++++ extend/fast/Form.php | 6 +++--- public/assets/css/backend.css | 12 +++++++++++ public/assets/js/require-table.js | 34 ++++++++++++++++++++++++++++-- public/assets/less/backend.less | 14 ++++++++++++ 6 files changed, 67 insertions(+), 7 deletions(-) diff --git a/application/admin/command/Crud.php b/application/admin/command/Crud.php index 12f5d0a3..c2ee128c 100755 --- a/application/admin/command/Crud.php +++ b/application/admin/command/Crud.php @@ -883,8 +883,8 @@ EOD; $itemArr = [$yes => 'Yes', $no => 'No']; } $stateNoClass = 'fa-flip-horizontal text-gray'; - $formAddElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'fieldYes' => $yes, 'fieldNo' => $no, 'attrStr' => Form::attributes($attrArr), 'fieldValue' => $defaultValue, 'fieldSwitchClass' => $defaultValue == $no ? $stateNoClass : '']); - $formEditElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'fieldYes' => $yes, 'fieldNo' => $no, 'attrStr' => Form::attributes($attrArr), 'fieldValue' => "{\$row.{$field}}", 'fieldSwitchClass' => "{eq name=\"\$row.{$field}\" value=\"{$no}\"}fa-flip-horizontal text-gray{/eq}"]); + $formAddElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'fieldYes' => $yes, 'fieldNo' => $no, 'attrStr' => Form::attributes($attrArr), 'fieldValue' => $defaultValue, 'fieldSwitchClass' => $defaultValue == $yes ? '' : $stateNoClass]); + $formEditElement = $this->getReplacedStub('html/' . $inputType, ['field' => $field, 'fieldName' => $fieldName, 'fieldYes' => $yes, 'fieldNo' => $no, 'attrStr' => Form::attributes($attrArr), 'fieldValue' => "{\$row.{$field}}", 'fieldSwitchClass' => "{neq name=\"\$row.{$field}\" value=\"{$yes}\"}fa-flip-horizontal text-gray{/neq}"]); } elseif ($inputType == 'citypicker') { $attrArr['class'] = implode(' ', $cssClassArr); $attrArr['data-toggle'] = "city-picker"; diff --git a/application/admin/lang/zh-cn.php b/application/admin/lang/zh-cn.php index 8e52c611..9d1b058c 100755 --- a/application/admin/lang/zh-cn.php +++ b/application/admin/lang/zh-cn.php @@ -181,6 +181,10 @@ return [ 'This page will be re-directed in %s seconds' => '页面将在 %s 秒后自动跳转', 'Click to uncheck all' => '点击取消全部', 'Multiple selection mode: %s checked' => '跨页选择模式,已选 %s 项', + 'Please select switch status' => '请选择开关状态', + 'switch status on' => '设定为开启', + 'switch status off' => '设定为关闭', + 'Status unknown, please manually change the status' => '状态未知,请手动修改开关状态', //菜单 'Dashboard' => '控制台', 'General' => '常规管理', diff --git a/extend/fast/Form.php b/extend/fast/Form.php index f12962cf..31d259ca 100644 --- a/extend/fast/Form.php +++ b/extend/fast/Form.php @@ -520,14 +520,14 @@ class FormBuilder $yes = $options['yes']; $no = $options['no']; } - $selected = $no == $value ? "fa-flip-horizontal text-gray" : ""; + $grayclass = $yes == $value ? "": "fa-flip-horizontal text-gray"; $disabled = (isset($options['disabled']) && $options['disabled']) || in_array('disabled', $options) ? "disabled" : ''; - $color = isset($options['color']) ? $options['color'] : 'success'; + $color = $options['color'] ?? 'success'; unset($options['yes'], $options['no'], $options['color'], $options['disabled']); $attr = $this->attributes($options); $html = << + EOD; return $html; } diff --git a/public/assets/css/backend.css b/public/assets/css/backend.css index e68bacd3..a7a9012d 100644 --- a/public/assets/css/backend.css +++ b/public/assets/css/backend.css @@ -1659,4 +1659,16 @@ table.table-nowrap thead > tr > th { color: #fff; outline: none; } +.btn-switcher { + margin-top: 5px; + display: inline-block; + min-height: 30px; +} +.switcher-unknown-val { + width: 30px; + border-radius: 10px; + background: #f2f281; + display: inline-block; + text-align: center; +} /*# sourceMappingURL=backend.css.map */ \ No newline at end of file diff --git a/public/assets/js/require-table.js b/public/assets/js/require-table.js index be96a03c..bed68dae 100644 --- a/public/assets/js/require-table.js +++ b/public/assets/js/require-table.js @@ -570,10 +570,36 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table table.bootstrapTable($(this).prop("checked") ? 'checkBy' : 'uncheckBy', {field: options.pk, values: [ids]}); }); table.on("click", "[data-id].btn-change", function (e) { + var that = this; e.preventDefault(); var changer = $.proxy(function () { Table.api.multi($(this).data("action") ? $(this).data("action") : '', [$(this).data("id")], table, this); }, this); + + var unknownSpan = $(this).find(".switcher-unknown-val"); + if (unknownSpan.length > 0) { + var field = $(this).data("field"); + var yes = $(this).data("yes"); + var no = $(this).data("no"); + Layer.alert(__('Please select switch status'), { + icon: 0, + title: __('Warning'), + btn: [__('Switch status on'), __('Switch status off')], + btn1: function (index) { + unknownSpan.replaceWith('') + $(that).data("params", field + "=" + yes); + changer(); + Layer.close(index); + }, + btn2: function (index) { + unknownSpan.replaceWith(''); + $(that).data("params", field + "=" + no); + changer(); + Layer.close(index); + } + }); + return false; + } if (typeof $(this).data("confirm") !== 'undefined') { Layer.confirm($(this).data("confirm"), function (index) { changer(); @@ -864,8 +890,12 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table if (typeof this.disable !== "undefined") { disable = typeof this.disable === "function" ? this.disable.call(this, value, row, index) : this.disable; } - return ""; + var isUnknown = yes == value || no == value ? false : true; + var html = isUnknown + ? '' + : ''; + return "" + html + ""; }, url: function (value, row, index) { value = value == null || value.length === 0 ? '' : value.toString(); diff --git a/public/assets/less/backend.less b/public/assets/less/backend.less index c51cc4fb..edde2197 100755 --- a/public/assets/less/backend.less +++ b/public/assets/less/backend.less @@ -1709,4 +1709,18 @@ table.table-nowrap { outline: none; } } +} + +.btn-switcher { + margin-top: 5px; + display: inline-block; + min-height: 30px; +} + +.switcher-unknown-val { + width: 30px; + border-radius: 10px; + background: #f2f281; + display: inline-block; + text-align: center; } \ No newline at end of file