Kaynağa Gözat

fix(knowledge): 修复健康知识库管理页列表无法显示($axios 从未注册)

health-knowledge.vue 自创建起使用项目从未注册的 this.$axios(main.js 无 Vue.prototype.$axios,仅注册 $message/$confirm 等),fetchList 在 mounted 即抛 TypeError,页面列表永远无法渲染。表为空时被"暂无数据"掩盖,809 篇菌群文章入表后暴露。

修复:改用项目标准请求封装 import request from "@/utils/request"(56 个页面通用,带 token/错误拦截器),4 处 $axios.post 全部替换,响应解析从 res.data.code 对齐为 res.code(拦截器已解包)。
Xiaogang Liao 6 gün önce
ebeveyn
işleme
799ea19704

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-188d9365973aa2437a265f39854859d041931f20
+d24fdb39fe54a61b2b119b568f37b95c63157f3e

+ 14 - 12
cfc-web/src/views/admin/health-knowledge.vue

@@ -113,6 +113,7 @@
 
 
 <script>
 <script>
 import SortMixin from '@/mixins/SortMixin'
 import SortMixin from '@/mixins/SortMixin'
+import request from '@/utils/request'
 
 
 export default {
 export default {
   mixins: [SortMixin],
   mixins: [SortMixin],
@@ -143,10 +144,9 @@ export default {
       if (this.filters.name) params.name = this.filters.name
       if (this.filters.name) params.name = this.filters.name
       if (this.filters.category) params.category = this.filters.category
       if (this.filters.category) params.category = this.filters.category
       if (this.sortState.length > 0) params.sort = this.sortState
       if (this.sortState.length > 0) params.sort = this.sortState
-      this.$axios.post('/api/health/knowledge/list', params).then(res => {
-        var data = res.data || {}
-        if (data.code === 200) {
-          var rows = data.data || []
+      request.post('/api/health/knowledge/list', params).then(res => {
+        if (res.code === 200) {
+          var rows = res.data || []
           if (this.filters.name) {
           if (this.filters.name) {
             rows = rows.filter(function(r) { return r.itemName && r.itemName.indexOf(this.filters.name) >= 0 }.bind(this))
             rows = rows.filter(function(r) { return r.itemName && r.itemName.indexOf(this.filters.name) >= 0 }.bind(this))
           }
           }
@@ -160,6 +160,8 @@ export default {
           })
           })
           this.categories = cats
           this.categories = cats
           this.list = rows
           this.list = rows
+        } else {
+          this.$message.error(res.message || '加载失败')
         }
         }
       }).finally(() => { this.loading = false })
       }).finally(() => { this.loading = false })
     },
     },
@@ -178,20 +180,20 @@ export default {
       }
       }
       this.dialog.saving = true
       this.dialog.saving = true
       var url = this.dialog.isEdit ? '/api/health/knowledge/update' : '/api/health/knowledge/add'
       var url = this.dialog.isEdit ? '/api/health/knowledge/update' : '/api/health/knowledge/add'
-      this.$axios.post(url, this.dialog.form).then(res => {
-        if (res.data.code === 200) {
+      request.post(url, this.dialog.form).then(res => {
+        if (res.code === 200) {
           this.$message.success('已保存')
           this.$message.success('已保存')
           this.dialog.visible = false
           this.dialog.visible = false
           this.fetchList()
           this.fetchList()
         } else {
         } else {
-          this.$message.error(res.data.message || '保存失败')
+          this.$message.error(res.message || '保存失败')
         }
         }
       }).finally(() => { this.dialog.saving = false })
       }).finally(() => { this.dialog.saving = false })
     },
     },
     deleteRow(row) {
     deleteRow(row) {
       this.$confirm('确认删除"' + row.itemName + '"?', '提示', { confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning' }).then(function() {
       this.$confirm('确认删除"' + row.itemName + '"?', '提示', { confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning' }).then(function() {
-        this.$axios.post('/api/health/knowledge/delete', { id: row.id }).then(function(res) {
-          if (res.data.code === 200) {
+        request.post('/api/health/knowledge/delete', { id: row.id }).then(function(res) {
+          if (res.code === 200) {
             this.$message.success('已删除')
             this.$message.success('已删除')
             this.fetchList()
             this.fetchList()
           }
           }
@@ -200,9 +202,9 @@ export default {
     },
     },
     importData() {
     importData() {
       this.$confirm('将从参考JSON导入知识库数据,是否继续?', '提示', { confirmButtonText: '导入', cancelButtonText: '取消' }).then(function() {
       this.$confirm('将从参考JSON导入知识库数据,是否继续?', '提示', { confirmButtonText: '导入', cancelButtonText: '取消' }).then(function() {
-        this.$axios.post('/api/health/knowledge/import', {}).then(function(res) {
-          if (res.data.code === 200) {
-            this.$message.success(res.data.data || '导入完成')
+        request.post('/api/health/knowledge/import', {}).then(function(res) {
+          if (res.code === 200) {
+            this.$message.success(res.data || '导入完成')
             this.fetchList()
             this.fetchList()
           }
           }
         }.bind(this))
         }.bind(this))