@@ -117,12 +117,6 @@ export default {
117117 type: Boolean ,
118118 default: false
119119 },
120- actionData: {
121- type: Array ,
122- default () {
123- return []
124- }
125- },
126120 treeStore: {
127121 type: Object ,
128122 default () {
@@ -163,22 +157,15 @@ export default {
163157 watch: {
164158 loading () {
165159 this .detailLoading = this .loading
166- },
167- treeData () {
168- if (this .oldTreeViewData . length === 0 ) {
160+ this . treeViewData = []
161+ this . arrExpand = []
162+ if (! this .loading ) {
169163 this .treeViewData = this .treeData
170164 this .treeVerticalData = this .treeData
171- }
172-
173- if (this .treeViewData .length > 0 ) {
174- this .oldTreeViewData = this .treeViewData
175- this .rootKey = this .treeViewData [0 ].key
176- }
177165
178- if (Object .keys (this .resource ).length > 0 ) {
179- const resourceIndex = this .treeVerticalData .findIndex (item => item .id === this .resource .id )
180- if (resourceIndex === - 1 ) {
181- this .$el .querySelector (` [title=${ this .resource .parentdomainname } ]` ).click ()
166+ if (this .treeViewData .length > 0 ) {
167+ this .oldTreeViewData = this .treeViewData
168+ this .rootKey = this .treeViewData [0 ].key
182169 }
183170 }
184171 },
@@ -213,13 +200,6 @@ export default {
213200 this .defaultSelected .push (arrSelected[0 ])
214201 }
215202 },
216- actionData (newData , oldData ) {
217- if (! newData || newData .length === 0 ) {
218- return
219- }
220-
221- this .reloadTreeData (newData)
222- },
223203 treeVerticalData () {
224204 if (! this .treeStore .isExpand ) {
225205 return
@@ -233,25 +213,6 @@ export default {
233213 if (keyVisible > - 1 ) this .arrExpand .push (expandKey)
234214 }
235215 }
236-
237- if (this .treeStore .selected ) {
238- this .selectedTreeKey = this .treeStore .selected
239- this .defaultSelected = [this .selectedTreeKey ]
240-
241- const resource = this .treeVerticalData .filter (item => item .id === this .selectedTreeKey )
242- if (resource .length > 0 ) {
243- this .resource = resource[0 ]
244- this .$emit (' change-resource' , this .resource )
245- } else {
246- const rootResource = this .treeVerticalData [0 ]
247- if (rootResource) {
248- this .resource = rootResource
249- this .selectedTreeKey = this .resource .key
250- this .defaultSelected = [this .selectedTreeKey ]
251- this .$emit (' change-resource' , this .resource )
252- }
253- }
254- }
255216 }
256217 },
257218 methods: {
@@ -297,10 +258,36 @@ export default {
297258 }
298259 }
299260
261+ this .onSelectResource ()
300262 resolve ()
301263 })
302264 })
303265 },
266+ onSelectResource () {
267+ if (this .treeStore .selected ) {
268+ this .selectedTreeKey = this .treeStore .selected
269+ this .defaultSelected = [this .selectedTreeKey ]
270+
271+ const resource = this .treeVerticalData .filter (item => item .id === this .selectedTreeKey )
272+ if (resource .length > 0 ) {
273+ this .resource = resource[0 ]
274+ this .$emit (' change-resource' , this .resource )
275+ } else {
276+ const resourceIdx = this .treeVerticalData .findIndex (item => item .id === this .resource .id )
277+ const parentIndex = this .treeVerticalData .findIndex (item => item .id === this .resource .parentdomainid )
278+ if (resourceIdx !== - 1 ) {
279+ this .resource = this .treeVerticalData [resourceIdx]
280+ } else if (parentIndex !== 1 ) {
281+ this .resource = this .treeVerticalData [parentIndex]
282+ } else {
283+ this .resource = this .treeVerticalData [0 ]
284+ }
285+ this .selectedTreeKey = this .resource .key
286+ this .defaultSelected = [this .selectedTreeKey ]
287+ this .$emit (' change-resource' , this .resource )
288+ }
289+ }
290+ },
304291 onSelect (selectedKeys , event ) {
305292 if (! event .selected ) {
306293 setTimeout (() => { event .node .$refs .selectHandle .click () })
@@ -398,53 +385,6 @@ export default {
398385 onTabChange (key ) {
399386 this .tabActive = key
400387 },
401- reloadTreeData (objData ) {
402- if (objData && objData[0 ].isDel ) {
403- this .treeVerticalData = this .treeVerticalData .filter (item => item .id !== objData[0 ].id )
404- this .treeVerticalData = this .treeVerticalData .filter (item => item .parentdomainid !== objData[0 ].id )
405- } else {
406- // data response from action
407- let jsonResponse = this .getResponseJsonData (objData[0 ])
408- jsonResponse = this .createResourceData (jsonResponse)
409-
410- // resource for check create or edit
411- const resource = this .treeVerticalData .filter (item => item .id === jsonResponse .id )
412-
413- // when edit
414- if (resource && resource[0 ]) {
415- this .treeVerticalData .filter ((item , index ) => {
416- if (item .id === jsonResponse .id ) {
417- // replace all value of tree data
418- Object .keys (jsonResponse).forEach ((value , idx ) => {
419- this .$set (this .treeVerticalData [index], value, jsonResponse[value])
420- })
421- }
422- })
423- } else {
424- // when create
425- let resourceExists = true
426-
427- // check is searching data
428- if (this .searchQuery !== ' ' ) {
429- resourceExists = jsonResponse .title .indexOf (this .searchQuery ) > - 1
430- }
431-
432- // push new resource to tree data
433- if (this .resource .haschild && resourceExists) {
434- this .treeVerticalData .push (jsonResponse)
435- }
436-
437- // set resource is currently active as a parent
438- this .treeVerticalData .filter ((item , index ) => {
439- if (item .id === this .resource .id ) {
440- this .$set (this .treeVerticalData [index], ' isLeaf' , false )
441- this .$set (this .treeVerticalData [index], ' haschild' , true )
442- }
443- })
444- }
445- }
446- this .recursiveTreeData (this .treeVerticalData )
447- },
448388 getDetailResource (selectedKey ) {
449389 // set api name and parameter
450390 const apiName = this .$route .meta .permission [0 ]
0 commit comments