export default {
  created() {
    this.addInit();
  },
  methods: {
    addInit() {
      var { type } = this.$route.query;
      if (type && this.callback[type]) {
        this.callback[type]();
      }
    },
    addOn(callback, typeStr = "add") {
      if (!this.callback) {
        this.callback = {};
      }
      if (callback) {
        this.callback[typeStr] = callback;
      }
      return () => {
        var { type, ...p } = this.$route.query;
        this.$router.push({
          query: {
            ...p,
            type: typeStr,
          },
        });
        callback && callback();
      };
    },
    addOff(callback) {
      return (...pm) => {
        var { type, ...p } = this.$route.query;
        this.$router.push({
          query: {
            ...p,
          },
        });
        callback && callback(...pm);
      };
    },
  },
};
