22import folder from ' @/assets/svg/folder.svg'
33import {type SQTreeNode } from ' @/views/dashboard/utils/treeNode'
44import {ref , reactive , computed } from ' vue'
5- import {dashboardApi } from " @/api /dashboard.ts" ;
6-
5+ import {saveDashboardResource } from " @/views /dashboard/utils/canvasUtils .ts" ;
6+ const emits = defineEmits ([ ' finish ' ])
77const state = reactive ({
8- placeholder:' ' ,
9- showParentSelected: false ,
8+ opt: null ,
9+ placeholder: ' ' ,
10+ nodeType: ' folder' ,
11+ parentSelect: false ,
1012 resourceFormNameLabel: ' Name' ,
1113 dialogTitle: ' ' ,
1214 tData: [],
@@ -17,8 +19,8 @@ const state = reactive({
1719
1820let tData: any = []
1921
20- const getTitle = (cmd : string ) => {
21- switch (cmd ) {
22+ const getTitle = (opt : string ) => {
23+ switch (opt ) {
2224 case ' newLeaf' :
2325 return ' New Dashboard'
2426 case ' newFolder' :
@@ -28,8 +30,8 @@ const getTitle = (cmd: string) => {
2830 }
2931}
3032
31- const getResourceNewName = (cmd : string ) => {
32- switch (cmd ) {
33+ const getResourceNewName = (opt : string ) => {
34+ switch (opt ) {
3335 case ' newLeaf' :
3436 return ' New Dashboard'
3537 case ' newFolder' :
@@ -41,19 +43,21 @@ const getResourceNewName = (cmd: string) => {
4143
4244const optInit = (params : any ) => {
4345 // @ts-ignore
44- state .dialogTitle = getTitle (params .cmd )
45- state .showParentSelected = params .parentSelect
46+ state .dialogTitle = getTitle (params .opt )
47+ state .opt = params .opt
48+ state .parentSelect = params .parentSelect
4649 state .targetInfo = params .data
50+ state .nodeType = params .nodeType || ' folder'
4751 resourceDialogShow .value = true
48- // @ts-ignore
49- resourceForm .name = getResourceNewName (params .cmd )
52+ // @ts-ignore
53+ resourceForm .name = params . name || getResourceNewName (params .opt )
5054}
5155
5256const resourceDialogShow = ref (false )
5357const loading = ref (false )
5458const pid = ref ()
5559const id = ref ()
56- const cmd = ref (' ' )
60+ const opt = ref (' ' )
5761const resourceForm = reactive ({
5862 pid: ' ' ,
5963 pName: ' ' ,
@@ -105,38 +109,40 @@ const editeInit = (param: SQTreeNode) => {
105109const propsTree = {
106110 label: ' name' ,
107111 children: ' children' ,
108- // @ts-ignore
112+ // @ts-ignore
109113 isLeaf : node => ! node .children ?.length
110114}
111115
112116const showPid = computed (() => {
113- return [' newLeaf' , ' copy ' , ' newLeafAfter ' ].includes (cmd .value ) && state .showParentSelected
117+ return [' newLeaf' ].includes (opt .value ) && state .parentSelect
114118})
115119
116120const saveResource = () => {
117- const params = {
118- nodeType: ' folder' ,
119- name: resourceForm .name ,
120- type: ' dashboard'
121- }
122- // @ts-ignore
123- dashboardApi .addResource (params ).then (res => {
124- ElMessage ({
125- type: ' success' ,
126- message: ' Save Success' ,
127- })
128-
129- resetForm ()
121+ const params = {
122+ nodeType: state .nodeType ,
123+ name: resourceForm .name ,
124+ opt: state .opt ,
125+ type: ' dashboard'
126+ }
127+ saveDashboardResource (params , function (rsp : any ) {
128+ ElMessage ({
129+ type: ' success' ,
130+ message: ' Save Success' ,
130131 })
132+ if (state .opt === ' newLeaf' ) {
133+ emits (' finish' , {opt: state .opt , resourceId: rsp .id })
134+ }
135+ resetForm ()
136+ })
131137}
132138
133139const nodeClick = (data : SQTreeNode ) => {
134140 resourceForm .pid = data .id as string
135141 resourceForm .pName = data .name as string
136142}
137143
138- const filterMethod = (value : any ) => {
139- // @ts-ignore
144+ const filterMethod = (value : any ) => {
145+ // @ts-ignore
140146 state .tData = [... tData ].filter (item => item .name .includes (value ))
141147}
142148
@@ -145,7 +151,6 @@ defineExpose({
145151 editeInit
146152})
147153
148- const emits = defineEmits ([' finish' ])
149154 </script >
150155
151156<template >
0 commit comments