| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- // components/button/button.ts
- Component({
- behaviors: ['wx://form-field-button'],
- lifetimes: {
- attached() {
- console.log('[Button] attached, initializing...');
- const mode = this.data.block ? 'block' : 'line';
- const index = this.data.index;
- this.setData({
- src: `../../assets/bg/button-${mode}-${index}.bg.png`,
- className: this.data.block ? 'block' : `line-${index}`,
- isDisabled: false
- });
- console.log('[Button] initialized with isDisabled:', this.data.isDisabled);
- }
- },
- properties: {
- block: { type: Boolean, value: false },
- index: { type: Number, value: 1 },
- loading: { type: Boolean, value: false },
- },
- data: {
- list: [
- {
- name: '保存',
- value: 'save',
- },
- {
- name: '提交',
- value: 'cancel',
- },
- {
- name: '确定',
- value: 'confirm',
- },
- ],
- src: '',
- isDisabled: false,
- _lastResetTime: 0
- },
- methods: {
- handleSubmit() {
- console.log('[Button] handleSubmit called, isDisabled:', this.data.isDisabled);
- if (this.data.isDisabled) {
- console.log('[Button] button is disabled, returning');
- return;
- }
-
- // 如果是刚刚重置的按钮(100ms内),不要立即禁用
- const now = Date.now();
- if (now - this.data._lastResetTime < 100) {
- console.log('[Button] button was just reset, not disabling');
- this.triggerEvent('submit');
- return;
- }
-
- console.log('[Button] setting isDisabled to true');
- this.setData({ isDisabled: true });
- this.triggerEvent('submit');
- },
-
- resetState() {
- console.log('[Button] resetState called');
- console.log('[Button] current isDisabled:', this.data.isDisabled);
- this.setData({
- isDisabled: false,
- _lastResetTime: Date.now()
- });
- console.log('[Button] isDisabled set to:', false);
- }
- }
- })
|