@/utils/utils#getPageQuery JavaScript Examples

The following examples show how to use @/utils/utils#getPageQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: login.js    From vpp with MIT License 5 votes vote down vote up
Model = {
  namespace: 'login',
  state: {
    status: undefined,
  },
  effects: {
    *login({ payload }, { call, put }) {
      const response = yield call(fakeAccountLogin, payload);
      yield put({
        type: 'changeLoginStatus',
        payload: response,
      }); // Login successfully

      if (response.status === 'ok') {
        const urlParams = new URL(window.location.href);
        const params = getPageQuery();
        let { redirect } = params;

        if (redirect) {
          const redirectUrlParams = new URL(redirect);

          if (redirectUrlParams.origin === urlParams.origin) {
            redirect = redirect.substr(urlParams.origin.length);

            if (redirect.match(/^\/.*#/)) {
              redirect = redirect.substr(redirect.indexOf('#') + 1);
            }
          } else {
            window.location.href = '/';
            return;
          }
        }

        history.replace(redirect || '/');
      }
    },

    logout() {
      const { redirect } = getPageQuery(); // Note: There may be security issues, please note

      if (window.location.pathname !== '/user/login' && !redirect) {
        history.replace({
          pathname: '/user/login',
          search: stringify({
            redirect: window.location.href,
          }),
        });
      }
    },
  },
  reducers: {
    changeLoginStatus(state, { payload }) {
      setAuthority(payload.currentAuthority);
      return { ...state, status: payload.status, type: payload.type };
    },
  },
}
Example #2
Source File: login.js    From spring-boot-plus-admin-react with Apache License 2.0 5 votes vote down vote up
Model = {
  namespace: 'login',
  state: {
    status: undefined,
  },
  effects: {
    *login({ payload }, { call, put }) {
      const response = yield call(login, payload);
      messageR(response);
      yield put({
        type: 'changeLoginStatus',
        payload: {...response, type: payload.type},
      }); // Login successfully
      if (response.success) {
        const { token , loginSysUserVo } = response.data;
        if( !loginSysUserVo.avatar ) {
          const avatar = "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png";
          loginSysUserVo.avatar = avatar;
        }
        localStorage.setItem(TOKEN, token );
        localStorage.setItem(USER, JSON.stringify(loginSysUserVo));

        const urlParams = new URL(window.location.href);
        const params = getPageQuery();
        let { redirect } = params;

        if (redirect) {
          const redirectUrlParams = new URL(redirect);

          if (redirectUrlParams.origin === urlParams.origin) {
            redirect = redirect.substr(urlParams.origin.length);

            if (redirect.match(/^\/.*#/)) {
              redirect = redirect.substr(redirect.indexOf('#') + 1);
            }
          } else {
            window.location.href = '/';
            return;
          }
        }

        router.replace(redirect || '/');
      }
    },

    *getCaptcha({ payload }, { call }) {
      yield call(getFakeCaptcha, payload);
    },

    logout() {
      const { redirect } = getPageQuery(); // Note: There may be security issues, please note

      if (window.location.pathname !== '/user/login' && !redirect) {
        router.replace({
          pathname: '/user/login',
          search: stringify({
            redirect: window.location.href,
          }),
        });
      }
    },
  },
  reducers: {
    changeLoginStatus(state, { payload }) {
      if (payload.success) {
        setAuthority(payload.currentAuthority);
      }
      return {
        ...state,
        status: payload.success ? 'ok' : 'error',
        type: payload.type,
      };
    },
  },
}
Example #3
Source File: login.js    From egoshop with Apache License 2.0 5 votes vote down vote up
Model = {
  namespace: 'login',
  state: {
    code: 0,
  },
  effects: {
    *login({ payload }, { call, put }) {
      const response = yield call(fakeAccountLogin, payload);
      yield put({
        type: 'changeLoginStatus',
        payload: response,
      }); // Login successfully
      if (response.code === 0) {
        const params = getPageQuery();
        let { redirect } = params;
        if (redirect) {
          window.location.href = redirect;
        }else {
          window.location.href = "/"
        }
      }else {
        message.error("登录失败,请检查用户名或密码是否正确!")
      }
    },

    *getCaptcha({ payload }, { call }) {
      yield call(getFakeCaptcha, payload);
    },

    *logout(_, { call, put  }) {
      const { redirect } = getPageQuery(); // redirect

      const response = yield call(accountLogout);
      // Login successfully
      console.log('logout response', response);

      if (response.code === 0) {
        yield put({
          type: 'changeLoginStatus',
          payload: {
            status: false,
            data: {
              currentAuthority: 'guest',
            },
          },
        });
        yield put(
          routerRedux.push({
            pathname: '/user/login',
            search: stringify({
              redirect: window.location.href,
            }),
          })
        );
      }

    },
  },
  reducers: {
    changeLoginStatus(state, { payload }) {
      if (payload.code === 0) {
        setAuthority(payload.data.currentAuthority);
      }else {
        setAuthority({
          currentAuthority: 'guest',
        });
      }
      return { ...state, code: payload.code, type: payload.type };
    },
  },
}
Example #4
Source File: login.js    From prometheusPro with MIT License 5 votes vote down vote up
Model = {
  namespace: 'login',
  state: {
    status: undefined,
  },
  effects: {
    *login({ payload }, { call, put }) {
      const response = yield call(fakeAccountLogin, payload);
      yield put({
        type: 'changeLoginStatus',
        payload: response,
      }); // Login successfully

      if (response.status === 'ok') {
        const urlParams = new URL(window.location.href);
        const params = getPageQuery();
        let { redirect } = params;

        if (redirect) {
          const redirectUrlParams = new URL(redirect);

          if (redirectUrlParams.origin === urlParams.origin) {
            redirect = redirect.substr(urlParams.origin.length);

            if (redirect.match(/^\/.*#/)) {
              redirect = redirect.substr(redirect.indexOf('#') + 1);
            }
          } else {
            window.location.href = '/';
            return;
          }
        }

        router.replace(redirect || '/');
      }
    },

    logout() {
      const { redirect } = getPageQuery(); // Note: There may be security issues, please note

      if (window.location.pathname !== '/user/login' && !redirect) {
        router.replace({
          pathname: '/user/login',
          search: stringify({
            redirect: window.location.href,
          }),
        });
      }
    },
  },
  reducers: {
    changeLoginStatus(state, { payload }) {
      setAuthority(payload.currentAuthority);
      return { ...state, status: payload.status, type: payload.type };
    },
  },
}
Example #5
Source File: login.js    From the-eye-knows-the-garbage with MIT License 4 votes vote down vote up
Model = {
  namespace: 'login',
  state: {
    status: undefined,
    errors: {},
  },
  effects: {
    * login({payload}, {call, put}) {
      yield put({
        type: 'clearErrors',
      });
      try {
        const response = yield call(AccountLogin, payload);
        yield put({
          type: 'changeLoginStatus',
          payload: response,
        }); // Login successfully

        if (response.status === 'ok') {
          const urlParams = new URL(window.location.href);
          const params = getPageQuery();
          let {redirect} = params;

          if (redirect) {
            const redirectUrlParams = new URL(redirect);

            if (redirectUrlParams.origin === urlParams.origin) {
              redirect = redirect.substr(urlParams.origin.length);

              if (redirect.match(/^\/.*#/)) {
                redirect = redirect.substr(redirect.indexOf('#') + 1);
              }
            } else {
              window.location.href = '/';
              return;
            }
          }

          history.replace(redirect || '/xadmin');
        }
        return response
      }catch (error){
        console.log(error)
        console.log("error in login")
        return error
      }
    },
    * email({email}, {call, put}) {
      try {
        yield put({
          type: 'clearErrors',
        });
        const res = yield call(getEmailCaptcha, email);
        if (res) {
          return res;
        }
      } catch (errors) {
        yield put({
          type: 'errorsHandle',
          payload: errors.data.fields_errors,
        });
      }


    },
    logout() {
      Logout().then(r =>
        message.success('成功退出登录'),
      );
      reloadAuthorized();
      localStorage.clear();
      const {redirect} = getPageQuery(); // Note: There may be security issues, please note

      if (window.location.pathname !== '/xadmin/login' && !redirect) {
        history.replace({
          pathname: '/xadmin/login',
          search: stringify({
            redirect: window.location.href,
          }),
        });
      }
    },
  },
  reducers: {
    errorsHandle(state, {payload}) {
      return {
        ...state,
        errors: payload,
      };
    },
    clearErrors(state, {}) {
      return {
        ...state,
        errors: {},
      };
    },
    changeLoginStatus(state, {payload}) {
      setAuthority(payload.currentAuthority);
      return {...state, status: payload.status, type: payload.type};
    },
  },
}