-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Expand file tree
/
Copy pathindex.vue
More file actions
246 lines (226 loc) · 8.01 KB
/
index.vue
File metadata and controls
246 lines (226 loc) · 8.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<template>
<div class="workspace-manage p-16-24">
<h2 class="mb-16">{{ $t('views.workspace.title') }}</h2>
<el-card style="--el-card-padding: 0">
<div class="flex main-calc-height">
<div class="workspace-left border-r">
<div class="p-24 pb-0">
<div class="flex-between mb-12">
<h4 class="medium">{{ $t('views.workspace.list') }}</h4>
<el-tooltip
effect="dark"
:content="`${$t('common.create')}${$t('views.workspace.title')}`"
placement="top"
>
<el-button
type="primary"
text
@click="createOrUpdateWorkspace()"
v-hasPermission="[RoleConst.ADMIN, PermissionConst.WORKSPACE_CREATE]"
>
<el-icon :size="18"><Plus /></el-icon>
</el-button>
</el-tooltip>
</div>
<el-input
v-model="filterText"
:placeholder="$t('common.search')"
prefix-icon="Search"
clearable
/>
</div>
<div class="list-height-left">
<el-scrollbar v-loading="loading">
<div class="p-8-16">
<common-list
:data="filterList"
@click="clickWorkspace"
:default-active="currentWorkspace?.id"
@mouseenter="mouseenter"
@mouseleave="mouseId = ''"
>
<template #default="{ row }">
<div class="flex-between">
<span class="ellipsis" :title="row.name">{{ row.name }}</span>
<div @click.stop v-show="mouseId === row.id">
<el-dropdown :teleported="false" trigger="click"
v-if="editPermission() || dlePermission()"
>
<el-button text>
<el-icon class="color-secondary">
<MoreFilled />
</el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu style="min-width: 80px">
<el-dropdown-item
@click.stop="createOrUpdateWorkspace(row)"
class="p-8"
v-if="editPermission()"
>
<el-icon><EditPen /></el-icon>
{{ $t('common.rename') }}
</el-dropdown-item>
<el-dropdown-item
@click.stop="deleteWorkspace(row)"
class="border-t p-8"
v-if="dlePermission()"
>
<el-icon><Delete /></el-icon>
{{ $t('common.delete') }}
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</div>
</template>
<template #empty>
<span></span>
</template>
</common-list>
</div>
</el-scrollbar>
</div>
</div>
<!-- 右边 -->
<div class="workspace-right p-24" v-loading="loading">
<div class="flex align-center mb-16">
<h4 class="medium">{{ currentWorkspace?.name }}</h4>
<el-divider direction="vertical" class="mr-8 ml-8" />
<el-icon class="color-input-placeholder"><UserFilled /></el-icon>
<span class="color-input-placeholder ml-4">
{{ currentWorkspace?.user_count }}
</span>
</div>
<Member :currentWorkspace="currentWorkspace" />
</div>
</div>
</el-card>
<CreateOrUpdateWorkspaceDialog ref="createOrUpdateWorkspaceDialogRef" @refresh="refresh" />
</div>
</template>
<script lang="ts" setup>
import { onMounted, ref, watch } from 'vue'
import { t } from '@/locales'
import Member from './component/Member.vue'
import CreateOrUpdateWorkspaceDialog from './component/CreateOrUpdateWorkspaceDialog.vue'
import type { WorkspaceItem } from '@/api/type/workspace'
import { MsgSuccess, MsgConfirm } from '@/utils/message'
import { PermissionConst, RoleConst } from '@/utils/permission/data'
import { hasPermission } from '@/utils/permission/index'
import { loadPermissionApi } from '@/utils/dynamics-api/permission-api.ts'
const filterText = ref('')
const loading = ref(false)
const list = ref<WorkspaceItem[]>([])
const filterList = ref<WorkspaceItem[]>([]) // 搜索过滤后列表
const currentWorkspace = ref<WorkspaceItem>()
async function getWorkspace() {
try {
const res = await loadPermissionApi('workspace').getSystemWorkspaceList(loading)
list.value = res.data
filterList.value = filter(list.value, filterText.value)
} catch (error) {
console.error(error)
}
}
onMounted(async () => {
await getWorkspace()
currentWorkspace.value = list.value[0]
})
const editPermission = () => {
return hasPermission([RoleConst.ADMIN,
PermissionConst.WORKSPACE_EDIT],'OR',)
}
const dlePermission = () => {
return hasPermission([RoleConst.ADMIN,
PermissionConst.WORKSPACE_DELETE],'OR',)
}
async function refresh(workspace?: WorkspaceItem) {
await getWorkspace()
// 创建后选中新建的
if (workspace) {
currentWorkspace.value = workspace
} else {
currentWorkspace.value = list.value.find((item) => item.id === currentWorkspace.value?.id)
}
}
function filter(list: WorkspaceItem[], filterText: string) {
if (!filterText.length) {
return list
}
return list.filter((v: WorkspaceItem) => v.name.toLowerCase().includes(filterText.toLowerCase()))
}
watch(filterText, (val: string) => {
filterList.value = filter(list.value, val)
})
function clickWorkspace(item: WorkspaceItem) {
currentWorkspace.value = item
}
const createOrUpdateWorkspaceDialogRef = ref<InstanceType<typeof CreateOrUpdateWorkspaceDialog>>()
function createOrUpdateWorkspace(item?: WorkspaceItem) {
createOrUpdateWorkspaceDialogRef.value?.open(item)
}
async function check(id: string) {
try {
return await loadPermissionApi('workspace').deleteWorkspaceCheck(id)
} catch (error) {
console.log(error)
}
}
async function deleteWorkspace(item: WorkspaceItem) {
// 判断是否能删除
const res = await check(item.id as string)
const canDelete = res ? res.data.can_delete : true
if (canDelete) {
MsgConfirm(
`${t('views.workspace.delete.confirmTitle')}${item.name} ?`,
t('views.workspace.delete.confirmContent'),
{
confirmButtonText: t('common.confirm'),
confirmButtonClass: 'danger',
},
).then(() => {
loadPermissionApi('workspace')
.deleteWorkspace(item.id as string, loading)
.then(async () => {
MsgSuccess(t('common.deleteSuccess'))
await getWorkspace()
currentWorkspace.value =
item.id === currentWorkspace.value?.id ? list.value[0] : currentWorkspace.value
})
})
} else {
MsgConfirm(
`${t('views.workspace.delete.confirmTitle')}${item.name} ?`,
res ? res.data.message : t('views.workspace.delete.confirmContent'),
{
showConfirmButton: false,
cancelButtonText: t('common.close'),
},
)
}
}
const mouseId = ref('')
function mouseenter(row: any) {
mouseId.value = row.id
}
</script>
<style lang="scss" scoped>
.workspace-manage {
.workspace-left {
box-sizing: border-box;
width: var(--setting-left-width);
min-width: var(--setting-left-width);
.list-height-left {
height: calc(100vh - 255px);
}
}
.workspace-right {
flex: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}
}
</style>