You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by qi...@apache.org on 2022/01/07 09:09:39 UTC

[incubator-shenyu-dashboard] branch master updated: System Manage User List Add Status Switch (#177) (#178)

This is an automated email from the ASF dual-hosted git repository.

qicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu-dashboard.git


The following commit(s) were added to refs/heads/master by this push:
     new e2cf75d  System Manage User List Add Status Switch (#177) (#178)
e2cf75d is described below

commit e2cf75d5a444031f53343e24cd0e6682313a3b87
Author: dayu <we...@qq.com>
AuthorDate: Fri Jan 7 17:09:32 2022 +0800

    System Manage User List Add Status Switch (#177) (#178)
    
    Co-authored-by: wenyu.dai <“wenyu.dai@qq.com”>
---
 src/locales/en-US.json          |  2 +-
 src/models/manage.js            | 12 +++++++
 src/routes/System/User/index.js | 76 +++++++++++++++++++++++++----------------
 3 files changed, 60 insertions(+), 30 deletions(-)

diff --git a/src/locales/en-US.json b/src/locales/en-US.json
index 297e5f9..c3c02eb 100644
--- a/src/locales/en-US.json
+++ b/src/locales/en-US.json
@@ -137,7 +137,7 @@
   "SHENYU.SYSTEM.ADDDATA": "Add",
   "SHENYU.SYSTEM.CREATETIME": "CreateTime",
   "SHENYU.SYSTEM.UPDATETIME": "UpdateTime",
-  "SHENYU.SYSTEM.EDITOR": "Editor",
+  "SHENYU.SYSTEM.EDITOR": "Edit",
   "SHENYU.SYSTEM.CUSTOM": "Custom",
   "SHENYU.SYSTEM.SYSTEM": "System",
   "SHENYU.SYSTEM.RESOURCE.MENULIST.TITLE": "MenuList",
diff --git a/src/models/manage.js b/src/models/manage.js
index 41e514b..70e34de 100644
--- a/src/models/manage.js
+++ b/src/models/manage.js
@@ -121,6 +121,18 @@ export default {
         message.warn(json.message);
       }
     },
+    *updateUserStatus(params, { call }) {
+      const { payload, callback } = params;
+      const json = yield call(updateUser, payload);
+      if (json.code === 200) {
+        message.success(
+          getIntlContent("SHENYU.COMMON.RESPONSE.UPDATE.SUCCESS")
+        );
+        callback();
+      } else {
+        message.warn(json.message);
+      }
+    },
     *reload(params, { put }) {
       const { fetchValue } = params;
       const { userName, currentPage, pageSize } = fetchValue;
diff --git a/src/routes/System/User/index.js b/src/routes/System/User/index.js
index df3aa5d..f914bc7 100644
--- a/src/routes/System/User/index.js
+++ b/src/routes/System/User/index.js
@@ -16,12 +16,12 @@
  */
 
 import React, { Component } from "react";
-import { Table, Input, Button, message, Popconfirm } from "antd";
+import { Table, Input, Button, message, Popconfirm, Switch } from "antd";
 import { connect } from "dva";
 import AddModal from "./AddModal";
 import DataPermModal from "./DataPermModal";
 import { getCurrentLocale, getIntlContent } from "../../../utils/IntlUtils";
-import AuthButton from '../../../utils/AuthButton';
+import AuthButton from "../../../utils/AuthButton";
 
 @connect(({ manage, role, loading }) => ({
   manage,
@@ -36,7 +36,7 @@ export default class Manage extends Component {
       selectedRowKeys: [],
       userName: "",
       popup: "",
-      localeName: ''
+      localeName: ""
     };
   }
 
@@ -64,13 +64,16 @@ export default class Manage extends Component {
   };
 
   getAllRoles = () => {
-    const { dispatch, role: { allRoles } } = this.props;
+    const {
+      dispatch,
+      role: { allRoles }
+    } = this.props;
     if (!allRoles || allRoles.length === 0) {
       dispatch({
         type: "role/fetchAll"
       });
     }
-  }
+  };
 
   pageOnchange = page => {
     this.setState({ currentPage: page });
@@ -82,7 +85,10 @@ export default class Manage extends Component {
   };
 
   editClick = record => {
-    const { dispatch, role: { allRoles } } = this.props;
+    const {
+      dispatch,
+      role: { allRoles }
+    } = this.props;
     const { currentPage } = this.state;
     const name = this.state.userName;
     dispatch({
@@ -175,7 +181,9 @@ export default class Manage extends Component {
   };
 
   addClick = () => {
-    const { role: { allRoles } } = this.props;
+    const {
+      role: { allRoles }
+    } = this.props;
     const { currentPage } = this.state;
     const name = this.state.userName;
     this.setState({
@@ -217,10 +225,10 @@ export default class Manage extends Component {
       localeName: locale
     });
     getCurrentLocale(this.state.localeName);
-  };
+  }
 
   render() {
-    const { manage, loading } = this.props;
+    const { manage, loading, dispatch } = this.props;
     const { userList, total } = manage;
     const { currentPage, selectedRowKeys, userName, popup } = this.state;
     const userColumns = [
@@ -229,44 +237,57 @@ export default class Manage extends Component {
         title: getIntlContent("SHENYU.SYSTEM.USERNAME"),
         dataIndex: "userName",
         key: "userName",
-        ellipsis:true,
+        ellipsis: true
       },
       {
         align: "center",
         title: getIntlContent("SHENYU.SYSTEM.STATUS"),
         dataIndex: "enabled",
         key: "enabled",
-        ellipsis:true,
-        render: text => {
-          if (text) {
-            return <div className="open">{getIntlContent("SHENYU.COMMON.OPEN")}</div>;
-          } else {
-            return <div className="close">{getIntlContent("SHENYU.COMMON.CLOSE")}</div>;
-          }
-        }
+        ellipsis: true,
+        render: (text, row) => (
+          <Switch
+            checkedChildren={getIntlContent("SHENYU.COMMON.OPEN")}
+            unCheckedChildren={getIntlContent("SHENYU.COMMON.CLOSE")}
+            checked={text}
+            onChange={checked => {
+              dispatch({
+                type: "manage/updateUserStatus",
+                payload: {
+                  id: row.id,
+                  enabled: checked,
+                  userName: row.userName
+                },
+                callback: () => {
+                  this.getAllUsers(currentPage);
+                }
+              });
+            }}
+          />
+        )
       },
       {
         align: "center",
         title: getIntlContent("SHENYU.SYSTEM.CREATETIME"),
         dataIndex: "dateCreated",
         key: "dateCreated",
-        ellipsis:true,
-        sorter: (a,b) => a.dateCreated > b.dateCreated ? 1 : -1,
+        ellipsis: true,
+        sorter: (a, b) => (a.dateCreated > b.dateCreated ? 1 : -1)
       },
       {
         align: "center",
         title: getIntlContent("SHENYU.SYSTEM.UPDATETIME"),
         dataIndex: "dateUpdated",
         key: "dateUpdated",
-        ellipsis:true,
-        sorter: (a,b) => a.dateUpdated > b.dateUpdated ? 1 : -1,
+        ellipsis: true,
+        sorter: (a, b) => (a.dateUpdated > b.dateUpdated ? 1 : -1)
       },
       {
         align: "center",
         title: getIntlContent("SHENYU.COMMON.OPERAT"),
         dataIndex: "operate",
         key: "operate",
-        ellipsis:true,
+        ellipsis: true,
         render: (text, record) => {
           return (
             <div>
@@ -325,17 +346,14 @@ export default class Manage extends Component {
           <AuthButton perms="system:manager:delete">
             <Popconfirm
               title={getIntlContent("SHENYU.COMMON.DELETE")}
-              placement='bottom'
+              placement="bottom"
               onConfirm={() => {
-                this.deleteClick()
+                this.deleteClick();
               }}
               okText={getIntlContent("SHENYU.COMMON.SURE")}
               cancelText={getIntlContent("SHENYU.COMMON.CALCEL")}
             >
-              <Button
-                style={{ marginLeft: 20 }}
-                type="danger"
-              >
+              <Button style={{ marginLeft: 20 }} type="danger">
                 {getIntlContent("SHENYU.SYSTEM.DELETEDATA")}
               </Button>
             </Popconfirm>