common.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { createSlice } from "@reduxjs/toolkit";
  2. interface CommonState {
  3. resources: [] | null;
  4. meal_tags: [] | null;
  5. food_scales: [] | null;
  6. configs: any | null;
  7. duration: {
  8. min: number;
  9. max: number;
  10. step: number;
  11. } | null;
  12. showTabbar: boolean | true;
  13. showFoodTabBadge: boolean | false;
  14. pageIndex: number | 0;
  15. recordSelID: any | null; //删除id
  16. }
  17. const initialState: CommonState = {
  18. resources: [],
  19. meal_tags: [],
  20. food_scales: [],
  21. configs: null,
  22. duration: null,
  23. showTabbar: true,
  24. showFoodTabBadge: false,
  25. pageIndex: 0,
  26. recordSelID:null
  27. }
  28. const commonSlice = createSlice({
  29. name: 'permission',
  30. initialState,
  31. reducers: {
  32. setSelID(state,action){
  33. state.recordSelID = action.payload;
  34. },
  35. //静态资源
  36. setResources(state, action) {
  37. state.resources = action.payload;
  38. },
  39. setMealTags(state, action) {
  40. state.meal_tags = action.payload
  41. },
  42. setFoodScales(state, action) {
  43. state.food_scales = action.payload
  44. },
  45. //是否disable并隐藏tabbar
  46. setTabbarStatus(state, action) {
  47. state.showTabbar = action.payload;
  48. },
  49. //time配置文件
  50. setConfigs(state, action) {
  51. state.configs = action.payload;
  52. if (state.configs) {
  53. state.duration = {
  54. min: state.configs.min / 60,
  55. max: state.configs.max / 60,
  56. step: state.configs.step
  57. }
  58. }
  59. },
  60. changeTabbar(state, action) {
  61. state.pageIndex = action.payload;
  62. },
  63. setFoodTabBadge(state, action) {
  64. state.showFoodTabBadge = action.payload;
  65. }
  66. }
  67. });
  68. export default commonSlice.reducer;
  69. export const {setSelID, setResources, setMealTags, setFoodScales, setConfigs, setTabbarStatus, changeTabbar, setFoodTabBadge } = commonSlice.actions;