feat: 优化字帖功能

This commit is contained in:
R524809
2026-02-11 16:03:39 +08:00
parent 943250b34a
commit cbf07faf27
11 changed files with 474 additions and 280 deletions
@@ -14,15 +14,27 @@ Component({
type: String,
value: '请输入文字',
},
value: {
type: String,
value: '', // 输入框的值(支持外部控制)
},
},
/**
* 组件的初始数据
*/
data: {
innerValue: '', // 内部维护的输入值
},
observers: {
// 监听外部传入的 value 变化
value(newVal: string) {
this.setData({ innerValue: newVal });
},
},
lifetimes: {
attached() {
(this as any).value = '';
// 初始化时同步外部传入的 value
this.setData({ innerValue: this.properties.value || '' });
},
},
/**
@@ -32,17 +44,14 @@ Component({
onInput(e: WechatMiniprogram.Input) {
let { value } = e.detail;
value = value.replace(/\s/g, '');
if (value.length > 0) {
(this as any).value = value;
}
this.setData({ innerValue: value });
},
onConfirm() {
const value = (this as any).value;
const value = this.data.innerValue;
if (value.length > 0) {
this.triggerEvent('onConfirm', { value });
}
// 触发确认事件(即使值为空也触发,让父组件处理清空逻辑)
this.triggerEvent('onConfirm', { value });
},
// onTap() {