kuaifan 5 jaren geleden
bovenliggende
commit
f276a2d594

+ 53 - 2
app/Http/Controllers/Api/DocsController.php

@@ -142,12 +142,16 @@ class DocsController extends Controller
         //
         $lists = Base::DBC2A(DB::table('docs_section')
             ->where('bookid', intval(Request::input('bookid')))
+            ->orderByDesc('inorder')
             ->orderByDesc('id')
-            ->take(200)
+            ->take(300)
             ->get());
         if (empty($lists)) {
             return Base::retError('暂无章节');
         }
+        foreach ($lists AS $key => $item) {
+            $lists[$key]['icon'] = Base::fillUrl('images/files/' . $item['type'] . '.png');
+        }
         return Base::retSuccess('success', Base::list2Tree($lists, 'id', 'parentid'));
     }
 
@@ -172,6 +176,10 @@ class DocsController extends Controller
         if (empty($bookRow)) {
             return Base::retError('知识库不存在或已被删除!');
         }
+        $count = DB::table('docs_section')->where('bookid', $bookid)->count();
+        if ($count >= 300) {
+            return Base::retError('知识库章节已经超过最大限制(300)!');
+        }
         //
         $id = intval(Request::input('id'));
         $title = trim(Request::input('title'));
@@ -192,7 +200,7 @@ class DocsController extends Controller
             return Base::retSuccess('修改成功!', $data);
         } else {
             // 添加
-            if (!in_array($type, ['text', 'mind', 'excel', 'chart'])) {
+            if (!in_array($type, ['document', 'mind', 'sheet', 'chart', 'folder'])) {
                 return Base::retError('参数错误!');
             }
             $parentid = 0;
@@ -208,6 +216,7 @@ class DocsController extends Controller
                 'username' => $user['username'],
                 'title' => $title,
                 'type' => $type,
+                'inorder' => intval(DB::table('docs_section')->select(['inorder'])->where('bookid', $bookid)->orderByDesc('inorder')->value('inorder')) + 1,
                 'indate' => Base::time(),
             ];
             $id = DB::table('docs_section')->insertGetId($data);
@@ -220,6 +229,47 @@ class DocsController extends Controller
     }
 
     /**
+     * 排序任务
+     *
+     * @apiParam {Number} bookid                知识库数据ID
+     * @apiParam {String} oldsort               旧排序数据
+     * @apiParam {String} newsort               新排序数据
+     */
+    public function section__sort()
+    {
+        $user = Users::authE();
+        if (Base::isError($user)) {
+            return $user;
+        } else {
+            $user = $user['data'];
+        }
+        //
+        $bookid = intval(Request::input('bookid'));
+        $bookRow = Base::DBC2A(DB::table('docs_book')->where('id', $bookid)->first());
+        if (empty($bookRow)) {
+            return Base::retError('知识库不存在或已被删除!');
+        }
+        //
+        $newSort = explode(";", Request::input('newsort'));
+        if (count($newSort) == 0) {
+            return Base::retError('参数错误!');
+        }
+        //
+        $count = count($newSort);
+        foreach ($newSort AS $sort => $item) {
+            list($newId, $newParentid) = explode(':', $item);
+            DB::table('docs_section')->where([
+                'id' => $newId,
+                'bookid' => $bookid
+            ])->update([
+                'inorder' => $count - intval($sort),
+                'parentid' => $newParentid
+            ]);
+        }
+        return Base::retSuccess('保存成功!');
+    }
+
+    /**
      * 删除章节
      *
      * @apiParam {Number} id                章节数据ID
@@ -238,6 +288,7 @@ class DocsController extends Controller
         if (empty($row)) {
             return Base::retError('文档不存在或已被删除!');
         }
+        DB::table('docs_section')->where('parentid', $id)->update([ 'parentid' => $row['parentid'] ]);
         DB::table('docs_section')->where('id', $id)->delete();
         //未完成,应该还要删除章节
         return Base::retSuccess('删除成功!');

+ 11 - 5
resources/assets/js/main/components/docs/NestedDraggable.vue

@@ -9,7 +9,7 @@
             <div class="item">
                 <div class="dashed"></div>
                 <div class="header">
-                    <div class="tip"><Icon type="ios-folder-outline" /></div>
+                    <div class="tip"><img :src="detail.icon"/></div>
                     <div class="title">{{ detail.title }}</div>
                 </div>
                 <div class="info">
@@ -62,15 +62,19 @@
                 .tip {
                     display: inline-block;
                     position: relative;
-                    > i {
+                    > img {
                         display: inline-block;
+                        width: 14px;
+                        height: 14px;
+                        margin-top: 5px;
+                        vertical-align: top;
                     }
                 }
                 .title {
                     display: inline-block;
                     border-bottom: 1px solid transparent;
                     cursor: pointer;
-                    padding: 0 4px;
+                    padding: 0 3px;
                     color: #555555;
                 }
             }
@@ -134,11 +138,13 @@
 
             handleClick(act, detail) {
                 if (act == 'sort') {
-                    if (!this.isChildren) {
+                    if (this.isChildren) {
+                        this.$emit("change", act, detail);
+                    } else {
                         let tempSortData = this.getSort(this.lists);
                         if (tempSortData != this.listSortData) {
                             this.listSortData = tempSortData;
-                            this.$emit("change", act, tempSortData)
+                            this.$emit("change", act, tempSortData);
                         }
                     }
                     return;

+ 47 - 12
resources/assets/js/main/pages/docs.vue

@@ -43,7 +43,7 @@
                                 </div>
                             </div>
                             <div class="docs-section">
-                                <nested-draggable :lists="sectionLists" @change="handleSection"></nested-draggable>
+                                <nested-draggable :lists="sectionLists" :disabled="sortDisabled" @change="handleSection"></nested-draggable>
                                 <div v-if="sectionLists.length == 0" class="none">{{sectionNoDataText}}</div>
                             </div>
                         </div>
@@ -215,15 +215,18 @@
                 addSectionShow: false,
                 formSectionAdd: {
                     title: '',
-                    type: 'text',
+                    type: 'document',
                 },
                 ruleSectionAdd: {},
                 sectionTypeLists: [
-                    {value: 'text', text: "文本"},
+                    {value: 'document', text: "文本"},
                     {value: 'mind', text: "脑图"},
-                    {value: 'excel', text: "表格"},
+                    {value: 'sheet', text: "表格"},
                     {value: 'chart', text: "流程图"},
+                    {value: 'folder', text: "目录"},
                 ],
+
+                sortDisabled: false,
             }
         },
 
@@ -481,14 +484,46 @@
             },
 
             handleSection(act, detail) {
-                if (act == 'edit') {
-                    this.addSectionId = detail.id;
-                    this.addSectionShow = true
-                } else if (act == 'add') {
-                    this.addSectionId = detail.id * -1;
-                    this.addSectionShow = true
-                } else if (act == 'delete') {
-                    this.onSectionDelete(detail.id);
+                switch (act) {
+                    case 'edit':
+                        this.addSectionId = detail.id;
+                        this.addSectionShow = true
+                        break;
+
+                    case 'add':
+                        this.addSectionId = detail.id * -1;
+                        this.addSectionShow = true
+                        break;
+
+                    case 'delete':
+                        this.onSectionDelete(detail.id);
+                        break;
+
+                    case 'sort':
+                        this.sortDisabled = true;
+                        $A.aAjax({
+                            url: 'docs/section/sort',
+                            data: {
+                                bookid: this.selectBookData.id,
+                                newsort: detail,
+                            },
+                            complete: () => {
+                                this.sortDisabled = false;
+                            },
+                            error: () => {
+                                this.getSectionLists();
+                                alert(this.$L('网络繁忙,请稍后再试!'));
+                            },
+                            success: (res) => {
+                                if (res.ret === 1) {
+                                    this.$Message.success(res.msg);
+                                } else {
+                                    this.getSectionLists();
+                                    this.$Modal.error({title: this.$L('温馨提示'), content: res.msg});
+                                }
+                            }
+                        });
+                        break;
                 }
             }
         },