Skip to content

Commit

Permalink
refactor(action-sheet): simplify initialization logic and enhance obs…
Browse files Browse the repository at this point in the history
…erver functionality
  • Loading branch information
betavs committed Jan 16, 2025
1 parent 6bb91a8 commit 4464026
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/action-sheet/action-sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,24 @@ export default class ActionSheet extends SuperComponent {
},
];

ready() {
this.memoInitialData();
this.splitGridThemeActions();
}
observers = {
'visible, items'(visible: boolean) {
if (!visible) return;
this.init();
},
};

methods = {
onSwiperChange(e: WechatMiniprogram.TouchEvent) {
const {
detail: { current },
} = e;
this.setData({
currentSwiperIndex: current,
});
init() {
this.memoInitialData();
this.splitGridThemeActions();
},

memoInitialData() {
this.initialData = {
...this.properties,
...this.data,
};
},

splitGridThemeActions() {
Expand All @@ -70,13 +75,6 @@ export default class ActionSheet extends SuperComponent {
this._trigger('visible-change', { visible: true });
},

memoInitialData() {
this.initialData = {
...this.properties,
...this.data,
};
},

/** 指令调用隐藏 */
close() {
this.triggerEvent('close', { trigger: 'command' });
Expand All @@ -95,6 +93,13 @@ export default class ActionSheet extends SuperComponent {
}
},

onSwiperChange(e: WechatMiniprogram.TouchEvent) {
const { current } = e.detail;
this.setData({
currentSwiperIndex: current,
});
},

onSelect(event: WechatMiniprogram.TouchEvent) {
const { currentSwiperIndex, items, gridThemeItems, count, theme } = this.data;
const { index } = event.currentTarget.dataset;
Expand Down

0 comments on commit 4464026

Please sign in to comment.