From b85f62c4a2b741b2ebaa275f60cd1d70b75af684 Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 17:37:31 +0800 Subject: [PATCH 01/16] =?UTF-8?q?redux=20=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 8 ++ read/md/redux.md | 3 + tpl/src/App.tsx | 12 ++- tpl/src/router/index.tsx | 6 +- tpl/src/stores/index.ts | 20 ++++ tpl/src/views/Action/_index.js | 3 + tpl/src/views/Action/index.jsx | 72 +++++++++++++ tpl/src/views/Action/index.jsx- | 53 +++++++++ tpl/src/views/Action/index0.jsx | 52 +++++++++ tpl/src/views/Action/item.jsx | 29 +++++ tpl/src/views/Action/redux/ActionTypes.js | 3 + tpl/src/views/Action/redux/Actions.js | 23 ++++ tpl/src/views/Action/redux/Reducer.js | 22 ++++ tpl/src/views/Action2/index.jsx | 18 ++++ yarn.lock | 124 ++++++++++++++++++++++ 15 files changed, 444 insertions(+), 4 deletions(-) create mode 100644 package.json create mode 100644 read/md/redux.md create mode 100644 tpl/src/stores/index.ts create mode 100644 tpl/src/views/Action/_index.js create mode 100644 tpl/src/views/Action/index.jsx create mode 100644 tpl/src/views/Action/index.jsx- create mode 100644 tpl/src/views/Action/index0.jsx create mode 100644 tpl/src/views/Action/item.jsx create mode 100644 tpl/src/views/Action/redux/ActionTypes.js create mode 100644 tpl/src/views/Action/redux/Actions.js create mode 100644 tpl/src/views/Action/redux/Reducer.js create mode 100644 tpl/src/views/Action2/index.jsx create mode 100644 yarn.lock diff --git a/package.json b/package.json new file mode 100644 index 0000000..ff6f3e5 --- /dev/null +++ b/package.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "@types/react-redux": "^7.1.20", + "react-redux": "^7.2.6", + "redux": "^4.1.2", + "redux-thunk": "^2.4.0" + } +} diff --git a/read/md/redux.md b/read/md/redux.md new file mode 100644 index 0000000..419f814 --- /dev/null +++ b/read/md/redux.md @@ -0,0 +1,3 @@ +yarn add react-redux redux + +yarn add @types/react-redux diff --git a/tpl/src/App.tsx b/tpl/src/App.tsx index 54101fe..db5952f 100644 --- a/tpl/src/App.tsx +++ b/tpl/src/App.tsx @@ -1,12 +1,18 @@ import React from 'react'; import { BrowserRouter, HashRouter} from 'react-router-dom'; - +import {Provider} from 'react-redux'; +import RootStore from '@/stores'; import Router from '@/router/'; - +const unsubscribe = RootStore.subscribe(() =>{ + // console.log(Store.getState()) + localStorage.setItem("LJMRoot", JSON.stringify(RootStore.getState())); +}) const App = () => ( - + + + ) export default App; diff --git a/tpl/src/router/index.tsx b/tpl/src/router/index.tsx index 6026b6c..4755872 100644 --- a/tpl/src/router/index.tsx +++ b/tpl/src/router/index.tsx @@ -3,6 +3,8 @@ import { lazy } from '@loadable/component'; import {NavLink,Redirect,Switch,Route} from 'react-router-dom'; const Home = lazy(() => import('@/views/Home')); const Test = lazy(() => import('@/views/Test')); +const Action = lazy(() => import('@/views/Action')); +const Action2 = lazy(() => import('@/views/Action2')); class Router extends Component { render(){ return( @@ -10,7 +12,9 @@ class Router extends Component { Loading...}> - + + + diff --git a/tpl/src/stores/index.ts b/tpl/src/stores/index.ts new file mode 100644 index 0000000..90c87dc --- /dev/null +++ b/tpl/src/stores/index.ts @@ -0,0 +1,20 @@ +import {createStore, combineReducers,applyMiddleware} from 'redux'; +import thunk from 'redux-thunk'; +import {reducer as addReducer} from '@/views/Action/_index.js'; +// import {reducer as testReducer} from '../views/Test/_index.js'; +// import {reducer as delReducer} from '../views/Test/_index.js'; +const reducer = combineReducers({ + add:addReducer, + // testList:testReducer, + // remove:removeReducer, + // edit:editReducer, +}) + +function newJson(str){ + var json = (new Function("return " + str))(); + return json; +} +export default createStore(reducer, + newJson(localStorage.getItem("LJMRoot"))||{}, + applyMiddleware(thunk) +); diff --git a/tpl/src/views/Action/_index.js b/tpl/src/views/Action/_index.js new file mode 100644 index 0000000..ce087e5 --- /dev/null +++ b/tpl/src/views/Action/_index.js @@ -0,0 +1,3 @@ +import * as actions from './redux/Actions.js'; +import reducer from './redux/Reducer.js'; +export {actions,reducer}; diff --git a/tpl/src/views/Action/index.jsx b/tpl/src/views/Action/index.jsx new file mode 100644 index 0000000..0d7fe95 --- /dev/null +++ b/tpl/src/views/Action/index.jsx @@ -0,0 +1,72 @@ +import React , { Component } from 'react'; +import {connect} from 'react-redux'; + +import {actions} from './_index.js'; +import { withRouter,NavLink,Switch,Redirect,Route} from 'react-router-dom'; +import Item from './item.jsx'; +class View extends Component { + // changeName(){ + // + // } + onAddFn(){ + const {dispatch,addList} = this.props; + console.log(addList.length) + dispatch(actions.add(addList.length)) + } + lists(){ + const { addList } = this.props; + return addList.map((val,index)=>{ + return( + + ) + }) + } + render(){ + console.log(this.props.addList) + const {addList,onAddFn,dispatch} = this.props; + return ( + + {addList.length}
+ action页面
+ {/**/} + 首页 + action + {this.onAddFn()}} + /> + { + addList.length!==0 + ? +
    {this.lists()}
+ : + '' + } +
+ ) + } +} +function mapStateToProps(state) { + console.log(state) + // this.props.addList + // { + // add:[], + // del:[] + // } + return { + addList:state.add + } +} +// const mapDispatchToProps = (dispatch, ownProps) => { +// // { +// // type:'ADD_TODO' +// // } +// // dispatch(actions.add()) +// return { +// onAddFn:()=>dispatch(actions.add()) +// } +// }; +export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index.jsx- b/tpl/src/views/Action/index.jsx- new file mode 100644 index 0000000..ba4a570 --- /dev/null +++ b/tpl/src/views/Action/index.jsx- @@ -0,0 +1,53 @@ +import React , { Component } from 'react'; +import {connect} from 'react-redux'; + +import {actions} from './_index.js'; + +class View extends Component { + // changeName(){ + // + // } + onAddFn(){ + const {dispatch} = this.props; + dispatch(actions.add()) + } + render(){ + console.log(this.props.addList) + const {addList,onAddFn} = this.props; + return ( + + {addList.length}
+ action页面
+ {/**/} + {this.onAddFn()}} + /> +
+ ) + } +} +function mapStateToProps(state) { + console.log(state) + // this.props.addList + // { + // add:[], + // del:[] + // } + return { + addList:state.add + } +} +const mapDispatchToProps = (dispatch, ownProps) => { + // { + // type:'ADD_TODO' + // } + // dispatch(actions.add()) + return { + onAddFn:()=>dispatch(actions.add()) + } +}; +export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index0.jsx b/tpl/src/views/Action/index0.jsx new file mode 100644 index 0000000..1a8ea51 --- /dev/null +++ b/tpl/src/views/Action/index0.jsx @@ -0,0 +1,52 @@ +import React , { Component } from 'react'; +import {connect} from 'react-redux'; + +import {actions} from './_index.js'; + +class View extends Component { + // changeName(){ + // + // } + render(){ + console.log(this.props.addList) + const {addList,onAddFn} = this.props; + return ( + + {addList.length}
+ action页面
+ {/**/} + {onAddFn()}} + /> +
+ ) + } +} +function mapStateToProps(state) { + console.log(state) + // this.props.addList + // { + // add:[], + // del:[] + // } + return { + addList:state.add + } +} +const mapDispatchToProps = (dispatch, ownProps) => { + // ownProps 父组件有任意参数 + // const {name} = ownProps; + // this.props.name + // { + // type:'ADD_TODO' + // } + // dispatch(actions.add()) + return { + onAddFn:()=>dispatch(actions.add()) + } +}; +export default connect(mapStateToProps,mapDispatchToProps)(View); diff --git a/tpl/src/views/Action/item.jsx b/tpl/src/views/Action/item.jsx new file mode 100644 index 0000000..c850abf --- /dev/null +++ b/tpl/src/views/Action/item.jsx @@ -0,0 +1,29 @@ +import React,{ Component } from 'react'; + +import {connect} from 'react-redux'; + +import { actions } from './_index.js'; + +class View extends Component { + constructor(props){ + super(props); + + } + render(){ + const {val,onRemoveFn} = this.props; + return( +
  • + {val.id}-{val.text}-{val.type} + {onRemoveFn()}}>删除 +
  • + ) + } +} +const mapDispatchToProps = (dispatch, ownProps) => { + const { val } = ownProps; + return { + onRemoveFn: () => dispatch(actions.del('删除',val.id)) + } +}; + +export default connect(null,mapDispatchToProps)(View); diff --git a/tpl/src/views/Action/redux/ActionTypes.js b/tpl/src/views/Action/redux/ActionTypes.js new file mode 100644 index 0000000..5d4a6f6 --- /dev/null +++ b/tpl/src/views/Action/redux/ActionTypes.js @@ -0,0 +1,3 @@ +export const ADD_TODO = 'ADD_TODO'; +export const DEL_TODO = 'DEL_TODO'; +export const EDIT_TODO = 'EDIT_TODO'; diff --git a/tpl/src/views/Action/redux/Actions.js b/tpl/src/views/Action/redux/Actions.js new file mode 100644 index 0000000..2a5ebe9 --- /dev/null +++ b/tpl/src/views/Action/redux/Actions.js @@ -0,0 +1,23 @@ +import * as ActionTypes from './ActionTypes'; +// import {a,b,c,d} from './ActionTypes'; +// ActionTypes.a +// ActionTypes.b +// ActionTypes.c +// { +// type:ActionTypes.ADD_TODO, +// text:'第一个demo' +// } +export const add = (_id) =>{ + return{ + type:ActionTypes.ADD_TODO, + text:'第一个demo', + id:_id++ + } +} +export const del = (text,id)=>{ + return { + type:ActionTypes.DEL_TODO, + text:text, + id:id + } +} diff --git a/tpl/src/views/Action/redux/Reducer.js b/tpl/src/views/Action/redux/Reducer.js new file mode 100644 index 0000000..cb45673 --- /dev/null +++ b/tpl/src/views/Action/redux/Reducer.js @@ -0,0 +1,22 @@ +import * as ActionTypes from './ActionTypes'; + +export default (state=[],action)=>{ + switch (action.type) { + case ActionTypes.ADD_TODO: + return [ + { + type:action.type, + text:action.text, + id:action.id + }, + ...state + ] + case ActionTypes.DEL_TODO: + return state.filter((item)=>{ + return item.id !== action.id; + }) + default: + return state; + } + +} diff --git a/tpl/src/views/Action2/index.jsx b/tpl/src/views/Action2/index.jsx new file mode 100644 index 0000000..8a5cc75 --- /dev/null +++ b/tpl/src/views/Action2/index.jsx @@ -0,0 +1,18 @@ +import React, {useState,useEffect} from 'react'; +import { useSelector, useDispatch } from "react-redux"; +import {actions} from '../Action/_index'; +const View = (props)=>{ + const state = useSelector((state)=>state); + const add = useSelector((state)=>state.add); + const dispatch = useDispatch(); + useEffect(()=>{ + dispatch(actions.add()) + // dispatch({ + // type:"ADD_TODO" + // }) + },[]) + return( +
    {add.length}
    + ) +} +export default View; diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..92a0df5 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,124 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@babel/runtime@^7.15.4", "@babel/runtime@^7.9.2": + version "7.16.3" + resolved "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.3.tgz?cache=0&sync_timestamp=1636495173603&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fruntime%2Fdownload%2F%40babel%2Fruntime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5" + integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ== + dependencies: + regenerator-runtime "^0.13.4" + +"@types/hoist-non-react-statics@^3.3.0": + version "3.3.1" + resolved "https://registry.nlark.com/@types/hoist-non-react-statics/download/@types/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" + integrity sha1-ESSq/lEYy1kZd66xzqrtEHDrA58= + dependencies: + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + +"@types/prop-types@*": + version "15.7.4" + resolved "https://registry.nlark.com/@types/prop-types/download/@types/prop-types-15.7.4.tgz?cache=0&sync_timestamp=1629708737049&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fprop-types%2Fdownload%2F%40types%2Fprop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" + integrity sha1-/PcgXCXf95Xuea8eMNosl5CAjxE= + +"@types/react-redux@^7.1.20": + version "7.1.20" + resolved "https://registry.npmmirror.com/@types/react-redux/download/@types/react-redux-7.1.20.tgz#42f0e61ababb621e12c66c96dda94c58423bd7df" + integrity sha1-QvDmGrq7Yh4SxmyW3alMWEI7198= + dependencies: + "@types/hoist-non-react-statics" "^3.3.0" + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + redux "^4.0.0" + +"@types/react@*": + version "17.0.34" + resolved "https://registry.npmmirror.com/@types/react/download/@types/react-17.0.34.tgz#797b66d359b692e3f19991b6b07e4b0c706c0102" + integrity sha1-eXtm01m2kuPxmZG2sH5LDHBsAQI= + dependencies: + "@types/prop-types" "*" + "@types/scheduler" "*" + csstype "^3.0.2" + +"@types/scheduler@*": + version "0.16.2" + resolved "https://registry.nlark.com/@types/scheduler/download/@types/scheduler-0.16.2.tgz?cache=0&sync_timestamp=1629709152024&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fscheduler%2Fdownload%2F%40types%2Fscheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" + integrity sha1-GmL4lSVyPd4kuhsBsJK/XfitTTk= + +csstype@^3.0.2: + version "3.0.9" + resolved "https://registry.nlark.com/csstype/download/csstype-3.0.9.tgz?cache=0&sync_timestamp=1631540709509&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fcsstype%2Fdownload%2Fcsstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b" + integrity sha1-ZBCvMbJr0FIJM9AsvGT86c4/vws= + +hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.2: + version "3.3.2" + resolved "https://registry.nlark.com/hoist-non-react-statics/download/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" + integrity sha1-7OCsr3HWLClpwuxZ/v9CpLGoW0U= + dependencies: + react-is "^16.7.0" + +"js-tokens@^3.0.0 || ^4.0.0": + version "4.0.0" + resolved "https://registry.nlark.com/js-tokens/download/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" + integrity sha1-GSA/tZmR35jjoocFDUZHzerzJJk= + +loose-envify@^1.4.0: + version "1.4.0" + resolved "https://registry.npm.taobao.org/loose-envify/download/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" + integrity sha1-ce5R+nvkyuwaY4OffmgtgTLTDK8= + dependencies: + js-tokens "^3.0.0 || ^4.0.0" + +object-assign@^4.1.1: + version "4.1.1" + resolved "https://registry.nlark.com/object-assign/download/object-assign-4.1.1.tgz?cache=0&sync_timestamp=1618847240432&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fobject-assign%2Fdownload%2Fobject-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= + +prop-types@^15.7.2: + version "15.7.2" + resolved "https://registry.nlark.com/prop-types/download/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" + integrity sha1-UsQedbjIfnK52TYOAga5ncv/psU= + dependencies: + loose-envify "^1.4.0" + object-assign "^4.1.1" + react-is "^16.8.1" + +react-is@^16.7.0, react-is@^16.8.1: + version "16.13.1" + resolved "https://registry.npmmirror.com/react-is/download/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" + integrity sha1-eJcppNw23imZ3BVt1sHZwYzqVqQ= + +react-is@^17.0.2: + version "17.0.2" + resolved "https://registry.npmmirror.com/react-is/download/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" + integrity sha1-5pHUqOnHiTZWVVOas3J2Kw77VPA= + +react-redux@^7.2.6: + version "7.2.6" + resolved "https://registry.npmmirror.com/react-redux/download/react-redux-7.2.6.tgz#49633a24fe552b5f9caf58feb8a138936ddfe9aa" + integrity sha1-SWM6JP5VK1+cr1j+uKE4k23f6ao= + dependencies: + "@babel/runtime" "^7.15.4" + "@types/react-redux" "^7.1.20" + hoist-non-react-statics "^3.3.2" + loose-envify "^1.4.0" + prop-types "^15.7.2" + react-is "^17.0.2" + +redux-thunk@^2.4.0: + version "2.4.0" + resolved "https://registry.npmmirror.com/redux-thunk/download/redux-thunk-2.4.0.tgz?cache=0&sync_timestamp=1635214108732&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fredux-thunk%2Fdownload%2Fredux-thunk-2.4.0.tgz#ac89e1d6b9bdb9ee49ce69a69071be41bbd82d67" + integrity sha1-rInh1rm9ue5JzmmmkHG+QbvYLWc= + +redux@^4.0.0, redux@^4.1.2: + version "4.1.2" + resolved "https://registry.npmmirror.com/redux/download/redux-4.1.2.tgz?cache=0&sync_timestamp=1635663041213&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fredux%2Fdownload%2Fredux-4.1.2.tgz#140f35426d99bb4729af760afcf79eaaac407104" + integrity sha1-FA81Qm2Zu0cpr3YK/PeeqqxAcQQ= + dependencies: + "@babel/runtime" "^7.9.2" + +regenerator-runtime@^0.13.4: + version "0.13.9" + resolved "https://registry.nlark.com/regenerator-runtime/download/regenerator-runtime-0.13.9.tgz?cache=0&sync_timestamp=1626993001371&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fregenerator-runtime%2Fdownload%2Fregenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52" + integrity sha1-iSV0Kpj/2QgUmI11Zq0wyjsmO1I= From 011f197b77d467f5c7ad12107696213e1b213814 Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 18:08:27 +0800 Subject: [PATCH 02/16] clearn --- package.json | 8 -- tpl/package.json | 8 +- tpl/src/stores/Actions.ts | 26 ++++ .../redux => stores/Add}/ActionTypes.js | 0 .../Actions.js => stores/Add/Actions.ts} | 0 .../Action/redux => stores/Add}/Reducer.js | 0 tpl/src/stores/index.ts | 10 +- tpl/src/views/Action/_index.js | 3 - tpl/src/views/Action/index.jsx | 13 +- tpl/src/views/Action/index.jsx- | 9 +- tpl/src/views/Action/index0.jsx | 11 +- tpl/src/views/Action/item.jsx | 4 +- tpl/src/views/Action2/index.jsx | 6 +- tpl/yarn.lock | 53 +++++++- yarn.lock | 124 ------------------ 15 files changed, 110 insertions(+), 165 deletions(-) delete mode 100644 package.json create mode 100644 tpl/src/stores/Actions.ts rename tpl/src/{views/Action/redux => stores/Add}/ActionTypes.js (100%) rename tpl/src/{views/Action/redux/Actions.js => stores/Add/Actions.ts} (100%) rename tpl/src/{views/Action/redux => stores/Add}/Reducer.js (100%) delete mode 100644 tpl/src/views/Action/_index.js delete mode 100644 yarn.lock diff --git a/package.json b/package.json deleted file mode 100644 index ff6f3e5..0000000 --- a/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "dependencies": { - "@types/react-redux": "^7.1.20", - "react-redux": "^7.2.6", - "redux": "^4.1.2", - "redux-thunk": "^2.4.0" - } -} diff --git a/tpl/package.json b/tpl/package.json index 527ee09..d7a4a12 100644 --- a/tpl/package.json +++ b/tpl/package.json @@ -15,6 +15,7 @@ "@types/node": "^12.0.0", "@types/react": "^17.0.0", "@types/react-dom": "^17.0.0", + "@types/react-redux": "^7.1.20", "@types/react-router-dom": "^5.3.2", "@typescript-eslint/eslint-plugin": "^4.5.0", "@typescript-eslint/parser": "^4.5.0", @@ -65,8 +66,11 @@ "react-app-polyfill": "^2.0.0", "react-dev-utils": "^11.0.3", "react-dom": "^17.0.2", + "react-redux": "^7.2.6", "react-refresh": "^0.8.3", "react-router-dom": "^5.3.0", + "redux": "^4.1.2", + "redux-thunk": "^2.4.0", "resolve": "1.18.1", "resolve-url-loader": "^3.1.2", "sass-loader": "^10.0.5", @@ -169,5 +173,7 @@ "devDependencies": { "@loadable/babel-plugin": "^5.13.2", "@loadable/webpack-plugin": "^5.15.1" - } + }, + "author": "llqfront@aliyun.com", + "license": "ISC" } diff --git a/tpl/src/stores/Actions.ts b/tpl/src/stores/Actions.ts new file mode 100644 index 0000000..df192f5 --- /dev/null +++ b/tpl/src/stores/Actions.ts @@ -0,0 +1,26 @@ +import * as AddActions from './Add/Actions.ts'; +import fs from 'fs'; + + +console.log(fs) + +// let components = [] +// const files = fs.readdirSync('@/store/') +// files.forEach(function (item, index) { +// let stat = fs.lstatSync("./" + item) +// if (stat.isDirectory() === true) { +// components.push(item) +// } +// }) + +console.log(components); +// let components = [] +// files.forEach(function (item, index) { +// let stat = fs.lstatSync("./" + item) +// if (stat.isDirectory() === true) { +// components.push(item) +// } +// }) +export { + AddActions +} diff --git a/tpl/src/views/Action/redux/ActionTypes.js b/tpl/src/stores/Add/ActionTypes.js similarity index 100% rename from tpl/src/views/Action/redux/ActionTypes.js rename to tpl/src/stores/Add/ActionTypes.js diff --git a/tpl/src/views/Action/redux/Actions.js b/tpl/src/stores/Add/Actions.ts similarity index 100% rename from tpl/src/views/Action/redux/Actions.js rename to tpl/src/stores/Add/Actions.ts diff --git a/tpl/src/views/Action/redux/Reducer.js b/tpl/src/stores/Add/Reducer.js similarity index 100% rename from tpl/src/views/Action/redux/Reducer.js rename to tpl/src/stores/Add/Reducer.js diff --git a/tpl/src/stores/index.ts b/tpl/src/stores/index.ts index 90c87dc..853c233 100644 --- a/tpl/src/stores/index.ts +++ b/tpl/src/stores/index.ts @@ -1,10 +1,12 @@ import {createStore, combineReducers,applyMiddleware} from 'redux'; import thunk from 'redux-thunk'; -import {reducer as addReducer} from '@/views/Action/_index.js'; -// import {reducer as testReducer} from '../views/Test/_index.js'; -// import {reducer as delReducer} from '../views/Test/_index.js'; +import addReducer from './Add/Reducer.js'; +// import {reducer as testReducer} from '@/Test/Reducer.js'; +// import {reducer as delReducer} from '@/Del/Reducer.js'; const reducer = combineReducers({ - add:addReducer, + addReducer, + // testReducer, + // delReducer // testList:testReducer, // remove:removeReducer, // edit:editReducer, diff --git a/tpl/src/views/Action/_index.js b/tpl/src/views/Action/_index.js deleted file mode 100644 index ce087e5..0000000 --- a/tpl/src/views/Action/_index.js +++ /dev/null @@ -1,3 +0,0 @@ -import * as actions from './redux/Actions.js'; -import reducer from './redux/Reducer.js'; -export {actions,reducer}; diff --git a/tpl/src/views/Action/index.jsx b/tpl/src/views/Action/index.jsx index 0d7fe95..761f6a4 100644 --- a/tpl/src/views/Action/index.jsx +++ b/tpl/src/views/Action/index.jsx @@ -1,7 +1,6 @@ import React , { Component } from 'react'; -import {connect} from 'react-redux'; - -import {actions} from './_index.js'; +import { connect } from 'react-redux'; +import {AddActions} from '@/stores/Actions.ts'; import { withRouter,NavLink,Switch,Redirect,Route} from 'react-router-dom'; import Item from './item.jsx'; class View extends Component { @@ -11,7 +10,7 @@ class View extends Component { onAddFn(){ const {dispatch,addList} = this.props; console.log(addList.length) - dispatch(actions.add(addList.length)) + dispatch(AddActions.add(addList.length)) } lists(){ const { addList } = this.props; @@ -57,16 +56,16 @@ function mapStateToProps(state) { // del:[] // } return { - addList:state.add + addList:state.addReducer } } // const mapDispatchToProps = (dispatch, ownProps) => { // // { // // type:'ADD_TODO' // // } -// // dispatch(actions.add()) +// // dispatch(AddActions.add()) // return { -// onAddFn:()=>dispatch(actions.add()) +// onAddFn:()=>dispatch(AddActions.add()) // } // }; export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index.jsx- b/tpl/src/views/Action/index.jsx- index ba4a570..c942ae3 100644 --- a/tpl/src/views/Action/index.jsx- +++ b/tpl/src/views/Action/index.jsx- @@ -1,15 +1,14 @@ import React , { Component } from 'react'; import {connect} from 'react-redux'; -import {actions} from './_index.js'; - +import {AddActions} from '@/stores/Actions.ts'; class View extends Component { // changeName(){ // // } onAddFn(){ const {dispatch} = this.props; - dispatch(actions.add()) + dispatch(AddActions.add()) } render(){ console.log(this.props.addList) @@ -45,9 +44,9 @@ const mapDispatchToProps = (dispatch, ownProps) => { // { // type:'ADD_TODO' // } - // dispatch(actions.add()) + // dispatch(AddActions.add()) return { - onAddFn:()=>dispatch(actions.add()) + onAddFn:()=>dispatch(AddActions.add()) } }; export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index0.jsx b/tpl/src/views/Action/index0.jsx index 1a8ea51..b05d044 100644 --- a/tpl/src/views/Action/index0.jsx +++ b/tpl/src/views/Action/index0.jsx @@ -1,8 +1,7 @@ import React , { Component } from 'react'; import {connect} from 'react-redux'; -import {actions} from './_index.js'; - +import {AddActions} from '@/stores/Actions.ts'; class View extends Component { // changeName(){ // @@ -34,19 +33,19 @@ function mapStateToProps(state) { // del:[] // } return { - addList:state.add + addList:state.addReducer } } const mapDispatchToProps = (dispatch, ownProps) => { - // ownProps 父组件有任意参数 + // ownProps 父组件有任意参数 // const {name} = ownProps; // this.props.name // { // type:'ADD_TODO' // } - // dispatch(actions.add()) + // dispatch(AddActions.add()) return { - onAddFn:()=>dispatch(actions.add()) + onAddFn:()=>dispatch(AddActions.add()) } }; export default connect(mapStateToProps,mapDispatchToProps)(View); diff --git a/tpl/src/views/Action/item.jsx b/tpl/src/views/Action/item.jsx index c850abf..74a11a9 100644 --- a/tpl/src/views/Action/item.jsx +++ b/tpl/src/views/Action/item.jsx @@ -2,7 +2,7 @@ import React,{ Component } from 'react'; import {connect} from 'react-redux'; -import { actions } from './_index.js'; +import {AddActions} from '@/stores/Actions.ts'; class View extends Component { constructor(props){ @@ -22,7 +22,7 @@ class View extends Component { const mapDispatchToProps = (dispatch, ownProps) => { const { val } = ownProps; return { - onRemoveFn: () => dispatch(actions.del('删除',val.id)) + onRemoveFn: () => dispatch(AddActions.del('删除',val.id)) } }; diff --git a/tpl/src/views/Action2/index.jsx b/tpl/src/views/Action2/index.jsx index 8a5cc75..ac7fa0d 100644 --- a/tpl/src/views/Action2/index.jsx +++ b/tpl/src/views/Action2/index.jsx @@ -1,12 +1,12 @@ import React, {useState,useEffect} from 'react'; import { useSelector, useDispatch } from "react-redux"; -import {actions} from '../Action/_index'; +import {AddActions} from '@/stores/Actions.ts'; const View = (props)=>{ const state = useSelector((state)=>state); - const add = useSelector((state)=>state.add); + const add = useSelector((state)=>state.addReducer); const dispatch = useDispatch(); useEffect(()=>{ - dispatch(actions.add()) + // dispatch(AddActions.add()) // dispatch({ // type:"ADD_TODO" // }) diff --git a/tpl/yarn.lock b/tpl/yarn.lock index 8324168..727f223 100644 --- a/tpl/yarn.lock +++ b/tpl/yarn.lock @@ -1172,6 +1172,13 @@ dependencies: regenerator-runtime "^0.13.4" +"@babel/runtime@^7.15.4": + version "7.16.3" + resolved "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.3.tgz?cache=0&sync_timestamp=1636494819594&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fruntime%2Fdownload%2F%40babel%2Fruntime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5" + integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ== + dependencies: + regenerator-runtime "^0.13.4" + "@babel/template@^7.10.4", "@babel/template@^7.16.0", "@babel/template@^7.3.3": version "7.16.0" resolved "https://registry.npmmirror.com/@babel/template/download/@babel/template-7.16.0.tgz#d16a35ebf4cd74e202083356fab21dd89363ddd6" @@ -1848,6 +1855,14 @@ resolved "https://registry.nlark.com/@types/history/download/@types/history-4.7.9.tgz#1cfb6d60ef3822c589f18e70f8b12f9a28ce8724" integrity sha1-HPttYO84IsWJ8Y5w+LEvmijOhyQ= +"@types/hoist-non-react-statics@^3.3.0": + version "3.3.1" + resolved "https://registry.nlark.com/@types/hoist-non-react-statics/download/@types/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" + integrity sha1-ESSq/lEYy1kZd66xzqrtEHDrA58= + dependencies: + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + "@types/html-minifier-terser@^5.0.0": version "5.1.2" resolved "https://registry.nlark.com/@types/html-minifier-terser/download/@types/html-minifier-terser-5.1.2.tgz?cache=0&sync_timestamp=1631043806613&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fhtml-minifier-terser%2Fdownload%2F%40types%2Fhtml-minifier-terser-5.1.2.tgz#693b316ad323ea97eed6b38ed1a3cc02b1672b57" @@ -1952,6 +1967,16 @@ dependencies: "@types/react" "*" +"@types/react-redux@^7.1.20": + version "7.1.20" + resolved "https://registry.npmmirror.com/@types/react-redux/download/@types/react-redux-7.1.20.tgz?cache=0&sync_timestamp=1634764733589&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40types%2Freact-redux%2Fdownload%2F%40types%2Freact-redux-7.1.20.tgz#42f0e61ababb621e12c66c96dda94c58423bd7df" + integrity sha1-QvDmGrq7Yh4SxmyW3alMWEI7198= + dependencies: + "@types/hoist-non-react-statics" "^3.3.0" + "@types/react" "*" + hoist-non-react-statics "^3.3.0" + redux "^4.0.0" + "@types/react-router-dom@^5.3.2": version "5.3.2" resolved "https://registry.npmmirror.com/@types/react-router-dom/download/@types/react-router-dom-5.3.2.tgz#ebd8e145cf056db5c66eb1dac63c72f52e8542ee" @@ -5636,7 +5661,7 @@ hmac-drbg@^1.0.1: minimalistic-assert "^1.0.0" minimalistic-crypto-utils "^1.0.1" -hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.1: +hoist-non-react-statics@^3.1.0, hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.1, hoist-non-react-statics@^3.3.2: version "3.3.2" resolved "https://registry.nlark.com/hoist-non-react-statics/download/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" integrity sha1-7OCsr3HWLClpwuxZ/v9CpLGoW0U= @@ -9342,11 +9367,23 @@ react-is@^16.12.0, react-is@^16.6.0, react-is@^16.7.0, react-is@^16.8.1: resolved "https://registry.npmmirror.com/react-is/download/react-is-16.13.1.tgz?cache=0&sync_timestamp=1636043968803&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Freact-is%2Fdownload%2Freact-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" integrity sha1-eJcppNw23imZ3BVt1sHZwYzqVqQ= -react-is@^17.0.1: +react-is@^17.0.1, react-is@^17.0.2: version "17.0.2" resolved "https://registry.npmmirror.com/react-is/download/react-is-17.0.2.tgz?cache=0&sync_timestamp=1636043968803&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Freact-is%2Fdownload%2Freact-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha1-5pHUqOnHiTZWVVOas3J2Kw77VPA= +react-redux@^7.2.6: + version "7.2.6" + resolved "https://registry.npmmirror.com/react-redux/download/react-redux-7.2.6.tgz#49633a24fe552b5f9caf58feb8a138936ddfe9aa" + integrity sha1-SWM6JP5VK1+cr1j+uKE4k23f6ao= + dependencies: + "@babel/runtime" "^7.15.4" + "@types/react-redux" "^7.1.20" + hoist-non-react-statics "^3.3.2" + loose-envify "^1.4.0" + prop-types "^15.7.2" + react-is "^17.0.2" + react-refresh@^0.8.3: version "0.8.3" resolved "https://registry.npmmirror.com/react-refresh/download/react-refresh-0.8.3.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Freact-refresh%2Fdownload%2Freact-refresh-0.8.3.tgz#721d4657672d400c5e3c75d063c4a85fb2d5d68f" @@ -9470,6 +9507,18 @@ redent@^3.0.0: indent-string "^4.0.0" strip-indent "^3.0.0" +redux-thunk@^2.4.0: + version "2.4.0" + resolved "https://registry.npmmirror.com/redux-thunk/download/redux-thunk-2.4.0.tgz?cache=0&sync_timestamp=1635214108732&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fredux-thunk%2Fdownload%2Fredux-thunk-2.4.0.tgz#ac89e1d6b9bdb9ee49ce69a69071be41bbd82d67" + integrity sha1-rInh1rm9ue5JzmmmkHG+QbvYLWc= + +redux@^4.0.0, redux@^4.1.2: + version "4.1.2" + resolved "https://registry.npmmirror.com/redux/download/redux-4.1.2.tgz#140f35426d99bb4729af760afcf79eaaac407104" + integrity sha1-FA81Qm2Zu0cpr3YK/PeeqqxAcQQ= + dependencies: + "@babel/runtime" "^7.9.2" + regenerate-unicode-properties@^9.0.0: version "9.0.0" resolved "https://registry.nlark.com/regenerate-unicode-properties/download/regenerate-unicode-properties-9.0.0.tgz?cache=0&sync_timestamp=1631617208210&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fregenerate-unicode-properties%2Fdownload%2Fregenerate-unicode-properties-9.0.0.tgz#54d09c7115e1f53dc2314a974b32c1c344efe326" diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index 92a0df5..0000000 --- a/yarn.lock +++ /dev/null @@ -1,124 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -"@babel/runtime@^7.15.4", "@babel/runtime@^7.9.2": - version "7.16.3" - resolved "https://registry.npmmirror.com/@babel/runtime/download/@babel/runtime-7.16.3.tgz?cache=0&sync_timestamp=1636495173603&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2F%40babel%2Fruntime%2Fdownload%2F%40babel%2Fruntime-7.16.3.tgz#b86f0db02a04187a3c17caa77de69840165d42d5" - integrity sha512-WBwekcqacdY2e9AF/Q7WLFUWmdJGJTkbjqTjoMDgXkVZ3ZRUvOPsLb5KdwISoQVsbP+DQzVZW4Zhci0DvpbNTQ== - dependencies: - regenerator-runtime "^0.13.4" - -"@types/hoist-non-react-statics@^3.3.0": - version "3.3.1" - resolved "https://registry.nlark.com/@types/hoist-non-react-statics/download/@types/hoist-non-react-statics-3.3.1.tgz#1124aafe5118cb591977aeb1ceaaed1070eb039f" - integrity sha1-ESSq/lEYy1kZd66xzqrtEHDrA58= - dependencies: - "@types/react" "*" - hoist-non-react-statics "^3.3.0" - -"@types/prop-types@*": - version "15.7.4" - resolved "https://registry.nlark.com/@types/prop-types/download/@types/prop-types-15.7.4.tgz?cache=0&sync_timestamp=1629708737049&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fprop-types%2Fdownload%2F%40types%2Fprop-types-15.7.4.tgz#fcf7205c25dff795ee79af1e30da2c9790808f11" - integrity sha1-/PcgXCXf95Xuea8eMNosl5CAjxE= - -"@types/react-redux@^7.1.20": - version "7.1.20" - resolved "https://registry.npmmirror.com/@types/react-redux/download/@types/react-redux-7.1.20.tgz#42f0e61ababb621e12c66c96dda94c58423bd7df" - integrity sha1-QvDmGrq7Yh4SxmyW3alMWEI7198= - dependencies: - "@types/hoist-non-react-statics" "^3.3.0" - "@types/react" "*" - hoist-non-react-statics "^3.3.0" - redux "^4.0.0" - -"@types/react@*": - version "17.0.34" - resolved "https://registry.npmmirror.com/@types/react/download/@types/react-17.0.34.tgz#797b66d359b692e3f19991b6b07e4b0c706c0102" - integrity sha1-eXtm01m2kuPxmZG2sH5LDHBsAQI= - dependencies: - "@types/prop-types" "*" - "@types/scheduler" "*" - csstype "^3.0.2" - -"@types/scheduler@*": - version "0.16.2" - resolved "https://registry.nlark.com/@types/scheduler/download/@types/scheduler-0.16.2.tgz?cache=0&sync_timestamp=1629709152024&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40types%2Fscheduler%2Fdownload%2F%40types%2Fscheduler-0.16.2.tgz#1a62f89525723dde24ba1b01b092bf5df8ad4d39" - integrity sha1-GmL4lSVyPd4kuhsBsJK/XfitTTk= - -csstype@^3.0.2: - version "3.0.9" - resolved "https://registry.nlark.com/csstype/download/csstype-3.0.9.tgz?cache=0&sync_timestamp=1631540709509&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fcsstype%2Fdownload%2Fcsstype-3.0.9.tgz#6410af31b26bd0520933d02cbc64fce9ce3fbf0b" - integrity sha1-ZBCvMbJr0FIJM9AsvGT86c4/vws= - -hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.2: - version "3.3.2" - resolved "https://registry.nlark.com/hoist-non-react-statics/download/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45" - integrity sha1-7OCsr3HWLClpwuxZ/v9CpLGoW0U= - dependencies: - react-is "^16.7.0" - -"js-tokens@^3.0.0 || ^4.0.0": - version "4.0.0" - resolved "https://registry.nlark.com/js-tokens/download/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499" - integrity sha1-GSA/tZmR35jjoocFDUZHzerzJJk= - -loose-envify@^1.4.0: - version "1.4.0" - resolved "https://registry.npm.taobao.org/loose-envify/download/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" - integrity sha1-ce5R+nvkyuwaY4OffmgtgTLTDK8= - dependencies: - js-tokens "^3.0.0 || ^4.0.0" - -object-assign@^4.1.1: - version "4.1.1" - resolved "https://registry.nlark.com/object-assign/download/object-assign-4.1.1.tgz?cache=0&sync_timestamp=1618847240432&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fobject-assign%2Fdownload%2Fobject-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" - integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM= - -prop-types@^15.7.2: - version "15.7.2" - resolved "https://registry.nlark.com/prop-types/download/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5" - integrity sha1-UsQedbjIfnK52TYOAga5ncv/psU= - dependencies: - loose-envify "^1.4.0" - object-assign "^4.1.1" - react-is "^16.8.1" - -react-is@^16.7.0, react-is@^16.8.1: - version "16.13.1" - resolved "https://registry.npmmirror.com/react-is/download/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" - integrity sha1-eJcppNw23imZ3BVt1sHZwYzqVqQ= - -react-is@^17.0.2: - version "17.0.2" - resolved "https://registry.npmmirror.com/react-is/download/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" - integrity sha1-5pHUqOnHiTZWVVOas3J2Kw77VPA= - -react-redux@^7.2.6: - version "7.2.6" - resolved "https://registry.npmmirror.com/react-redux/download/react-redux-7.2.6.tgz#49633a24fe552b5f9caf58feb8a138936ddfe9aa" - integrity sha1-SWM6JP5VK1+cr1j+uKE4k23f6ao= - dependencies: - "@babel/runtime" "^7.15.4" - "@types/react-redux" "^7.1.20" - hoist-non-react-statics "^3.3.2" - loose-envify "^1.4.0" - prop-types "^15.7.2" - react-is "^17.0.2" - -redux-thunk@^2.4.0: - version "2.4.0" - resolved "https://registry.npmmirror.com/redux-thunk/download/redux-thunk-2.4.0.tgz?cache=0&sync_timestamp=1635214108732&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fredux-thunk%2Fdownload%2Fredux-thunk-2.4.0.tgz#ac89e1d6b9bdb9ee49ce69a69071be41bbd82d67" - integrity sha1-rInh1rm9ue5JzmmmkHG+QbvYLWc= - -redux@^4.0.0, redux@^4.1.2: - version "4.1.2" - resolved "https://registry.npmmirror.com/redux/download/redux-4.1.2.tgz?cache=0&sync_timestamp=1635663041213&other_urls=https%3A%2F%2Fregistry.npmmirror.com%2Fredux%2Fdownload%2Fredux-4.1.2.tgz#140f35426d99bb4729af760afcf79eaaac407104" - integrity sha1-FA81Qm2Zu0cpr3YK/PeeqqxAcQQ= - dependencies: - "@babel/runtime" "^7.9.2" - -regenerator-runtime@^0.13.4: - version "0.13.9" - resolved "https://registry.nlark.com/regenerator-runtime/download/regenerator-runtime-0.13.9.tgz?cache=0&sync_timestamp=1626993001371&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fregenerator-runtime%2Fdownload%2Fregenerator-runtime-0.13.9.tgz#8925742a98ffd90814988d7566ad30ca3b263b52" - integrity sha1-iSV0Kpj/2QgUmI11Zq0wyjsmO1I= From dbeeff0034e973cb72a38412c48a2fe33433b510 Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 18:24:07 +0800 Subject: [PATCH 03/16] redux --- tpl/src/stores/Actions.ts | 29 ++++++----------------------- tpl/src/views/Action/index.jsx | 8 ++++---- tpl/src/views/Action/index.jsx- | 8 ++++---- tpl/src/views/Action/index0.jsx | 6 +++--- tpl/src/views/Action/item.jsx | 4 ++-- tpl/src/views/Action2/index.jsx | 4 ++-- 6 files changed, 21 insertions(+), 38 deletions(-) diff --git a/tpl/src/stores/Actions.ts b/tpl/src/stores/Actions.ts index df192f5..9891cfd 100644 --- a/tpl/src/stores/Actions.ts +++ b/tpl/src/stores/Actions.ts @@ -1,26 +1,9 @@ -import * as AddActions from './Add/Actions.ts'; -import fs from 'fs'; +import * as actionsAdd from './Add/Actions.ts'; +// import * as actionsApp from './App/Actions.ts'; +// import * as actionsEnter from './Enter/Actions.ts'; - -console.log(fs) - -// let components = [] -// const files = fs.readdirSync('@/store/') -// files.forEach(function (item, index) { -// let stat = fs.lstatSync("./" + item) -// if (stat.isDirectory() === true) { -// components.push(item) -// } -// }) - -console.log(components); -// let components = [] -// files.forEach(function (item, index) { -// let stat = fs.lstatSync("./" + item) -// if (stat.isDirectory() === true) { -// components.push(item) -// } -// }) export { - AddActions + actionsAdd, + // actionsApp, + // actionsEnter } diff --git a/tpl/src/views/Action/index.jsx b/tpl/src/views/Action/index.jsx index 761f6a4..f23b4dc 100644 --- a/tpl/src/views/Action/index.jsx +++ b/tpl/src/views/Action/index.jsx @@ -1,6 +1,6 @@ import React , { Component } from 'react'; import { connect } from 'react-redux'; -import {AddActions} from '@/stores/Actions.ts'; +import {actionsAdd} from '@/stores/Actions.ts'; import { withRouter,NavLink,Switch,Redirect,Route} from 'react-router-dom'; import Item from './item.jsx'; class View extends Component { @@ -10,7 +10,7 @@ class View extends Component { onAddFn(){ const {dispatch,addList} = this.props; console.log(addList.length) - dispatch(AddActions.add(addList.length)) + dispatch(actionsAdd.add(addList.length)) } lists(){ const { addList } = this.props; @@ -63,9 +63,9 @@ function mapStateToProps(state) { // // { // // type:'ADD_TODO' // // } -// // dispatch(AddActions.add()) +// // dispatch(actionsAdd.add()) // return { -// onAddFn:()=>dispatch(AddActions.add()) +// onAddFn:()=>dispatch(actionsAdd.add()) // } // }; export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index.jsx- b/tpl/src/views/Action/index.jsx- index c942ae3..aab0225 100644 --- a/tpl/src/views/Action/index.jsx- +++ b/tpl/src/views/Action/index.jsx- @@ -1,14 +1,14 @@ import React , { Component } from 'react'; import {connect} from 'react-redux'; -import {AddActions} from '@/stores/Actions.ts'; +import {actionsAdd} from '@/stores/Actions.ts'; class View extends Component { // changeName(){ // // } onAddFn(){ const {dispatch} = this.props; - dispatch(AddActions.add()) + dispatch(actionsAdd.add()) } render(){ console.log(this.props.addList) @@ -44,9 +44,9 @@ const mapDispatchToProps = (dispatch, ownProps) => { // { // type:'ADD_TODO' // } - // dispatch(AddActions.add()) + // dispatch(actionsAdd.add()) return { - onAddFn:()=>dispatch(AddActions.add()) + onAddFn:()=>dispatch(actionsAdd.add()) } }; export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index0.jsx b/tpl/src/views/Action/index0.jsx index b05d044..4e915eb 100644 --- a/tpl/src/views/Action/index0.jsx +++ b/tpl/src/views/Action/index0.jsx @@ -1,7 +1,7 @@ import React , { Component } from 'react'; import {connect} from 'react-redux'; -import {AddActions} from '@/stores/Actions.ts'; +import {actionsAdd} from '@/stores/Actions.ts'; class View extends Component { // changeName(){ // @@ -43,9 +43,9 @@ const mapDispatchToProps = (dispatch, ownProps) => { // { // type:'ADD_TODO' // } - // dispatch(AddActions.add()) + // dispatch(actionsAdd.add()) return { - onAddFn:()=>dispatch(AddActions.add()) + onAddFn:()=>dispatch(actionsAdd.add()) } }; export default connect(mapStateToProps,mapDispatchToProps)(View); diff --git a/tpl/src/views/Action/item.jsx b/tpl/src/views/Action/item.jsx index 74a11a9..1ec0f99 100644 --- a/tpl/src/views/Action/item.jsx +++ b/tpl/src/views/Action/item.jsx @@ -2,7 +2,7 @@ import React,{ Component } from 'react'; import {connect} from 'react-redux'; -import {AddActions} from '@/stores/Actions.ts'; +import {actionsAdd} from '@/stores/Actions.ts'; class View extends Component { constructor(props){ @@ -22,7 +22,7 @@ class View extends Component { const mapDispatchToProps = (dispatch, ownProps) => { const { val } = ownProps; return { - onRemoveFn: () => dispatch(AddActions.del('删除',val.id)) + onRemoveFn: () => dispatch(actionsAdd.del('删除',val.id)) } }; diff --git a/tpl/src/views/Action2/index.jsx b/tpl/src/views/Action2/index.jsx index ac7fa0d..cb46839 100644 --- a/tpl/src/views/Action2/index.jsx +++ b/tpl/src/views/Action2/index.jsx @@ -1,12 +1,12 @@ import React, {useState,useEffect} from 'react'; import { useSelector, useDispatch } from "react-redux"; -import {AddActions} from '@/stores/Actions.ts'; +import {actionsAdd} from '@/stores/Actions.ts'; const View = (props)=>{ const state = useSelector((state)=>state); const add = useSelector((state)=>state.addReducer); const dispatch = useDispatch(); useEffect(()=>{ - // dispatch(AddActions.add()) + // dispatch(actionsAdd.add()) // dispatch({ // type:"ADD_TODO" // }) From 60d43549b4b527e19ff76567b3ed246bb5d50dde Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 18:51:22 +0800 Subject: [PATCH 04/16] =?UTF-8?q?redux=20=E7=9B=AE=E5=BD=95=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- read/md/redux.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/read/md/redux.md b/read/md/redux.md index 419f814..ad5e920 100644 --- a/read/md/redux.md +++ b/read/md/redux.md @@ -1,3 +1,8 @@ -yarn add react-redux redux +yarn add @types/react-redux react-redux redux redux-thunk -yarn add @types/react-redux +目录创建 未完成 +1、servers +2、epics +3、helpers +4、untils +5、enums From 8fb9dbde9d591bceef362ba1f4405edd4f01863f Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 19:12:28 +0800 Subject: [PATCH 05/16] up --- tpl/src/enums/index.ts | 0 tpl/src/epics/index.ts | 0 tpl/src/helpers/index.ts | 0 tpl/src/servers/index.ts | 0 tpl/src/utils/ajax.ts | 77 ++++++++++++++++++++++++++++++++++++++++ tpl/src/utils/index.ts | 0 6 files changed, 77 insertions(+) create mode 100644 tpl/src/enums/index.ts create mode 100644 tpl/src/epics/index.ts create mode 100644 tpl/src/helpers/index.ts create mode 100644 tpl/src/servers/index.ts create mode 100644 tpl/src/utils/ajax.ts create mode 100644 tpl/src/utils/index.ts diff --git a/tpl/src/enums/index.ts b/tpl/src/enums/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/tpl/src/epics/index.ts b/tpl/src/epics/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/tpl/src/helpers/index.ts b/tpl/src/helpers/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/tpl/src/servers/index.ts b/tpl/src/servers/index.ts new file mode 100644 index 0000000..e69de29 diff --git a/tpl/src/utils/ajax.ts b/tpl/src/utils/ajax.ts new file mode 100644 index 0000000..d0b569d --- /dev/null +++ b/tpl/src/utils/ajax.ts @@ -0,0 +1,77 @@ +import axios from 'axios'; +import qs from 'qs'; +const Unit = { + async getApi(ajaxCfg){ + let data = await axios.get( + ajaxCfg.url,{ + params:ajaxCfg.cfg + }, + { + headers: ajaxCfg.headers, + }) + return data; + }, + async postApi(url,cfg,headers){ + let fd = new FormData(); + for(let key in cfg){ + fd.append(key, cfg[key]); + } + let data = await axios.post(url,fd, + { + headers: headers + }) + return data; + }, + async putApi(url,cfg,headers){ + let data = await axios.put(url,qs.stringify(cfg),{ + headers: { + 'Content-Type':'application/x-www-form-urlencoded', + } + }) + return data; + }, + async _postApi(url,cfg,headers){ + let data = await axios.post(url,cfg, + { + headers: headers + }) + return data; + }, + async __postApi(url,cfg,headers){ + let data = await axios.post(url,qs.stringify(cfg),{ + headers: { + 'Content-Type':'application/x-www-form-urlencoded', + } + }) + return data; + }, + async delApi(url,cfg,headers){ + let data = await axios.delete(url,{params:cfg},{ + headers: headers + }) + return data; + }, + async requestApi(cfg,headers,file){ + let fd = new FormData(); + fd.append('param', JSON.stringify(cfg)); + if(file){ + // 上传证明 + if(file.length){ + for(let i=0,len=file.length;i Date: Wed, 10 Nov 2021 19:40:00 +0800 Subject: [PATCH 06/16] services --- tpl/src/servers/index.ts | 0 tpl/src/services/index.ts | 5 +++++ tpl/src/services/loginService.ts | 1 + tpl/src/stores/Actions.ts | 2 +- tpl/src/stores/index.ts | 2 +- 5 files changed, 8 insertions(+), 2 deletions(-) delete mode 100644 tpl/src/servers/index.ts create mode 100644 tpl/src/services/index.ts create mode 100644 tpl/src/services/loginService.ts diff --git a/tpl/src/servers/index.ts b/tpl/src/servers/index.ts deleted file mode 100644 index e69de29..0000000 diff --git a/tpl/src/services/index.ts b/tpl/src/services/index.ts new file mode 100644 index 0000000..3ec0367 --- /dev/null +++ b/tpl/src/services/index.ts @@ -0,0 +1,5 @@ +import * as loginApi from '@/services/loginService.ts'; + +export { + loginApi, +} diff --git a/tpl/src/services/loginService.ts b/tpl/src/services/loginService.ts new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tpl/src/services/loginService.ts @@ -0,0 +1 @@ + diff --git a/tpl/src/stores/Actions.ts b/tpl/src/stores/Actions.ts index 9891cfd..05fd950 100644 --- a/tpl/src/stores/Actions.ts +++ b/tpl/src/stores/Actions.ts @@ -1,4 +1,4 @@ -import * as actionsAdd from './Add/Actions.ts'; +import * as actionsAdd from '@/stores/Add/Actions.ts'; // import * as actionsApp from './App/Actions.ts'; // import * as actionsEnter from './Enter/Actions.ts'; diff --git a/tpl/src/stores/index.ts b/tpl/src/stores/index.ts index 853c233..7676a4c 100644 --- a/tpl/src/stores/index.ts +++ b/tpl/src/stores/index.ts @@ -1,6 +1,6 @@ import {createStore, combineReducers,applyMiddleware} from 'redux'; import thunk from 'redux-thunk'; -import addReducer from './Add/Reducer.js'; +import addReducer from '@/stores/Add/Reducer.js'; // import {reducer as testReducer} from '@/Test/Reducer.js'; // import {reducer as delReducer} from '@/Del/Reducer.js'; const reducer = combineReducers({ From e1ce9da506be3002561918abd715a7c08cfdf4fa Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 21:17:05 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tpl/src/{helpers/index.ts => utils/helpers.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tpl/src/{helpers/index.ts => utils/helpers.ts} (100%) diff --git a/tpl/src/helpers/index.ts b/tpl/src/utils/helpers.ts similarity index 100% rename from tpl/src/helpers/index.ts rename to tpl/src/utils/helpers.ts From 906665dd0dccf52cddd9e0fa94573b79045a3003 Mon Sep 17 00:00:00 2001 From: llqfront Date: Wed, 10 Nov 2021 23:48:51 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tpl/src/doc/readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tpl/src/doc/readme.md diff --git a/tpl/src/doc/readme.md b/tpl/src/doc/readme.md new file mode 100644 index 0000000..e69de29 From 4fa3f853d1fdc0f833b73bfe60e87069244a0481 Mon Sep 17 00:00:00 2001 From: llqfront Date: Thu, 11 Nov 2021 19:17:52 +0800 Subject: [PATCH 09/16] =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tpl/src/doc/readme.md | 11 +++++++++++ tpl/src/router/index.tsx | 2 +- tpl/src/stores/Add/Actions.ts | 17 +++++++++++++++++ tpl/src/views/Action2/{index.jsx => index.tsx} | 5 ++++- 4 files changed, 33 insertions(+), 2 deletions(-) rename tpl/src/views/Action2/{index.jsx => index.tsx} (83%) diff --git a/tpl/src/doc/readme.md b/tpl/src/doc/readme.md index e69de29..0b78330 100644 --- a/tpl/src/doc/readme.md +++ b/tpl/src/doc/readme.md @@ -0,0 +1,11 @@ +目录介绍: +- components: +- doc: +- enums: +- epics: +- images: +- router: +- services: +- stores: +- utils: +- views: diff --git a/tpl/src/router/index.tsx b/tpl/src/router/index.tsx index 4755872..0dedb5a 100644 --- a/tpl/src/router/index.tsx +++ b/tpl/src/router/index.tsx @@ -4,7 +4,7 @@ import {NavLink,Redirect,Switch,Route} from 'react-router-dom'; const Home = lazy(() => import('@/views/Home')); const Test = lazy(() => import('@/views/Test')); const Action = lazy(() => import('@/views/Action')); -const Action2 = lazy(() => import('@/views/Action2')); +const Action2 = lazy(() => import('@/views/Action2/index.tsx')); class Router extends Component { render(){ return( diff --git a/tpl/src/stores/Add/Actions.ts b/tpl/src/stores/Add/Actions.ts index 2a5ebe9..dd1e6fb 100644 --- a/tpl/src/stores/Add/Actions.ts +++ b/tpl/src/stores/Add/Actions.ts @@ -7,6 +7,23 @@ import * as ActionTypes from './ActionTypes'; // type:ActionTypes.ADD_TODO, // text:'第一个demo' // } + + +export const newAdd = ( + type:string, + payload?:T, + handleCallback?:(res:ResponseData)=>void, +):T =>{ + console.log(payload) + console.log(handleCallback) + return { + type, + payload:payload || {}, + handleCallback + } +} + + export const add = (_id) =>{ return{ type:ActionTypes.ADD_TODO, diff --git a/tpl/src/views/Action2/index.jsx b/tpl/src/views/Action2/index.tsx similarity index 83% rename from tpl/src/views/Action2/index.jsx rename to tpl/src/views/Action2/index.tsx index cb46839..2e7ac97 100644 --- a/tpl/src/views/Action2/index.jsx +++ b/tpl/src/views/Action2/index.tsx @@ -6,7 +6,10 @@ const View = (props)=>{ const add = useSelector((state)=>state.addReducer); const dispatch = useDispatch(); useEffect(()=>{ - // dispatch(actionsAdd.add()) + dispatch(actionsAdd.newAdd( + 'test', + {name:'1',age:32} + )) // dispatch({ // type:"ADD_TODO" // }) From 0751c70b938a58b48ec50e9c70a1184bcb12c420 Mon Sep 17 00:00:00 2001 From: llqfront Date: Sat, 13 Nov 2021 23:19:20 +0800 Subject: [PATCH 10/16] redux --- README.md | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index b291d3b..572fac1 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,41 @@ # react-cli react-typescript-router-mobx-redux-hook +```html +main 分支为 路由版本 +redux 分支为 redux 结构 +mobx 分支为 mobx 结构代码 补充中... +rematch 分支为reamatch 结构代码 补充中... +整体在维护中 +``` +> 切换到分支 redux 可以看到完整redux 搭建的代码 -#### step1 -```cmd -eg: -mv react-cli/tpl react-cli/projectName -eg +## step1 +```cmd +把demo 文件改成自己需要的项目名,然后移动。后期会维护一步创建. +``` +##### step1-1 +```cmd +进入文件夹: cd react-cli +``` +##### step1-2 +```cmd 改名 mv tpl candy-react -移动 +``` +##### step1-3 +```cmd +移动到上一级 mv tpl ../ +``` +##### step1-4 +```cmd +退出当前文件夹 cd .. rm -rf react-cli ``` - -#### step2 - +## step2 ```cmd node -v v14.15.3 @@ -25,7 +43,8 @@ yarn config get registry yarn config set registry http://registry.npm.taobao.org/ ``` -#### step3 +## step3 ```cmd - +yarn +yarn start ``` From 62452ac32fa1fae6a5e0fdd169ed4932056d9199 Mon Sep 17 00:00:00 2001 From: llqfront Date: Mon, 22 Nov 2021 12:17:18 +0800 Subject: [PATCH 11/16] step1 --- tpl/src/App.tsx | 14 ++++++++--- tpl/src/actions/add.ts | 3 +++ tpl/src/actions/index.ts | 5 ++++ tpl/src/reducers/addPageReducer.ts | 14 +++++++++++ tpl/src/reducers/index.ts | 12 ++++++++++ tpl/src/setupProxy.js | 8 +------ tpl/src/stores/index.ts | 37 +++++++++++++++--------------- 7 files changed, 64 insertions(+), 29 deletions(-) create mode 100644 tpl/src/actions/add.ts create mode 100644 tpl/src/actions/index.ts create mode 100644 tpl/src/reducers/addPageReducer.ts create mode 100644 tpl/src/reducers/index.ts diff --git a/tpl/src/App.tsx b/tpl/src/App.tsx index db5952f..389759b 100644 --- a/tpl/src/App.tsx +++ b/tpl/src/App.tsx @@ -2,15 +2,23 @@ import React from 'react'; import { BrowserRouter, HashRouter} from 'react-router-dom'; import {Provider} from 'react-redux'; + import RootStore from '@/stores'; -import Router from '@/router/'; -const unsubscribe = RootStore.subscribe(() =>{ +import Router from '@/router'; + +const unsubscribe = RootStore().subscribe(() =>{ // console.log(Store.getState()) localStorage.setItem("LJMRoot", JSON.stringify(RootStore.getState())); }) +// +function newJson(str){ + var json = (new Function("return " + str))(); + return json; +} +let prevStore = newJson(localStorage.getItem("LJMRoot"))||{}; const App = () => ( - + diff --git a/tpl/src/actions/add.ts b/tpl/src/actions/add.ts new file mode 100644 index 0000000..8dad92b --- /dev/null +++ b/tpl/src/actions/add.ts @@ -0,0 +1,3 @@ +const NAMESPACE = 'ADDPAGE/'; +export const FETCH_USER = `${NAMESPACE}/FETCH_USER`; +export const FETCH_USER_FULFILLED = `${NAMESPACE}/FETCH_USER_FULFILLED`; diff --git a/tpl/src/actions/index.ts b/tpl/src/actions/index.ts new file mode 100644 index 0000000..4a12535 --- /dev/null +++ b/tpl/src/actions/index.ts @@ -0,0 +1,5 @@ +import * as actionAdd from './add'; + +export { + actionAdd, +} diff --git a/tpl/src/reducers/addPageReducer.ts b/tpl/src/reducers/addPageReducer.ts new file mode 100644 index 0000000..1c0d316 --- /dev/null +++ b/tpl/src/reducers/addPageReducer.ts @@ -0,0 +1,14 @@ +import { actionAdd } from '@/actions'; + + +export default (state = {},action)=>{ + switch (action.type) { + case actionAdd.FETCH_USER_FULFILLED: + return { + ...state, + success:action.payload + }; + default: + return state; + } +} diff --git a/tpl/src/reducers/index.ts b/tpl/src/reducers/index.ts new file mode 100644 index 0000000..530d3b4 --- /dev/null +++ b/tpl/src/reducers/index.ts @@ -0,0 +1,12 @@ +import { combineReducers } from 'redux'; +import add from './addPageReducer'; + +const rootReducer = combineReducers({ + add, + // testReducer, + // delReducer + // testList:testReducer, + // remove:removeReducer, + // edit:editReducer, +}) +export default rootReducer; diff --git a/tpl/src/setupProxy.js b/tpl/src/setupProxy.js index d1a5f90..2347dd7 100644 --- a/tpl/src/setupProxy.js +++ b/tpl/src/setupProxy.js @@ -2,13 +2,7 @@ const { createProxyMiddleware } = require('http-proxy-middleware'); module.exports = function(app) { app.use( '/home',createProxyMiddleware({ - target: 'https://####.com/', - changeOrigin: true, - }) - ); - app.use( - '/api',createProxyMiddleware({ - target: 'http://####.cn/', + target: 'https://home-api.pinduoduo.com/', changeOrigin: true, }) ); diff --git a/tpl/src/stores/index.ts b/tpl/src/stores/index.ts index 7676a4c..656ee3f 100644 --- a/tpl/src/stores/index.ts +++ b/tpl/src/stores/index.ts @@ -1,22 +1,21 @@ -import {createStore, combineReducers,applyMiddleware} from 'redux'; +import {createStore, applyMiddleware} from 'redux'; import thunk from 'redux-thunk'; -import addReducer from '@/stores/Add/Reducer.js'; -// import {reducer as testReducer} from '@/Test/Reducer.js'; -// import {reducer as delReducer} from '@/Del/Reducer.js'; -const reducer = combineReducers({ - addReducer, - // testReducer, - // delReducer - // testList:testReducer, - // remove:removeReducer, - // edit:editReducer, -}) -function newJson(str){ - var json = (new Function("return " + str))(); - return json; +import rootReducer from '@/reducers'; + +const configureStore = (prevStore)=> { + const store = createStore( + rootReducer, + prevStore, + applyMiddleware(thunk) + ); + return store; +} +let store = configureStore(); + +const RootStore = (prevStore?) =>{ + store = configureStore(prevStore); + return store; } -export default createStore(reducer, - newJson(localStorage.getItem("LJMRoot"))||{}, - applyMiddleware(thunk) -); + +export default RootStore; From 5cd4ed689fd3defadd15d1b215ba8f81c9d8f149 Mon Sep 17 00:00:00 2001 From: llqfront Date: Mon, 22 Nov 2021 12:38:17 +0800 Subject: [PATCH 12/16] step2 --- tpl/src/actions/index.ts | 2 + tpl/src/actions/old.ts | 4 ++ tpl/src/reducers/index.ts | 11 ++--- tpl/src/reducers/oldPageReducer.ts | 14 ++++++ tpl/src/router/index.tsx | 6 +-- tpl/src/stores/Actions.ts | 9 ---- tpl/src/stores/Add/ActionTypes.js | 3 -- tpl/src/stores/Add/Actions.ts | 40 ----------------- tpl/src/stores/Add/Reducer.js | 22 --------- tpl/src/utils/helpers.ts | 25 +++++++++++ tpl/src/utils/index.ts | 4 ++ tpl/src/utils/types.ts | 6 +++ tpl/src/views/Action/index.jsx | 71 ------------------------------ tpl/src/views/Action/index.jsx- | 52 ---------------------- tpl/src/views/Action/index.tsx | 39 ++++++++++++++++ tpl/src/views/Action/index0.jsx | 51 --------------------- tpl/src/views/Action/item.jsx | 29 ------------ tpl/src/views/Action2/index.tsx | 21 --------- tpl/src/views/Test/index.jsx | 15 ------- 19 files changed, 99 insertions(+), 325 deletions(-) create mode 100644 tpl/src/actions/old.ts create mode 100644 tpl/src/reducers/oldPageReducer.ts delete mode 100644 tpl/src/stores/Actions.ts delete mode 100644 tpl/src/stores/Add/ActionTypes.js delete mode 100644 tpl/src/stores/Add/Actions.ts delete mode 100644 tpl/src/stores/Add/Reducer.js create mode 100644 tpl/src/utils/types.ts delete mode 100644 tpl/src/views/Action/index.jsx delete mode 100644 tpl/src/views/Action/index.jsx- create mode 100644 tpl/src/views/Action/index.tsx delete mode 100644 tpl/src/views/Action/index0.jsx delete mode 100644 tpl/src/views/Action/item.jsx delete mode 100644 tpl/src/views/Action2/index.tsx delete mode 100644 tpl/src/views/Test/index.jsx diff --git a/tpl/src/actions/index.ts b/tpl/src/actions/index.ts index 4a12535..8932751 100644 --- a/tpl/src/actions/index.ts +++ b/tpl/src/actions/index.ts @@ -1,5 +1,7 @@ import * as actionAdd from './add'; +import * as actionOld from './old'; export { actionAdd, + actionOld } diff --git a/tpl/src/actions/old.ts b/tpl/src/actions/old.ts new file mode 100644 index 0000000..9b76614 --- /dev/null +++ b/tpl/src/actions/old.ts @@ -0,0 +1,4 @@ +const NAMESPACE = 'OLDPAGE/'; +export const ADD_TODO = `${NAMESPACE}/ADD_TODO`; +export const DEL_TODO = `${NAMESPACE}/DEL_TODO`; +export const EDIT_TODO = `${NAMESPACE}/EDIT_TODO`; diff --git a/tpl/src/reducers/index.ts b/tpl/src/reducers/index.ts index 530d3b4..82d9483 100644 --- a/tpl/src/reducers/index.ts +++ b/tpl/src/reducers/index.ts @@ -1,12 +1,9 @@ import { combineReducers } from 'redux'; -import add from './addPageReducer'; +import addReducer from './addPageReducer'; +import oldReducer from './oldPageReducer'; const rootReducer = combineReducers({ - add, - // testReducer, - // delReducer - // testList:testReducer, - // remove:removeReducer, - // edit:editReducer, + addReducer, + oldReducer }) export default rootReducer; diff --git a/tpl/src/reducers/oldPageReducer.ts b/tpl/src/reducers/oldPageReducer.ts new file mode 100644 index 0000000..f40f0ea --- /dev/null +++ b/tpl/src/reducers/oldPageReducer.ts @@ -0,0 +1,14 @@ +import { actionOld } from '@/actions'; + +export default (state={},action)=>{ + switch (action.type) { + case actionOld.ADD_TODO: + return { + data:action.payload, + ...state + } + default: + return state; + } + +} diff --git a/tpl/src/router/index.tsx b/tpl/src/router/index.tsx index 0dedb5a..66a5595 100644 --- a/tpl/src/router/index.tsx +++ b/tpl/src/router/index.tsx @@ -2,9 +2,7 @@ import React , { Component,Suspense} from 'react'; import { lazy } from '@loadable/component'; import {NavLink,Redirect,Switch,Route} from 'react-router-dom'; const Home = lazy(() => import('@/views/Home')); -const Test = lazy(() => import('@/views/Test')); -const Action = lazy(() => import('@/views/Action')); -const Action2 = lazy(() => import('@/views/Action2/index.tsx')); +const Action = lazy(() => import('@/views/Action/index.tsx')); class Router extends Component { render(){ return( @@ -12,9 +10,7 @@ class Router extends Component { Loading...}> - - diff --git a/tpl/src/stores/Actions.ts b/tpl/src/stores/Actions.ts deleted file mode 100644 index 05fd950..0000000 --- a/tpl/src/stores/Actions.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as actionsAdd from '@/stores/Add/Actions.ts'; -// import * as actionsApp from './App/Actions.ts'; -// import * as actionsEnter from './Enter/Actions.ts'; - -export { - actionsAdd, - // actionsApp, - // actionsEnter -} diff --git a/tpl/src/stores/Add/ActionTypes.js b/tpl/src/stores/Add/ActionTypes.js deleted file mode 100644 index 5d4a6f6..0000000 --- a/tpl/src/stores/Add/ActionTypes.js +++ /dev/null @@ -1,3 +0,0 @@ -export const ADD_TODO = 'ADD_TODO'; -export const DEL_TODO = 'DEL_TODO'; -export const EDIT_TODO = 'EDIT_TODO'; diff --git a/tpl/src/stores/Add/Actions.ts b/tpl/src/stores/Add/Actions.ts deleted file mode 100644 index dd1e6fb..0000000 --- a/tpl/src/stores/Add/Actions.ts +++ /dev/null @@ -1,40 +0,0 @@ -import * as ActionTypes from './ActionTypes'; -// import {a,b,c,d} from './ActionTypes'; -// ActionTypes.a -// ActionTypes.b -// ActionTypes.c -// { -// type:ActionTypes.ADD_TODO, -// text:'第一个demo' -// } - - -export const newAdd = ( - type:string, - payload?:T, - handleCallback?:(res:ResponseData)=>void, -):T =>{ - console.log(payload) - console.log(handleCallback) - return { - type, - payload:payload || {}, - handleCallback - } -} - - -export const add = (_id) =>{ - return{ - type:ActionTypes.ADD_TODO, - text:'第一个demo', - id:_id++ - } -} -export const del = (text,id)=>{ - return { - type:ActionTypes.DEL_TODO, - text:text, - id:id - } -} diff --git a/tpl/src/stores/Add/Reducer.js b/tpl/src/stores/Add/Reducer.js deleted file mode 100644 index cb45673..0000000 --- a/tpl/src/stores/Add/Reducer.js +++ /dev/null @@ -1,22 +0,0 @@ -import * as ActionTypes from './ActionTypes'; - -export default (state=[],action)=>{ - switch (action.type) { - case ActionTypes.ADD_TODO: - return [ - { - type:action.type, - text:action.text, - id:action.id - }, - ...state - ] - case ActionTypes.DEL_TODO: - return state.filter((item)=>{ - return item.id !== action.id; - }) - default: - return state; - } - -} diff --git a/tpl/src/utils/helpers.ts b/tpl/src/utils/helpers.ts index e69de29..5e3e6c3 100644 --- a/tpl/src/utils/helpers.ts +++ b/tpl/src/utils/helpers.ts @@ -0,0 +1,25 @@ +import { ResponseData } from './types'; + +// export const createAction = ( +// type:string, +// payload?:T, +// handleCallback?:(res:ResponseData)=>void, +// ):T =>{ +// return { +// type, +// payload:payload || {}, +// handleCallback +// } +// } + +export function createAction( + type: string, + payload?: T, + handleCallback?: (res: ResponseData) => void, +){ + return { + type, + payload:payload || {}, + handleCallback, + }; +} diff --git a/tpl/src/utils/index.ts b/tpl/src/utils/index.ts index e69de29..038a183 100644 --- a/tpl/src/utils/index.ts +++ b/tpl/src/utils/index.ts @@ -0,0 +1,4 @@ +import * as helpers from './helpers'; + + +export { helpers }; diff --git a/tpl/src/utils/types.ts b/tpl/src/utils/types.ts new file mode 100644 index 0000000..97e550c --- /dev/null +++ b/tpl/src/utils/types.ts @@ -0,0 +1,6 @@ +export interface ResponseData{ + code?: number; + status_code?: number; + data?: any; + msg?: string +} diff --git a/tpl/src/views/Action/index.jsx b/tpl/src/views/Action/index.jsx deleted file mode 100644 index f23b4dc..0000000 --- a/tpl/src/views/Action/index.jsx +++ /dev/null @@ -1,71 +0,0 @@ -import React , { Component } from 'react'; -import { connect } from 'react-redux'; -import {actionsAdd} from '@/stores/Actions.ts'; -import { withRouter,NavLink,Switch,Redirect,Route} from 'react-router-dom'; -import Item from './item.jsx'; -class View extends Component { - // changeName(){ - // - // } - onAddFn(){ - const {dispatch,addList} = this.props; - console.log(addList.length) - dispatch(actionsAdd.add(addList.length)) - } - lists(){ - const { addList } = this.props; - return addList.map((val,index)=>{ - return( - - ) - }) - } - render(){ - console.log(this.props.addList) - const {addList,onAddFn,dispatch} = this.props; - return ( - - {addList.length}
    - action页面
    - {/**/} - 首页 - action - {this.onAddFn()}} - /> - { - addList.length!==0 - ? -
      {this.lists()}
    - : - '' - } -
    - ) - } -} -function mapStateToProps(state) { - console.log(state) - // this.props.addList - // { - // add:[], - // del:[] - // } - return { - addList:state.addReducer - } -} -// const mapDispatchToProps = (dispatch, ownProps) => { -// // { -// // type:'ADD_TODO' -// // } -// // dispatch(actionsAdd.add()) -// return { -// onAddFn:()=>dispatch(actionsAdd.add()) -// } -// }; -export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index.jsx- b/tpl/src/views/Action/index.jsx- deleted file mode 100644 index aab0225..0000000 --- a/tpl/src/views/Action/index.jsx- +++ /dev/null @@ -1,52 +0,0 @@ -import React , { Component } from 'react'; -import {connect} from 'react-redux'; - -import {actionsAdd} from '@/stores/Actions.ts'; -class View extends Component { - // changeName(){ - // - // } - onAddFn(){ - const {dispatch} = this.props; - dispatch(actionsAdd.add()) - } - render(){ - console.log(this.props.addList) - const {addList,onAddFn} = this.props; - return ( - - {addList.length}
    - action页面
    - {/**/} - {this.onAddFn()}} - /> -
    - ) - } -} -function mapStateToProps(state) { - console.log(state) - // this.props.addList - // { - // add:[], - // del:[] - // } - return { - addList:state.add - } -} -const mapDispatchToProps = (dispatch, ownProps) => { - // { - // type:'ADD_TODO' - // } - // dispatch(actionsAdd.add()) - return { - onAddFn:()=>dispatch(actionsAdd.add()) - } -}; -export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index.tsx b/tpl/src/views/Action/index.tsx new file mode 100644 index 0000000..2d8a597 --- /dev/null +++ b/tpl/src/views/Action/index.tsx @@ -0,0 +1,39 @@ +import React , { Component } from 'react'; +import { connect } from 'react-redux'; + +import { helpers } from '@/utils'; +import { actionOld } from '@/actions'; + +class View extends Component { + onAddFn = () => { + const {dispatch} = this.props; + dispatch( + helpers.createAction( + actionOld.ADD_TODO + ) + ) + } + render(){ + return ( + + action页面
    + +
    + ) + } +} +const mapStateToProps = (state) => { + console.log(state) + return { + addList:state + } +} +// const mapDispatchToProps = (dispatch, ownProps) => { +// return { +// onAddFn:()=>dispatch(actionsAdd.add()) +// } +// }; +export default connect(mapStateToProps,null)(View); diff --git a/tpl/src/views/Action/index0.jsx b/tpl/src/views/Action/index0.jsx deleted file mode 100644 index 4e915eb..0000000 --- a/tpl/src/views/Action/index0.jsx +++ /dev/null @@ -1,51 +0,0 @@ -import React , { Component } from 'react'; -import {connect} from 'react-redux'; - -import {actionsAdd} from '@/stores/Actions.ts'; -class View extends Component { - // changeName(){ - // - // } - render(){ - console.log(this.props.addList) - const {addList,onAddFn} = this.props; - return ( - - {addList.length}
    - action页面
    - {/**/} - {onAddFn()}} - /> -
    - ) - } -} -function mapStateToProps(state) { - console.log(state) - // this.props.addList - // { - // add:[], - // del:[] - // } - return { - addList:state.addReducer - } -} -const mapDispatchToProps = (dispatch, ownProps) => { - // ownProps 父组件有任意参数 - // const {name} = ownProps; - // this.props.name - // { - // type:'ADD_TODO' - // } - // dispatch(actionsAdd.add()) - return { - onAddFn:()=>dispatch(actionsAdd.add()) - } -}; -export default connect(mapStateToProps,mapDispatchToProps)(View); diff --git a/tpl/src/views/Action/item.jsx b/tpl/src/views/Action/item.jsx deleted file mode 100644 index 1ec0f99..0000000 --- a/tpl/src/views/Action/item.jsx +++ /dev/null @@ -1,29 +0,0 @@ -import React,{ Component } from 'react'; - -import {connect} from 'react-redux'; - -import {actionsAdd} from '@/stores/Actions.ts'; - -class View extends Component { - constructor(props){ - super(props); - - } - render(){ - const {val,onRemoveFn} = this.props; - return( -
  • - {val.id}-{val.text}-{val.type} - {onRemoveFn()}}>删除 -
  • - ) - } -} -const mapDispatchToProps = (dispatch, ownProps) => { - const { val } = ownProps; - return { - onRemoveFn: () => dispatch(actionsAdd.del('删除',val.id)) - } -}; - -export default connect(null,mapDispatchToProps)(View); diff --git a/tpl/src/views/Action2/index.tsx b/tpl/src/views/Action2/index.tsx deleted file mode 100644 index 2e7ac97..0000000 --- a/tpl/src/views/Action2/index.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React, {useState,useEffect} from 'react'; -import { useSelector, useDispatch } from "react-redux"; -import {actionsAdd} from '@/stores/Actions.ts'; -const View = (props)=>{ - const state = useSelector((state)=>state); - const add = useSelector((state)=>state.addReducer); - const dispatch = useDispatch(); - useEffect(()=>{ - dispatch(actionsAdd.newAdd( - 'test', - {name:'1',age:32} - )) - // dispatch({ - // type:"ADD_TODO" - // }) - },[]) - return( -
    {add.length}
    - ) -} -export default View; diff --git a/tpl/src/views/Test/index.jsx b/tpl/src/views/Test/index.jsx deleted file mode 100644 index a5738c5..0000000 --- a/tpl/src/views/Test/index.jsx +++ /dev/null @@ -1,15 +0,0 @@ -import React, { Component } from 'react'; -class View extends Component { - render(){ - const obj = { - a:'1' - } - let index = 1; - return( -
    - test -
    - ) - } -} -export default View; From 64b7825ebcfdc6e5423f4b1c552ca25961f98d19 Mon Sep 17 00:00:00 2001 From: llqfront Date: Mon, 22 Nov 2021 12:48:31 +0800 Subject: [PATCH 13/16] step3 --- tpl/src/reducers/oldPageReducer.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tpl/src/reducers/oldPageReducer.ts b/tpl/src/reducers/oldPageReducer.ts index f40f0ea..6670a4c 100644 --- a/tpl/src/reducers/oldPageReducer.ts +++ b/tpl/src/reducers/oldPageReducer.ts @@ -1,12 +1,15 @@ import { actionOld } from '@/actions'; -export default (state={},action)=>{ +export default (state=[],action)=>{ switch (action.type) { case actionOld.ADD_TODO: - return { - data:action.payload, + return [ + { + type:action.type, + text:action.type + }, ...state - } + ] default: return state; } From df17d586e1784399a1a1525d70098e2bddaef5e1 Mon Sep 17 00:00:00 2001 From: llqfront Date: Mon, 22 Nov 2021 14:11:36 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E5=AE=8C=E7=BE=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tpl/src/App.tsx | 2 +- tpl/src/actions/ajaxpage.ts | 3 ++ tpl/src/actions/index.ts | 4 +- tpl/src/reducers/ajaxPageReducer.ts | 14 ++++++ tpl/src/reducers/index.ts | 4 +- tpl/src/router/index.tsx | 2 + tpl/src/utils/ajax.ts | 2 +- tpl/src/utils/helpers.ts | 37 ++++++++-------- tpl/src/views/AjaxPage/index.tsx | 68 +++++++++++++++++++++++++++++ 9 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 tpl/src/actions/ajaxpage.ts create mode 100644 tpl/src/reducers/ajaxPageReducer.ts create mode 100644 tpl/src/views/AjaxPage/index.tsx diff --git a/tpl/src/App.tsx b/tpl/src/App.tsx index 389759b..0319de4 100644 --- a/tpl/src/App.tsx +++ b/tpl/src/App.tsx @@ -8,7 +8,7 @@ import Router from '@/router'; const unsubscribe = RootStore().subscribe(() =>{ // console.log(Store.getState()) - localStorage.setItem("LJMRoot", JSON.stringify(RootStore.getState())); + localStorage.setItem("LJMRoot", JSON.stringify(RootStore().getState())); }) // function newJson(str){ diff --git a/tpl/src/actions/ajaxpage.ts b/tpl/src/actions/ajaxpage.ts new file mode 100644 index 0000000..244df2d --- /dev/null +++ b/tpl/src/actions/ajaxpage.ts @@ -0,0 +1,3 @@ +const NAMESPACE = 'ADDPAGE/'; +export const GETPDD = `${NAMESPACE}/GETPDD`; +export const PDDDATA = `${NAMESPACE}/PDDDATA`; diff --git a/tpl/src/actions/index.ts b/tpl/src/actions/index.ts index 8932751..a0af013 100644 --- a/tpl/src/actions/index.ts +++ b/tpl/src/actions/index.ts @@ -1,7 +1,9 @@ import * as actionAdd from './add'; import * as actionOld from './old'; +import * as actionAjaxPage from './ajaxpage'; export { actionAdd, - actionOld + actionOld, + actionAjaxPage } diff --git a/tpl/src/reducers/ajaxPageReducer.ts b/tpl/src/reducers/ajaxPageReducer.ts new file mode 100644 index 0000000..b3ea917 --- /dev/null +++ b/tpl/src/reducers/ajaxPageReducer.ts @@ -0,0 +1,14 @@ +import { actionAjaxPage } from '@/actions'; + +export default (state = {}, action)=>{ + switch (action.type) { + case actionAjaxPage.PDDDATA: + return { + ...state, + action + }; + default: + return state; + } + +} diff --git a/tpl/src/reducers/index.ts b/tpl/src/reducers/index.ts index 82d9483..798d690 100644 --- a/tpl/src/reducers/index.ts +++ b/tpl/src/reducers/index.ts @@ -1,9 +1,11 @@ import { combineReducers } from 'redux'; import addReducer from './addPageReducer'; import oldReducer from './oldPageReducer'; +import ajaxReducer from './ajaxPageReducer'; const rootReducer = combineReducers({ addReducer, - oldReducer + oldReducer, + ajaxReducer }) export default rootReducer; diff --git a/tpl/src/router/index.tsx b/tpl/src/router/index.tsx index 66a5595..c77d367 100644 --- a/tpl/src/router/index.tsx +++ b/tpl/src/router/index.tsx @@ -3,6 +3,7 @@ import { lazy } from '@loadable/component'; import {NavLink,Redirect,Switch,Route} from 'react-router-dom'; const Home = lazy(() => import('@/views/Home')); const Action = lazy(() => import('@/views/Action/index.tsx')); +const AjaxPage = lazy(() => import('@/views/AjaxPage/index.tsx')); class Router extends Component { render(){ return( @@ -11,6 +12,7 @@ class Router extends Component { + diff --git a/tpl/src/utils/ajax.ts b/tpl/src/utils/ajax.ts index d0b569d..0be9668 100644 --- a/tpl/src/utils/ajax.ts +++ b/tpl/src/utils/ajax.ts @@ -74,4 +74,4 @@ const Unit = { return data; } } -export default ajax; +export default Unit; diff --git a/tpl/src/utils/helpers.ts b/tpl/src/utils/helpers.ts index 5e3e6c3..2715aa8 100644 --- a/tpl/src/utils/helpers.ts +++ b/tpl/src/utils/helpers.ts @@ -1,25 +1,24 @@ import { ResponseData } from './types'; -// export const createAction = ( -// type:string, -// payload?:T, -// handleCallback?:(res:ResponseData)=>void, -// ):T =>{ -// return { -// type, -// payload:payload || {}, -// handleCallback -// } -// } - -export function createAction( - type: string, - payload?: T, - handleCallback?: (res: ResponseData) => void, -){ +export const createAction = ( + type:string, + payload?:T, + handleCallback?:(res:ResponseData)=>void, +):T =>{ return { type, payload:payload || {}, - handleCallback, - }; + handleCallback + } } +// export function createAction( +// type: string, +// payload?: T, +// handleCallback?: (res: ResponseData) => void, +// ){ +// return { +// type, +// payload:payload || {}, +// handleCallback, +// }; +// } diff --git a/tpl/src/views/AjaxPage/index.tsx b/tpl/src/views/AjaxPage/index.tsx new file mode 100644 index 0000000..2c14575 --- /dev/null +++ b/tpl/src/views/AjaxPage/index.tsx @@ -0,0 +1,68 @@ +import React, { Component } from 'react'; +import {connect} from 'react-redux'; +import { helpers } from '@/utils'; +import { actionAjaxPage } from '@/actions'; +import Unit from '@/utils/ajax.ts' +class View extends Component { + constructor(props){ + super(props); + this.state = { + } + } + handleCallback(){ + const {dispatch} = this.props; + const ajaxCfg = { + url:'/home/mediareports', + cfg:{ + page_number:1, + page_size:10, + }, + headers:{} + } + Unit.getApi(ajaxCfg).then((res)=>{ + dispatch( + helpers.createAction(actionAjaxPage.PDDDATA,res.data) + ) + }) + } + pageGetPdd(){ + const {dispatch} = this.props; + dispatch( + helpers.createAction(actionAjaxPage.GETPDD,{},this.handleCallback()) + ) + } + componentDidMount(){ + this.pageGetPdd() + } + lists(data){ + return data.map((val,index)=>{ + return( +
  • + {val.id} +
  • + ) + }) + } + render(){ + // const {pddData} = this.props; + return( +
    + {/* + pddData.length!==0 + ? +
      {this.lists(pddData.data.data)}
    + : + '' + */} + asdfasdf +
    + ) + } +} +const mapStateToProps = (state)=>{ + console.log(state) + return { + // pddData:state.pddReducer + } +} +export default connect(mapStateToProps,null)(View); From 7f776c87bbf639d659a7aa1788b44a49946562b5 Mon Sep 17 00:00:00 2001 From: llqfront Date: Mon, 22 Nov 2021 15:14:34 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E5=AE=8C=E7=BE=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tpl/src/services/index.ts | 4 +- tpl/src/services/loginService.ts | 1 - tpl/src/services/pddService.ts | 5 + tpl/src/utils/ajax.ts | 153 ++++++++++++++++--------------- tpl/src/utils/index.ts | 3 +- tpl/src/views/AjaxPage/index.tsx | 58 +++++++++--- 6 files changed, 133 insertions(+), 91 deletions(-) delete mode 100644 tpl/src/services/loginService.ts create mode 100644 tpl/src/services/pddService.ts diff --git a/tpl/src/services/index.ts b/tpl/src/services/index.ts index 3ec0367..89a3944 100644 --- a/tpl/src/services/index.ts +++ b/tpl/src/services/index.ts @@ -1,5 +1,5 @@ -import * as loginApi from '@/services/loginService.ts'; +import * as pddApi from './pddService.ts'; export { - loginApi, + pddApi, } diff --git a/tpl/src/services/loginService.ts b/tpl/src/services/loginService.ts deleted file mode 100644 index 8b13789..0000000 --- a/tpl/src/services/loginService.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tpl/src/services/pddService.ts b/tpl/src/services/pddService.ts new file mode 100644 index 0000000..94d8dea --- /dev/null +++ b/tpl/src/services/pddService.ts @@ -0,0 +1,5 @@ +import { ajaxs } from '@/utils'; + +export const pddFnApi = (params)=>{ + return ajaxs.getApi2('/home/mediareports',params) +} diff --git a/tpl/src/utils/ajax.ts b/tpl/src/utils/ajax.ts index 0be9668..323b0e3 100644 --- a/tpl/src/utils/ajax.ts +++ b/tpl/src/utils/ajax.ts @@ -1,77 +1,86 @@ import axios from 'axios'; import qs from 'qs'; -const Unit = { - async getApi(ajaxCfg){ - let data = await axios.get( - ajaxCfg.url,{ - params:ajaxCfg.cfg - }, - { - headers: ajaxCfg.headers, - }) - return data; +export const getApi = async(ajaxCfg)=>{ + let data = await axios.get( + ajaxCfg.url,{ + params:ajaxCfg.cfg }, - async postApi(url,cfg,headers){ - let fd = new FormData(); - for(let key in cfg){ - fd.append(key, cfg[key]); - } - let data = await axios.post(url,fd, - { - headers: headers - }) - return data; - }, - async putApi(url,cfg,headers){ - let data = await axios.put(url,qs.stringify(cfg),{ - headers: { - 'Content-Type':'application/x-www-form-urlencoded', - } - }) - return data; - }, - async _postApi(url,cfg,headers){ - let data = await axios.post(url,cfg, - { - headers: headers - }) - return data; - }, - async __postApi(url,cfg,headers){ - let data = await axios.post(url,qs.stringify(cfg),{ - headers: { - 'Content-Type':'application/x-www-form-urlencoded', - } - }) - return data; - }, - async delApi(url,cfg,headers){ - let data = await axios.delete(url,{params:cfg},{ - headers: headers - }) - return data; + { + headers: ajaxCfg.headers, + }) + return data; +} +export const getApi2 = async(url,cfg,headers)=>{ + let data = await axios.get( + url,{ + params:cfg }, - async requestApi(cfg,headers,file){ - let fd = new FormData(); - fd.append('param', JSON.stringify(cfg)); - if(file){ - // 上传证明 - if(file.length){ - for(let i=0,len=file.length;i{ + // dispatch( + // helpers.createAction(actionAjaxPage.PDDDATA,res.data) + // ) + // }) + // } + // pageGetPdd(){ + // const {dispatch} = this.props; + // dispatch( + // helpers.createAction(actionAjaxPage.GETPDD,{},this.handleCallback()) + // ) + // } + handleCallback2(){ const {dispatch} = this.props; - const ajaxCfg = { - url:'/home/mediareports', - cfg:{ - page_number:1, - page_size:10, - }, - headers:{} + const params = { + page_number:1, + page_size:10, } - Unit.getApi(ajaxCfg).then((res)=>{ + // Unit.getApi(ajaxCfg).then((res)=>{ + // dispatch( + // helpers.createAction(actionAjaxPage.PDDDATA,res.data) + // ) + // }) + // 把url 提到services中 + pddApi.pddFnApi(params).then((res)=>{ dispatch( - helpers.createAction(actionAjaxPage.PDDDATA,res.data) - ) + helpers.createAction(actionAjaxPage.PDDDATA,res.data) + // helpers.createAction(actionAjaxPage.PDDDATA,res.data,this.handleCallback()) + ) }) } - pageGetPdd(){ + newApi(){ const {dispatch} = this.props; dispatch( - helpers.createAction(actionAjaxPage.GETPDD,{},this.handleCallback()) + helpers.createAction(actionAjaxPage.GETPDD,{},this.handleCallback2()) ) } componentDidMount(){ - this.pageGetPdd() + // this.pageGetPdd() + this.newApi(); } lists(data){ return data.map((val,index)=>{ From caafde5cb1105ddcca02a49f0e8adb704e133c9f Mon Sep 17 00:00:00 2001 From: llqfront Date: Fri, 26 Aug 2022 19:59:16 +0800 Subject: [PATCH 16/16] node -v --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 572fac1..e58ba44 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # react-cli +node 15+ react-typescript-router-mobx-redux-hook ```html main 分支为 路由版本