mirror of
https://gitee.com/goploy/goploy.git
synced 2024-11-30 03:07:59 +08:00
U opt namespace list
This commit is contained in:
parent
378a48bb01
commit
58b8c4a7db
@ -14,6 +14,7 @@ func (n Namespace) Routes() []core.Route {
|
|||||||
return []core.Route{
|
return []core.Route{
|
||||||
core.NewRoute("/namespace/getList", http.MethodGet, n.GetList),
|
core.NewRoute("/namespace/getList", http.MethodGet, n.GetList),
|
||||||
core.NewRoute("/namespace/getTotal", http.MethodGet, n.GetTotal),
|
core.NewRoute("/namespace/getTotal", http.MethodGet, n.GetTotal),
|
||||||
|
core.NewRoute("/namespace/getOption", http.MethodGet, n.GetOption),
|
||||||
core.NewRoute("/namespace/getBindUserList", http.MethodGet, n.GetBindUserList),
|
core.NewRoute("/namespace/getBindUserList", http.MethodGet, n.GetBindUserList),
|
||||||
core.NewRoute("/namespace/getUserOption", http.MethodGet, n.GetUserOption),
|
core.NewRoute("/namespace/getUserOption", http.MethodGet, n.GetUserOption),
|
||||||
core.NewRoute("/namespace/add", http.MethodPost, n.Add).Roles(core.RoleAdmin),
|
core.NewRoute("/namespace/add", http.MethodPost, n.Add).Roles(core.RoleAdmin),
|
||||||
@ -52,6 +53,18 @@ func (Namespace) GetTotal(gp *core.Goploy) core.Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (Namespace) GetOption(gp *core.Goploy) core.Response {
|
||||||
|
namespaceUsers, err := model.NamespaceUser{UserID: gp.UserInfo.ID}.GetUserNamespaceList()
|
||||||
|
if err != nil {
|
||||||
|
return response.JSON{Code: response.Error, Message: err.Error()}
|
||||||
|
}
|
||||||
|
return response.JSON{
|
||||||
|
Data: struct {
|
||||||
|
NamespaceUsers model.NamespaceUsers `json:"list"`
|
||||||
|
}{NamespaceUsers: namespaceUsers},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (Namespace) GetUserOption(gp *core.Goploy) core.Response {
|
func (Namespace) GetUserOption(gp *core.Goploy) core.Response {
|
||||||
namespaceUsers, err := model.NamespaceUser{NamespaceID: gp.Namespace.ID}.GetAllUserByNamespaceID()
|
namespaceUsers, err := model.NamespaceUser{NamespaceID: gp.Namespace.ID}.GetAllUserByNamespaceID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -23,7 +23,29 @@ type NamespaceUser struct {
|
|||||||
// NamespaceUsers -
|
// NamespaceUsers -
|
||||||
type NamespaceUsers []NamespaceUser
|
type NamespaceUsers []NamespaceUser
|
||||||
|
|
||||||
// GetBindUserListByNamespaceID -
|
func (nu NamespaceUser) GetUserNamespaceList() (NamespaceUsers, error) {
|
||||||
|
rows, err := sq.
|
||||||
|
Select("namespace_id, namespace.name, namespace_user.role").
|
||||||
|
From(namespaceUserTable).
|
||||||
|
Join(namespaceTable + " ON namespace_user.namespace_id = namespace.id").
|
||||||
|
Where(sq.Eq{"user_id": nu.UserID}).
|
||||||
|
RunWith(DB).
|
||||||
|
Query()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
namespaceUsers := NamespaceUsers{}
|
||||||
|
for rows.Next() {
|
||||||
|
var namespaceUser NamespaceUser
|
||||||
|
|
||||||
|
if err := rows.Scan(&namespaceUser.NamespaceID, &namespaceUser.NamespaceName, &namespaceUser.Role); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
namespaceUsers = append(namespaceUsers, namespaceUser)
|
||||||
|
}
|
||||||
|
return namespaceUsers, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (nu NamespaceUser) GetBindUserListByNamespaceID() (NamespaceUsers, error) {
|
func (nu NamespaceUser) GetBindUserListByNamespaceID() (NamespaceUsers, error) {
|
||||||
rows, err := sq.
|
rows, err := sq.
|
||||||
Select("namespace_user.id, namespace_id, user_id, user.name, namespace_user.role, namespace_user.insert_time, namespace_user.update_time").
|
Select("namespace_user.id, namespace_id, user_id, user.name, namespace_user.role, namespace_user.insert_time, namespace_user.update_time").
|
||||||
@ -47,7 +69,6 @@ func (nu NamespaceUser) GetBindUserListByNamespaceID() (NamespaceUsers, error) {
|
|||||||
return namespaceUsers, nil
|
return namespaceUsers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllUserByNamespaceID -
|
|
||||||
func (nu NamespaceUser) GetAllUserByNamespaceID() (NamespaceUsers, error) {
|
func (nu NamespaceUser) GetAllUserByNamespaceID() (NamespaceUsers, error) {
|
||||||
rows, err := sq.
|
rows, err := sq.
|
||||||
Select("user_id, user.name, namespace_user.role").
|
Select("user_id, user.name, namespace_user.role").
|
||||||
@ -71,7 +92,6 @@ func (nu NamespaceUser) GetAllUserByNamespaceID() (NamespaceUsers, error) {
|
|||||||
return namespaceUsers, nil
|
return namespaceUsers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllGteManagerByNamespaceID -
|
|
||||||
func (nu NamespaceUser) GetAllGteManagerByNamespaceID() (NamespaceUsers, error) {
|
func (nu NamespaceUser) GetAllGteManagerByNamespaceID() (NamespaceUsers, error) {
|
||||||
rows, err := sq.
|
rows, err := sq.
|
||||||
Select("user_id, role").
|
Select("user_id, role").
|
||||||
@ -97,7 +117,6 @@ func (nu NamespaceUser) GetAllGteManagerByNamespaceID() (NamespaceUsers, error)
|
|||||||
return namespaceUsers, nil
|
return namespaceUsers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddMany -
|
|
||||||
func (nu NamespaceUsers) AddMany() error {
|
func (nu NamespaceUsers) AddMany() error {
|
||||||
if len(nu) == 0 {
|
if len(nu) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@ -113,7 +132,6 @@ func (nu NamespaceUsers) AddMany() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAdminByNamespaceID -
|
|
||||||
func (nu NamespaceUser) AddAdminByNamespaceID() error {
|
func (nu NamespaceUser) AddAdminByNamespaceID() error {
|
||||||
|
|
||||||
builder := sq.
|
builder := sq.
|
||||||
@ -127,7 +145,6 @@ func (nu NamespaceUser) AddAdminByNamespaceID() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAdminByUserID -
|
|
||||||
func (nu NamespaceUser) AddAdminByUserID() error {
|
func (nu NamespaceUser) AddAdminByUserID() error {
|
||||||
builder := sq.
|
builder := sq.
|
||||||
Replace(namespaceUserTable).
|
Replace(namespaceUserTable).
|
||||||
@ -139,7 +156,6 @@ func (nu NamespaceUser) AddAdminByUserID() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteRow -
|
|
||||||
func (nu NamespaceUser) DeleteRow() error {
|
func (nu NamespaceUser) DeleteRow() error {
|
||||||
_, err := sq.
|
_, err := sq.
|
||||||
Delete(namespaceUserTable).
|
Delete(namespaceUserTable).
|
||||||
@ -149,7 +165,6 @@ func (nu NamespaceUser) DeleteRow() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteByUserID -
|
|
||||||
func (nu NamespaceUser) DeleteByUserID() error {
|
func (nu NamespaceUser) DeleteByUserID() error {
|
||||||
_, err := sq.
|
_, err := sq.
|
||||||
Delete(namespaceUserTable).
|
Delete(namespaceUserTable).
|
||||||
|
@ -3,7 +3,7 @@ import { ElMessageBox, ElMessage } from 'element-plus'
|
|||||||
import {
|
import {
|
||||||
NamespaceKey,
|
NamespaceKey,
|
||||||
getNamespaceId,
|
getNamespaceId,
|
||||||
removeNamespaceId,
|
removeNamespace,
|
||||||
} from '@/utils/namespace'
|
} from '@/utils/namespace'
|
||||||
import { logout } from '@/utils/auth'
|
import { logout } from '@/utils/auth'
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ service.interceptors.response.use(
|
|||||||
})
|
})
|
||||||
return Promise.reject(res.message)
|
return Promise.reject(res.message)
|
||||||
} else if (10002 === res.code) {
|
} else if (10002 === res.code) {
|
||||||
removeNamespaceId()
|
removeNamespace()
|
||||||
return Promise.reject(res.message)
|
return Promise.reject(res.message)
|
||||||
} else {
|
} else {
|
||||||
ElMessage({
|
ElMessage({
|
||||||
|
@ -56,6 +56,15 @@ export class NamespaceUserOption extends Request {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class NamespaceOption extends Request {
|
||||||
|
readonly url = '/namespace/getOption'
|
||||||
|
readonly method = 'get'
|
||||||
|
|
||||||
|
public datagram!: {
|
||||||
|
list: NamespaceUserData['datagram'][]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class NamespaceUserList extends Request {
|
export class NamespaceUserList extends Request {
|
||||||
readonly url = '/namespace/getBindUserList'
|
readonly url = '/namespace/getBindUserList'
|
||||||
readonly method = 'get'
|
readonly method = 'get'
|
||||||
|
@ -11,7 +11,6 @@ export interface HttpResponse<T> {
|
|||||||
export interface Pagination {
|
export interface Pagination {
|
||||||
page: number
|
page: number
|
||||||
rows: number
|
rows: number
|
||||||
// total: number
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Total {
|
export interface Total {
|
||||||
|
@ -11,19 +11,20 @@
|
|||||||
trigger="click"
|
trigger="click"
|
||||||
size="medium"
|
size="medium"
|
||||||
placement="bottom-start"
|
placement="bottom-start"
|
||||||
|
@visible-change="handleNamespaceVisible"
|
||||||
@command="handleNamespaceChange"
|
@command="handleNamespaceChange"
|
||||||
>
|
>
|
||||||
<span class="el-dropdown-link">
|
<span class="el-dropdown-link">
|
||||||
{{ namespace.name }}<i class="el-icon-arrow-down el-icon--right" />
|
{{ namespace.name }}<i class="el-icon-arrow-down el-icon--right" />
|
||||||
</span>
|
</span>
|
||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu>
|
<el-dropdown-menu v-loading="namespaceListLoading">
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
v-for="item in namespaceList"
|
v-for="item in namespaceList"
|
||||||
:key="item.id"
|
:key="item.namespaceId"
|
||||||
:command="item"
|
:command="item"
|
||||||
>
|
>
|
||||||
{{ item.name }}
|
{{ item.namespaceName }}
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</template>
|
</template>
|
||||||
@ -121,12 +122,8 @@ import logo from '@/assets/images/logo.png'
|
|||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import Breadcrumb from '@/components/Breadcrumb/index.vue'
|
import Breadcrumb from '@/components/Breadcrumb/index.vue'
|
||||||
import Hamburger from '@/components/Hamburger/index.vue'
|
import Hamburger from '@/components/Hamburger/index.vue'
|
||||||
import {
|
import { NamespaceOption } from '@/api/namespace'
|
||||||
getNamespace,
|
import { getNamespace, setNamespace, removeNamespace } from '@/utils/namespace'
|
||||||
getNamespaceList,
|
|
||||||
setNamespaceId,
|
|
||||||
removeNamespaceId,
|
|
||||||
} from '@/utils/namespace'
|
|
||||||
import { ElLoading } from 'element-plus'
|
import { ElLoading } from 'element-plus'
|
||||||
import { defineComponent } from 'vue'
|
import { defineComponent } from 'vue'
|
||||||
|
|
||||||
@ -140,26 +137,40 @@ export default defineComponent({
|
|||||||
logo: logo,
|
logo: logo,
|
||||||
starCount: 0,
|
starCount: 0,
|
||||||
forkCount: 0,
|
forkCount: 0,
|
||||||
|
namespaceListLoading: false,
|
||||||
namespace: getNamespace(),
|
namespace: getNamespace(),
|
||||||
namespaceList: getNamespaceList(),
|
namespaceList: [],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
...mapState(['app', 'user']),
|
...mapState(['app', 'user']),
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
// fetch('https://api.github.com/repos/zhenorzz/goploy').then(response => response.json()).then(data => {
|
|
||||||
// this.starCount = data.stargazers_count
|
|
||||||
// this.forkCount = data.forks_count
|
|
||||||
// })
|
|
||||||
document.title = `Goploy-${this.namespace.name}`
|
document.title = `Goploy-${this.namespace.name}`
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
toggleSideBar() {
|
toggleSideBar() {
|
||||||
this.$store.dispatch('app/toggleSideBar')
|
this.$store.dispatch('app/toggleSideBar')
|
||||||
},
|
},
|
||||||
|
handleNamespaceVisible(visible) {
|
||||||
|
if (visible === true) {
|
||||||
|
this.namespaceListLoading = true
|
||||||
|
new NamespaceOption()
|
||||||
|
.request()
|
||||||
|
.then((response) => {
|
||||||
|
this.namespaceList = response.data.list
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.namespaceListLoading = false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
handleNamespaceChange(namespace) {
|
handleNamespaceChange(namespace) {
|
||||||
setNamespaceId(namespace.id.toString())
|
setNamespace({
|
||||||
|
id: namespace.namespaceId,
|
||||||
|
name: namespace.namespaceName,
|
||||||
|
role: namespace.role,
|
||||||
|
})
|
||||||
ElLoading.service({ fullscreen: true })
|
ElLoading.service({ fullscreen: true })
|
||||||
location.reload()
|
location.reload()
|
||||||
},
|
},
|
||||||
@ -171,7 +182,7 @@ export default defineComponent({
|
|||||||
async logout() {
|
async logout() {
|
||||||
await this.$store.dispatch('user/logout')
|
await this.$store.dispatch('user/logout')
|
||||||
await this.$store.dispatch('tagsView/delAllViews')
|
await this.$store.dispatch('tagsView/delAllViews')
|
||||||
removeNamespaceId()
|
removeNamespace()
|
||||||
this.$router.push(`/login`)
|
this.$router.push(`/login`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -221,104 +232,6 @@ export default defineComponent({
|
|||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.github {
|
|
||||||
display: inline-block;
|
|
||||||
line-height: 50px;
|
|
||||||
.github-btn {
|
|
||||||
display: inline-block;
|
|
||||||
font: 700 11px/14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
||||||
height: 20px;
|
|
||||||
overflow: hidden;
|
|
||||||
margin-right: 3px;
|
|
||||||
position: relative;
|
|
||||||
top: 5px;
|
|
||||||
.gh-btn,
|
|
||||||
.gh-count {
|
|
||||||
padding: 2px 5px 2px 4px;
|
|
||||||
color: #333;
|
|
||||||
text-decoration: none;
|
|
||||||
text-shadow: 0 1px 0 #fff;
|
|
||||||
white-space: nowrap;
|
|
||||||
cursor: pointer;
|
|
||||||
border-radius: 3px;
|
|
||||||
}
|
|
||||||
.gh-btn,
|
|
||||||
.gh-count,
|
|
||||||
.gh-ico {
|
|
||||||
float: left;
|
|
||||||
}
|
|
||||||
.gh-btn {
|
|
||||||
background-color: #eee;
|
|
||||||
background-image: linear-gradient(to bottom, #fcfcfc 0, #eee 100%);
|
|
||||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fcfcfc', endColorstr='#eeeeee', GradientType=0);
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
border: 1px solid #d5d5d5;
|
|
||||||
position: relative;
|
|
||||||
&:focus,
|
|
||||||
&:hover {
|
|
||||||
text-decoration: none;
|
|
||||||
background-color: #ddd;
|
|
||||||
background-image: linear-gradient(to bottom, #eee 0, #ddd 100%);
|
|
||||||
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#eeeeee', endColorstr='#dddddd', GradientType=0);
|
|
||||||
border-color: #ccc;
|
|
||||||
}
|
|
||||||
&:active {
|
|
||||||
background-image: none;
|
|
||||||
background-color: #dcdcdc;
|
|
||||||
border-color: #b5b5b5;
|
|
||||||
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.gh-ico {
|
|
||||||
width: 14px;
|
|
||||||
height: 14px;
|
|
||||||
margin-right: 4px;
|
|
||||||
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIGlkPSJMYXllcl8xIiB4PSIwcHgiIHk9IjBweCIgd2lkdGg9IjQwcHgiIGhlaWdodD0iNDBweCIgdmlld0JveD0iMTIgMTIgNDAgNDAiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMTIgMTIgNDAgNDAiIHhtbDpzcGFjZT0icHJlc2VydmUiPjxwYXRoIGZpbGw9IiMzMzMzMzMiIGQ9Ik0zMiAxMy40Yy0xMC41IDAtMTkgOC41LTE5IDE5YzAgOC40IDUuNSAxNS41IDEzIDE4YzEgMC4yIDEuMy0wLjQgMS4zLTAuOWMwLTAuNSAwLTEuNyAwLTMuMiBjLTUuMyAxLjEtNi40LTIuNi02LjQtMi42QzIwIDQxLjYgMTguOCA0MSAxOC44IDQxYy0xLjctMS4yIDAuMS0xLjEgMC4xLTEuMWMxLjkgMC4xIDIuOSAyIDIuOSAyYzEuNyAyLjkgNC41IDIuMSA1LjUgMS42IGMwLjItMS4yIDAuNy0yLjEgMS4yLTIuNmMtNC4yLTAuNS04LjctMi4xLTguNy05LjRjMC0yLjEgMC43LTMuNyAyLTUuMWMtMC4yLTAuNS0wLjgtMi40IDAuMi01YzAgMCAxLjYtMC41IDUuMiAyIGMxLjUtMC40IDMuMS0wLjcgNC44LTAuN2MxLjYgMCAzLjMgMC4yIDQuNyAwLjdjMy42LTIuNCA1LjItMiA1LjItMmMxIDIuNiAwLjQgNC42IDAuMiA1YzEuMiAxLjMgMiAzIDIgNS4xYzAgNy4zLTQuNSA4LjktOC43IDkuNCBjMC43IDAuNiAxLjMgMS43IDEuMyAzLjVjMCAyLjYgMCA0LjYgMCA1LjJjMCAwLjUgMC40IDEuMSAxLjMgMC45YzcuNS0yLjYgMTMtOS43IDEzLTE4LjFDNTEgMjEuOSA0Mi41IDEzLjQgMzIgMTMuNHoiLz48L3N2Zz4=);
|
|
||||||
background-size: 100% 100%;
|
|
||||||
background-repeat: no-repeat;
|
|
||||||
}
|
|
||||||
.gh-count {
|
|
||||||
position: relative;
|
|
||||||
display: none;
|
|
||||||
margin-left: 4px;
|
|
||||||
background-color: #fafafa;
|
|
||||||
border: 1px solid #d4d4d4;
|
|
||||||
z-index: 1;
|
|
||||||
display: block;
|
|
||||||
&:focus,
|
|
||||||
&:hover {
|
|
||||||
color: #4183c4;
|
|
||||||
}
|
|
||||||
&:after,
|
|
||||||
&:before {
|
|
||||||
content: '';
|
|
||||||
position: absolute;
|
|
||||||
display: inline-block;
|
|
||||||
width: 0;
|
|
||||||
height: 0;
|
|
||||||
border-color: transparent;
|
|
||||||
border-style: solid;
|
|
||||||
}
|
|
||||||
&:before {
|
|
||||||
top: 50%;
|
|
||||||
left: -2px;
|
|
||||||
margin-top: -3px;
|
|
||||||
border-width: 2px 2px 2px 0;
|
|
||||||
border-right-color: #fafafa;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:after {
|
|
||||||
top: 50%;
|
|
||||||
left: -3px;
|
|
||||||
z-index: -1;
|
|
||||||
margin-top: -4px;
|
|
||||||
border-width: 3px 3px 3px 0;
|
|
||||||
border-right-color: #d4d4d4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.user-menu {
|
.user-menu {
|
||||||
float: right;
|
float: right;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
@ -3,11 +3,7 @@ import { UserState } from './types'
|
|||||||
import { RootState } from '../../types'
|
import { RootState } from '../../types'
|
||||||
import { Login, Info } from '@/api/user'
|
import { Login, Info } from '@/api/user'
|
||||||
import { setLogin, logout } from '@/utils/auth'
|
import { setLogin, logout } from '@/utils/auth'
|
||||||
import {
|
import { getNamespaceId, setNamespace } from '@/utils/namespace'
|
||||||
getNamespaceId,
|
|
||||||
setNamespaceId,
|
|
||||||
setNamespaceList,
|
|
||||||
} from '@/utils/namespace'
|
|
||||||
import { resetRouter } from '@/router'
|
import { resetRouter } from '@/router'
|
||||||
|
|
||||||
const state: UserState = {
|
const state: UserState = {
|
||||||
@ -43,9 +39,8 @@ const actions: ActionTree<UserState, RootState> = {
|
|||||||
const { data } = response
|
const { data } = response
|
||||||
if (!getNamespaceId()) {
|
if (!getNamespaceId()) {
|
||||||
const namespace = data.namespaceList[data.namespaceList.length - 1]
|
const namespace = data.namespaceList[data.namespaceList.length - 1]
|
||||||
setNamespaceId(namespace.id.toString())
|
setNamespace(namespace)
|
||||||
}
|
}
|
||||||
setNamespaceList(data.namespaceList)
|
|
||||||
|
|
||||||
setLogin('ok')
|
setLogin('ok')
|
||||||
resolve(response)
|
resolve(response)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
export const NamespaceKey = 'G-N-ID'
|
export const NamespaceKey = 'G-N-ID'
|
||||||
const NamespaceListKey = 'goploy_namespace_list'
|
|
||||||
|
|
||||||
export interface Namespace {
|
export interface Namespace {
|
||||||
id: number
|
id: number
|
||||||
@ -42,37 +41,22 @@ export function getRole() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getNamespace(): Namespace {
|
export function getNamespace(): Namespace {
|
||||||
const namespaceId = getNamespaceId()
|
const n =
|
||||||
const namespaceList = getNamespaceList()
|
|
||||||
if (namespaceId && namespaceList) {
|
|
||||||
return namespaceList.find(
|
|
||||||
(_) => _.id.toString() === namespaceId
|
|
||||||
) as Namespace
|
|
||||||
}
|
|
||||||
return { id: 0, name: '', role: '' }
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNamespaceId(): string | undefined {
|
|
||||||
const namespaceId =
|
|
||||||
sessionStorage.getItem(NamespaceKey) || localStorage.getItem(NamespaceKey)
|
sessionStorage.getItem(NamespaceKey) || localStorage.getItem(NamespaceKey)
|
||||||
return namespaceId || undefined
|
return n ? JSON.parse(n) : { id: 0, name: '', role: '' }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setNamespaceId(namespaceId: string): void {
|
export function getNamespaceId(): number {
|
||||||
sessionStorage.setItem(NamespaceKey, namespaceId)
|
const namespaceId = getNamespace().id
|
||||||
localStorage.setItem(NamespaceKey, namespaceId)
|
return namespaceId
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeNamespaceId(): void {
|
export function setNamespace(namespace: Namespace): void {
|
||||||
|
sessionStorage.setItem(NamespaceKey, JSON.stringify(namespace))
|
||||||
|
localStorage.setItem(NamespaceKey, JSON.stringify(namespace))
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeNamespace(): void {
|
||||||
sessionStorage.removeItem(NamespaceKey)
|
sessionStorage.removeItem(NamespaceKey)
|
||||||
localStorage.removeItem(NamespaceKey)
|
localStorage.removeItem(NamespaceKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getNamespaceList(): Array<Namespace> {
|
|
||||||
const namespaceList = localStorage.getItem(NamespaceListKey)
|
|
||||||
return namespaceList ? JSON.parse(namespaceList) : []
|
|
||||||
}
|
|
||||||
|
|
||||||
export function setNamespaceList(namespaceList: Array<Namespace>): void {
|
|
||||||
localStorage.setItem(NamespaceListKey, JSON.stringify(namespaceList))
|
|
||||||
}
|
|
||||||
|
@ -215,7 +215,6 @@ export default defineComponent({
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
this.getList()
|
this.getList()
|
||||||
this.getTotal()
|
this.getTotal()
|
||||||
ElMessage.success('Need to login again')
|
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
this.formProps.disabled = this.dialogVisible = false
|
this.formProps.disabled = this.dialogVisible = false
|
||||||
|
@ -54,9 +54,11 @@ export class xterm {
|
|||||||
)
|
)
|
||||||
this.terminal.loadAddon(new AttachAddon(this.websocket))
|
this.terminal.loadAddon(new AttachAddon(this.websocket))
|
||||||
this.websocket.onclose = function (evt) {
|
this.websocket.onclose = function (evt) {
|
||||||
|
if (evt.reason !== '') {
|
||||||
ElMessage.error(evt.reason)
|
ElMessage.error(evt.reason)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public close(): void {
|
public close(): void {
|
||||||
this.terminal.dispose()
|
this.terminal.dispose()
|
||||||
this.websocket.close()
|
this.websocket.close()
|
||||||
|
Loading…
Reference in New Issue
Block a user