提交
This commit is contained in:
1 parent
5b3edb1700
commit
74e5a0f0cf
30 files changed
+9036
-7974
No files matched your search
@@ -4,15 +4,43 @@
|
||||
import { buildTreePathLabelFromFlat } from '@/utils/tree-path'
|
||||
import { fetchStorageSlotSelectOptions } from '@/api/admin'
|
||||
|
||||
export type StorageSlotSelectOption = { id: string; name: string }
|
||||
export type StorageSlotSelectOption = {
|
||||
id: string
|
||||
name: string
|
||||
/** 是否可分配(空格子);已占用项仍展示但应置灰 */
|
||||
available?: boolean
|
||||
}
|
||||
|
||||
export type LoadStorageSlotSelectOptions = {
|
||||
/** 仅返回空格子(编辑时可配合 includeSlotIds 保留当前格) */
|
||||
/** 无关键词初始加载时仅返回空格子(默认 true) */
|
||||
availableOnly?: boolean
|
||||
/** 额外保留在选项中的格子 ID(如编辑态当前储物格) */
|
||||
includeSlotIds?: string[]
|
||||
}
|
||||
|
||||
function mapRemoteSlotSelectOption(item: Record<string, unknown>): StorageSlotSelectOption {
|
||||
const id = String(item.id || '')
|
||||
const baseName = String(item.name || item.fullSlotCode || item.slot_code || item.slotCode || id)
|
||||
const status = String(item.slotStatus ?? item.slot_status ?? '')
|
||||
const occupied = Number(item.occupiedCount ?? item.occupied_count ?? 0)
|
||||
const available = status === '空' || occupied === 0
|
||||
return {
|
||||
id,
|
||||
name: available ? baseName : `${baseName}(已占用)`,
|
||||
available
|
||||
}
|
||||
}
|
||||
|
||||
/** 下拉项是否应禁用(保留当前已选格便于编辑展示) */
|
||||
export function isStorageSlotSelectOptionDisabled(
|
||||
opt: StorageSlotSelectOption,
|
||||
keepSlotId?: string
|
||||
): boolean {
|
||||
const keep = String(keepSlotId ?? '').trim()
|
||||
if (keep && opt.id === keep) return false
|
||||
return opt.available === false
|
||||
}
|
||||
|
||||
/** 远程检索防抖(毫秒):用户停顿后再请求 */
|
||||
export const STORAGE_SLOT_REMOTE_SEARCH_DEBOUNCE_MS = 1000
|
||||
|
||||
@@ -39,18 +67,20 @@ export async function remoteSearchStorageSlotSelectOptions(
|
||||
.filter(Boolean)
|
||||
.join(',')
|
||||
try {
|
||||
const hasKeyword = !!trimmed
|
||||
const availableOnlyDefault = opts?.availableOnly !== false
|
||||
const res = await fetchStorageSlotSelectOptions({
|
||||
keyword: trimmed || undefined,
|
||||
availableOnly: opts?.availableOnly ? true : undefined,
|
||||
// 无关键词:只列空格子;有关键词:返回全部匹配编号,已占用由前端置灰
|
||||
availableOnly: availableOnlyDefault && !hasKeyword ? true : undefined,
|
||||
includeSlotIds: includeSlotIds || undefined,
|
||||
page: 1,
|
||||
pageSize: STORAGE_SLOT_SELECT_PAGE_SIZE
|
||||
})
|
||||
if (seq !== storageSlotRemoteSearchSeq) return null
|
||||
return (res?.list || []).map((item) => ({
|
||||
id: String(item.id || ''),
|
||||
name: String(item.name || item.fullSlotCode || item.slotCode || item.id || '')
|
||||
}))
|
||||
return (res?.list || []).map((item) =>
|
||||
mapRemoteSlotSelectOption(item as Record<string, unknown>)
|
||||
)
|
||||
} catch {
|
||||
if (seq !== storageSlotRemoteSearchSeq) return null
|
||||
return []
|
||||
@@ -302,7 +332,8 @@ export function ensureStorageSlotsInOptions(
|
||||
seen.add(id)
|
||||
next.unshift({
|
||||
id,
|
||||
name: String(stub.name || id)
|
||||
name: String(stub.name || id),
|
||||
available: true
|
||||
})
|
||||
}
|
||||
return next
|
||||
|
||||
Reference in new issue
Block a user