queryCurrent.js 1.1 KB
Newer Older
钟是志's avatar
钟是志 committed
1
import request from '@/webPublic/zyd_public/request/request';
钟是志's avatar
钟是志 committed
2
import { getCurrentUser, getToken } from '@/webPublic/one_stop_public/utils/token';
3

4
export const getTime = () => {
5 6
  const config = window.specialImportantSystemConfig || {};
  if (config.mockServer) {
7
    return request(
8
      `${config.mockServer}/${config.gateWayUrl.zydxg}/InstructorConfigApi/getCurrentDate`,
9 10 11 12
      {
        method: 'POST',
        body: {},
      },
13 14 15 16 17 18 19
    ).then(t => {
      if (t) {
        return t - new Date().getTime(); // 服务器时间 与 客户端时间的差值;
      } else {
        return 0;
      }
    });
20
  } else {
21
    return new Promise(resolve => {
钟是志's avatar
钟是志 committed
22
      resolve(0);
钟是志's avatar
钟是志 committed
23
      return 0;
24 25
    });
  }
钟是志's avatar
钟是志 committed
26 27 28
};

export async function queryCurrent() {
29
  const config = window.specialImportantSystemConfig || {};
钟是志's avatar
钟是志 committed
30 31 32
  let token = getToken();
  let userInfo = getCurrentUser();
  if (token && userInfo.token === token) {
33
    return new Promise(resolve => {
钟是志's avatar
钟是志 committed
34 35 36 37
      resolve(userInfo);
      return userInfo;
    });
  }
38
  if (config.mockServer) {
39 40 41 42
    return request(`${config.mockServer}/${config.gateWayUrl.zydxg}/UserApi/queryCurrent`, {
      method: 'POST',
      body: {},
    });
43
  }
钟是志's avatar
钟是志 committed
44
}