Commit 4d35e7f3 authored by 郭铭瑶's avatar 郭铭瑶 🤘

所有获取数据判断非空

parent af9f585f
...@@ -304,7 +304,8 @@ function fetchSubjects() { ...@@ -304,7 +304,8 @@ function fetchSubjects() {
}) })
.then((res) => { .then((res) => {
console.log('subject', res.data.content) console.log('subject', res.data.content)
const [{ links, nodes }] = res.data.content const { links = [], nodes = [] } =
res.data && res.data.content && res.data.content[0]
subjectOptions.value = nodes.map((item) => ({ subjectOptions.value = nodes.map((item) => ({
label: item.subjectName, label: item.subjectName,
value: item.nodeId, value: item.nodeId,
...@@ -325,7 +326,7 @@ function fetchTags() { ...@@ -325,7 +326,7 @@ function fetchTags() {
url: api.GET_TAG_CLASS, url: api.GET_TAG_CLASS,
}) })
.then((res) => { .then((res) => {
const data = res.data.content const data = (res.data && res.data.content) || []
tagClassOptions.value = data.map((e) => ({ tagClassOptions.value = data.map((e) => ({
label: e.classification, label: e.classification,
value: e.classification, value: e.classification,
...@@ -342,7 +343,6 @@ function fetchTags() { ...@@ -342,7 +343,6 @@ function fetchTags() {
label: e.labelName, label: e.labelName,
value: e.nodeId + '', value: e.nodeId + '',
})) }))
console.log(tagOptions.value)
}) })
} }
fetchTags() fetchTags()
...@@ -353,8 +353,8 @@ function getSelectOptions() { ...@@ -353,8 +353,8 @@ function getSelectOptions() {
url: api.GET_RELATIONS, url: api.GET_RELATIONS,
}) })
.then((res) => { .then((res) => {
if (!res.data || !res.data.content) return const data = (res.data && res.data.content) || []
relationOptions.value = res.data.content.map((item) => ({ relationOptions.value = data.map((item) => ({
label: item.relationName, label: item.relationName,
value: item.id + '', value: item.id + '',
})) }))
...@@ -364,8 +364,8 @@ function getSelectOptions() { ...@@ -364,8 +364,8 @@ function getSelectOptions() {
url: api.GET_SYSTEMS, url: api.GET_SYSTEMS,
}) })
.then((res) => { .then((res) => {
if (!res.data || !res.data.content) return const data = (res.data && res.data.content) || []
systemOptions.value = res.data.content.map((item) => ({ systemOptions.value = data.map((item) => ({
label: item.systemName, label: item.systemName,
value: item.nodeId + '', value: item.nodeId + '',
})) }))
...@@ -383,7 +383,7 @@ function fetchSubordinates(params = null) { ...@@ -383,7 +383,7 @@ function fetchSubordinates(params = null) {
}, },
}) })
.then((res) => { .then((res) => {
const { links, nodes } = res.data.content const { links = [], nodes = [] } = res.data && res.data.content
graphData.value = { graphData.value = {
nodes: [ nodes: [
...graphData.value.nodes, ...graphData.value.nodes,
...@@ -442,7 +442,6 @@ function selectTag(nodeId, i) { ...@@ -442,7 +442,6 @@ function selectTag(nodeId, i) {
function submitNewNode(e) { function submitNewNode(e) {
e.preventDefault() e.preventDefault()
console.log(formData.value)
formRef.value.validate(async (errors) => { formRef.value.validate(async (errors) => {
if (!errors) { if (!errors) {
isLoading.value = true isLoading.value = true
...@@ -625,7 +624,10 @@ const searchNodes = (type, key) => { ...@@ -625,7 +624,10 @@ const searchNodes = (type, key) => {
params, params,
}) })
.then((res) => { .then((res) => {
graphData.value = res.data.content graphData.value = (res.data && res.data.content) || {
links: [],
nodes: [],
}
}) })
} }
......
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