mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2026-05-09 18:27:56 +08:00
update
This commit is contained in:
@@ -11,7 +11,9 @@ export const store = configureStore({
|
||||
[subscribeApi.reducerPath]: subscribeApi.reducer,
|
||||
[weightApi.reducerPath]: weightApi.reducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(subscribeApi.middleware),
|
||||
middleware: (getDefaultMiddleware) => getDefaultMiddleware()
|
||||
.concat(subscribeApi.middleware)
|
||||
.concat(weightApi.middleware),
|
||||
});
|
||||
|
||||
export type AppDispatch = typeof store.dispatch;
|
||||
|
||||
@@ -1,9 +1,28 @@
|
||||
import React from 'react';
|
||||
import { useGetWeightQuery } from './weightConfigSlice';
|
||||
import { WeightConfig } from '../../utils/type';
|
||||
import { useGetWeightQuery, useUpdateWeightMutation } from './weightConfigSlice';
|
||||
|
||||
export default function WeightManager() {
|
||||
const { data: weight } = useGetWeightQuery();
|
||||
const [updateWeight] = useUpdateWeightMutation();
|
||||
|
||||
const doUpdate = () => {
|
||||
const weightConfig: WeightConfig = {
|
||||
default: 20,
|
||||
time_config: [
|
||||
{
|
||||
start_time: '01:00',
|
||||
end_time: '02:00',
|
||||
weight: 50,
|
||||
},
|
||||
],
|
||||
};
|
||||
updateWeight({ weight: weightConfig, platform_name: 'weibo', target: '' });
|
||||
};
|
||||
return (
|
||||
<div>{weight && JSON.stringify(weight)}</div>
|
||||
<>
|
||||
<div>{weight && JSON.stringify(weight)}</div>
|
||||
<button type="button" onClick={doUpdate}> 123</button>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createApi } from '@reduxjs/toolkit/query/react';
|
||||
import { PlatformWeightConfigResp, StatusResp } from '../../utils/type';
|
||||
import baseQueryWithAuth from '../auth/authQuery';
|
||||
|
||||
export const weightApi = createApi({
|
||||
@@ -6,13 +7,22 @@ export const weightApi = createApi({
|
||||
baseQuery: baseQueryWithAuth,
|
||||
tagTypes: ['Weight'],
|
||||
endpoints: (builder) => ({
|
||||
getWeight: builder.query<any, void>({
|
||||
getWeight: builder.query<PlatformWeightConfigResp, void>({
|
||||
query: () => '/weight',
|
||||
providesTags: ['Weight'],
|
||||
}),
|
||||
updateWeight: builder.mutation<StatusResp,
|
||||
Pick<PlatformWeightConfigResp, 'platform_name' | 'target' | 'weight' >>({
|
||||
query: ({ platform_name: platformName, target, weight }) => ({
|
||||
method: 'PUT',
|
||||
url: `/weight?platform_name=${platformName}&target=${target}`,
|
||||
body: weight,
|
||||
}),
|
||||
invalidatesTags: ['Weight'],
|
||||
}),
|
||||
}),
|
||||
});
|
||||
|
||||
export const {
|
||||
useGetWeightQuery,
|
||||
useGetWeightQuery, useUpdateWeightMutation,
|
||||
} = weightApi;
|
||||
|
||||
@@ -58,3 +58,15 @@ export interface TimeWeightConfig {
|
||||
end_time: string;
|
||||
weight: number;
|
||||
}
|
||||
|
||||
export interface WeightConfig {
|
||||
default: number;
|
||||
time_config: TimeWeightConfig[];
|
||||
}
|
||||
|
||||
export interface PlatformWeightConfigResp {
|
||||
target: string;
|
||||
target_name: string;
|
||||
platform_name: string;
|
||||
weight: WeightConfig;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user