This commit is contained in:
2026-08-06 15:32:02 +08:00
parent 9e7e1afac8
commit 33a0c48b78
22 changed files with 685 additions and 402 deletions
@@ -32,7 +32,7 @@ describe('CarrierRatesView source contract', () => {
expect(source.indexOf("key: 'customerId'")).toBeLessThan(source.indexOf("key: 'rateCode'"))
expect(source).toContain("'aria-label': '所属企业'")
expect(source).toContain('listPlatformTenants')
expect(source).toContain('loadedCustomerId')
expect(source).toContain('masterDataLoaded')
expect(source).not.toContain('PlatformTenantSelector')
expect(source).not.toContain('selectedTenantId')
expect(source).not.toContain('租户')
@@ -69,6 +69,13 @@ describe('CarrierRatesView source contract', () => {
expect(source).toContain('平台仓库或船司资料加载失败')
expect(source).not.toContain('listPlatformPartners(customerId,')
expect(source).not.toContain('所属企业的仓库或船司资料加载失败')
expect(source).toContain('async function loadPlatformMasterData()')
expect(source).not.toContain('loadCustomerMasterData')
})
it('keeps customer rate queries independent from edit-only master data', () => {
expect(source).toContain('await loadRateData(customerId)')
expect(source).not.toContain('loadPlatformMasterData(customerId)')
})
it('inherits QueryToolbar wrapping and full-width mobile controls', () => {
@@ -54,7 +54,7 @@ const access = useAccessPreviewStore()
const customers = ref<PlatformCustomerResource[]>([])
const customersLoading = ref(false)
const customerLoadError = ref<ApiErrorDetails | null>(null)
const loadedCustomerId = ref<string | null>(null)
const masterDataLoaded = ref(false)
const rows = ref<PlatformCarrierRateResource[]>([])
const warehouses = ref<PlatformWarehouseResource[]>([])
const carriers = ref<PlatformPartnerResource[]>([])
@@ -188,12 +188,7 @@ const rules: FormRules<RateForm> = {
effectiveTo: [{ validator: validateEffectiveTo, trigger: 'change' }],
}
watch(() => filters.value.customerId, (customerId) => {
if (customerId === loadedCustomerId.value) return
masterDataSequence += 1
warehouses.value = []
carriers.value = []
loadedCustomerId.value = null
watch(() => filters.value.customerId, () => {
page.value = 1
})
@@ -269,8 +264,8 @@ async function loadRateData(customerId = filters.value.customerId) {
}
}
async function loadCustomerMasterData(customerId: string) {
if (!customerId) return false
async function loadPlatformMasterData() {
if (masterDataLoaded.value) return true
const sequence = ++masterDataSequence
masterDataLoading.value = true
try {
@@ -281,13 +276,13 @@ async function loadCustomerMasterData(customerId: string) {
if (sequence !== masterDataSequence) return false
warehouses.value = warehouseResult.records.map((item) => ({ ...item, id: String(item.id), tenantId: String(item.tenantId) }))
carriers.value = partnerResult.records.map((item) => ({ ...item, id: String(item.id), tenantId: String(item.tenantId), dataScopeId: String(item.dataScopeId) }))
loadedCustomerId.value = customerId
masterDataLoaded.value = true
return true
} catch (error) {
if (sequence === masterDataSequence) {
warehouses.value = []
carriers.value = []
loadedCustomerId.value = null
masterDataLoaded.value = false
ElMessage.error(getApiErrorDetails(error, '平台仓库或船司资料加载失败').message)
}
return false
@@ -307,10 +302,7 @@ async function applyQuery(model: QueryModel) {
status: (model.status || '') as CarrierRateStatus | '',
}
page.value = 1
await Promise.all([
loadRateData(customerId),
customerId && loadedCustomerId.value !== customerId ? loadCustomerMasterData(customerId) : Promise.resolve(true),
])
await loadRateData(customerId)
}
function resetQuery(model: QueryModel) {
@@ -349,8 +341,8 @@ async function openCreate(rate?: PlatformCarrierRateResource) {
ElMessage.warning('新增价格版本需要先选择所属企业')
return
}
if (loadedCustomerId.value !== customerId) {
const loaded = await loadCustomerMasterData(customerId)
if (!masterDataLoaded.value) {
const loaded = await loadPlatformMasterData()
if (!loaded) return
}
editorCustomerId.value = customerId