import axios from 'axios';
import { nanoid } from 'nanoid';
import { useMessage } from '../hooks/web/useMessage';
export async function isNewVersion() {
  const { createMessage } = useMessage();
  const url = `//${window.location.host}/version.json?id=${nanoid(10)}`;
  const res = await axios.get(url);
  console.log('🚀 ~ file: versionUpdate.ts ~ line 6 ~ isNewVersion ~ res', res);
  const version = res.data.version;
  const localVersion = localStorage.getItem('version');
  if (localVersion && localVersion != version) {
    createMessage.warning('后台系统更新,即将刷新页面');
    localStorage.removeItem('infusionTable');
    localStorage.setItem('version', version);
    window.location.reload();
  } else {
    localStorage.setItem('version', version);
  }
}
