|
@@ -1,17 +1,33 @@
|
|
<template>
|
|
<template>
|
|
<div class="question-folder">
|
|
<div class="question-folder">
|
|
<div v-if="isEdit" class="folder-action box-justify margin-bottom-15">
|
|
<div v-if="isEdit" class="folder-action box-justify margin-bottom-15">
|
|
- <el-button
|
|
|
|
- type="primary"
|
|
|
|
- :disabled="curNodeData.level >= MAX_FOLDER_LEVEL"
|
|
|
|
- @click="toAddFolder"
|
|
|
|
- >新建文件夹</el-button
|
|
|
|
- >
|
|
|
|
|
|
+ <div>
|
|
|
|
+ <el-button
|
|
|
|
+ type="primary"
|
|
|
|
+ size="small"
|
|
|
|
+ plain
|
|
|
|
+ icon="el-icon-circle-plus-outline"
|
|
|
|
+ :disabled="curNodeData.level >= MAX_FOLDER_LEVEL"
|
|
|
|
+ @click="toAddFolder"
|
|
|
|
+ >新建</el-button
|
|
|
|
+ >
|
|
|
|
+ <el-button
|
|
|
|
+ type="primary"
|
|
|
|
+ size="small"
|
|
|
|
+ icon="el-icon-edit"
|
|
|
|
+ plain
|
|
|
|
+ @click="toEditFolder"
|
|
|
|
+ >编辑</el-button
|
|
|
|
+ >
|
|
|
|
+ </div>
|
|
<el-button
|
|
<el-button
|
|
type="danger"
|
|
type="danger"
|
|
|
|
+ size="small"
|
|
|
|
+ icon="el-icon-circle-close"
|
|
|
|
+ plain
|
|
:disabled="curNodeData.level >= MAX_FOLDER_LEVEL"
|
|
:disabled="curNodeData.level >= MAX_FOLDER_LEVEL"
|
|
@click="toDeleteFolder"
|
|
@click="toDeleteFolder"
|
|
- >删除文件夹</el-button
|
|
|
|
|
|
+ >删除</el-button
|
|
>
|
|
>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@@ -25,12 +41,17 @@
|
|
:draggable="isEdit"
|
|
:draggable="isEdit"
|
|
:allow-drop="allowDrop"
|
|
:allow-drop="allowDrop"
|
|
:allow-drag="allowDrag"
|
|
:allow-drag="allowDrag"
|
|
|
|
+ @node-drag-enter="handleDragEnter"
|
|
|
|
+ @node-drag-leave="handleDragLeave"
|
|
@node-drop="handleDrop"
|
|
@node-drop="handleDrop"
|
|
@node-click="nodeClick"
|
|
@node-click="nodeClick"
|
|
>
|
|
>
|
|
<span slot-scope="{ node, data }">
|
|
<span slot-scope="{ node, data }">
|
|
<i class="icon icon-files-act node-icon"></i>
|
|
<i class="icon icon-files-act node-icon"></i>
|
|
- <span v-if="data.id === null" class="node-form">
|
|
|
|
|
|
+ <span
|
|
|
|
+ v-if="data.id === null || curEditClassifyId === data.id"
|
|
|
|
+ class="node-form"
|
|
|
|
+ >
|
|
<el-form
|
|
<el-form
|
|
ref="modalFormComp"
|
|
ref="modalFormComp"
|
|
:model="modalForm"
|
|
:model="modalForm"
|
|
@@ -51,9 +72,11 @@
|
|
type="primary"
|
|
type="primary"
|
|
icon="el-icon-check"
|
|
icon="el-icon-check"
|
|
:disabled="loading"
|
|
:disabled="loading"
|
|
- @click="toCreateFolder"
|
|
|
|
|
|
+ @click="toModifyFolder"
|
|
></el-button>
|
|
></el-button>
|
|
|
|
+ <!-- 新增的时候可以删除临时文件 -->
|
|
<el-button
|
|
<el-button
|
|
|
|
+ v-if="!modalForm.id"
|
|
type="danger"
|
|
type="danger"
|
|
icon="el-icon-close"
|
|
icon="el-icon-close"
|
|
:disabled="loading"
|
|
:disabled="loading"
|
|
@@ -65,7 +88,13 @@
|
|
</span>
|
|
</span>
|
|
<span
|
|
<span
|
|
v-else
|
|
v-else
|
|
- :class="['node-cont', { 'is-active': curNodeData.id === data.id }]"
|
|
|
|
|
|
+ :class="[
|
|
|
|
+ 'node-cont',
|
|
|
|
+ {
|
|
|
|
+ 'is-active': curNodeData.id === data.id,
|
|
|
|
+ 'is-drag-over': dragOverClassifyId === data.id,
|
|
|
|
+ },
|
|
|
|
+ ]"
|
|
>{{ data.name }}</span
|
|
>{{ data.name }}</span
|
|
>
|
|
>
|
|
</span>
|
|
</span>
|
|
@@ -74,7 +103,12 @@
|
|
</template>
|
|
</template>
|
|
|
|
|
|
<script>
|
|
<script>
|
|
-import { classifyTreeApi, updateClassifyApi, deleteClassifyApi } from "../api";
|
|
|
|
|
|
+import {
|
|
|
|
+ classifyTreeApi,
|
|
|
|
+ updateClassifyApi,
|
|
|
|
+ deleteClassifyApi,
|
|
|
|
+ moveClassifyApi,
|
|
|
|
+} from "../api";
|
|
|
|
|
|
const initModalForm = {
|
|
const initModalForm = {
|
|
id: null,
|
|
id: null,
|
|
@@ -111,6 +145,8 @@ export default {
|
|
},
|
|
},
|
|
curNodeData: {},
|
|
curNodeData: {},
|
|
loading: false,
|
|
loading: false,
|
|
|
|
+ dragOverClassifyId: null,
|
|
|
|
+ curEditClassifyId: null,
|
|
modalForm: {
|
|
modalForm: {
|
|
...initModalForm,
|
|
...initModalForm,
|
|
},
|
|
},
|
|
@@ -138,6 +174,16 @@ export default {
|
|
async getClassifyTree() {
|
|
async getClassifyTree() {
|
|
const res = await classifyTreeApi();
|
|
const res = await classifyTreeApi();
|
|
this.classifyTree[0].children = res.data || [];
|
|
this.classifyTree[0].children = res.data || [];
|
|
|
|
+
|
|
|
|
+ const findNode = (data, level) => {
|
|
|
|
+ level++;
|
|
|
|
+ data.forEach((item) => {
|
|
|
|
+ this.$set(item, "level", level);
|
|
|
|
+ if (item.children && item.children.length)
|
|
|
|
+ findNode(item.children, level);
|
|
|
|
+ });
|
|
|
|
+ };
|
|
|
|
+ findNode(this.classifyTree, -1);
|
|
},
|
|
},
|
|
nodeClick(data) {
|
|
nodeClick(data) {
|
|
if (!data.id && data.id !== 0) {
|
|
if (!data.id && data.id !== 0) {
|
|
@@ -156,22 +202,19 @@ export default {
|
|
},
|
|
},
|
|
findNodeById(id) {
|
|
findNodeById(id) {
|
|
let curNode = null;
|
|
let curNode = null;
|
|
- const findNode = (data, level) => {
|
|
|
|
|
|
+ const findNode = (data) => {
|
|
if (curNode) return;
|
|
if (curNode) return;
|
|
- level++;
|
|
|
|
data.forEach((item) => {
|
|
data.forEach((item) => {
|
|
if (curNode) return;
|
|
if (curNode) return;
|
|
|
|
|
|
if (item.id === id) {
|
|
if (item.id === id) {
|
|
curNode = item;
|
|
curNode = item;
|
|
- curNode.level = level;
|
|
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- if (item.children && item.children.length)
|
|
|
|
- findNode(item.children, level);
|
|
|
|
|
|
+ if (item.children && item.children.length) findNode(item.children);
|
|
});
|
|
});
|
|
};
|
|
};
|
|
- findNode(this.classifyTree, -1);
|
|
|
|
|
|
+ findNode(this.classifyTree);
|
|
|
|
|
|
return curNode || {};
|
|
return curNode || {};
|
|
},
|
|
},
|
|
@@ -213,7 +256,15 @@ export default {
|
|
this.curNodeData.children.push(newChild);
|
|
this.curNodeData.children.push(newChild);
|
|
this.modalForm = { ...newChild };
|
|
this.modalForm = { ...newChild };
|
|
},
|
|
},
|
|
- async toCreateFolder() {
|
|
|
|
|
|
+ toEditFolder() {
|
|
|
|
+ if (!this.curNodeData.id && this.curNodeData.id !== 0) {
|
|
|
|
+ this.$message.error("请先选择文件夹!");
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ this.curEditClassifyId = this.curNodeData.id;
|
|
|
|
+ this.modalForm = { ...this.curNodeData };
|
|
|
|
+ },
|
|
|
|
+ async toModifyFolder() {
|
|
const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
if (!valid) return;
|
|
if (!valid) return;
|
|
|
|
|
|
@@ -225,11 +276,17 @@ export default {
|
|
this.loading = false;
|
|
this.loading = false;
|
|
if (!res) return;
|
|
if (!res) return;
|
|
this.$message.success("操作成功");
|
|
this.$message.success("操作成功");
|
|
- const newChild = this.curNodeData.children.find(
|
|
|
|
- (item) => item.id === null
|
|
|
|
- );
|
|
|
|
- newChild.id = res.data;
|
|
|
|
- newChild.name = this.modalForm.name;
|
|
|
|
|
|
+ this.curEditClassifyId = null;
|
|
|
|
+
|
|
|
|
+ if (this.modalForm.id) {
|
|
|
|
+ this.curNodeData.name = this.modalForm.name;
|
|
|
|
+ } else {
|
|
|
|
+ const newChild = this.curNodeData.children.find(
|
|
|
|
+ (item) => item.id === null
|
|
|
|
+ );
|
|
|
|
+ newChild.id = res.data;
|
|
|
|
+ newChild.name = this.modalForm.name;
|
|
|
|
+ }
|
|
},
|
|
},
|
|
toRemoveFolder(node, data) {
|
|
toRemoveFolder(node, data) {
|
|
const parent = node.parent;
|
|
const parent = node.parent;
|
|
@@ -256,10 +313,23 @@ export default {
|
|
return this.curNodeData;
|
|
return this.curNodeData;
|
|
},
|
|
},
|
|
// drop
|
|
// drop
|
|
- handleDrop(draggingNode, dropNode, dropType) {
|
|
|
|
- console.log("draggingNode", draggingNode);
|
|
|
|
- console.log("dropNode", dropNode);
|
|
|
|
- console.log("dropType", dropType);
|
|
|
|
|
|
+ handleDragEnter(draggingNode, dropNode) {
|
|
|
|
+ this.dragOverClassifyId = dropNode.data.id;
|
|
|
|
+ },
|
|
|
|
+ handleDragLeave() {
|
|
|
|
+ this.dragOverClassifyId = null;
|
|
|
|
+ },
|
|
|
|
+ async handleDrop(draggingNode, dropNode, dropType) {
|
|
|
|
+ // console.log("draggingNode", draggingNode);
|
|
|
|
+ // console.log("dropNode", dropNode);
|
|
|
|
+ // console.log("dropType", dropType);
|
|
|
|
+ this.dragOverClassifyId = null;
|
|
|
|
+ const targetClassifyId =
|
|
|
|
+ dropType === "inner" ? dropNode.data.id : dropNode.data.parentId;
|
|
|
|
+ if (targetClassifyId === draggingNode.data.parentId) return;
|
|
|
|
+
|
|
|
|
+ await moveClassifyApi(draggingNode.data.id, targetClassifyId);
|
|
|
|
+ this.initData();
|
|
},
|
|
},
|
|
allowDrop(draggingNode, dropNode, type) {
|
|
allowDrop(draggingNode, dropNode, type) {
|
|
if (
|
|
if (
|