This commit is contained in:
2026-08-04 09:05:19 +08:00
parent fa922ca96f
commit 815d4e8daf
21 changed files with 994 additions and 128 deletions
@@ -96,7 +96,7 @@ function normalizePartner(resource: PlatformPartnerResource): PlatformPartnerRes
}
}
export async function listPlatformPartners(tenantId: number, query: PlatformPartnerQuery) {
export async function listPlatformPartners(tenantId: number | string, query: PlatformPartnerQuery) {
const response = await http.get<ApiEnvelope<PlatformPartnerPagePayload>, ApiEnvelope<PlatformPartnerPagePayload>>(basePath, {
params: { tenantId, ...query },
})
@@ -111,7 +111,7 @@ export async function listPlatformPartners(tenantId: number, query: PlatformPart
}
}
export async function getPlatformPartner(tenantId: number, partnerId: number | string) {
export async function getPlatformPartner(tenantId: number | string, partnerId: number | string) {
const response = await http.get<ApiEnvelope<PlatformPartnerResource>, ApiEnvelope<PlatformPartnerResource>>(
`${basePath}/${partnerId}`,
{ params: { tenantId } },
@@ -123,7 +123,7 @@ export async function downloadPlatformPartnerImportTemplate() {
return http.get<Blob, Blob>(`${basePath}/import-template`, { responseType: 'blob' })
}
export async function importPlatformPartners(tenantId: number, file: File) {
export async function importPlatformPartners(tenantId: number | string, file: File) {
const form = new FormData()
form.append('file', file)
const response = await http.post<ApiEnvelope<PlatformPartnerImportResult>, ApiEnvelope<PlatformPartnerImportResult>>(
@@ -134,7 +134,7 @@ export async function importPlatformPartners(tenantId: number, file: File) {
return unwrapApiResponse(response)
}
export async function createPlatformPartner(tenantId: number, payload: SavePlatformPartnerRequest) {
export async function createPlatformPartner(tenantId: number | string, payload: SavePlatformPartnerRequest) {
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload, {
params: { tenantId },
})
@@ -142,7 +142,7 @@ export async function createPlatformPartner(tenantId: number, payload: SavePlatf
}
export async function updatePlatformPartner(
tenantId: number,
tenantId: number | string,
partnerId: number | string,
payload: SavePlatformPartnerRequest,
) {
@@ -153,7 +153,7 @@ export async function updatePlatformPartner(
}
export async function changePlatformPartnerStatus(
tenantId: number,
tenantId: number | string,
partnerId: number | string,
status: PlatformPartnerStatus,
) {
@@ -8,6 +8,8 @@ import {
} from '@/modules/master-data/counterparties/api/platformPartners'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { useAuthStore } from '@/core/auth/auth'
import { listPlatformTenants, type PlatformTenantResource } from '../../../iam/api/platformIam'
import PlatformTenantSelector from '../../../iam/components/PlatformTenantSelector.vue'
import PartnersView from './PartnersView.vue'
vi.mock('@/modules/master-data/counterparties/api/platformPartners', () => ({
@@ -20,6 +22,8 @@ vi.mock('@/modules/master-data/counterparties/api/platformPartners', () => ({
changePlatformPartnerStatus: vi.fn(),
}))
vi.mock('../../../iam/api/platformIam', () => ({ listPlatformTenants: vi.fn() }))
class ResizeObserverStub implements ResizeObserver {
observe() {}
unobserve() {}
@@ -60,6 +64,16 @@ const partner: PlatformPartnerResource = {
updatedAt: '2026-07-30T22:45:00',
}
const tenant = (id: number | string, tenantName: string): PlatformTenantResource => ({
id, tenantCode: String(id), tenantName, status: 'ACTIVE', legalName: tenantName,
legalRepresentative: null, unifiedSocialCreditCode: null, contactName: null,
contactPhone: null, contactEmail: null, servicePackage: null, contactWechat: null,
salesOwnerName: null, paymentTermDays: null, enterpriseType: null, establishedDate: null,
registeredCapital: null, registeredCapitalCurrency: null, registeredAddress: null,
internalRemark: null, createdAt: null, approvedAt: null,
})
const snowflakeTenantId = '9223372036854775806'
async function mountView() {
vi.stubGlobal('localStorage', createMemoryStorage())
vi.stubGlobal('sessionStorage', createMemoryStorage())
@@ -89,6 +103,9 @@ describe('PartnersView real API integration', () => {
beforeEach(() => {
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
document.body.innerHTML = ''
vi.mocked(listPlatformTenants).mockReset().mockResolvedValue({
records: [tenant(10001, '默认企业'), tenant(snowflakeTenantId, '雪花企业')], page: 1, size: 200, total: 2, pages: 1,
})
vi.mocked(listPlatformPartners).mockReset().mockResolvedValue({
records: [partner], page: 1, size: 20, total: 1, pages: 1,
})
@@ -111,6 +128,17 @@ describe('PartnersView real API integration', () => {
expect(wrapper.find('.table-panel').exists()).toBe(true)
})
it('preserves a snowflake tenant id as a string when switching enterprises', async () => {
const wrapper = await mountView()
wrapper.findComponent(PlatformTenantSelector).vm.$emit('update:modelValue', snowflakeTenantId)
await flushPromises()
expect(listPlatformPartners).toHaveBeenLastCalledWith(snowflakeTenantId, {
page: 1, size: 20, keyword: undefined, type: undefined, status: undefined,
})
})
it('updates filters locally and only requests after search', async () => {
const wrapper = await mountView()
const keywordInput = wrapper.find('input[placeholder="单位名称、编码、联系人或电话"]')
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { computed, reactive, ref, watch } from 'vue'
import { ElMessage, ElMessageBox, type FormInstance, type FormRules, type UploadFile } from 'element-plus'
import { Building2, Download, Eye, MapPin, Pencil, Plus, Power, Upload } from '@lucide/vue'
import ApiErrorMeta from '@/shared/components/ApiErrorMeta.vue'
@@ -23,8 +23,8 @@ import {
type SavePlatformPartnerRequest,
} from '@/modules/master-data/counterparties/api/platformPartners'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { PlatformTenantSelector } from '@/modules/iam'
const fixedTenantId = 10001
const pageSize = ref(20)
const access = useAccessPreviewStore()
const loading = ref(false)
@@ -42,8 +42,11 @@ const formRef = ref<FormInstance>()
const rows = ref<PlatformPartnerResource[]>([])
const page = ref(1)
const total = ref(0)
const selectedTenantId = ref('')
const loadedTenantId = ref<string | null>(null)
const loadError = ref<ApiErrorDetails | null>(null)
const statusLoadingIds = ref(new Set<string>())
let loadSequence = 0
type PartnerFilters = QueryModel & {
keyword: string
@@ -116,6 +119,17 @@ const { captureBaseline } = useUnsavedWorkRegistration({
requiredPermission: editorPermission,
})
const tenantReady = computed(() => Boolean(selectedTenantId.value)
&& loadedTenantId.value === selectedTenantId.value
&& !loading.value)
const tenantSwitchDisabled = computed(() => editorOpen.value
|| detailOpen.value
|| importOpen.value
|| saving.value
|| detailLoading.value
|| importing.value
|| statusLoadingIds.value.size > 0)
const rules: FormRules<PartnerForm> = {
partnerCode: [{ required: true, whitespace: true, message: '请输入往来单位编码', trigger: 'blur' }],
partnerName: [{ required: true, whitespace: true, message: '请输入往来单位名称', trigger: 'blur' }],
@@ -174,17 +188,37 @@ function queryParams() {
}
}
async function loadPartners() {
function apiTenantId(value: string) {
const numeric = Number(value)
return Number.isSafeInteger(numeric) ? numeric : value
}
function requireCurrentTenant() {
if (!tenantReady.value) {
ElMessage.warning('往来单位数据尚未加载完成,请稍后重试')
return null
}
return apiTenantId(selectedTenantId.value)
}
async function loadPartners(tenantId = selectedTenantId.value) {
if (!tenantId) return
const sequence = ++loadSequence
loading.value = true
loadError.value = null
try {
const result = await listPlatformPartners(fixedTenantId, queryParams())
const result = await listPlatformPartners(apiTenantId(tenantId), queryParams())
if (sequence !== loadSequence) return
rows.value = result.records
total.value = result.total
loadedTenantId.value = tenantId
} catch (error) {
if (sequence !== loadSequence) return
rows.value = []
total.value = 0
loadError.value = getApiErrorDetails(error, '往来单位加载失败,请稍后重试')
} finally {
loading.value = false
if (sequence === loadSequence) loading.value = false
}
}
@@ -202,6 +236,7 @@ function searchPartners(model: QueryModel) {
}
function openCreate() {
if (!requireCurrentTenant()) return
Object.assign(form, emptyForm())
captureBaseline()
editorOpen.value = true
@@ -213,6 +248,7 @@ function nullable(value: string | null) {
}
function openEdit(row: PlatformPartnerResource) {
if (!requireCurrentTenant()) return
Object.assign(form, {
id: String(row.id),
partnerCode: row.partnerCode,
@@ -258,11 +294,13 @@ function savePayload(): SavePlatformPartnerRequest {
}
async function openDetail(row: PlatformPartnerResource) {
const tenantId = requireCurrentTenant()
if (!tenantId) return
detailOpen.value = true
detailLoading.value = true
detail.value = null
try {
detail.value = await getPlatformPartner(fixedTenantId, row.id)
detail.value = await getPlatformPartner(tenantId, row.id)
} catch (error) {
const meta = getApiErrorDetails(error, '往来单位详情加载失败')
ElMessage.error(meta.requestId ? `${meta.message}(requestId: ${meta.requestId})` : meta.message)
@@ -305,6 +343,8 @@ async function downloadTemplate() {
}
async function submitImport() {
const tenantId = requireCurrentTenant()
if (!tenantId) return
if (!importFile.value) {
ElMessage.warning('请先选择 XLSX 文件')
return
@@ -312,7 +352,7 @@ async function submitImport() {
importing.value = true
importResult.value = null
try {
importResult.value = await importPlatformPartners(fixedTenantId, importFile.value)
importResult.value = await importPlatformPartners(tenantId, importFile.value)
if (importResult.value.success) {
ElMessage.success(`成功导入 ${importResult.value.importedRows} 条往来单位`)
await loadPartners()
@@ -342,16 +382,18 @@ function downloadImportErrors() {
}
async function savePartner() {
const tenantId = requireCurrentTenant()
if (!tenantId) return
const valid = await formRef.value?.validate().catch(() => false)
if (!valid) return
saving.value = true
try {
const payload = savePayload()
if (form.id) {
await updatePlatformPartner(fixedTenantId, form.id, payload)
await updatePlatformPartner(tenantId, form.id, payload)
ElMessage.success('往来单位已更新')
} else {
await createPlatformPartner(fixedTenantId, payload)
await createPlatformPartner(tenantId, payload)
ElMessage.success('往来单位已新增')
}
editorOpen.value = false
@@ -365,6 +407,8 @@ async function savePartner() {
}
async function toggleStatus(row: PlatformPartnerResource) {
const tenantId = requireCurrentTenant()
if (!tenantId) return
const nextStatus: PlatformPartnerStatus = row.status === 'ACTIVE' ? 'INACTIVE' : 'ACTIVE'
const action = nextStatus === 'ACTIVE' ? '启用' : '停用'
try {
@@ -379,7 +423,7 @@ async function toggleStatus(row: PlatformPartnerResource) {
const id = String(row.id)
statusLoadingIds.value = new Set(statusLoadingIds.value).add(id)
try {
await changePlatformPartnerStatus(fixedTenantId, row.id, nextStatus)
await changePlatformPartnerStatus(tenantId, row.id, nextStatus)
ElMessage.success(`往来单位已${action}`)
await loadPartners()
} catch (error) {
@@ -397,12 +441,24 @@ function formatUpdatedAt(value?: string | null) {
}
watch([page, pageSize], () => { void loadPartners() })
onMounted(loadPartners)
watch(selectedTenantId, (tenantId) => {
editorOpen.value = false
detailOpen.value = false
importOpen.value = false
detail.value = null
importFile.value = null
importResult.value = null
rows.value = []
total.value = 0
loadedTenantId.value = null
page.value = 1
void loadPartners(tenantId)
})
</script>
<template>
<div class="business-page partners-page">
<PlatformTenantSelector v-model="selectedTenantId" :disabled="tenantSwitchDisabled" />
<QueryToolbar v-model="filters" class="surface-panel" ariaLabel="往来单位筛选" :fields="queryFields" @search="searchPartners" />
<section v-if="loadError" class="surface-panel partners-error" role="alert">
@@ -411,18 +467,18 @@ onMounted(loadPartners)
<p>{{ loadError.message }}</p>
<ApiErrorMeta :details="loadError" />
</div>
<el-button type="primary" :loading="loading" @click="loadPartners">重新加载</el-button>
<el-button type="primary" :loading="loading" @click="loadPartners()">重新加载</el-button>
</section>
<section v-else class="surface-panel table-panel" :aria-busy="loading">
<div class="partners-table-header">
<div class="partners-table-heading">
<h2>往来单位列表</h2>
<span>共 {{ total }} 个往来单位</span>
<span>租户 {{ selectedTenantId || '—' }} · 共 {{ total }} 个往来单位</span>
</div>
<div class="partners-primary-actions">
<el-button v-if="access.can('platform:counterparty:import')" :disabled="loading" @click="openImport"><Upload :size="16" />批量导入</el-button>
<el-button v-if="access.can('platform:counterparty:create')" type="primary" :disabled="loading" @click="openCreate"><Plus :size="16" />新增往来单位</el-button>
<el-button v-if="access.can('platform:counterparty:import')" :disabled="loading || !tenantReady" @click="openImport"><Upload :size="16" />批量导入</el-button>
<el-button v-if="access.can('platform:counterparty:create')" type="primary" :disabled="loading || !tenantReady" @click="openCreate"><Plus :size="16" />新增往来单位</el-button>
</div>
</div>
<DataTable
@@ -440,8 +496,8 @@ onMounted(loadPartners)
<template #actions="{ row }">
<div class="table-actions">
<el-button link type="primary" @click="openDetail(row as PlatformPartnerResource)"><Eye :size="15" />详情</el-button>
<el-button v-if="access.can('platform:counterparty:edit')" link type="primary" @click="openEdit(row as PlatformPartnerResource)"><Pencil :size="15" />编辑</el-button>
<el-button v-if="access.can('platform:counterparty:status')" link :type="(row as PlatformPartnerResource).status === 'ACTIVE' ? 'danger' : 'success'" :loading="statusLoadingIds.has(String((row as PlatformPartnerResource).id))" @click="toggleStatus(row as PlatformPartnerResource)"><Power :size="15" />{{ (row as PlatformPartnerResource).status === 'ACTIVE' ? '停用' : '启用' }}</el-button>
<el-button v-if="access.can('platform:counterparty:edit')" link type="primary" :disabled="!tenantReady" @click="openEdit(row as PlatformPartnerResource)"><Pencil :size="15" />编辑</el-button>
<el-button v-if="access.can('platform:counterparty:status')" link :disabled="!tenantReady" :type="(row as PlatformPartnerResource).status === 'ACTIVE' ? 'danger' : 'success'" :loading="statusLoadingIds.has(String((row as PlatformPartnerResource).id))" @click="toggleStatus(row as PlatformPartnerResource)"><Power :size="15" />{{ (row as PlatformPartnerResource).status === 'ACTIVE' ? '停用' : '启用' }}</el-button>
</div>
</template>
<template #partner="{ row }"><div class="partner-cell"><span><Building2 :size="18" /></span><div><strong>{{ (row as PlatformPartnerResource).partnerName }}</strong><small>{{ (row as PlatformPartnerResource).partnerCode }}</small></div></div></template>
@@ -51,7 +51,7 @@ export interface PlatformExpressCompanyImportResult {
const basePath = '/platform/v1/express-companies'
export async function listPlatformExpressCompanies(
tenantId: number,
tenantId: number | string,
page = 1,
size = 20,
keyword = '',
@@ -76,7 +76,7 @@ export async function listPlatformExpressCompanies(
}
}
export async function getPlatformExpressCompany(tenantId: number, id: number | string) {
export async function getPlatformExpressCompany(tenantId: number | string, id: number | string) {
const response = await http.get<ApiEnvelope<PlatformExpressCompanyResource>, ApiEnvelope<PlatformExpressCompanyResource>>(
`${basePath}/${id}`,
{ params: { tenantId } },
@@ -84,7 +84,7 @@ export async function getPlatformExpressCompany(tenantId: number, id: number | s
return unwrapApiResponse(response)
}
export async function createPlatformExpressCompany(tenantId: number, payload: SavePlatformExpressCompanyRequest) {
export async function createPlatformExpressCompany(tenantId: number | string, payload: SavePlatformExpressCompanyRequest) {
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload, {
params: { tenantId },
})
@@ -92,7 +92,7 @@ export async function createPlatformExpressCompany(tenantId: number, payload: Sa
}
export async function updatePlatformExpressCompany(
tenantId: number,
tenantId: number | string,
id: number | string,
payload: SavePlatformExpressCompanyRequest,
) {
@@ -103,7 +103,7 @@ export async function updatePlatformExpressCompany(
}
export async function changePlatformExpressCompanyStatus(
tenantId: number,
tenantId: number | string,
id: number | string,
status: PlatformExpressCompanyStatus,
) {
@@ -117,7 +117,7 @@ export async function downloadPlatformExpressCompanyImportTemplate() {
return http.get<Blob, Blob>(`${basePath}/import-template`, { responseType: 'blob' })
}
export async function importPlatformExpressCompanies(tenantId: number, file: File) {
export async function importPlatformExpressCompanies(tenantId: number | string, file: File) {
const formData = new FormData()
formData.append('file', file)
const response = await http.post<ApiEnvelope<PlatformExpressCompanyImportResult>, ApiEnvelope<PlatformExpressCompanyImportResult>>(
@@ -5,6 +5,8 @@ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vites
import { listPlatformExpressCompanies, type PlatformExpressCompanyResource } from '@/modules/master-data/express-companies/api/platformExpressCompanies'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { useAuthStore } from '@/core/auth/auth'
import { listPlatformTenants, type PlatformTenantResource } from '../../../iam/api/platformIam'
import PlatformTenantSelector from '../../../iam/components/PlatformTenantSelector.vue'
import ExpressCompaniesView from './ExpressCompaniesView.vue'
vi.mock('@/modules/master-data/express-companies/api/platformExpressCompanies', () => ({
@@ -14,6 +16,8 @@ vi.mock('@/modules/master-data/express-companies/api/platformExpressCompanies',
changePlatformExpressCompanyStatus: vi.fn(),
}))
vi.mock('../../../iam/api/platformIam', () => ({ listPlatformTenants: vi.fn() }))
class ResizeObserverStub implements ResizeObserver {
observe() {}
unobserve() {}
@@ -45,6 +49,16 @@ const company: PlatformExpressCompanyResource = {
updatedAt: '2026-07-31T10:20:00',
}
const tenant = (id: number | string, tenantName: string): PlatformTenantResource => ({
id, tenantCode: String(id), tenantName, status: 'ACTIVE', legalName: tenantName,
legalRepresentative: null, unifiedSocialCreditCode: null, contactName: null,
contactPhone: null, contactEmail: null, servicePackage: null, contactWechat: null,
salesOwnerName: null, paymentTermDays: null, enterpriseType: null, establishedDate: null,
registeredCapital: null, registeredCapitalCurrency: null, registeredAddress: null,
internalRemark: null, createdAt: null, approvedAt: null,
})
const snowflakeTenantId = '9223372036854775806'
async function mountView() {
vi.stubGlobal('localStorage', createMemoryStorage())
vi.stubGlobal('sessionStorage', createMemoryStorage())
@@ -69,6 +83,9 @@ describe('ExpressCompaniesView query and table migration', () => {
beforeEach(() => {
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
document.body.innerHTML = ''
vi.mocked(listPlatformTenants).mockReset().mockResolvedValue({
records: [tenant(10001, '默认企业'), tenant(snowflakeTenantId, '雪花企业')], page: 1, size: 200, total: 2, pages: 1,
})
vi.mocked(listPlatformExpressCompanies).mockReset().mockResolvedValue({
records: [company], page: 1, size: 20, total: 1, pages: 1,
})
@@ -95,4 +112,13 @@ describe('ExpressCompaniesView query and table migration', () => {
expect(listPlatformExpressCompanies).toHaveBeenLastCalledWith(10001, 1, 20, '顺丰', '')
})
it('preserves a snowflake tenant id as a string when switching enterprises', async () => {
const wrapper = await mountView()
wrapper.findComponent(PlatformTenantSelector).vm.$emit('update:modelValue', snowflakeTenantId)
await flushPromises()
expect(listPlatformExpressCompanies).toHaveBeenLastCalledWith(snowflakeTenantId, 1, 20, '', '')
})
})
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, onMounted, reactive, ref, watch } from 'vue'
import { computed, reactive, ref, watch } from 'vue'
import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'element-plus'
import { Download, ExternalLink, FileSpreadsheet, Pencil, Plus, Power, Truck, Upload } from '@lucide/vue'
import ApiErrorMeta from '@/shared/components/ApiErrorMeta.vue'
@@ -21,8 +21,8 @@ import {
type SavePlatformExpressCompanyRequest,
} from '@/modules/master-data/express-companies/api/platformExpressCompanies'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { PlatformTenantSelector } from '@/modules/iam'
const fixedTenantId = 10001
const access = useAccessPreviewStore()
const loading = ref(false)
const saving = ref(false)
@@ -34,6 +34,8 @@ const rows = ref<PlatformExpressCompanyResource[]>([])
const page = ref(1)
const pageSize = ref(20)
const total = ref(0)
const selectedTenantId = ref('')
const loadedTenantId = ref<string | null>(null)
const loadError = ref<ApiErrorDetails | null>(null)
const statusLoadingIds = ref(new Set<string>())
const editLoadingIds = ref(new Set<string>())
@@ -91,6 +93,16 @@ const { captureBaseline } = useUnsavedWorkRegistration({
requiredPermission: editorPermission,
})
const tenantReady = computed(() => Boolean(selectedTenantId.value)
&& loadedTenantId.value === selectedTenantId.value
&& !loading.value)
const tenantSwitchDisabled = computed(() => editorOpen.value
|| importOpen.value
|| saving.value
|| importing.value
|| editLoadingIds.value.size > 0
|| statusLoadingIds.value.size > 0)
watch(
() => access.can(editorPermission.value),
(canWrite) => {
@@ -131,13 +143,27 @@ const expressCompanyColumns: DataTableColumn[] = [
{ key: 'status', label: '状态', width: 100, slotName: 'status' },
]
async function loadExpressCompanies() {
function apiTenantId(value: string) {
const numeric = Number(value)
return Number.isSafeInteger(numeric) ? numeric : value
}
function requireCurrentTenant() {
if (!tenantReady.value) {
ElMessage.warning('快递公司数据尚未加载完成,请稍后重试')
return null
}
return apiTenantId(selectedTenantId.value)
}
async function loadExpressCompanies(tenantId = selectedTenantId.value) {
if (!tenantId) return
const sequence = ++loadSequence
loading.value = true
loadError.value = null
try {
const result = await listPlatformExpressCompanies(
fixedTenantId,
apiTenantId(tenantId),
page.value,
pageSize.value,
appliedFilters.value.keyword,
@@ -146,6 +172,7 @@ async function loadExpressCompanies() {
if (sequence !== loadSequence) return
rows.value = result.records
total.value = result.total
loadedTenantId.value = tenantId
} catch (error) {
if (sequence !== loadSequence) return
rows.value = []
@@ -169,6 +196,7 @@ function applyFilters(model: QueryModel) {
}
function openCreate() {
if (!requireCurrentTenant()) return
Object.assign(form, emptyForm())
captureBaseline()
editorOpen.value = true
@@ -192,12 +220,14 @@ function assignEditor(row: PlatformExpressCompanyResource) {
}
async function openEdit(row: PlatformExpressCompanyResource) {
const tenantId = requireCurrentTenant()
if (!tenantId) return
const id = String(row.id)
const pending = new Set(editLoadingIds.value)
pending.add(id)
editLoadingIds.value = pending
try {
assignEditor(await getPlatformExpressCompany(fixedTenantId, row.id))
assignEditor(await getPlatformExpressCompany(tenantId, row.id))
} catch (error) {
const details = getApiErrorDetails(error, '快递公司详情加载失败,请稍后重试')
ElMessage.error(details.requestId ? `${details.message}(requestId: ${details.requestId})` : details.message)
@@ -262,6 +292,8 @@ function selectImportFile(event: Event) {
}
async function submitImport() {
const tenantId = requireCurrentTenant()
if (!tenantId) return
if (!importFile.value) {
ElMessage.warning('请先选择填写完成的 XLSX 文件')
return
@@ -270,7 +302,7 @@ async function submitImport() {
importError.value = null
importResult.value = null
try {
const result = await importPlatformExpressCompanies(fixedTenantId, importFile.value)
const result = await importPlatformExpressCompanies(tenantId, importFile.value)
importResult.value = result
if (result.success) {
ElMessage.success(`成功导入 ${result.importedRows} 家快递公司`)
@@ -308,13 +340,15 @@ function buildPayload(): SavePlatformExpressCompanyRequest {
}
async function saveExpressCompany() {
const tenantId = requireCurrentTenant()
if (!tenantId) return
const valid = await formRef.value?.validate().catch(() => false)
if (!valid) return
saving.value = true
try {
const payload = buildPayload()
if (form.id) await updatePlatformExpressCompany(fixedTenantId, form.id, payload)
else await createPlatformExpressCompany(fixedTenantId, payload)
if (form.id) await updatePlatformExpressCompany(tenantId, form.id, payload)
else await createPlatformExpressCompany(tenantId, payload)
editorOpen.value = false
ElMessage.success(form.id ? '快递公司资料已更新' : '快递公司已创建')
await loadExpressCompanies()
@@ -327,6 +361,8 @@ async function saveExpressCompany() {
}
async function toggleStatus(row: PlatformExpressCompanyResource) {
const tenantId = requireCurrentTenant()
if (!tenantId) return
const nextStatus: PlatformExpressCompanyStatus = row.status === 'ACTIVE' ? 'INACTIVE' : 'ACTIVE'
const action = nextStatus === 'ACTIVE' ? '启用' : '停用'
try {
@@ -343,7 +379,7 @@ async function toggleStatus(row: PlatformExpressCompanyResource) {
pending.add(id)
statusLoadingIds.value = pending
try {
await changePlatformExpressCompanyStatus(fixedTenantId, row.id, nextStatus)
await changePlatformExpressCompanyStatus(tenantId, row.id, nextStatus)
ElMessage.success(`已${action}${row.companyName}`)
await loadExpressCompanies()
} catch (error) {
@@ -357,19 +393,28 @@ async function toggleStatus(row: PlatformExpressCompanyResource) {
}
watch([page, pageSize], () => { void loadExpressCompanies() })
onMounted(() => {
void loadExpressCompanies()
watch(selectedTenantId, (tenantId) => {
editorOpen.value = false
importOpen.value = false
importFile.value = null
importResult.value = null
importError.value = null
rows.value = []
total.value = 0
loadedTenantId.value = null
page.value = 1
void loadExpressCompanies(tenantId)
})
</script>
<template>
<div class="business-page express-company-page">
<PlatformTenantSelector v-model="selectedTenantId" :disabled="tenantSwitchDisabled" />
<el-alert v-if="loadError" type="error" :closable="false" show-icon class="state-alert">
<template #title>快递公司加载失败</template>
<p>{{ loadError.message }}</p>
<ApiErrorMeta :details="loadError" />
<el-button size="small" @click="loadExpressCompanies">重新查询</el-button>
<el-button size="small" @click="loadExpressCompanies()">重新查询</el-button>
</el-alert>
<QueryToolbar v-model="filters" class="surface-panel" ariaLabel="快递公司筛选" :fields="queryFields" @search="applyFilters" />
@@ -378,11 +423,11 @@ onMounted(() => {
<div class="panel-heading">
<div>
<h2>快递公司列表</h2>
<p>共 {{ total }} 家快递公司</p>
<p>租户 {{ selectedTenantId || '—' }} · 共 {{ total }} 家快递公司</p>
</div>
<div class="panel-actions">
<el-button v-if="access.can('platform:express:import')" @click="openImport"><Upload :size="16" />批量导入</el-button>
<el-button v-if="access.can('platform:express:create')" type="primary" @click="openCreate"><Plus :size="16" />新增快递公司</el-button>
<el-button v-if="access.can('platform:express:import')" :disabled="!tenantReady" @click="openImport"><Upload :size="16" />批量导入</el-button>
<el-button v-if="access.can('platform:express:create')" type="primary" :disabled="!tenantReady" @click="openCreate"><Plus :size="16" />新增快递公司</el-button>
</div>
</div>
<DataTable
@@ -403,12 +448,14 @@ onMounted(() => {
v-if="access.can('platform:express:edit')"
link
type="primary"
:disabled="!tenantReady"
:loading="editLoadingIds.has(String((row as PlatformExpressCompanyResource).id))"
@click="openEdit(row as PlatformExpressCompanyResource)"
><Pencil :size="15" />编辑</el-button>
<el-button
v-if="access.can('platform:express:status')"
link
:disabled="!tenantReady"
:type="(row as PlatformExpressCompanyResource).status === 'ACTIVE' ? 'danger' : 'success'"
:loading="statusLoadingIds.has(String((row as PlatformExpressCompanyResource).id))"
@click="toggleStatus(row as PlatformExpressCompanyResource)"