From f46786f11c5c08ead7501a82e5a71430ad69b782 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期日, 27 四月 2025 17:39:24 +0800
Subject: [PATCH] 修复线索问题定位错误问题

---
 miniprogram_npm/tdesign-miniprogram/input/input.js |   21 ++++++++++++++++-----
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/miniprogram_npm/tdesign-miniprogram/input/input.js b/miniprogram_npm/tdesign-miniprogram/input/input.js
index c926018..3780064 100644
--- a/miniprogram_npm/tdesign-miniprogram/input/input.js
+++ b/miniprogram_npm/tdesign-miniprogram/input/input.js
@@ -7,7 +7,7 @@
 import { SuperComponent, wxComponent } from '../common/src/index';
 import config from '../common/config';
 import props from './props';
-import { getCharacterLength, calcIcon } from '../common/utils';
+import { getCharacterLength, calcIcon, isDef } from '../common/utils';
 const { prefix } = config;
 const name = `${prefix}-input`;
 let Input = class Input extends SuperComponent {
@@ -32,11 +32,13 @@
             prefix,
             classPrefix: name,
             classBasePrefix: prefix,
+            showClearIcon: true,
         };
         this.lifetimes = {
             ready() {
-                const { value } = this.properties;
-                this.updateValue(value == null ? '' : value);
+                var _a;
+                const { value, defaultValue } = this.properties;
+                this.updateValue((_a = value !== null && value !== void 0 ? value : defaultValue) !== null && _a !== void 0 ? _a : '');
             },
         };
         this.observers = {
@@ -55,6 +57,9 @@
                     _clearIcon: calcIcon(v, 'close-circle-filled'),
                 });
             },
+            clearTrigger() {
+                this.updateClearIconVisible();
+            },
         };
         this.methods = {
             updateValue(value) {
@@ -66,7 +71,7 @@
                         count: length,
                     });
                 }
-                else if (maxlength > 0 && !Number.isNaN(maxlength)) {
+                else if (maxlength && maxlength > 0 && !Number.isNaN(maxlength)) {
                     const { length, characters } = getCharacterLength('maxlength', value, maxlength);
                     this.setData({
                         value: characters,
@@ -76,9 +81,13 @@
                 else {
                     this.setData({
                         value,
-                        count: value ? String(value).length : 0,
+                        count: isDef(value) ? String(value).length : 0,
                     });
                 }
+            },
+            updateClearIconVisible(value = false) {
+                const { clearTrigger } = this.properties;
+                this.setData({ showClearIcon: value || clearTrigger === 'always' });
             },
             onInput(e) {
                 const { value, cursor, keyCode } = e.detail;
@@ -86,9 +95,11 @@
                 this.triggerEvent('change', { value: this.data.value, cursor, keyCode });
             },
             onFocus(e) {
+                this.updateClearIconVisible(true);
                 this.triggerEvent('focus', e.detail);
             },
             onBlur(e) {
+                this.updateClearIconVisible();
                 this.triggerEvent('blur', e.detail);
             },
             onConfirm(e) {

--
Gitblit v1.9.3