fix
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
import { request } from "@/api/request";
|
import { request } from "@/api/request";
|
||||||
|
|
||||||
|
/** 获取所有已启用数据中心(下拉,不分页) */
|
||||||
|
export const fetchDatacenterAll = (params?: { keyword?: string }) => {
|
||||||
|
return request.get("/Assets/v1/datacenter/all", { params });
|
||||||
|
};
|
||||||
|
|
||||||
/** 获取数据中心列表(分页) */
|
/** 获取数据中心列表(分页) */
|
||||||
export const fetchDatacenterList = (data?: {
|
export const fetchDatacenterList = (data?: {
|
||||||
page?: number;
|
page?: number;
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ export const fetchRackList = (data?: {
|
|||||||
return request.post("/Assets/v1/rack/list", data || {});
|
return request.post("/Assets/v1/rack/list", data || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** 根据数据中心获取机柜列表(下拉,不分页) */
|
||||||
|
export const fetchRackListByDatacenter = (
|
||||||
|
datacenterId: number,
|
||||||
|
params?: { name?: string }
|
||||||
|
) => {
|
||||||
|
return request.get(`/Assets/v1/rack/datacenter/${datacenterId}`, { params });
|
||||||
|
};
|
||||||
|
|
||||||
/** 获取机柜详情 */
|
/** 获取机柜详情 */
|
||||||
export const fetchRackDetail = (id: number) => {
|
export const fetchRackDetail = (id: number) => {
|
||||||
return request.get(`/Assets/v1/rack/detail/${id}`);
|
return request.get(`/Assets/v1/rack/detail/${id}`);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
v-model="localModel[item.field]"
|
v-model="localModel[item.field]"
|
||||||
:options="item.options"
|
:options="item.options"
|
||||||
:placeholder="item.placeholder || '请选择'"
|
:placeholder="item.placeholder || '请选择'"
|
||||||
|
:disabled="item.disabled"
|
||||||
allow-clear
|
allow-clear
|
||||||
/>
|
/>
|
||||||
<!-- 日期范围选择器 -->
|
<!-- 日期范围选择器 -->
|
||||||
|
|||||||
@@ -7,4 +7,6 @@ export interface FormItem {
|
|||||||
span?: number
|
span?: number
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
options?: SelectOptionData[]
|
options?: SelectOptionData[]
|
||||||
|
/** 仅对 select 生效 */
|
||||||
|
disabled?: boolean
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, reactive, computed } from 'vue'
|
import { ref, reactive, computed, onMounted, watch } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { Message, Modal } from '@arco-design/web-vue'
|
import { Message, Modal } from '@arco-design/web-vue'
|
||||||
import {
|
import {
|
||||||
@@ -202,6 +202,8 @@ import {
|
|||||||
fetchServerList,
|
fetchServerList,
|
||||||
deleteServer,
|
deleteServer,
|
||||||
} from '@/api/ops/server'
|
} from '@/api/ops/server'
|
||||||
|
import { fetchDatacenterAll } from '@/api/ops/datacenter'
|
||||||
|
import { fetchRackListByDatacenter } from '@/api/ops/rack'
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -428,8 +430,74 @@ const pagination = reactive({
|
|||||||
total: 0,
|
total: 0,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 表单项配置
|
const datacenterSelectOptions = ref<{ label: string; value: number }[]>([])
|
||||||
const formItems = computed<FormItem[]>(() => searchFormConfig)
|
const rackSelectOptions = ref<{ label: string; value: number }[]>([])
|
||||||
|
|
||||||
|
const loadDatacenterOptions = async () => {
|
||||||
|
try {
|
||||||
|
const res: any = await fetchDatacenterAll()
|
||||||
|
if (res.code === 0) {
|
||||||
|
const list = res.details?.data ?? res.data ?? res.details ?? []
|
||||||
|
const rows = Array.isArray(list) ? list : []
|
||||||
|
datacenterSelectOptions.value = rows.map((d: any) => ({
|
||||||
|
label: d.name || d.code || String(d.id),
|
||||||
|
value: d.id,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载数据中心列表失败:', error)
|
||||||
|
Message.error('加载数据中心列表失败')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadRackOptions = async (datacenterId: number) => {
|
||||||
|
try {
|
||||||
|
const res: any = await fetchRackListByDatacenter(datacenterId)
|
||||||
|
if (res.code === 0) {
|
||||||
|
const list = res.details?.data ?? res.data ?? res.details ?? []
|
||||||
|
const rows = Array.isArray(list) ? list : []
|
||||||
|
rackSelectOptions.value = rows.map((r: any) => ({
|
||||||
|
label: r.floor?.name ? `${r.name}(${r.floor.name})` : r.name || r.code || String(r.id),
|
||||||
|
value: r.id,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('加载机柜列表失败:', error)
|
||||||
|
Message.error('加载机柜列表失败')
|
||||||
|
rackSelectOptions.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => formModel.value.datacenter_id,
|
||||||
|
(newId, oldId) => {
|
||||||
|
if (newId !== oldId) {
|
||||||
|
formModel.value.rack_id = undefined
|
||||||
|
}
|
||||||
|
if (newId) {
|
||||||
|
loadRackOptions(newId)
|
||||||
|
} else {
|
||||||
|
rackSelectOptions.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// 表单项配置(数据中心:GET /Assets/v1/datacenter/all;机柜:GET /Assets/v1/rack/datacenter/:id)
|
||||||
|
const formItems = computed<FormItem[]>(() =>
|
||||||
|
searchFormConfig.map((item) => {
|
||||||
|
if (item.field === 'datacenter_id') {
|
||||||
|
return { ...item, options: datacenterSelectOptions.value }
|
||||||
|
}
|
||||||
|
if (item.field === 'rack_id') {
|
||||||
|
return {
|
||||||
|
...item,
|
||||||
|
options: rackSelectOptions.value,
|
||||||
|
disabled: !formModel.value.datacenter_id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
// 表格列配置
|
// 表格列配置
|
||||||
const columns = computed(() => columnsConfig)
|
const columns = computed(() => columnsConfig)
|
||||||
@@ -525,6 +593,7 @@ const handleReset = () => {
|
|||||||
rack_id: undefined,
|
rack_id: undefined,
|
||||||
status: undefined,
|
status: undefined,
|
||||||
}
|
}
|
||||||
|
rackSelectOptions.value = []
|
||||||
pagination.current = 1
|
pagination.current = 1
|
||||||
fetchServers()
|
fetchServers()
|
||||||
}
|
}
|
||||||
@@ -625,8 +694,10 @@ const handleDelete = async (record: any) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化加载数据
|
onMounted(() => {
|
||||||
fetchServers()
|
loadDatacenterOptions()
|
||||||
|
fetchServers()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
|||||||
Reference in New Issue
Block a user