feat: lots updates

This commit is contained in:
zerosoul
2022-01-30 21:30:12 +08:00
parent e18c7323a6
commit ceb02d834f
38 changed files with 1943 additions and 1832 deletions
+7 -5
View File
@@ -1,9 +1,8 @@
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import BASE_URL from "../config";
import { createApi } from "@reduxjs/toolkit/query/react";
import baseQuery from "./base.query";
export const authApi = createApi({
reducerPath: "auth",
baseQuery: fetchBaseQuery({ baseUrl: BASE_URL }),
baseQuery,
endpoints: (builder) => ({
login: builder.mutation({
query: (credentials) => ({
@@ -19,7 +18,10 @@ export const authApi = createApi({
// return resp;
// },
}),
logout: builder.query({
query: () => ({ url: `token/logout` }),
}),
}),
});
export const { useLoginMutation } = authApi;
export const { useLoginMutation, useLazyLogoutQuery } = authApi;
+4 -12
View File
@@ -1,20 +1,12 @@
import { fetchBaseQuery } from "@reduxjs/toolkit/query";
import BASE_URL, { tokenHeader } from "../config";
// const whiteList = [
// "/resource/avatar",
// "/resource/company/logo",
// "/resource/thumbnail",
// "/resource/image",
// "/token/login",
// "/token/renew",
// "/user",
// "/admin/system/company",
// ];
const whiteList = ["login"];
const baseQuery = fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState }) => {
prepareHeaders: (headers, { getState, endpoint }) => {
console.log("req", endpoint);
const { token } = getState().authData;
if (token) {
if (token && !whiteList.includes(endpoint)) {
headers.set(tokenHeader, token);
}
return headers;
+1 -1
View File
@@ -2,7 +2,7 @@ import { createApi } from "@reduxjs/toolkit/query/react";
import baseQuery from "./base.query";
import { REHYDRATE } from "redux-persist";
export const channelApi = createApi({
reducerPath: "groups",
reducerPath: "channel",
baseQuery,
extractRehydrationInfo(action, { reducerPath }) {
if (action.type === REHYDRATE) {
+1 -1
View File
@@ -3,7 +3,7 @@ import baseQuery from "./base.query";
import BASE_URL from "../config";
import { REHYDRATE } from "redux-persist";
export const contactApi = createApi({
reducerPath: "contacts",
reducerPath: "contact",
baseQuery,
extractRehydrationInfo(action, { reducerPath }) {
if (action.type === REHYDRATE) {
+2 -2
View File
@@ -14,9 +14,9 @@ export const serverApi = createApi({
// },
endpoints: (builder) => ({
getServer: builder.query({
query: () => ({ url: `admin/system/company` }),
query: () => ({ url: `admin/system/organization` }),
transformResponse: (data) => {
data.logo = `${BASE_URL}/resource/company/logo`;
data.logo = `${BASE_URL}/resource/organization/logo`;
return data;
},
}),