Commit 3260a18b authored by 郭铭瑶's avatar 郭铭瑶 🤘

修改选择系统id

parent 3f389244
...@@ -89,17 +89,6 @@ export default { ...@@ -89,17 +89,6 @@ export default {
} }
function init() { function init() {
if (!container.value) return if (!container.value) return
// if (instance) {
// instance.graph.selectAll('*').remove()
// }
// instance = new RelationGraph(
// container.value,
// props.data,
// props.config,
// menuData,
// colorList,
// setCurNode
// )
if (instance) { if (instance) {
instance.update(props.data) instance.update(props.data)
} else { } else {
...@@ -114,9 +103,11 @@ export default { ...@@ -114,9 +103,11 @@ export default {
} }
setLegend() setLegend()
} }
function setKey(key) { function setKey(key) {
instance.setKey(key) instance.setKey(key)
} }
watch( watch(
() => props.data, () => props.data,
() => init(), () => init(),
......
...@@ -110,5 +110,5 @@ export default defineComponent({ ...@@ -110,5 +110,5 @@ export default defineComponent({
box-shadow 10px 6px 10px 0 #000 box-shadow 10px 6px 10px 0 #000
margin-top 4px margin-top 4px
.search-bar .search-bar
width 50% width 46%
</style> </style>
...@@ -7,17 +7,17 @@ ...@@ -7,17 +7,17 @@
class="graph" class="graph"
:data="graphData" :data="graphData"
@branch="fetchSubordinates" @branch="fetchSubordinates"
@add="handleAdd" @add="openAddDrawer"
@curNode="curNode = $event" @curNode="curNode = $event"
@del="handleDelete" @del="deleteNode"
/> />
<Side style="grid-area: side" /> <Side style="grid-area: side" />
<Footer <Footer
style="grid-area: footer" style="grid-area: footer"
:node="curNode" :node="curNode"
@add="showSubjectDrawer = true" @add="showSubjectDrawer = true"
@set="setKey" @set="setLabelKey"
@search="handleSearch" @search="searchSubject"
/> />
</div> </div>
<n-drawer v-model:show="showDrawer" :width="400" placement="left"> <n-drawer v-model:show="showDrawer" :width="400" placement="left">
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
/> />
</n-form-item> </n-form-item>
<n-space justify="end"> <n-space justify="end">
<n-button :loading="isLoading" type="primary" @click="submit"> <n-button :loading="isLoading" type="primary" @click="submitNewNode">
提交 提交
</n-button> </n-button>
</n-space> </n-space>
...@@ -102,6 +102,7 @@ export default { ...@@ -102,6 +102,7 @@ export default {
const systemOptions = ref([]) const systemOptions = ref([])
const graphData = ref({ nodes: [], links: [] }) const graphData = ref({ nodes: [], links: [] })
const subjectNodes = ref([]) const subjectNodes = ref([])
function fetchSubjects() { function fetchSubjects() {
ajax ajax
.get({ .get({
...@@ -117,6 +118,8 @@ export default { ...@@ -117,6 +118,8 @@ export default {
}) })
} }
fetchSubjects() fetchSubjects()
function getSelectOptions() {
ajax ajax
.get({ .get({
url: api.GET_RELATIONS, url: api.GET_RELATIONS,
...@@ -136,9 +139,12 @@ export default { ...@@ -136,9 +139,12 @@ export default {
if (!res.data || !res.data.content) return if (!res.data || !res.data.content) return
systemOptions.value = res.data.content.map((item) => ({ systemOptions.value = res.data.content.map((item) => ({
label: item.systemName, label: item.systemName,
value: item.id + '', value: item.nodeId + '',
})) }))
}) })
}
getSelectOptions()
function fetchSubordinates(params = null) { function fetchSubordinates(params = null) {
ajax ajax
.get({ .get({
...@@ -168,7 +174,8 @@ export default { ...@@ -168,7 +174,8 @@ export default {
} }
}) })
} }
function handleAdd({ nodeId }) {
function openAddDrawer({ nodeId }) {
formData.value = { formData.value = {
propertyName: null, propertyName: null,
relationId: null, relationId: null,
...@@ -177,10 +184,12 @@ export default { ...@@ -177,10 +184,12 @@ export default {
subjectId.value = nodeId subjectId.value = nodeId
showDrawer.value = true showDrawer.value = true
} }
function setKey(key) {
function setLabelKey(key) {
d3Ref.value.setKey(key) d3Ref.value.setKey(key)
} }
function submit(e) {
function submitNewNode(e) {
e.preventDefault() e.preventDefault()
formRef.value.validate((errors) => { formRef.value.validate((errors) => {
if (!errors) { if (!errors) {
...@@ -205,8 +214,10 @@ export default { ...@@ -205,8 +214,10 @@ export default {
} }
}) })
} }
const curNode = ref(null) const curNode = ref(null)
function handleDelete(data) {
function deleteNode(data) {
dialog.error({ dialog.error({
title: '删除节点', title: '删除节点',
content: `确定是否删除 '${ content: `确定是否删除 '${
...@@ -262,7 +273,8 @@ export default { ...@@ -262,7 +273,8 @@ export default {
} }
}) })
} }
const handleSearch = (key) => {
const searchSubject = (key) => {
if (!key) { if (!key) {
fetchSubjects() fetchSubjects()
return return
...@@ -280,16 +292,16 @@ export default { ...@@ -280,16 +292,16 @@ export default {
formRef, formRef,
formData, formData,
showDrawer, showDrawer,
submit, submitNewNode,
isLoading, isLoading,
relationOptions, relationOptions,
systemOptions, systemOptions,
graphData, graphData,
mockData, mockData,
fetchSubordinates, fetchSubordinates,
handleAdd, openAddDrawer,
d3Ref, d3Ref,
setKey, setLabelKey,
rules: { rules: {
subjectName: [ subjectName: [
{ {
...@@ -321,12 +333,12 @@ export default { ...@@ -321,12 +333,12 @@ export default {
], ],
}, },
curNode, curNode,
handleDelete, deleteNode,
showSubjectDrawer, showSubjectDrawer,
subjectFormRef, subjectFormRef,
subjectData, subjectData,
addSubject, addSubject,
handleSearch, searchSubject,
} }
}, },
} }
......
import * as d3 from 'd3' import * as d3 from 'd3'
import RadialMenu from './menu' import RadialMenu from './menu'
// import branch from '@/assets/images/branch.svg'
// import more from '@/assets/images/more.svg'
// import add from '@/assets/images/add.svg'
// import del from '@/assets/images/delete.svg'
// 求两点间的距离 // 求两点间的距离
function getDis(s, t) { function getDis(s, t) {
...@@ -96,12 +92,6 @@ const defaultConfig = { ...@@ -96,12 +92,6 @@ const defaultConfig = {
}, },
} }
// const menuData = [
// { icon: branch, action: () => console.log('branch'), title: '分支' },
// { icon: more, action: () => console.log('more'), title: '更多' },
// { icon: add, action: () => console.log('add'), title: '新增' },
// { icon: del, action: () => console.log('del'), title: '删除' },
// ]
let menu = null let menu = null
export default class RelationGraph { export default class RelationGraph {
......
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