ProjectVisNetwork.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <div class="project-mind-map">
  3. <MenuPage cur-key="/project_manage/project" />
  4. <div class="project-mind-map__header">
  5. <span class="name">{{ project_info.name }}</span>
  6. <div class="courseware">
  7. <div class="operator flex">
  8. <span class="link" @click="getMangerGenerateVisNetworkByBook">根据教材内容生成知识图谱</span>
  9. <span class="link" @click="saveBookVisnetwork">保存</span>
  10. <span class="link" @click="goBackBookList">返回项目列表</span>
  11. </div>
  12. </div>
  13. </div>
  14. <p v-if="isWaiting" class="waiting">数据生成中...请等待</p>
  15. <VisNetwork v-if="isChildDataLoad" ref="visNetworRef" :book-id="book_id" :is-edit="true" />
  16. </div>
  17. </template>
  18. <script>
  19. import MenuPage from '@/views/personal_workbench/common/menu.vue';
  20. import VisNetwork from '@/components/VisNetwork.vue';
  21. import { GetProjectBaseInfo } from '@/api/project';
  22. import { MangerGenerateKnowledgeGraphByBookContent, SaveBookKnowledgeGraph } from '@/api/book';
  23. export default {
  24. name: 'ProjectVisNetwork',
  25. components: {
  26. MenuPage,
  27. VisNetwork,
  28. },
  29. data() {
  30. return {
  31. project_id: this.$route.params.projectId || '',
  32. book_id: '',
  33. project_info: {}, // 项目基本信息
  34. isWaiting: false,
  35. isChildDataLoad: false,
  36. jsonData: '',
  37. };
  38. },
  39. created() {
  40. this.getProjectBaseInfo();
  41. },
  42. methods: {
  43. goBackBookList() {
  44. this.$router.push({ path: `/project_manage/project` });
  45. },
  46. /**
  47. * 获取项目基本信息
  48. * @param {string} id - 项目ID
  49. */
  50. getProjectBaseInfo() {
  51. GetProjectBaseInfo({ id: this.project_id }).then(({ project_info, book_info_PBE }) => {
  52. this.project_info = project_info;
  53. this.book_id = book_info_PBE.id;
  54. this.isChildDataLoad = true;
  55. });
  56. },
  57. /**
  58. * 生成知识图谱
  59. * @param {string} id - 教材ID
  60. */
  61. getMangerGenerateVisNetworkByBook() {
  62. this.isChildDataLoad = false;
  63. this.isWaiting = true;
  64. MangerGenerateKnowledgeGraphByBookContent({ book_id: this.book_id }).then((res) => {
  65. if (res && res.status === 1) {
  66. this.isChildDataLoad = true;
  67. this.isWaiting = false;
  68. }
  69. });
  70. },
  71. saveBookVisnetwork() {
  72. let data = this.$refs?.visNetworRef.saveData();
  73. if (!data) {
  74. this.$message.error('请先生成数据');
  75. return;
  76. }
  77. let node = { nodes: data.nodes };
  78. let edge = { edges: data.edges };
  79. const loading = this.$loading({
  80. lock: true,
  81. text: '保存中...',
  82. spinner: 'el-icon-loading',
  83. background: 'rgba(0, 0, 0, 0.7)',
  84. });
  85. SaveBookKnowledgeGraph({
  86. book_id: this.book_id,
  87. content_node: JSON.stringify(node),
  88. content_edge: JSON.stringify(edge),
  89. }).then(() => {
  90. this.$message.success('保存成功');
  91. loading.close();
  92. });
  93. },
  94. },
  95. };
  96. </script>
  97. <style lang="scss" scoped>
  98. @use '@/styles/mixin.scss' as *;
  99. .project-mind-map {
  100. @include page-content(true);
  101. &__header {
  102. .name {
  103. width: 240px;
  104. font-size: 16px;
  105. font-weight: bold;
  106. border-right: $border;
  107. }
  108. .operator {
  109. display: flex;
  110. flex: 1;
  111. justify-content: flex-end;
  112. }
  113. }
  114. .waiting {
  115. display: flex;
  116. align-items: center; /* 垂直居中 */
  117. justify-content: center; /* 水平居中 */
  118. height: calc(100vh - 250px);
  119. }
  120. }
  121. </style>