ソースを参照

add changeParams

KaysonCui 4 年 前
コミット
cc9e7ee7b1
3 ファイル変更20 行追加27 行削除
  1. 5 23
      front/.eslintrc
  2. 12 4
      front/src/containers/Page.js
  3. 3 0
      front/src/services/index.js

+ 5 - 23
front/.eslintrc

@@ -1,30 +1,11 @@
 {
   "parser": "babel-eslint",
-  "extends": [
-    "standard-react",
-    "airbnb-base"
-  ],
-  "plugins": [
-    "react",
-    "import"
-  ],
+  "extends": ["standard-react", "airbnb-base"],
+  "plugins": ["react", "import"],
   "settings": {
     "import/resolver": {
       "alias": {
-        "map": [
-          [
-            "@src",
-            "./src"
-          ],
-          [
-            "@project",
-            "./project/admin"
-          ],
-          [
-            "@components",
-            "./components"
-          ]
-        ]
+        "map": [["@src", "./src"], ["@project", "./project/admin"], ["@components", "./components"]]
       }
     }
   },
@@ -43,6 +24,7 @@
     "__DEBUG__": false,
     "__API_PATH__": false,
     "__BASE_NAME__": false,
+    "changeParams": false,
     "linkTo": false,
     "replaceLink": false,
     "goBack": false,
@@ -84,4 +66,4 @@
     "import/no-named-as-default": "off",
     "operator-linebreak": "off"
   }
-}
+}

+ 12 - 4
front/src/containers/Page.js

@@ -65,7 +65,7 @@ export default class extends Component {
     this.outPage();
   }
 
-  init() { }
+  init() {}
 
   initState() {
     return {};
@@ -140,16 +140,24 @@ export default class extends Component {
     });
   }
 
-  search(data) {
-    this.refreshQuery(Object.assign(this.state.search, data));
+  search(data, refresh) {
+    const query = Object.assign(this.state.search, data);
+    if (refresh) {
+      this.refreshQuery(query);
+    } else {
+      this.changeQuery(query);
+    }
   }
 
   refresh() {
     this.refreshQuery(this.state.search);
   }
 
+  changeQuery(query) {
+    changeParams(`?${querystring.stringify(query)}`);
+  }
+
   refreshQuery(query) {
-    // this.inited = false;
     replaceLink(`${this.props.location.pathname}?${querystring.stringify(query)}`);
   }
 

+ 3 - 0
front/src/services/index.js

@@ -11,6 +11,9 @@ export const Api = new ApiManage();
 
 export const History = createHistory({ basename: __BASE_NAME__ });
 
+window.changeParams = params => {
+  window.history.pushState(null, null, params);
+};
 window.linkTo = link => {
   /**
    * 跳转页面