diff --git a/pkg/api/credential.go b/pkg/api/credential.go
index 94b22b7..bfe4a1d 100644
--- a/pkg/api/credential.go
+++ b/pkg/api/credential.go
@@ -58,7 +58,17 @@ func CredentialPagingEndpoint(c echo.Context) error {
pageSize, _ := strconv.Atoi(c.QueryParam("pageSize"))
name := c.QueryParam("name")
- items, total, _ := model.FindPageCredential(pageIndex, pageSize, name)
+ var (
+ total int64
+ items []model.CredentialVo
+ )
+
+ account, _ := GetCurrentAccount(c)
+ if account.Role == model.RoleUser {
+ items, total, _ = model.FindPageCredential(pageIndex, pageSize, name, account.ID)
+ } else {
+ items, total, _ = model.FindPageCredential(pageIndex, pageSize, name, "")
+ }
return Success(c, H{
"total": total,
diff --git a/pkg/model/credential.go b/pkg/model/credential.go
index 8f4580e..e2b893c 100644
--- a/pkg/model/credential.go
+++ b/pkg/model/credential.go
@@ -27,20 +27,34 @@ func (r *Credential) TableName() string {
return "credentials"
}
+type CredentialVo struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Type string `json:"type"`
+ Username string `json:"username"`
+ Created utils.JsonTime `json:"created"`
+ Creator string `json:"creator"`
+ CreatorName string `json:"creatorName"`
+}
+
func FindAllCredential() (o []Credential, err error) {
err = global.DB.Find(&o).Error
return
}
-func FindPageCredential(pageIndex, pageSize int, name string) (o []Credential, total int64, err error) {
+func FindPageCredential(pageIndex, pageSize int, name, creator string) (o []CredentialVo, total int64, err error) {
db := global.DB
+ db = db.Table("credentials").Select("credentials.id,credentials.name,credentials.type,credentials.username,credentials.creator,credentials.created,users.nickname as creator_name").Joins("left join users on credentials.creator = users.id")
if len(name) > 0 {
- db = db.Where("name like ?", "%"+name+"%")
+ db = db.Where("credentials.name like ?", "%"+name+"%")
+ }
+ if len(creator) > 0 {
+ db = db.Where("credentials.creator = ?", creator)
}
- err = db.Order("created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
+ err = db.Order("credentials.created desc").Find(&o).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Count(&total).Error
if o == nil {
- o = make([]Credential, 0)
+ o = make([]CredentialVo, 0)
}
return
}
diff --git a/pkg/model/user.go b/pkg/model/user.go
index 3be3acc..69c55df 100644
--- a/pkg/model/user.go
+++ b/pkg/model/user.go
@@ -6,6 +6,11 @@ import (
"reflect"
)
+const (
+ RoleUser = "user"
+ RoleAdmin = "admin"
+)
+
type User struct {
ID string `gorm:"primary_key" json:"id"`
Username string `json:"username"`
@@ -60,6 +65,11 @@ func FindUserById(id string) (o User, err error) {
return
}
+func FindUserByIdIn(ids []string) (o []User, err error) {
+ err = global.DB.Where("id in ?", ids).First(&o).Error
+ return
+}
+
func FindUserByUsername(username string) (o User, err error) {
err = global.DB.Where("username = ?", username).First(&o).Error
return
diff --git a/web/src/components/asset/Asset.js b/web/src/components/asset/Asset.js
index 511d315..1ee3bb9 100644
--- a/web/src/components/asset/Asset.js
+++ b/web/src/components/asset/Asset.js
@@ -5,8 +5,10 @@ import {
Button,
Col,
Divider,
+ Dropdown,
Input,
Layout,
+ Menu,
Modal,
PageHeader,
Row,
@@ -25,11 +27,8 @@ import {isEmpty, itemRender} from "../../utils/utils";
import {
- CodeTwoTone,
- CopyTwoTone,
DeleteOutlined,
- DeleteTwoTone,
- EditTwoTone,
+ DownOutlined,
ExclamationCircleOutlined,
PlusOutlined,
SyncOutlined,
@@ -409,16 +408,37 @@ class Asset extends Component {
title: '操作',
key: 'action',
render: (text, record) => {
+
+ const menu = (
+
+ );
+
return (
-
)
},
diff --git a/web/src/components/credential/Credential.js b/web/src/components/credential/Credential.js
index 2633bde..d193c02 100644
--- a/web/src/components/credential/Credential.js
+++ b/web/src/components/credential/Credential.js
@@ -1,20 +1,25 @@
import React, {Component} from 'react';
-import {Button, Col, Divider, Input, Layout, Modal, PageHeader, Row, Space, Table, Tooltip, Typography} from "antd";
+import {
+ Button,
+ Col,
+ Divider,
+ Input,
+ Layout,
+ Modal,
+ PageHeader,
+ Row,
+ Space,
+ Table,
+ Tag,
+ Tooltip,
+ Typography
+} from "antd";
import qs from "qs";
import CredentialModal from "./CredentialModal";
import request from "../../common/request";
import {message} from "antd/es";
-import {
- DeleteOutlined,
- DeleteTwoTone,
- EditTwoTone,
- ExclamationCircleOutlined,
- EyeTwoTone,
- PlusOutlined,
- SyncOutlined,
- UndoOutlined
-} from '@ant-design/icons';
+import {DeleteOutlined, ExclamationCircleOutlined, PlusOutlined, SyncOutlined, UndoOutlined} from '@ant-design/icons';
import {itemRender} from "../../utils/utils";
import Logout from "../user/Logout";
@@ -251,11 +256,11 @@ class Credential extends Component {
if (type === 'private-key') {
return (
- 密钥
+ 密钥
);
} else {
return (
- 密码
+ 密码
);
}
@@ -264,6 +269,14 @@ class Credential extends Component {
title: '授权账户',
dataIndex: 'username',
key: 'username',
+ }, {
+ title: '创建人',
+ dataIndex: 'creatorName',
+ key: 'creatorName',
+ }, {
+ title: '创建时间',
+ dataIndex: 'created',
+ key: 'created',
},
{
title: '操作',
@@ -272,11 +285,9 @@ class Credential extends Component {
return (
- }
- onClick={() => this.showModal('查看凭证', record)}>查看
- }
+ this.showModal('更新凭证', record)}>编辑
- }
+ this.showDeleteConfirm(record.id, record.name)}>删除
)
diff --git a/web/src/components/user/User.js b/web/src/components/user/User.js
index b2c839f..7629d0d 100644
--- a/web/src/components/user/User.js
+++ b/web/src/components/user/User.js
@@ -5,7 +5,8 @@ import {
Badge,
Button,
Col,
- Divider, Dropdown,
+ Divider,
+ Dropdown,
Input,
Layout,
Menu,
@@ -14,6 +15,7 @@ import {
Row,
Space,
Table,
+ Tag,
Tooltip,
Typography,
} from "antd";
@@ -22,9 +24,11 @@ import UserModal from "./UserModal";
import request from "../../common/request";
import {message} from "antd/es";
import {
- DeleteOutlined, DownOutlined,
- ExclamationCircleOutlined, IssuesCloseOutlined,
- PlusOutlined, SmileOutlined,
+ DeleteOutlined,
+ DownOutlined,
+ ExclamationCircleOutlined,
+ IssuesCloseOutlined,
+ PlusOutlined,
StopOutlined,
SyncOutlined,
UndoOutlined
@@ -261,6 +265,25 @@ class User extends Component {
title: '用户昵称',
dataIndex: 'nickname',
key: 'nickname',
+ }, {
+ title: '用户角色',
+ dataIndex: 'role',
+ key: 'role',
+ render: (role, record) => {
+
+ if (role === 'normal') {
+ return (
+ 普通用户
+ );
+ } else if (role === 'admin') {
+ return (
+ 管理用户
+ );
+ } else {
+ return role;
+ }
+
+ }
}, {
title: '在线状态',
dataIndex: 'online',
@@ -282,33 +305,13 @@ class User extends Component {
key: 'action',
render: (text, record) => {
- const menu = (
-
- );
return (
this.showModal('更新用户', record)}>编辑
-
-
- 更多
-
-
+ this.showDeleteConfirm(record.id, record.name)}>删除
)
},
@@ -391,51 +394,52 @@ class User extends Component {
-
- }
- loading={this.state.delBtnLoading}
- onClick={() => {
- const content =
- 您确定要启用选中的{this.state.selectedRowKeys.length}条记录吗?
-
;
- confirm({
- icon: ,
- content: content,
- onOk: () => {
+ {/**/}
+ {/* }*/}
+ {/* loading={this.state.delBtnLoading}*/}
+ {/* onClick={() => {*/}
+ {/* const content = */}
+ {/* 您确定要启用选中的{this.state.selectedRowKeys.length}条记录吗?*/}
+ {/*
;*/}
+ {/* confirm({*/}
+ {/* icon: ,*/}
+ {/* content: content,*/}
+ {/* onOk: () => {*/}
- },
- onCancel() {
+ {/* },*/}
+ {/* onCancel() {*/}
- },
- });
- }}>
+ {/* },*/}
+ {/* });*/}
+ {/* }}>*/}
-
-
+ {/* */}
+ {/**/}
-
- }
- loading={this.state.delBtnLoading}
- onClick={() => {
- const content =
- 您确定要禁用选中的{this.state.selectedRowKeys.length}条记录吗?
-
;
- confirm({
- icon: ,
- content: content,
- onOk: () => {
+ {/**/}
+ {/* }*/}
+ {/* loading={this.state.delBtnLoading}*/}
+ {/* onClick={() => {*/}
+ {/* const content = */}
+ {/* 您确定要禁用选中的{this.state.selectedRowKeys.length}条记录吗?*/}
+ {/*
;*/}
+ {/* confirm({*/}
+ {/* icon: ,*/}
+ {/* content: content,*/}
+ {/* onOk: () => {*/}
- },
- onCancel() {
+ {/* },*/}
+ {/* onCancel() {*/}
- },
- });
- }}>
+ {/* },*/}
+ {/* });*/}
+ {/* }}>*/}
-
-
+ {/* */}
+ {/**/}
}
diff --git a/web/src/components/user/UserModal.js b/web/src/components/user/UserModal.js
index 8541da4..d85331f 100644
--- a/web/src/components/user/UserModal.js
+++ b/web/src/components/user/UserModal.js
@@ -1,5 +1,5 @@
import React from 'react';
-import {Form, Input, Modal} from "antd/lib/index";
+import {Form, Input, Modal, Radio} from "antd/lib/index";
const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, model}) => {
@@ -22,7 +22,8 @@ const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, mode
form.resetFields();
handleOk(values);
})
- .catch(info => {});
+ .catch(info => {
+ });
}}
onCancel={handleCancel}
confirmLoading={confirmLoading}
@@ -43,6 +44,13 @@ const UserModal = ({title, visible, handleOk, handleCancel, confirmLoading, mode
+
+
+ 普通用户
+ 管理用户
+
+
+
{
title.indexOf('新增') > -1 ?
(