fix: restore tenant filter on search reset in IM pages
BasicForm resetFields clears tenantId along with other fields, so the auto-query after reset hit the empty-list guard (or was rejected by the backend). Add a shared imSearchReset handler in imTenantOptions.ts that refills the tenant select with its first option (bound users keep their own tenant) before reloading, and wire it into the 9 IM list pages whose reset did not already refill the tenant condition.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<BasicTable
|
||||
@@ -66,6 +66,7 @@
|
||||
statusOptions,
|
||||
tenantOptions,
|
||||
} from './model';
|
||||
import { imSearchReset } from '../../imTenantOptions';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import CreateModal from './CreateModal.vue';
|
||||
import BatchViewModal from './BatchViewModal.vue';
|
||||
@@ -153,6 +154,9 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致后端拒绝查询)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
function selectedTenantId() {
|
||||
return Number(searchFormRef.value?.formModel?.tenantId || 0);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<BasicTable
|
||||
@@ -31,6 +31,7 @@
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { List } from '@/api/imDeadLetter';
|
||||
import { columns, loadOptions, loadTenantOptions, schemas, State, tenantOptions } from './model';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import ViewModal from './view.vue';
|
||||
|
||||
@@ -89,6 +90,9 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
onMounted(async () => {
|
||||
loadOptions();
|
||||
await loadTenantOptions();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<BasicTable
|
||||
@@ -34,6 +34,7 @@
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { List } from '@/api/imGroup';
|
||||
import { columns, loadOptions, loadTenantOptions, schemas, State, tenantOptions } from './model';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import ViewModal from './view.vue';
|
||||
import MembersModal from './members.vue';
|
||||
@@ -104,6 +105,9 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
// 查看详情
|
||||
function handleView(record: Recordable) {
|
||||
viewRef.value.openModal(record);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<n-space class="table-toolbar">
|
||||
@@ -36,6 +36,7 @@
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { CacheInvalidate, List, WorkbenchEvent } from '@/api/imKafkaCommand';
|
||||
import { columns, loadOptions, loadTenantOptions, schemas, State, tenantOptions } from './model';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import ViewModal from './view.vue';
|
||||
|
||||
@@ -80,6 +81,9 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
async function sendCacheInvalidate() {
|
||||
const tenant = getFirstTenant();
|
||||
if (!tenant) {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
/>
|
||||
<BasicTable
|
||||
ref="actionRef"
|
||||
@@ -31,6 +31,7 @@
|
||||
import { BasicForm, useForm } from '@/components/Form/index';
|
||||
import { List, Review } from '@/api/imRealname';
|
||||
import { columns, loadOptions, loadTenantOptions, schemas, State, tenantOptions } from './model';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import ViewModal from './view.vue';
|
||||
|
||||
@@ -94,6 +95,9 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
function handleReview(record: State, status: string, reviewReason = '') {
|
||||
Review({ tenantId: record.tenantId, id: record.id, status, reviewReason }).then(() => {
|
||||
message.success('操作成功');
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reload"
|
||||
@reset="reload"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reload"
|
||||
/>
|
||||
<BasicTable
|
||||
@@ -159,6 +159,7 @@
|
||||
parseJSON,
|
||||
policyTenantOptions,
|
||||
} from '@/views/imPolicyShared';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
const dict = useDictStore(),
|
||||
message = useMessage(),
|
||||
dialog = useDialog(),
|
||||
@@ -212,6 +213,11 @@
|
||||
? List({ ...searchFormRef.value?.formModel, ...res })
|
||||
: Promise.resolve({});
|
||||
const reload = () => tableRef.value?.reload();
|
||||
// 重置后回填商户下拉再查询;回填跳过「全局默认」(value=0),与初始加载 getDefaultTenantValue 行为一致
|
||||
const resetTenantOptions = computed(() =>
|
||||
policyTenantOptions.value.filter((v) => Number(v.value) > 0)
|
||||
);
|
||||
const onSearchReset = imSearchReset(searchFormRef, resetTenantOptions, reload);
|
||||
const actionColumn = reactive({
|
||||
width: 150,
|
||||
title: '操作',
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="handleReset"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<BasicTable
|
||||
@@ -30,6 +30,7 @@
|
||||
import { BasicTable } from '@/components/Table';
|
||||
import { List } from '@/api/imTaskDashboard';
|
||||
import { columns, loadOptions, loadTenantOptions, schemas, tenantOptions } from './model';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
|
||||
const message = useMessage();
|
||||
@@ -58,10 +59,8 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
async function handleReset() {
|
||||
await setFieldsValue({});
|
||||
reloadTable();
|
||||
}
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致后端拒绝查询)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
onMounted(async () => {
|
||||
loadOptions();
|
||||
|
||||
@@ -71,6 +71,31 @@ export function lockTenantSchema(schema?: FormSchema) {
|
||||
props.clearable = false;
|
||||
}
|
||||
|
||||
interface ImSearchFormRef {
|
||||
setFieldsValue: (values: Record<string, any>) => Promise<void>;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一搜索重置回调:BasicForm 的 resetFields 会把包括 tenantId 在内的全部搜索字段清空,
|
||||
* 随后的自动查询因缺商户条件命中前端空列表 guard(或被后端以「请选择IM租户」拒绝)。
|
||||
* 此工厂返回的回调在 reset 之后把商户下拉回填为当前选项列表的第一项
|
||||
* (商户绑定账号=自己商户;平台账号=全部商户列表第一项),再触发查询——
|
||||
* 与各页面初始加载(onMounted 默认选中第一项)的行为保持一致。
|
||||
*/
|
||||
export function imSearchReset(
|
||||
searchFormRef: Ref<ImSearchFormRef | null>,
|
||||
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 reload();
|
||||
};
|
||||
}
|
||||
|
||||
function toTenantOption(item: any): ImTenantOption {
|
||||
return {
|
||||
label: formatImTenantLabel(item),
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<BasicTable
|
||||
@@ -236,6 +236,7 @@
|
||||
State,
|
||||
tenantOptions,
|
||||
} from './model';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
import { DownloadOutlined, PlusOutlined, UploadOutlined } from '@vicons/antd';
|
||||
import { adaTableScrollX } from '@/utils/hotgo';
|
||||
import ViewModal from './view.vue';
|
||||
@@ -380,6 +381,9 @@
|
||||
actionRef.value?.reload();
|
||||
}
|
||||
|
||||
// 重置后回填商户下拉第一个选项再查询(避免 tenantId 被清空导致列表为空)
|
||||
const onSearchReset = imSearchReset(searchFormRef, tenantOptions, reloadTable);
|
||||
|
||||
// 查看详情
|
||||
function handleView(record: Recordable) {
|
||||
viewRef.value.openModal(record);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
ref="searchFormRef"
|
||||
@register="register"
|
||||
@submit="reloadTable"
|
||||
@reset="reloadTable"
|
||||
@reset="onSearchReset"
|
||||
@keyup.enter="reloadTable"
|
||||
/>
|
||||
<n-alert type="info" :show-icon="true" class="whitelist-summary">
|
||||
@@ -241,6 +241,7 @@
|
||||
parseJSON,
|
||||
policyTenantOptions,
|
||||
} from '@/views/imPolicyShared';
|
||||
import { imSearchReset } from '../imTenantOptions';
|
||||
|
||||
const dict = useDictStore(),
|
||||
message = useMessage(),
|
||||
@@ -298,6 +299,11 @@
|
||||
actionRef.value?.reload();
|
||||
refreshLoginIPSummary();
|
||||
};
|
||||
// 重置后回填商户下拉再查询;回填跳过「全局默认」(value=0),与初始加载 getDefaultTenantValue 行为一致
|
||||
const resetTenantOptions = computed(() =>
|
||||
policyTenantOptions.value.filter((v) => Number(v.value) > 0)
|
||||
);
|
||||
const onSearchReset = imSearchReset(searchFormRef, resetTenantOptions, reloadTable);
|
||||
const actionColumn = reactive({
|
||||
width: 300,
|
||||
title: '操作',
|
||||
|
||||
Reference in New Issue
Block a user