import request from '@/H5Public/utils/request';
import { setCurrentUser } from '@/H5Public/utils/2022new/currentUser';

window.differenceBetweenServerAndClientTime = 0;
const config = window.specialImportantSystemConfig || {};
const getTime = () => {
    return request(`${config.mockServer}${config?.gateWayUrl?.zydxg}/InstructorConfigApi/getCurrentDate`, {
      method: 'POST',
      body: {},
    });
};

export async function queryCurrent() {
  let t = await getTime();
  if (t) {
    window.differenceBetweenServerAndClientTime = t - new Date().getTime(); // 服务器时间 与 客户端时间的差值
    console.log(window.differenceBetweenServerAndClientTime);
  }
  return request(`${config.mockServer}${config?.gateWayUrl?.zydxg}/UserApi/queryCurrent`, {
    method: 'POST',
    body: {},
  }).then((res) => {
    if (res) {
      setCurrentUser(res);
    }
  });
}
