增加多租户隔离初版

This commit is contained in:
dushixiang 2021-01-13 20:09:48 +08:00
parent e00453cbad
commit 499dd3ab85
7 changed files with 96 additions and 10 deletions

13
main.go
View File

@ -28,6 +28,16 @@ func main() {
func Run() error {
fmt.Printf(`
_______ __ ___________ .__ .__
\ \ ____ ___ ____/ |_ \__ ___/__________ _____ |__| ____ _____ | |
/ | \_/ __ \\ \/ /\ __\ | |_/ __ \_ __ \/ \| |/ \\__ \ | |
/ | \ ___/ > < | | | |\ ___/| | \/ Y Y \ | | \/ __ \| |__
\____|__ /\___ >__/\_ \ |__| |____| \___ >__| |__|_| /__|___| (____ /____/
\/ \/ \/ \/ \/ \/ \/
`)
var err error
//logrus.SetReportCaller(true)
logrus.SetFormatter(&nested.Formatter{
@ -49,7 +59,7 @@ func Run() error {
return err
}
logrus.Infof("当前数据库模式为:%v", global.Config.DB)
fmt.Printf("当前数据库模式为:%v\n", global.Config.DB)
if global.Config.DB == "mysql" {
dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
global.Config.Mysql.Username,
@ -123,6 +133,7 @@ func Run() error {
global.Cache = cache.New(5*time.Minute, 10*time.Minute)
global.Store = global.NewStore()
e := api.SetupRoutes()
if err := handle.InitProperties(); err != nil {
return err

View File

@ -14,6 +14,7 @@ const Token = "X-Auth-Token"
func SetupRoutes() *echo.Echo {
e := echo.New()
e.HideBanner = true
e.File("/", "web/build/index.html")
e.File("/logo.svg", "web/build/logo.svg")

View File

@ -22,6 +22,7 @@ type Asset struct {
Active bool `json:"active"`
Created utils.JsonTime `json:"created"`
Tags string `json:"tags"`
Creator string `json:"creator"`
}
func (r *Asset) TableName() string {

View File

@ -10,6 +10,7 @@ type Command struct {
Name string `json:"name"`
Content string `json:"content"`
Created utils.JsonTime `json:"created"`
Creator string `json:"creator"`
}
func (r *Command) TableName() string {

View File

@ -20,6 +20,7 @@ type Credential struct {
PrivateKey string `json:"privateKey"`
Passphrase string `json:"passphrase"`
Created utils.JsonTime `json:"created"`
Creator string `json:"creator"`
}
func (r *Credential) TableName() string {

View File

@ -15,6 +15,7 @@ type User struct {
Online bool `json:"online"`
Enabled bool `json:"enabled"`
Created utils.JsonTime `json:"created"`
Role string `json:"role"`
}
func (r *User) TableName() string {

View File

@ -5,9 +5,10 @@ import {
Badge,
Button,
Col,
Divider,
Divider, Dropdown,
Input,
Layout,
Menu,
Modal,
PageHeader,
Row,
@ -21,10 +22,10 @@ import UserModal from "./UserModal";
import request from "../../common/request";
import {message} from "antd/es";
import {
DeleteOutlined, DeleteTwoTone,
EditTwoTone,
ExclamationCircleOutlined,
PlusOutlined,
DeleteOutlined, DownOutlined,
ExclamationCircleOutlined, IssuesCloseOutlined,
PlusOutlined, SmileOutlined,
StopOutlined,
SyncOutlined,
UndoOutlined
} from '@ant-design/icons';
@ -127,7 +128,8 @@ class User extends Component {
queryParams: queryParams
});
this.loadTableData(queryParams).then(r => {})
this.loadTableData(queryParams).then(r => {
})
};
showDeleteConfirm(id, content) {
@ -279,12 +281,34 @@ class User extends Component {
title: '操作',
key: 'action',
render: (text, record) => {
const menu = (
<Menu>
<Menu.Item key="1">
<Button type="text" size='small'
onClick={() => this.showDeleteConfirm(record.id, record.name)}>禁用</Button>
</Menu.Item>
<Menu.Item key="2">
<Button type="text" size='small'
onClick={() => this.showDeleteConfirm(record.id, record.name)}>启用</Button>
</Menu.Item>
<Menu.Divider />
<Menu.Item key="3">
<Button type="text" size='small'
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
</Menu.Item>
</Menu>
);
return (
<div>
<Button type="link" size='small' icon={<EditTwoTone/>}
<Button type="link" size='small'
onClick={() => this.showModal('更新用户', record)}>编辑</Button>
<Button type="link" size='small' icon={<DeleteTwoTone/>}
onClick={() => this.showDeleteConfirm(record.id, record.name)}>删除</Button>
<Dropdown overlay={menu}>
<Button type="link" size='small'>
更多 <DownOutlined />
</Button>
</Dropdown>
</div>
)
},
@ -367,6 +391,52 @@ class User extends Component {
</Button>
</Tooltip>
<Tooltip title="批量启用">
<Button type="dashed" danger disabled={!hasSelected} icon={<IssuesCloseOutlined />}
loading={this.state.delBtnLoading}
onClick={() => {
const content = <div>
您确定要启用选中的<Text style={{color: '#1890FF'}}
strong>{this.state.selectedRowKeys.length}</Text>
</div>;
confirm({
icon: <ExclamationCircleOutlined/>,
content: content,
onOk: () => {
},
onCancel() {
},
});
}}>
</Button>
</Tooltip>
<Tooltip title="批量禁用">
<Button type="default" danger disabled={!hasSelected} icon={<StopOutlined/>}
loading={this.state.delBtnLoading}
onClick={() => {
const content = <div>
您确定要禁用选中的<Text style={{color: '#1890FF'}}
strong>{this.state.selectedRowKeys.length}</Text>
</div>;
confirm({
icon: <ExclamationCircleOutlined/>,
content: content,
onOk: () => {
},
onCancel() {
},
});
}}>
</Button>
</Tooltip>
<Tooltip title="批量删除">
<Button type="primary" danger disabled={!hasSelected} icon={<DeleteOutlined/>}
loading={this.state.delBtnLoading}