fix: backfill tenant via useForm channel and skip empty-tenant watch on search reset
- imSearchReset now receives setFieldsValue from useForm() instead of the template ref instance method, which was unreliable for backfilling tenantId - imUser/imSensitiveWord watches skip tenantId<=0 so reset no longer fires policy-group/group requests that get rejected with empty tenant - loadImTenantOptions wraps platform-branch TenantList in try/catch so a failed request no longer aborts page initialization
This commit is contained in:
@@ -155,7 +155,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致后端拒绝查询)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
function selectedTenantId() {
|
||||
return Number(searchFormRef.value?.formModel?.tenantId || 0);
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
onMounted(async () => {
|
||||
loadOptions();
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
// 查看详情
|
||||
function handleView(record: Recordable) {
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
async function sendCacheInvalidate() {
|
||||
const tenant = getFirstTenant();
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
function handleReview(record: State, status: string, reviewReason = '') {
|
||||
Review({ tenantId: record.tenantId, id: record.id, status, reviewReason }).then(() => {
|
||||
|
||||
@@ -217,7 +217,7 @@
|
||||
const resetTenantOptions = computed(() =>
|
||||
policyTenantOptions.value.filter((v) => Number(v.value) > 0)
|
||||
);
|
||||
const onSearchReset = imSearchReset(searchFormRef, resetTenantOptions, reload);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, resetTenantOptions, reload);
|
||||
const actionColumn = reactive({
|
||||
width: 150,
|
||||
title: '操作',
|
||||
@@ -315,7 +315,11 @@
|
||||
}
|
||||
watch(
|
||||
() => searchFormRef.value?.formModel?.tenantId,
|
||||
() => loadGroups()
|
||||
() => {
|
||||
// 重置瞬间 tenantId 会被清空,此时发起 tenantId=0 的分组查询必被后端拒绝;
|
||||
// 跳过空租户,等回填后再加载。
|
||||
if (Number(searchFormRef.value?.formModel?.tenantId || 0) > 0) loadGroups();
|
||||
}
|
||||
);
|
||||
onMounted(async () => {
|
||||
loadOptions();
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致后端拒绝查询)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
onMounted(async () => {
|
||||
loadOptions();
|
||||
|
||||
@@ -46,8 +46,13 @@ export async function loadImTenantOptions(
|
||||
return target.value;
|
||||
}
|
||||
|
||||
const res = await TenantList(params);
|
||||
target.value = (res?.list || []).map(toTenantOption);
|
||||
// 平台账号:加载全部商户;失败时保留旧选项,避免页面初始化被单个请求失败打断
|
||||
try {
|
||||
const res = await TenantList(params);
|
||||
target.value = (res?.list || []).map(toTenantOption);
|
||||
} catch (err) {
|
||||
console.error('loadImTenantOptions failed:', err);
|
||||
}
|
||||
return target.value;
|
||||
}
|
||||
|
||||
@@ -71,26 +76,25 @@ export function lockTenantSchema(schema?: FormSchema) {
|
||||
props.clearable = false;
|
||||
}
|
||||
|
||||
interface ImSearchFormRef {
|
||||
setFieldsValue: (values: Record<string, any>) => Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一搜索重置回调:BasicForm 的 resetFields 会把包括 tenantId 在内的全部搜索字段清空,
|
||||
* 随后的自动查询因缺商户条件命中前端空列表 guard(或被后端以「请选择IM租户」拒绝)。
|
||||
* 此工厂返回的回调在 reset 之后把商户下拉回填为当前选项列表的第一项
|
||||
* (商户绑定账号=自己商户;平台账号=全部商户列表第一项),再触发查询——
|
||||
* 与各页面初始加载(onMounted 默认选中第一项)的行为保持一致。
|
||||
*
|
||||
* setFieldsValueFn 必须传页面 useForm() 解构出的 setFieldsValue(与 onMounted 同一通道),
|
||||
* 不要用模板 ref 上的实例方法(可靠性不足)。
|
||||
*/
|
||||
export function imSearchReset(
|
||||
searchFormRef: Ref<ImSearchFormRef | null>,
|
||||
setFieldsValueFn: (values: Record<string, any>) => Promise<void> | void,
|
||||
tenantOptions: Ref<ImTenantOption[]>,
|
||||
reload: () => unknown,
|
||||
) {
|
||||
return async () => {
|
||||
const first = Number(tenantOptions.value[0]?.value || 0);
|
||||
if (first > 0) {
|
||||
await searchFormRef.value?.setFieldsValue({ tenantId: first });
|
||||
await setFieldsValueFn({ tenantId: first });
|
||||
}
|
||||
await reload();
|
||||
};
|
||||
|
||||
@@ -382,7 +382,7 @@
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, tenantOptions, reloadTable);
|
||||
|
||||
// 查看详情
|
||||
function handleView(record: Recordable) {
|
||||
@@ -595,7 +595,12 @@
|
||||
|
||||
watch(
|
||||
() => searchFormRef.value?.formModel?.tenantId,
|
||||
(tenantId) => loadPolicyGroupOptions(Number(tenantId || 0))
|
||||
(tenantId) => {
|
||||
// 重置瞬间 formModel.tenantId 会被清空,此时发起 tenantId=0 的策略组查询必被后端拒绝;
|
||||
// 跳过空租户,等回填后再加载。
|
||||
const tid = Number(tenantId || 0);
|
||||
if (tid > 0) loadPolicyGroupOptions(tid);
|
||||
}
|
||||
);
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
@@ -303,7 +303,7 @@
|
||||
const resetTenantOptions = computed(() =>
|
||||
policyTenantOptions.value.filter((v) => Number(v.value) > 0)
|
||||
);
|
||||
const onSearchReset = imSearchReset(searchFormRef, resetTenantOptions, reloadTable);
|
||||
const onSearchReset = imSearchReset(setFieldsValue, resetTenantOptions, reloadTable);
|
||||
const actionColumn = reactive({
|
||||
width: 300,
|
||||
title: '操作',
|
||||
|
||||
Reference in New Issue
Block a user