Commit 7efb3722 authored by 郭铭瑶's avatar 郭铭瑶 🤘

获取要素接口更换v2

parent ef69b7de
...@@ -7,7 +7,8 @@ switch (process.env.NODE_ENV) { ...@@ -7,7 +7,8 @@ switch (process.env.NODE_ENV) {
export default { export default {
BASE_URL, BASE_URL,
GET_SUBJECTS: '/subjects', GET_SUBJECTS: '/subjects/v2',
PUT_SUBJECT: '/subject/{id}',
GET_RELATIONS: '/relations', GET_RELATIONS: '/relations',
POST_SUBJECT: '/subject', POST_SUBJECT: '/subject',
POST_NODE: '/node/relation', POST_NODE: '/node/relation',
...@@ -16,4 +17,5 @@ export default { ...@@ -16,4 +17,5 @@ export default {
DELETE_NODE: '/node/{id}', DELETE_NODE: '/node/{id}',
GET_SYSTEMS: '/systems', GET_SYSTEMS: '/systems',
POST_LINK_SUBJECTS: '/node/relations', POST_LINK_SUBJECTS: '/node/relations',
GET_TAGS: '/label/classification',
} }
...@@ -174,59 +174,66 @@ ...@@ -174,59 +174,66 @@
</n-drawer> </n-drawer>
</template> </template>
<script> <script setup>
import D3 from './d3.vue' import D3 from './d3.vue'
import Nav from './nav.vue' import Nav from './nav.vue'
import Side from './side.vue' import Side from './side.vue'
import Footer from './footer.vue' import Footer from './footer.vue'
import mockData from '@/util/mock.js'
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
import { ajax, api } from '@/ajax' import { ajax, api } from '@/ajax'
import { useMessage, useDialog } from 'naive-ui' import { useMessage, useDialog } from 'naive-ui'
export default {
name: 'Main', const message = useMessage()
components: { D3, Nav, Side, Footer }, const dialog = useDialog()
setup() { const curSubject = ref(null)
const message = useMessage() const formRef = ref(null)
const dialog = useDialog() const formData = ref([
const curSubject = ref(null)
const formRef = ref(null)
const formData = ref([
{ {
propertyName: null, propertyName: null,
relationId: null, relationId: null,
systemIds: null, systemIds: null,
}, },
]) ])
const showDrawer = ref(false) const showDrawer = ref(false)
const isLoading = ref(false) const isLoading = ref(false)
const d3Ref = ref(null) const d3Ref = ref(null)
const relationOptions = ref([]) const relationOptions = ref([])
const systemOptions = ref([]) const systemOptions = ref([])
const graphData = ref({ nodes: [], links: [] }) const graphData = ref({ nodes: [], links: [] })
const subjectOptions = ref([]) const subjectOptions = ref([])
function fetchSubjects() { function fetchSubjects() {
ajax ajax
.get({ .get({
url: api.GET_SUBJECTS, url: api.GET_SUBJECTS,
}) })
.then((res) => { .then((res) => {
console.log('subject', res.data.content) console.log('subject', res.data.content)
const data = res.data.content const [{ links, nodes }] = res.data.content
subjectOptions.value = data.map((item) => ({ subjectOptions.value = nodes.map((item) => ({
label: item.subjectName, label: item.subjectName,
value: item.nodeId, value: item.nodeId,
})) }))
graphData.value = { graphData.value = {
nodes: [...data], nodes: [...nodes],
links: [], links: [...links],
} }
}) })
} }
fetchSubjects() fetchSubjects()
function fetchTags() {
ajax
.get({
url: api.GET_TAGS,
})
.then((res) => {
console.log('tags', res.data.content)
})
}
fetchTags()
function getSelectOptions() { function getSelectOptions() {
ajax ajax
.get({ .get({
url: api.GET_RELATIONS, url: api.GET_RELATIONS,
...@@ -249,10 +256,10 @@ export default { ...@@ -249,10 +256,10 @@ export default {
value: item.nodeId + '', value: item.nodeId + '',
})) }))
}) })
} }
getSelectOptions() getSelectOptions()
function fetchSubordinates(params = null) { function fetchSubordinates(params = null) {
ajax ajax
.get({ .get({
url: api.GET_NODES, url: api.GET_NODES,
...@@ -280,9 +287,9 @@ export default { ...@@ -280,9 +287,9 @@ export default {
], ],
} }
}) })
} }
function openAddDrawer(node) { function openAddDrawer(node) {
formData.value = [ formData.value = [
{ {
propertyName: null, propertyName: null,
...@@ -292,13 +299,13 @@ export default { ...@@ -292,13 +299,13 @@ export default {
] ]
curSubject.value = node curSubject.value = node
showDrawer.value = true showDrawer.value = true
} }
function setLabelKey(key) { function setLabelKey(key) {
d3Ref.value.setKey(key) d3Ref.value.setKey(key)
} }
function submitNewNode(e) { function submitNewNode(e) {
e.preventDefault() e.preventDefault()
formRef.value.validate((errors) => { formRef.value.validate((errors) => {
if (!errors) { if (!errors) {
...@@ -325,11 +332,11 @@ export default { ...@@ -325,11 +332,11 @@ export default {
}) })
} }
}) })
} }
const curNode = ref(null) const curNode = ref(null)
function deleteNode(data) { function deleteNode(data) {
dialog.error({ dialog.error({
title: '删除节点', title: '删除节点',
content: `确定是否删除 '${ content: `确定是否删除 '${
...@@ -348,12 +355,9 @@ export default { ...@@ -348,12 +355,9 @@ export default {
fetchSubjects() fetchSubjects()
} else { } else {
graphData.value = { graphData.value = {
nodes: graphData.value.nodes.filter( nodes: graphData.value.nodes.filter((node) => node.id != data.id),
(node) => node.id != data.id
),
links: graphData.value.links.filter( links: graphData.value.links.filter(
(link) => (link) => link.source.id != data.id && link.target.id != data.id
link.source.id != data.id && link.target.id != data.id
), ),
} }
} }
...@@ -361,9 +365,9 @@ export default { ...@@ -361,9 +365,9 @@ export default {
}) })
}, },
}) })
} }
function deleteLink(data) { function deleteLink(data) {
const { source, target } = data const { source, target } = data
dialog.error({ dialog.error({
title: '删除关联', title: '删除关联',
...@@ -379,25 +383,23 @@ export default { ...@@ -379,25 +383,23 @@ export default {
.then(() => { .then(() => {
graphData.value = { graphData.value = {
nodes: graphData.value.nodes, nodes: graphData.value.nodes,
links: graphData.value.links.filter( links: graphData.value.links.filter((link) => link.id != data.id),
(link) => link.id != data.id
),
} }
message.success('删除成功!') message.success('删除成功!')
}) })
}, },
}) })
} }
const subjectFormRef = ref(null) const subjectFormRef = ref(null)
const showSubjectDrawer = ref(false) const showSubjectDrawer = ref(false)
const subjectData = ref({ const subjectData = ref({
subjectName: null, subjectName: null,
subjectType: null, subjectType: null,
targetSubjectId: null, targetSubjectId: null,
sourceSubjectId: null, sourceSubjectId: null,
}) })
const addSubject = (e) => { const addSubject = (e) => {
e.preventDefault() e.preventDefault()
subjectFormRef.value.validate((errors) => { subjectFormRef.value.validate((errors) => {
if (!errors) { if (!errors) {
...@@ -415,9 +417,9 @@ export default { ...@@ -415,9 +417,9 @@ export default {
}) })
} }
}) })
} }
const searchNodes = (type, key) => { const searchNodes = (type, key) => {
if (!key) { if (!key) {
fetchSubjects() fetchSubjects()
return return
...@@ -430,14 +432,14 @@ export default { ...@@ -430,14 +432,14 @@ export default {
.then((res) => { .then((res) => {
graphData.value = res.data.content graphData.value = res.data.content
}) })
} }
const showLinkDrawer = ref(false) const showLinkDrawer = ref(false)
const linkData = ref({ const linkData = ref({
sourceNodeId: null, sourceNodeId: null,
targetNodeId: null, targetNodeId: null,
}) })
watch( watch(
() => curNode.value, () => curNode.value,
(cur) => { (cur) => {
linkData.value = { linkData.value = {
...@@ -445,9 +447,9 @@ export default { ...@@ -445,9 +447,9 @@ export default {
targetNodeId: null, targetNodeId: null,
} }
} }
) )
const linkFormRef = ref(null) const linkFormRef = ref(null)
const linkSubject = (e) => { const linkSubject = (e) => {
e.preventDefault() e.preventDefault()
linkFormRef.value.validate((errors) => { linkFormRef.value.validate((errors) => {
if (!errors) { if (!errors) {
...@@ -468,8 +470,8 @@ export default { ...@@ -468,8 +470,8 @@ export default {
}) })
} }
}) })
} }
const rules = { const rules = {
subjectName: [ subjectName: [
{ {
required: true, required: true,
...@@ -537,8 +539,8 @@ export default { ...@@ -537,8 +539,8 @@ export default {
message: '源要素不能与目标要素相同', message: '源要素不能与目标要素相同',
}, },
], ],
} }
function openSubjectDrawer() { function openSubjectDrawer() {
showSubjectDrawer.value = true showSubjectDrawer.value = true
subjectData.value = { subjectData.value = {
subjectName: null, subjectName: null,
...@@ -546,58 +548,23 @@ export default { ...@@ -546,58 +548,23 @@ export default {
targetSubjectId: null, targetSubjectId: null,
sourceSubjectId: null, sourceSubjectId: null,
} }
} }
function openLinkDrawer() { function openLinkDrawer() {
showLinkDrawer.value = true showLinkDrawer.value = true
linkData.value = { linkData.value = {
sourceNodeId: null, sourceNodeId: null,
targetNodeId: null, targetNodeId: null,
} }
} }
function addNewItem() { function addNewItem() {
formData.value.push({ formData.value.push({
propertyName: null, propertyName: null,
relationId: null, relationId: null,
systemIds: null, systemIds: null,
}) })
} }
function deleteItem(i) { function deleteItem(i) {
formData.value.splice(i, 1) formData.value.splice(i, 1)
}
return {
formRef,
formData,
showDrawer,
submitNewNode,
isLoading,
relationOptions,
systemOptions,
graphData,
mockData,
fetchSubordinates,
openAddDrawer,
d3Ref,
setLabelKey,
rules,
curNode,
deleteNode,
deleteLink,
showSubjectDrawer,
subjectFormRef,
subjectData,
addSubject,
searchNodes,
showLinkDrawer,
linkFormRef,
linkData,
linkSubject,
subjectOptions,
openSubjectDrawer,
openLinkDrawer,
addNewItem,
deleteItem,
}
},
} }
</script> </script>
......
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