Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/daas/src/i18n/langs/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default {
data_import_export_git_operation_records: 'Git Operation Records',
data_import_export_stack_trace: 'Stack Trace',
data_import_export_load_group_failed: 'Failed to load group list',
data_import_export_load_resource_failed: 'Failed to load resource list',
data_import_export_select_at_least_one: 'Please select at least one group',
data_import_export_git_info_required: 'Please configure Git info first',
data_import_export_branch_name: 'Branch Name',
Expand Down
1 change: 1 addition & 0 deletions apps/daas/src/i18n/langs/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default {
data_import_export_git_operation_records: 'Git 操作记录',
data_import_export_stack_trace: '堆栈信息',
data_import_export_load_group_failed: '加载分组列表失败',
data_import_export_load_resource_failed: '加载资源列表失败',
data_import_export_select_at_least_one: '请至少选择一个分组',
data_import_export_git_info_required: '请先配置 Git 信息',
data_import_export_branch_name: '分支名',
Expand Down
1 change: 1 addition & 0 deletions apps/daas/src/i18n/langs/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default {
data_import_export_git_operation_records: 'Git 操作記錄',
data_import_export_stack_trace: '堆疊信息',
data_import_export_load_group_failed: '加載分組列表失敗',
data_import_export_load_resource_failed: '加載資源列表失敗',
data_import_export_select_at_least_one: '請至少選擇一個分組',
data_import_export_git_info_required: '請先配置 Git 信息',
data_import_export_branch_name: '分支名',
Expand Down
87 changes: 71 additions & 16 deletions apps/daas/src/views/data-import-export/ProjectManagement.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import {
createGroupInfo,
deleteGroupInfo,
fetchGroupInfoApis,
fetchGroupInfoList,
fetchGroupInfoTasks,
updateGroupInfo,
type GroupInfoDto,
type ResourceItem,
type ResourceType,
} from '@tap/api/core/group-info'
import { fetchApiModules } from '@tap/api/core/modules'
import { fetchTasks } from '@tap/api/core/task'
import { PageContainer } from '@tap/business'
import TaskStatus from '@tap/business/src/components/TaskStatus.vue'
import { makeStatusAndDisabled } from '@tap/business/src/shared'
Expand Down Expand Up @@ -215,6 +215,23 @@ const handleGroupCommand = (command: string, group: GroupInfoDto) => {
}
}

// 判断资源是否属于其他分组
const isResourceInOtherGroup = (resource: any) => {
return (
resource.groupId &&
selectedGroup.value?.id &&
resource.groupId !== selectedGroup.value.id
)
}

// 点击分组名称跳转到对应分组
const handleNavigateToGroup = (resource: any) => {
const targetGroup = groupList.value.find((g) => g.id === resource.groupId)
if (targetGroup) {
selectedGroup.value = targetGroup
}
}

// 加载资源列表
const loadResources = async () => {
resourceLoading.value = true
Expand All @@ -240,23 +257,25 @@ const loadResources = async () => {
name: item.name,
status: item.status,
type,
groupId: item.groupId || null,
groupName: item.groupName || null,
}
}

switch (type) {
case 'SYNC_TASK':
filter.where.syncType = 'sync'
result = await fetchTasks(filter)
result = await fetchGroupInfoTasks(filter)
resourceList.value = result.items.map(mapTask)
break
case 'MIGRATE_TASK':
filter.where.syncType = 'migrate'
result = await fetchTasks(filter)
result = await fetchGroupInfoTasks(filter)
resourceList.value = result.items.map(mapTask)
break
case 'MODULE':
result = await fetchApiModules(filter)
resourceList.value = result.items.map((item) => {
result = await fetchGroupInfoApis(filter)
resourceList.value = result.items.map((item: any) => {
const pathJoin: string[] = []
item.apiVersion && pathJoin.push(item.apiVersion)
item.prefix && pathJoin.push(item.prefix)
Expand All @@ -266,14 +285,17 @@ const loadResources = async () => {
name: item.name,
path: `/${pathJoin.join('/')}`,
type,
groupId: item.groupId || null,
groupName: item.groupName || null,
}
})
break
}

totalCount.value = result?.total || 0
} catch {
ElMessage.error('加载资源列表失败')
} catch (error) {
ElMessage.error(t('data_import_export_load_resource_failed'))
console.error(error)
} finally {
resourceLoading.value = false
}
Expand All @@ -284,9 +306,14 @@ const isResourceAdded = (id: string) => {
return addedResources.value.some((item) => item.id === id)
}

// 判断资源是否不可操作(已添加或属于其他分组)
const isResourceDisabled = (resource: any) => {
return isResourceAdded(resource.id) || isResourceInOtherGroup(resource)
}

// 切换资源选中状态
const toggleResourceSelection = (resource: any) => {
if (isResourceAdded(resource.id)) {
if (isResourceDisabled(resource)) {
return
}
const index = selectedResources.value.indexOf(resource.id)
Expand Down Expand Up @@ -490,7 +517,7 @@ onMounted(() => {
// 全选/取消全选可用资源
const isAllSelected = computed(() => {
const availableResources = resourceList.value.filter(
(item) => !isResourceAdded(item.id),
(item) => !isResourceDisabled(item),
)
return (
availableResources.length > 0 &&
Expand All @@ -503,7 +530,7 @@ const isAllSelected = computed(() => {
const handleSelectAll = (checked: any) => {
if (checked) {
const availableResources = resourceList.value.filter(
(item) => !isResourceAdded(item.id),
(item) => !isResourceDisabled(item),
)
selectedResources.value = availableResources.map((item) => item.id)
} else {
Expand Down Expand Up @@ -689,13 +716,16 @@ const handleSelectAll = (checked: any) => {
v-for="resource in resourceList"
:key="resource.id"
class="resource-item rounded-xl"
:class="{ 'is-disabled': isResourceAdded(resource.id) }"
:class="{
'is-disabled': isResourceDisabled(resource),
'is-other-group': isResourceInOtherGroup(resource),
}"
@click="toggleResourceSelection(resource)"
>
<el-checkbox
v-model="selectedResources"
:label="resource.id"
:disabled="isResourceAdded(resource.id)"
:disabled="isResourceDisabled(resource)"
@click.stop
>
<div class="resource-content">
Expand All @@ -711,8 +741,18 @@ const handleSelectAll = (checked: any) => {
<TaskStatus v-else :task="resource" class="zoom-xs" />
</div>
</el-checkbox>
<el-tag
v-if="isResourceInOtherGroup(resource)"
type="warning"
class="group-tag"
disable-transitions
@click.stop="handleNavigateToGroup(resource)"
>
<el-icon class="mr-1"><i-lucide-folder /></el-icon>
{{ resource.groupName }}
</el-tag>
<el-button
v-if="!isResourceAdded(resource.id)"
v-else-if="!isResourceAdded(resource.id)"
text
class="add-btn"
@click.stop="addSingleResource(resource)"
Expand Down Expand Up @@ -767,8 +807,8 @@ const handleSelectAll = (checked: any) => {

<!-- 右侧:已选资源树 -->
<div class="selected-panel">
<div class="panel-header p-3">
<span class="fw-sub font-color-dark lh-6">{{
<div class="panel-header p-3" style="height: 49px">
<span class="fw-sub font-color-dark">{{
t('data_import_export_selected')
}}</span>
<div class="flex gap-2" style="--btn-space: 0">
Expand Down Expand Up @@ -1049,6 +1089,21 @@ const handleSelectAll = (checked: any) => {
background-color: var(--el-fill-color-lighter);
}

&.is-other-group {
opacity: 0.7;
border-color: var(--el-color-warning-light-5);
background-color: var(--el-color-warning-light-9);
}

.group-tag {
cursor: pointer;
flex-shrink: 0;

&:hover {
opacity: 0.8;
}
}

.resource-content {
display: flex;
align-items: center;
Expand Down
22 changes: 22 additions & 0 deletions packages/api/src/core/group-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,25 @@ export function fetchGroupInfoRecordList(filter?: Filter) {
export function fetchLastestGitTag(groupId: string) {
return requestClient.get(`${BASE_URL}/lastestGitTag/${groupId}`)
}

/**
* 获取带有分组信息的任务列表
*/
export function fetchGroupInfoTasks(filter?: any) {
return requestClient.get<PageFetchResult<any>>(`${BASE_URL}/tasks`, {
params: {
filter: filter ? JSON.stringify(filter) : undefined,
},
})
}

/**
* 获取带有分组信息的 API(模块)列表
*/
export function fetchGroupInfoApis(filter?: any) {
return requestClient.get<PageFetchResult<any>>(`${BASE_URL}/apis`, {
params: {
filter: filter ? JSON.stringify(filter) : undefined,
},
})
}
Loading