/* eslint-disable no-proto */
import { connect } from 'herculex';

Component(connect({
  mapStateToProps: {
  },
})({
  props: {
    text: '应用重载',
    onCallBack: '',
  },
  data: {
  },
  methods: {
    async onClick() {
      if (this.props.onCallBack) {
        this.props.onCallBack();
      } else {
        // 重载应用
        my.removeStorageSync({
          key: 'PAGE_DATA_KEY',
        });
        const url = getCurrentPages()[0].__proto__.route;
        const options = getCurrentPages()[0].options || {};
        let params = '';
        Object.keys(options).forEach(key => {
          params = options[key] && (typeof (options[key]) === 'string' || typeof (options[key]) === 'number') ? `&${key}=${options[key]}` : params;
        });
        my.reLaunch({
          url: `/${url}?${params}`,
        });
        // 页面刷新
        // const options = getCurrentPages().pop().options || {};
        // await this.dispatch('init', {
        //   ...options,
        //   noCache: true,
        //   isPullRefresh: true,
        // });
      }
    },
  },
}));
