mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-10 02:07:12 +08:00
refactor: new resource
This commit is contained in:
@@ -8,5 +8,6 @@ export const dashboardApi = {
|
||||
addResource: (data: any) => request.post('/dashboard/add',data),
|
||||
updateResource: (data: any) => request.post('/dashboard/update',data),
|
||||
saveCanvas: (data: any) => request.post('/dashboard/add_canvas',data),
|
||||
updateCanvas: (data: any) => request.post('/dashboard/update_',data)
|
||||
updateCanvas: (data: any) => request.post('/dashboard/update_',data),
|
||||
check_name: (data: any) => request.post('/dashboard/check_name',data)
|
||||
}
|
||||
@@ -51,13 +51,11 @@ const optInit = (params: any) => {
|
||||
resourceDialogShow.value = true
|
||||
// @ts-ignore
|
||||
resourceForm.name = params.name || getResourceNewName(params.opt)
|
||||
resourceForm.pid = params.pid || 'root'
|
||||
}
|
||||
|
||||
const resourceDialogShow = ref(false)
|
||||
const loading = ref(false)
|
||||
const pid = ref()
|
||||
const id = ref()
|
||||
const opt = ref('')
|
||||
const resourceForm = reactive({
|
||||
pid: '',
|
||||
pName: '',
|
||||
@@ -101,11 +99,6 @@ const resetForm = () => {
|
||||
resourceDialogShow.value = false
|
||||
}
|
||||
|
||||
const editeInit = (param: SQTreeNode) => {
|
||||
pid.value = param['pid']
|
||||
id.value = param.id
|
||||
}
|
||||
|
||||
const propsTree = {
|
||||
label: 'name',
|
||||
children: 'children',
|
||||
@@ -114,7 +107,7 @@ const propsTree = {
|
||||
}
|
||||
|
||||
const showPid = computed(() => {
|
||||
return ['newLeaf'].includes(opt.value) && state.parentSelect
|
||||
return state.opt && ['newLeaf'].includes(state.opt) && state.parentSelect
|
||||
})
|
||||
|
||||
const saveResource = () => {
|
||||
@@ -122,6 +115,7 @@ const saveResource = () => {
|
||||
nodeType: state.nodeType,
|
||||
name: resourceForm.name,
|
||||
opt: state.opt,
|
||||
pid: resourceForm.pid,
|
||||
type: 'dashboard'
|
||||
}
|
||||
saveDashboardResource(params, function (rsp:any) {
|
||||
@@ -147,8 +141,7 @@ const filterMethod = (value: any) => {
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
optInit,
|
||||
editeInit
|
||||
optInit
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
@@ -205,7 +205,7 @@ onMounted(() => {
|
||||
|
||||
// @ts-ignore
|
||||
const addOperation = (params: any) => {
|
||||
if (params.cmd === 'newLeaf') {
|
||||
if (params.opt === 'newLeaf') {
|
||||
const newCanvasUrl = '#/canvas?opt=create' + (params?.id ? `&pid=${params?.id}` : '')
|
||||
window.open(newCanvasUrl, '_blank')
|
||||
} else {
|
||||
@@ -232,7 +232,7 @@ defineExpose({
|
||||
<el-icon
|
||||
class="custom-icon btn"
|
||||
style="margin-right: 10px"
|
||||
@click="addOperation({cmd:'newFolder',type:'folder'} )"
|
||||
@click="addOperation({opt:'newFolder',type:'folder',pid:'root'} )"
|
||||
>
|
||||
<Icon name="dv-new-folder">
|
||||
<newFolder class="svg-icon"/>
|
||||
@@ -243,7 +243,7 @@ defineExpose({
|
||||
<el-icon
|
||||
class="custom-icon btn"
|
||||
style="margin-right: 10px"
|
||||
@click="addOperation({cmd:'newLeaf',type:'dashboard'} )"
|
||||
@click="addOperation({opt:'newLeaf',type:'dashboard'} )"
|
||||
>
|
||||
<Icon name="dv-new-folder">
|
||||
<icon_fileAdd_outlined class="svg-icon"/>
|
||||
@@ -303,7 +303,7 @@ defineExpose({
|
||||
v-on:click.stop
|
||||
v-if="!data.leaf"
|
||||
class="hover-icon"
|
||||
@click="addOperation({cmd:'newLeaf',type:'dashboard',id:data.id} )"
|
||||
@click="addOperation({opt:'newLeaf',type:'dashboard',id:data.id} )"
|
||||
>
|
||||
<Icon><icon_add_outlined class="svg-icon"/></Icon>
|
||||
</el-icon>
|
||||
@@ -315,14 +315,14 @@ defineExpose({
|
||||
>
|
||||
<Icon><icon_edit_outlined class="svg-icon"/></Icon>
|
||||
</el-icon>
|
||||
<!-- <HandleMore-->
|
||||
<!-- @handle-command=" (cmd:string) => addOperation({cmd})-->
|
||||
<!-- "-->
|
||||
<!-- :menu-list="resourceTypeList"-->
|
||||
<!-- :icon-name="icon_add_outlined"-->
|
||||
<!-- placement="bottom-start"-->
|
||||
<!-- v-if="!data.leaf"-->
|
||||
<!-- ></HandleMore>-->
|
||||
<!-- <HandleMore-->
|
||||
<!-- @handle-command=" (opt:string) => addOperation({opt})-->
|
||||
<!-- "-->
|
||||
<!-- :menu-list="resourceTypeList"-->
|
||||
<!-- :icon-name="icon_add_outlined"-->
|
||||
<!-- placement="bottom-start"-->
|
||||
<!-- v-if="!data.leaf"-->
|
||||
<!-- ></HandleMore>-->
|
||||
</div>
|
||||
</span>
|
||||
</template>
|
||||
|
||||
@@ -40,7 +40,7 @@ const props = defineProps({
|
||||
|
||||
const groupOptFinish = (result: any) => {
|
||||
let url = window.location.href
|
||||
url = url.replace(/(#\/[^?]*)(?:\?[^#]*)?/, `$1?dvId=${result.id}`)
|
||||
url = url.replace(/(#\/[^?]*)(?:\?[^#]*)?/, `$1?resourceId=${result.resourceId}`)
|
||||
window.history.replaceState( { path: url }, '', url )
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import {dashboardApi} from "@/api/dashboard.ts";
|
||||
import {dashboardStoreWithOut} from "@/stores/dashboard/dashboard.ts";
|
||||
import {storeToRefs} from "pinia";
|
||||
const dashboardStore = dashboardStoreWithOut()
|
||||
const {componentData,canvasStyle} = storeToRefs(dashboardStore)
|
||||
|
||||
const dashboardStore = dashboardStoreWithOut()
|
||||
const {componentData, canvasStyle} = storeToRefs(dashboardStore)
|
||||
|
||||
const workspace_id = 'default' // temp
|
||||
export const initCanvasData = (params: any, callBack: Function) => {
|
||||
dashboardApi.getDashboardInfo(params).then((res: any) => {
|
||||
const canvasInfo = res.data;
|
||||
@@ -28,20 +30,24 @@ export const initCanvasData = (params: any, callBack: Function) => {
|
||||
}
|
||||
|
||||
export const saveDashboardResource = (params: any, callBack: Function) => {
|
||||
if(params.opt === 'newLeaf'){// create canvas
|
||||
const reqeustParams = {
|
||||
...params,
|
||||
component_data:JSON.stringify(componentData.value),
|
||||
canvas_style_data:JSON.stringify(canvasStyle.value)
|
||||
params['workspace_id'] = workspace_id
|
||||
dashboardApi.check_name(params).then((res: any) => {
|
||||
if (!res) {
|
||||
if (params.opt === 'newLeaf') {// create canvas
|
||||
const reqeustParams = {
|
||||
...params,
|
||||
component_data: JSON.stringify(componentData.value),
|
||||
canvas_style_data: JSON.stringify(canvasStyle.value)
|
||||
}
|
||||
dashboardApi.saveCanvas(reqeustParams).then((res: any) => {
|
||||
dashboardStore.updateDashboardInfo({id: res.id, dataState: 'ready'})
|
||||
callBack(res)
|
||||
})
|
||||
} else if (params.opt === 'newFolder') {
|
||||
dashboardApi.addResource(params).then((res: any) => {
|
||||
callBack(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
dashboardApi.saveCanvas(reqeustParams).then((res: any) => {
|
||||
dashboardStore.updateDashboardInfo({id:res.id,dataState:'ready'})
|
||||
callBack(res)
|
||||
})
|
||||
}else if(params.opt === 'newFolder'){
|
||||
dashboardApi.addResource(params).then((res: any) => {
|
||||
callBack(res)
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user