import store from './store';
import { getSharePath } from '../../utils';

const createPage = function (options) {
  return Page(store.register(options));
};

createPage({
  async onLoad(options) {
    this.options = options;
    this.dispatch('init', this.options);
    this.dispatch('resetStorage', {});
  },
  async onResume() {
    this.dispatch('onResume');
  },
  async onReloadHandle() {
    await this.dispatch('init', {
      ...this.options,
      /*
      * 刷新关闭页面数据缓存
      * */
      noCache: true,
      isPullRefresh: true,
    });
  },
  onReachBottom() {
  },
  onPageScroll() {},
  onShow() {
  },
  /*
  * 增加下拉刷新
  * */
  async onPullDownRefresh() {
    await this.onReloadHandle();
    my.stopPullDownRefresh();
  },
  onPullIntercept() {
  },
  onShareAppMessage() {
    return {
      title: this.data.pageName || '',
      path: getSharePath(),
    };
  },
});
