Commit bcfd01c7 authored by 郭铭瑶's avatar 郭铭瑶 🤘

节点添加及删除操作

parent 57460837
...@@ -7,6 +7,7 @@ switch (process.env.NODE_ENV) { ...@@ -7,6 +7,7 @@ switch (process.env.NODE_ENV) {
export default { export default {
BASE_URL, BASE_URL,
GET_SUBJECTS: '/subjects',
GET_RELATIONS: '/relations', GET_RELATIONS: '/relations',
POST_SUBJECT: '/subject', POST_SUBJECT: '/subject',
POST_NODE: '/node/relation', POST_NODE: '/node/relation',
......
...@@ -100,6 +100,18 @@ export default { ...@@ -100,6 +100,18 @@ export default {
colorList, colorList,
setCurNode setCurNode
) )
// if (instance) {
// instance.update(props.data)
// } else {
// instance = new RelationGraph(
// container.value,
// props.data,
// props.config,
// menuData,
// colorList,
// setCurNode
// )
// }
setLegend() setLegend()
} }
function setKey(key) { function setKey(key) {
......
<template> <template>
<div class="footer"> <div class="footer">
<n-button type="primary" ghost @click="addSubject">Add Subject</n-button>
<n-space> <n-space>
<n-tag v-show="nodeVal" size="small" round :color="color"> <n-tag v-show="nodeVal" size="small" round :color="color">
{{ nodeVal && nodeVal.nodeLabel }} {{ nodeVal && nodeVal.nodeLabel }}
...@@ -31,7 +32,7 @@ export default defineComponent({ ...@@ -31,7 +32,7 @@ export default defineComponent({
}), }),
}, },
}, },
emits: ['set'], emits: ['set', 'add'],
setup(props, ctx) { setup(props, ctx) {
const colorList = { const colorList = {
default: 'skyblue', default: 'skyblue',
...@@ -65,12 +66,16 @@ export default defineComponent({ ...@@ -65,12 +66,16 @@ export default defineComponent({
'nodeId', 'nodeId',
'nodeLabel', 'nodeLabel',
]) ])
const addSubject = () => {
ctx.emit('add')
}
return { return {
curKey, curKey,
setKey, setKey,
list, list,
color, color,
nodeVal, nodeVal,
addSubject,
} }
}, },
}) })
...@@ -80,7 +85,7 @@ export default defineComponent({ ...@@ -80,7 +85,7 @@ export default defineComponent({
.footer .footer
display flex display flex
align-items center align-items center
justify-content flex-end justify-content space-between
padding 0 15px 8px padding 0 15px 8px
background #f8f9fb background #f8f9fb
box-shadow 10px 6px 10px 0 #000 box-shadow 10px 6px 10px 0 #000
......
<template> <template>
<div class="main"> <div class="main">
<Nav style="grid-area: nav" /> <Nav style="grid-area: nav" @search="handleSearch" />
<D3 <D3
ref="d3Ref" ref="d3Ref"
style="grid-area: content" style="grid-area: content"
class="graph" class="graph"
:data="data" :data="data"
@branch="handleBranch" @branch="fetchSubordinates"
@add="handleAdd" @add="handleAdd"
@curNode="curNode = $event" @curNode="curNode = $event"
@del="handleDelete" @del="handleDelete"
/> />
<Side style="grid-area: side" /> <Side style="grid-area: side" />
<Footer style="grid-area: footer" :node="curNode" @set="setKey" /> <Footer
style="grid-area: footer"
:node="curNode"
@add="showSubjectDrawer = true"
@set="setKey"
/>
</div> </div>
<n-drawer v-model:show="showDrawer" :width="400" placement="left"> <n-drawer v-model:show="showDrawer" :width="400" placement="left">
<n-drawer-content title="新增节点"> <n-drawer-content title="新增节点">
...@@ -46,6 +51,24 @@ ...@@ -46,6 +51,24 @@
</n-form> </n-form>
</n-drawer-content> </n-drawer-content>
</n-drawer> </n-drawer>
<n-drawer v-model:show="showSubjectDrawer" :width="400" placement="left">
<n-drawer-content title="新增Suject">
<n-form ref="subjectFormRef" :model="subjectData" :rules="rules">
<n-form-item path="subjectName" label="名称">
<n-input
v-model:value="subjectData.subjectName"
placeholder="请输入"
@keydown.enter.prevent
/>
</n-form-item>
<n-space justify="end">
<n-button :loading="isLoading" type="primary" @click="addSubject">
提交
</n-button>
</n-space>
</n-form>
</n-drawer-content>
</n-drawer>
</template> </template>
<script> <script>
...@@ -69,6 +92,7 @@ export default { ...@@ -69,6 +92,7 @@ export default {
const formData = ref({ const formData = ref({
propertyName: null, propertyName: null,
relationId: null, relationId: null,
systemId: null,
}) })
const showDrawer = ref(false) const showDrawer = ref(false)
const isLoading = ref(false) const isLoading = ref(false)
...@@ -76,20 +100,32 @@ export default { ...@@ -76,20 +100,32 @@ export default {
const relationOptions = ref([]) const relationOptions = ref([])
const systemOptions = ref([]) const systemOptions = ref([])
const data = ref([]) const data = ref([])
function getData() { const subjectNodes = ref([])
function fetchSubjects() {
// ajax
// .get({
// url: api.GET_NODES,
// params: { nodeId: '572563400077869056' },
// })
// .then((res) => {
// console.log('nodes:', res)
// data.value = res.data.content
// systemOptions.value = data.value.nodes
// .filter((node) => node.nodeLabel === 'System')
// .map((node) => ({ label: node.systemName, value: node.nodeId }))
// })
ajax ajax
.get({ .get({
url: api.GET_NODES, url: api.GET_SUBJECTS,
}) })
.then((res) => { .then((res) => {
console.log('nodes:', res) console.log('subject', res.data.content)
data.value = res.data.content subjectNodes.value = res.data.content
systemOptions.value = data.value.nodes data.value = { nodes: subjectNodes.value, links: [] }
.filter((node) => node.nodeLabel === 'System')
.map((node) => ({ label: node.systemName, value: node.nodeId }))
}) })
} }
getData() fetchSubjects()
ajax ajax
.get({ .get({
url: api.GET_RELATIONS, url: api.GET_RELATIONS,
...@@ -101,18 +137,32 @@ export default { ...@@ -101,18 +137,32 @@ export default {
value: item.id, value: item.id,
})) }))
}) })
function handleBranch({ nodeId }) { function fetchSubordinates(params = null) {
ajax ajax
.get({ .get({
url: api.GET_NODES, url: api.GET_NODES,
params: { nodeId }, params,
}) })
.then((res) => { .then((res) => {
console.log('nodes:', res) const { links, nodes } = res.data.content
// data.value = res.data.content data.value = {
nodes: [
...data.value.nodes,
...nodes.filter((node) => node.nodeLabel !== 'Subject'),
],
links: [...data.value.links, ...links],
}
systemOptions.value = data.value.nodes
.filter((node) => node.nodeLabel === 'System')
.map((node) => ({ label: node.systemName, value: node.nodeId }))
}) })
} }
function handleAdd({ nodeId }) { function handleAdd({ nodeId }) {
formData.value = {
propertyName: null,
relationId: null,
systemId: null,
}
subjectId.value = nodeId subjectId.value = nodeId
showDrawer.value = true showDrawer.value = true
} }
...@@ -133,7 +183,8 @@ export default { ...@@ -133,7 +183,8 @@ export default {
}, },
}) })
.then(() => { .then(() => {
getData() // fetchSubjects()
fetchSubordinates({ nodeId: subjectId.value })
isLoading.value = false isLoading.value = false
showDrawer.value = false showDrawer.value = false
message.success('提交成功') message.success('提交成功')
...@@ -152,11 +203,61 @@ export default { ...@@ -152,11 +203,61 @@ export default {
negativeText: '取消', negativeText: '取消',
maskClosable: false, maskClosable: false,
onPositiveClick: () => { onPositiveClick: () => {
console.log('delete', data) ajax
.delete({
url: api.DELETE_NODE.replace('{id}', data.id),
})
.then(() => {
if (data.nodeLabel === 'Subject') {
fetchSubjects()
} else {
fetchSubordinates({ nodeId: null })
}
message.success('删除成功!') message.success('删除成功!')
})
}, },
}) })
} }
const subjectFormRef = ref(null)
const showSubjectDrawer = ref(false)
const subjectData = ref({ subjectName: null })
const addSubject = (e) => {
e.preventDefault()
subjectFormRef.value.validate((errors) => {
if (!errors) {
isLoading.value = true
ajax
.post({
url: api.POST_SUBJECT,
params: subjectData.value,
})
.then(() => {
fetchSubjects()
isLoading.value = false
showSubjectDrawer.value = false
message.success('提交成功')
})
}
})
}
const handleSearch = (key) => {
if (!key) {
fetchSubjects()
return
}
ajax
.get({
url: api.GET_NODES,
params: { nodeName: key },
})
.then((res) => {
data.value = res.data.content
systemOptions.value = data.value.nodes
.filter((node) => node.nodeLabel === 'System')
.map((node) => ({ label: node.systemName, value: node.nodeId }))
})
}
return { return {
formRef, formRef,
formData, formData,
...@@ -167,35 +268,47 @@ export default { ...@@ -167,35 +268,47 @@ export default {
systemOptions, systemOptions,
data, data,
mockData, mockData,
handleBranch, fetchSubordinates,
handleAdd, handleAdd,
d3Ref, d3Ref,
setKey, setKey,
rules: { rules: {
propertyName: [ subjectName: [
{ {
required: true, required: true,
message: '请输入节点名称', message: '请输入名称',
trigger: ['input', 'blur'], trigger: ['input', 'blur'],
}, },
], ],
relationId: [ propertyName: [
{ {
required: true, required: true,
message: '请选择从属类型', message: '请输入节点名称',
trigger: ['input', 'blur'], trigger: ['input', 'blur'],
}, },
], ],
systemId: [ relationId: [
{ {
required: true, required: true,
message: '请选择所属系统', message: '请选择从属类型',
trigger: ['input', 'blur'], trigger: ['input', 'blur'],
}, },
], ],
// systemId: [
// {
// required: true,
// message: '请选择所属系统',
// trigger: ['input', 'blur'],
// },
// ],
}, },
curNode, curNode,
handleDelete, handleDelete,
showSubjectDrawer,
subjectFormRef,
subjectData,
addSubject,
handleSearch,
} }
}, },
} }
...@@ -209,7 +322,7 @@ export default { ...@@ -209,7 +322,7 @@ export default {
overflow hidden overflow hidden
grid-template-areas 'nav nav' 'side content' 'side footer' grid-template-areas 'nav nav' 'side content' 'side footer'
grid-template-columns 0px 1fr grid-template-columns 0px 1fr
grid-template-rows 0px 1fr 70px grid-template-rows 40px 1fr 70px
padding 4px padding 4px
font-weight bold !important font-weight bold !important
</style> </style>
<template> <template>
<div class="nav"></div> <div class="nav">
<n-input
v-model:value="searchKey"
type="text"
placeholder="搜索Subject"
clearable
@keypress.enter="search"
/>
</div>
</template> </template>
<script> <script>
import { defineComponent } from 'vue' import { defineComponent, ref } from 'vue'
export default defineComponent({ export default defineComponent({
name: 'Nav', name: 'Nav',
setup() {}, emits: ['search'],
setup(_, ctx) {
const searchKey = ref(null)
return {
searchKey,
search: () => ctx.emit('search', searchKey.value),
}
},
}) })
</script> </script>
...@@ -15,4 +30,5 @@ export default defineComponent({ ...@@ -15,4 +30,5 @@ export default defineComponent({
.nav .nav
background #f9fbfd background #f9fbfd
border-bottom 4px solid #fff border-bottom 4px solid #fff
padding 0 10px
</style> </style>
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment