@@ -55,11 +55,18 @@ const userOptions = ref<Array<{ label: string; value: string }>>([])
5555
5656async function getUserFormItem() {
5757 try {
58- const res = await UserApi .getUserList ({}, memberFormContentLoading )
59- userOptions .value = res .data ?.map ((item ) => ({
60- label: item .nick_name ,
61- value: item .id ,
62- })) || []
58+ const fetchUserOptions = async (query ? : string ) => {
59+ const res = await UserApi .getUserList (query ? {nick_name: query } : {}, memberFormContentLoading )
60+ return res .data ?.map ((item ) => ({
61+ label: item .nick_name ,
62+ value: item .id ,
63+ })) || []
64+ }
65+
66+ // 初始加载
67+ const initialOptions = await fetchUserOptions ()
68+ userOptions .value = initialOptions
69+
6370 userFormItem .value = [
6471 {
6572 path: ' user_ids' ,
@@ -75,14 +82,16 @@ async function getUserFormItem() {
7582 placeholder: ` ${t (' common.selectPlaceholder' )}${t (' views.role.member.title' )} ` ,
7683 remoteSearchDebounce: 300 ,
7784 remoteMethod : async (query : string , element : any ) => {
78- if (! query ) {
79- return userOptions .value
85+ // 关键:直接更新 selectProps.options
86+ const newOptions = await fetchUserOptions (query )
87+ // 更新当前项的 options
88+ const currentItem = userFormItem .value .find (
89+ item => item .path === ' user_ids'
90+ )
91+ if (currentItem ?.selectProps ) {
92+ currentItem .selectProps .options = newOptions
8093 }
81- const res = await UserApi .getUserList ({nick_name: query }, memberFormContentLoading )
82- return res .data ?.map ((item ) => ({
83- label: item .nick_name ,
84- value: item .id ,
85- })) || []
94+ return newOptions
8695 }
8796 },
8897 },
@@ -92,9 +101,22 @@ async function getUserFormItem() {
92101 }
93102}
94103
104+ // 同样修改 workspace
95105async function getWorkspaceFormItem() {
96106 try {
97- const res = await loadPermissionApi (' workspace' ).getWorkspaceList (memberFormContentLoading )
107+ const fetchWorkspaceOptions = async (query ? : string ) => {
108+ const res = await loadPermissionApi (' workspace' ).getWorkspaceList (
109+ query ? {name: query } : {},
110+ memberFormContentLoading
111+ )
112+ return res .data ?.map ((item : any ) => ({
113+ label: item .name ,
114+ value: item .id ,
115+ })) || []
116+ }
117+
118+ const initialOptions = await fetchWorkspaceOptions ()
119+
98120 workspaceFormItem .value = [
99121 {
100122 path: ' workspace_ids' ,
@@ -106,12 +128,18 @@ async function getWorkspaceFormItem() {
106128 },
107129 ],
108130 selectProps: {
109- options:
110- res .data ?.map ((item : any ) => ({
111- label: item .name ,
112- value: item .id ,
113- })) || [],
131+ options: initialOptions ,
114132 placeholder: ` ${t (' common.selectPlaceholder' )}${t (' views.role.member.workspace' )} ` ,
133+ remoteMethod : async (query : string , element : any ) => {
134+ const newOptions = await fetchWorkspaceOptions (query )
135+ const currentItem = workspaceFormItem .value .find (
136+ item => item .path === ' workspace_ids'
137+ )
138+ if (currentItem ?.selectProps ) {
139+ currentItem .selectProps .options = newOptions
140+ }
141+ return newOptions
142+ }
115143 },
116144 },
117145 ]
0 commit comments