import Vue from 'vue';
import _ from 'lodash';
const Plugin = {
  install(Vue, options) {
    // 3. 注入组件
    Vue.mixin({
      created() {
        if (this.$store && !this.$store.$toUndefined) {
          this.$store.$toUndefined = this.$toUndefined;
        }
      },
    });
    // 4. 添加实例方法
    Vue.prototype.$toUndefined = object => {
      let keys = Object.keys(object);
      keys.map(item => {
        object[item] = object[item] === '' ? (object[item] = undefined) : object[item];
      });
      return object;
    };
    Vue.prototype.$isBindWx = () => {
      let user = sessionStorage.getItem('user');
      if (user) {
        user = JSON.parse(user);
        return _.get(user, `openid`, false);
      } else {
        return false;
      }
    };
  },
};

Vue.use(Plugin);
