2929 <template #label >
3030 <tooltip-label :title =" $t('label.account')" :tooltip =" apiParams.accountids.description" />
3131 </template >
32- <a -select
32+ <infinite-scroll -select
3333 v-model:value =" form.accountids"
3434 mode =" multiple"
35- :loading =" accountLoading"
3635 :placeholder =" apiParams.accountids.description"
37- showSearch
38- optionFilterProp =" label"
39- :filterOption =" (input, option) => {
40- return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
41- }" >
42- <a-select-option v-for =" (opt, optIndex) in accounts" :key =" optIndex" :label =" opt.name || opt.description" >
43- <span >
44- <resource-icon v-if =" opt.icon" :image =" opt.icon.base64image" size =" 1x" style =" margin-right : 5px " />
45- <global-outlined style =" margin-right : 5px " />
46- {{ opt.name || opt.description }}
47- </span >
48- </a-select-option >
49- </a-select >
36+ api =" listAccounts"
37+ :apiParams =" accountsApiParams"
38+ resourceType =" account"
39+ defaultIcon =" team-outlined" />
5040 </a-form-item >
5141 <a-form-item v-if =" isAdminOrDomainAdmin()" name =" projectids" ref =" projectids" >
5242 <template #label >
5343 <tooltip-label :title =" $t('label.project')" :tooltip =" apiParams.projectids.description" />
5444 </template >
55- <a -select
45+ <infinite-scroll -select
5646 v-model:value =" form.projectids"
5747 mode =" multiple"
58- :loading =" projectLoading"
5948 :placeholder =" apiParams.projectids.description"
60- showSearch
61- optionFilterProp =" label"
62- :filterOption =" (input, option) => {
63- return option.label.toLowerCase().indexOf(input.toLowerCase()) >= 0
64- }" >
65- <a-select-option v-for =" (opt, optIndex) in projects" :key =" optIndex" :label =" opt.name || opt.description" >
66- <span >
67- <resource-icon v-if =" opt.icon" :image =" opt.icon.base64image" size =" 1x" style =" margin-right : 5px " />
68- <global-outlined style =" margin-right : 5px " />
69- {{ opt.name || opt.description }}
70- </span >
71- </a-select-option >
72- </a-select >
49+ api =" listProjects"
50+ resourceType =" project"
51+ defaultIcon =" project-outlined" />
7352 </a-form-item >
7453 <a-form-item v-if =" !isAdminOrDomainAdmin()" >
7554 <template #label >
@@ -106,12 +85,14 @@ import { isAdminOrDomainAdmin } from '@/role'
10685import { ref , reactive , toRaw } from ' vue'
10786import ResourceIcon from ' @/components/view/ResourceIcon'
10887import TooltipLabel from ' @/components/widgets/TooltipLabel'
88+ import InfiniteScrollSelect from ' @/components/widgets/InfiniteScrollSelect'
10989
11090export default {
11191 name: ' CreateNetworkPermissions' ,
11292 components: {
11393 TooltipLabel,
114- ResourceIcon
94+ ResourceIcon,
95+ InfiniteScrollSelect
11596 },
11697 props: {
11798 resource: {
@@ -121,89 +102,40 @@ export default {
121102 },
122103 data () {
123104 return {
124- loading: false ,
125- accountLoading: false ,
126- projectLoading: false ,
127- accounts: [],
128- projects: []
105+ loading: false
129106 }
130107 },
131108 created () {
132109 this .formRef = ref ()
133110 this .form = reactive ({})
134111 this .rules = reactive ({})
135112 this .apiParams = this .$getApiParams (' createNetworkPermissions' )
136- this .fetchData ()
113+ },
114+ computed: {
115+ accountsApiParams () {
116+ return {
117+ details: ' min' ,
118+ domainid: this .resource .domainid
119+ }
120+ }
137121 },
138122 methods: {
139123 isAdminOrDomainAdmin () {
140124 return isAdminOrDomainAdmin ()
141125 },
142- async fetchData () {
143- this .fetchAccountData ()
144- this .fetchProjectData ()
145- },
146- fetchAccountData () {
147- this .accounts = []
148- const params = {}
149- params .showicon = true
150- params .details = ' min'
151- params .domainid = this .resource .domainid
152- this .accountLoading = true
153- api (' listAccounts' , params).then (json => {
154- const listaccounts = json .listaccountsresponse .account || []
155- this .accounts = listaccounts
156- }).finally (() => {
157- this .accountLoading = false
158- })
159- },
160- fetchProjectData () {
161- this .projects = []
162- const params = {}
163- params .listall = true
164- params .showicon = true
165- params .details = ' min'
166- params .domainid = this .resource .domainid
167- this .projectLoading = true
168- api (' listProjects' , params).then (json => {
169- const listProjects = json .listprojectsresponse .project || []
170- this .projects = listProjects
171- }).finally (() => {
172- this .projectLoading = false
173- })
174- },
175126 handleSubmit (e ) {
176127 e .preventDefault ()
177128 if (this .loading ) return
178129 this .formRef .value .validate ().then (() => {
179130 const values = toRaw (this .form )
180131 const params = {}
181132 params .networkid = this .resource .id
182- var accountIndexes = values .accountids
183- var accountId = null
184- if (accountIndexes && accountIndexes .length > 0 ) {
185- var accountIds = []
186- for (var i = 0 ; i < accountIndexes .length ; i++ ) {
187- accountIds = accountIds .concat (this .accounts [accountIndexes[i]].id )
188- }
189- accountId = accountIds .join (' ,' )
190- }
191- if (accountId) {
192- params .accountids = accountId
133+ if (values .accountids && values .accountids .length > 0 ) {
134+ params .accountids = values .accountids .join (' ,' )
193135 }
194- var projectIndexes = values .projectids
195- var projectId = null
196- if (projectIndexes && projectIndexes .length > 0 ) {
197- var projectIds = []
198- for (var j = 0 ; j < projectIndexes .length ; j++ ) {
199- projectIds = projectIds .concat (this .projects [projectIndexes[j]].id )
200- }
201- projectId = projectIds .join (' ,' )
136+ if (values .projectids && values .projectids .length > 0 ) {
137+ params .projectids = values .projectids .join (' ,' )
202138 }
203- if (projectId) {
204- params .projectids = projectId
205- }
206-
207139 if (values .accounts && values .accounts .length > 0 ) {
208140 params .accounts = values .accounts
209141 }
0 commit comments