为什么都没了

This commit is contained in:
路 范
2021-09-24 12:59:34 +08:00
parent a975b3bdee
commit a66921f0f4
962 changed files with 252792 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { createStore } from 'redux'
import { cloneDeep, result, isEqual } from 'lodash'
import reducer from './reducer'
const _store = createStore(reducer)
const store = cloneDeep(_store)
/**
* 允许传入第一个参数path,只监听指定属性路径的对象
* @param {...any} args
* @returns
*/
store.subscribe = (...args) => {
let path,
listener,
snapshot
if (typeof args[0] === 'string' && typeof args[1] === 'function') {
path = args[0]
listener = args[1]
snapshot = cloneDeep(result(_store.getState(), path))
} else {
listener = args[0]
}
return _store.subscribe((...args) => {
const state = _store.getState()
if (path) {
const resultState = cloneDeep(result(state, path))
if (!isEqual(snapshot, resultState)) {
listener.apply(this, [resultState, ...args])
}
snapshot = resultState
} else {
listener.apply(this, [state, ...args])
}
})
}
/**
* 允许传入参数path,只返回指定属性路径的对象
* @param {*} path
* @returns
*/
store.getState = (path) => {
if (path) {
return result(_store.getState(), path)
}
return _store.getState()
}
export default store

View File

@@ -0,0 +1,33 @@
const business = (state = {}, action) => {
switch (action.type) {
case 'PATROL_INIT_GRADE_BY_COMPLETED_DATE':
{
const completedDate = state.completedDate || []
const { date } = action
const record = completedDate.find(p => p.id === date.id)
if (record) {
record.value = date.value
} else {
completedDate.push(date)
}
const _state = { ...state, completedDate }
return _state
}
case 'PATROL_REMOVE_INIT_GRADE_BY_COMPLETED_DATE':
{
const completedDate = state.completedDate || []
const record = completedDate.find(p => p.id === action.id)
if (!record) {
return state
} else {
completedDate.splice(completedDate.indexOf(record), 1)
const _state = { ...state, completedDate }
return _state
}
}
default:
return state
}
}
export default business

View File

@@ -0,0 +1,11 @@
const dictData = (state = {}, action) => {
switch (action.type) {
case 'ADD_DICT_DATA':
const _state = { ...state, ...action.value }
return _state
default:
return state
}
}
export default dictData

View File

@@ -0,0 +1,18 @@
import { combineReducers } from 'redux'
import user from './user'
import layout from './layout'
import nav from './nav'
import dictData from './dict-data'
import notice from './notice'
import business from './business'
const combine = combineReducers({
user,
layout,
nav,
dictData,
notice,
business
})
export default combine

View File

@@ -0,0 +1,62 @@
import { SETTING_KEY } from "common/storage"
import { SIDER_BREAK_POINT } from "util/global"
const defaultState = {
siderCollapsed: false,
allowSiderCollapsed: true,
theme: 'default'
}
const localStorageState = () => {
return JSON.parse(window.localStorage.getItem(SETTING_KEY)) || {}
}
const mergeState = {
...defaultState,
...localStorageState()
}
const layout = (state = mergeState, action) => {
switch (action.type) {
// 打开窗口
case 'OPEN_WINDOW':
return state
// 关闭窗口
case 'CLOSE_WINDOW':
return state
// 重新加载窗口
case 'RELOAD_WINDOW':
return state
// 侧边收起状态
case 'TOGGLE_COLLAPSED':
{
if (window.innerWidth <= SIDER_BREAK_POINT) {
return state
}
const _state = { ...state, siderCollapsed: action.siderCollapsed }
window.localStorage.setItem(SETTING_KEY, JSON.stringify(_state))
return _state
}
// 自动收起侧边
case 'AUTO_TOGGLE_COLLAPSED':
{
const _state = {
...state,
siderCollapsed: localStorageState().siderCollapsed || action.siderCollapsed,
allowSiderCollapsed: !action.siderCollapsed
}
return _state
}
// 切换主题
case 'SET_THEME':
{
const _state = { ...state, theme: action.theme }
window.localStorage.setItem(SETTING_KEY, JSON.stringify(_state))
return _state
}
default:
return state
}
}
export default layout

View File

@@ -0,0 +1,16 @@
const defaultState = { nav: [] }
const nav = (state = defaultState, action) => {
// 写入各种action对应的操作
switch (action.type) {
case 'SET_NAV':
const _state = { ...state, nav: action.nav }
return _state
case 'RESET_NAV':
return defaultState
default:
return state
}
}
export default nav

View File

@@ -0,0 +1,40 @@
const defaultState = {
count: 0,
list: []
}
const layout = (state = defaultState, action) => {
switch (action.type) {
case 'SET_NOTICE_COUNT':
{
const _state = {
...state,
count: action.count
}
return _state
}
case 'SET_NOTICE_LIST':
{
const _state = {
...state,
list: action.list
}
return _state
}
case 'READ_NOTICE':
{
const notice = state.list.find(p => p.id === action.id)
if (notice && !notice.readStatus) {
notice.readStatus = 1
state.count -= 1
}
return {
...state
}
}
default:
return state
}
}
export default layout

View File

@@ -0,0 +1,16 @@
const defaultState = {}
const user = (state = defaultState, action) => {
// 写入各种action对应的操作
switch (action.type) {
case 'SET_USER_ACCOUNT':
const _state = { ...state, ...action.user }
return _state
case 'RESET_USER_ACCOUNT':
return defaultState
default:
return state
}
}
export default user