Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(action-sheet): simplify initialization logic and enhance observer functionality #3438

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading