import Vue from 'vue'

Vue.prototype.$SearchLog = []
Vue.prototype.$fleetList = []
Vue.prototype.$originAllShipRankList = []
Vue.prototype.$sourceShips = []
Vue.prototype.$MessageInfo = []
Vue.prototype.$showComponents = new Map<string, any>() // 显示的组件
Vue.prototype.$MiniList = [] // 最小化列表
Vue.prototype.$HistoryLog = [] // 轨迹记录
Vue.prototype.$menuGroup = new Map<string, any>() // 菜单分组

let localStorageMock = (function (win) {
  let storage = win.localStorage;
  return {
    setItem: function (key: any, value: any) {
      let setItemEvent: any = new Event("setItemEvent");
      let oldValue = storage[key];
      setItemEvent.key = key;
      // 新旧值深度判断，派发监听事件
      if (oldValue !== value) {
        setItemEvent.newValue = value;
        setItemEvent.oldValue = oldValue;
        win.dispatchEvent(setItemEvent);
        storage[key] = value;
        return true;
      }
      return false;
    },
    getItem: function (key: any) {
      return storage[key];
    },
    removeItem: function (key: any) {
      storage[key] = null;
      return true;
    },
    clear: function () {
      storage.clear();
      return true;
    },
    key: function (index: any) {
      return storage.key(index);
    }
  };
}(window));

Object.defineProperty(window, 'localStorage', {value: localStorageMock, writable: true});
