Parcourir la source

Optimize the default selected catalog logic / 优化默认选中目录逻辑

star7th il y a 4 ans
Parent
commit
a51693f3c7

+ 3 - 1
server/Application/Api/Controller/CatalogController.class.php

@@ -218,7 +218,9 @@ class CatalogController extends BaseController {
             $this->sendResult($return);
         }
     }
-
+    
+    // 此方法开始慢慢少用。现在准备让前端自己用逻辑判断目录,不再需要后台获取。新建页面的时候默认使用当前打开页面的目录。
+    // 但由于可能有些老旧客户端用到,先暂时保留该接口
     //编辑页面时,自动帮助用户选中目录
     //选中的规则是:编辑页面则选中该页面目录,复制页面则选中目标页面目录;
     //              如果是恢复历史页面则使用历史页面的目录,如果都没有则选中用户上次使用的目录

+ 1 - 1
web_src/src/components/item/show/show_regular_item/Index.vue

@@ -136,7 +136,7 @@ export default {
             data.data.page_content,
             that.$store.state.item_info.global_param
           )
-
+          that.$store.dispatch('changeOpenCatId', data.data.cat_id)
           that.page_title = data.data.page_title
           that.page_info = data.data
           that.attachment_count =

+ 7 - 19
web_src/src/components/page/edit/Index.vue

@@ -344,6 +344,7 @@ export default {
             }, 1000)
             that.title = response.data.data.page_title
             that.item_id = response.data.data.item_id
+            that.cat_id = response.data.data.cat_id
             that.s_number = response.data.data.s_number
             that.attachment_count =
               response.data.data.attachment_count > 0 ? '...' : ''
@@ -369,7 +370,6 @@ export default {
             var Info = response.data.data
 
             that.catalogs = Info
-            that.get_default_cat()
           } else {
             that.$alert(response.data.error_message)
           }
@@ -378,25 +378,7 @@ export default {
           console.log(error)
         })
     },
-    // 获取默认该选中的目录
-    get_default_cat() {
-      var that = this
-      var url = DocConfig.server + '/api/catalog/getDefaultCat'
-      var params = new URLSearchParams()
-      params.append('page_id', this.page_id)
-      params.append('item_id', that.$route.params.item_id)
-      params.append('copy_page_id', this.copy_page_id)
 
-      that.axios.post(url, params).then(function(response) {
-        if (response.data.error_code === 0) {
-          // that.$message.success("加载成功");
-          var json = response.data.data
-          that.cat_id = json.default_cat_id
-        } else {
-          that.$alert(response.data.error_message)
-        }
-      })
-    },
     // 插入数据到编辑器中。插入到光标处。如果参数is_cover为真,则清空后再插入(即覆盖)。
     insertValue(value, is_cover) {
       if (value) {
@@ -779,6 +761,12 @@ export default {
     document.addEventListener('paste', this.upload_paste_img)
     this.lang = DocConfig.lang
     window.addEventListener('beforeunload', this.unLockOnClose)
+    let g_open_cat_id = this.$store.state.open_cat_id // 全局变量-当前打开的目录id
+    // 如果this.page_id无效,则可以判定用户是在新建页面
+    // 此时可以考虑把目录设置为用户当前打开的页面的所属目录
+    if (this.page_id <= 0 && g_open_cat_id > 0) {
+      this.cat_id = g_open_cat_id
+    }
   },
 
   beforeDestroy() {

+ 5 - 0
web_src/src/store/actions.js

@@ -10,5 +10,10 @@ export default {
     // console.log(val)  //val是dispatch派发传递过来的值
     // console.log(ctx)  //ctx是上下文,必传
     ctx.commit('changeItemInfo', val)// commit到mutation
+  },
+  changeOpenCatId(ctx, val) {
+    // console.log(val)  //val是dispatch派发传递过来的值
+    // console.log(ctx)  //ctx是上下文,必传
+    ctx.commit('changeOpenCatId', val)// commit到mutation
   }
 }

+ 3 - 0
web_src/src/store/mutations.js

@@ -8,6 +8,9 @@ export default {
   changeItemInfo(state, val) {
     state.item_info = val
   },
+  changeOpenCatId(state, val) {
+    state.open_cat_id = val
+  },
   [SOME_MUTATION](state) {
     // mutate state
   }

+ 2 - 1
web_src/src/store/state.js

@@ -1,7 +1,8 @@
 
 const state = {
   count: '1',
-  item_info: {}
+  item_info: {},
+  open_cat_id: 0
 }
 
 export default state