@@ -15,24 +15,17 @@ import $http from '@/api'
15
15
import { CONTAINER_OBJECTS , CONTAINER_OBJECT_NAMES } from '@/dictionary/container.js'
16
16
17
17
const state = {
18
- classifications : [ ]
18
+ classifications : [ ] ,
19
+ models : [ ] ,
20
+ viewAuthFreeModels : [ ] ,
21
+ viewAuthFreeModelSet : new Set ( )
19
22
}
20
23
21
24
const getters = {
22
25
classifications : state => state . classifications ,
23
- models : ( state ) => {
24
- const models = [ ]
25
- state . classifications . forEach ( ( classification ) => {
26
- ( classification . bk_objects || [ ] ) . forEach ( ( model ) => {
27
- models . push ( {
28
- ...model ,
29
- bk_classification_name : classification . bk_classification_name ,
30
- bk_classification_id : classification . bk_classification_id
31
- } )
32
- } )
33
- } )
34
- return models
35
- } ,
26
+ models : state => state . models ,
27
+ viewAuthFreeModels : state => state . viewAuthFreeModels ,
28
+ viewAuthFreeModelSet : state => state . viewAuthFreeModelSet ,
36
29
getModelById : ( state , getters ) => id => getters . models . find ( model => model . bk_obj_id === id ) ,
37
30
presetModels : ( state , getters ) => getters . models . filter ( model => model . ispre )
38
31
}
@@ -143,6 +136,44 @@ const actions = {
143
136
const mutations = {
144
137
setClassificationsObjects ( state , classifications ) {
145
138
state . classifications = classifications
139
+ this . commit ( 'objectModelClassify/setModels' )
140
+ this . commit ( 'objectModelClassify/setViewAuthFreeModels' )
141
+ this . commit ( 'objectModelClassify/setViewAuthFreeModelSet' )
142
+ } ,
143
+ setViewAuthFreeModelSet ( state ) {
144
+ state . viewAuthFreeModels . forEach ( ( item ) => {
145
+ state . viewAuthFreeModelSet . add ( item ?. bk_obj_id || item ?. id )
146
+ } )
147
+ } ,
148
+ setViewAuthFreeModels ( state ) {
149
+ const begin = new Date ( ) . valueOf ( )
150
+ const presetModels = this . getters [ 'objectModelClassify/presetModels' ]
151
+ const allModels = state . models
152
+ // mainLineModel中默认没有id,在此先补充
153
+ const mainLineModels = this . getters [ 'objectMainLineModule/mainLineModels' ] . map ( mainItem => ( {
154
+ id : allModels . find ( preItem => preItem . bk_obj_id === mainItem . bk_obj_id ) ?. id ,
155
+ bk_obj_id : mainItem . bk_obj_id ,
156
+ bk_obj_name : mainItem . bk_obj_name
157
+ } ) )
158
+
159
+ state . viewAuthFreeModels = ( [ ...mainLineModels , ...presetModels ] ) . map ( model => ( {
160
+ id : model . id ,
161
+ bk_obj_id : model . bk_obj_id ,
162
+ bk_obj_name : model . bk_obj_name
163
+ } ) )
164
+ } ,
165
+ setModels ( state ) {
166
+ const models = [ ]
167
+ state . classifications . forEach ( ( classification ) => {
168
+ ( classification . bk_objects || [ ] ) . forEach ( ( model ) => {
169
+ models . push ( {
170
+ ...model ,
171
+ bk_classification_name : classification . bk_classification_name ,
172
+ bk_classification_id : classification . bk_classification_id
173
+ } )
174
+ } )
175
+ } )
176
+ state . models = models
146
177
} ,
147
178
updateClassify ( state , classification ) {
148
179
// eslint-disable-next-line max-len
0 commit comments