|
@@ -12,8 +12,8 @@
|
|
|
>
|
|
|
<el-tree
|
|
|
class="folder-tree"
|
|
|
- :data="folderTree"
|
|
|
- node-key="id"
|
|
|
+ :data="classifyTree"
|
|
|
+ node-key="questionClassifyId"
|
|
|
default-expand-all
|
|
|
:expand-on-click-node="false"
|
|
|
:props="defaultProps"
|
|
@@ -21,7 +21,7 @@
|
|
|
>
|
|
|
<span slot-scope="{ node, data }">
|
|
|
<i class="icon icon-files-act node-icon"></i>
|
|
|
- <span v-if="data.id === 'none'" class="node-form">
|
|
|
+ <span v-if="data.id === null" class="node-form">
|
|
|
<el-form
|
|
|
ref="modalFormComp"
|
|
|
:model="modalForm"
|
|
@@ -78,6 +78,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
+import { classifyTreeApi, updateClassifyApi } from "../api";
|
|
|
+
|
|
|
+const initModalForm = {
|
|
|
+ id: null,
|
|
|
+ parentId: null,
|
|
|
+ name: "",
|
|
|
+ remark: "",
|
|
|
+};
|
|
|
export default {
|
|
|
name: "QuestionFolderDialog",
|
|
|
props: {
|
|
@@ -94,31 +102,21 @@ export default {
|
|
|
return {
|
|
|
modalIsShow: false,
|
|
|
MAX_FOLDER_LEVEL: 3,
|
|
|
- folderTree: [
|
|
|
+ classifyTree: [
|
|
|
{
|
|
|
- id: "1",
|
|
|
+ id: 0,
|
|
|
parent: null,
|
|
|
name: "根目录",
|
|
|
- children: [
|
|
|
- {
|
|
|
- id: "101",
|
|
|
- parent: "1",
|
|
|
- name: "2021-2022第一学期期末考试用",
|
|
|
- },
|
|
|
- {
|
|
|
- id: "102",
|
|
|
- parent: "1",
|
|
|
- name: "2021-2022第二学期期末考试用",
|
|
|
- },
|
|
|
- ],
|
|
|
+ children: [],
|
|
|
},
|
|
|
],
|
|
|
defaultProps: {
|
|
|
- label: "name",
|
|
|
+ label: "questionClassifyName",
|
|
|
},
|
|
|
curNodeData: {},
|
|
|
+ loading: false,
|
|
|
modalForm: {
|
|
|
- name: "",
|
|
|
+ ...initModalForm,
|
|
|
},
|
|
|
rules: {
|
|
|
name: [
|
|
@@ -137,7 +135,8 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- visibleChange() {
|
|
|
+ async visibleChange() {
|
|
|
+ await this.getClassifyTree();
|
|
|
if (this.folderId && !this.isEdit) {
|
|
|
this.curNodeData = this.findNodeById(this.folderId);
|
|
|
}
|
|
@@ -148,8 +147,12 @@ export default {
|
|
|
open() {
|
|
|
this.modalIsShow = true;
|
|
|
},
|
|
|
+ async getClassifyTree() {
|
|
|
+ const res = await classifyTreeApi();
|
|
|
+ this.classifyTree[0].children = res.data || [];
|
|
|
+ },
|
|
|
nodeClick(data) {
|
|
|
- if (data.id === "none" || data.id === this.curNodeData.id) return;
|
|
|
+ if (data.id === null || data.id === this.curNodeData.id) return;
|
|
|
this.clearPreNewNode();
|
|
|
this.$nextTick(() => {
|
|
|
this.curNodeData = this.findNodeById(data.id);
|
|
@@ -172,20 +175,20 @@ export default {
|
|
|
findNode(item.children, level);
|
|
|
});
|
|
|
};
|
|
|
- findNode(this.folderTree, 0);
|
|
|
+ findNode(this.classifyTree, 0);
|
|
|
|
|
|
return curNode || {};
|
|
|
},
|
|
|
clearPreNewNode() {
|
|
|
const removePreNewChild = (data) => {
|
|
|
- data = data.filter((item) => item.id !== "none");
|
|
|
+ data = data.filter((item) => item.id !== null);
|
|
|
return data.map((item) => {
|
|
|
if (item.children && item.children.length)
|
|
|
item.children = removePreNewChild(item.children);
|
|
|
return item;
|
|
|
});
|
|
|
};
|
|
|
- this.folderTree = removePreNewChild(this.folderTree);
|
|
|
+ this.classifyTree = removePreNewChild(this.classifyTree);
|
|
|
},
|
|
|
toAddFolder() {
|
|
|
if (!this.curNodeData.id) {
|
|
@@ -198,22 +201,36 @@ export default {
|
|
|
}
|
|
|
if (
|
|
|
this.curNodeData.children &&
|
|
|
- this.curNodeData.children.find((item) => item.id === "none")
|
|
|
+ this.curNodeData.children.find((item) => item.id === null)
|
|
|
) {
|
|
|
this.$message.closeAll();
|
|
|
this.$message.error("有未创建完成的目录!");
|
|
|
return;
|
|
|
}
|
|
|
- const newChild = { id: "none", name: "", parentId: this.curNodeData.id };
|
|
|
+ const newChild = {
|
|
|
+ ...initModalForm,
|
|
|
+ parentId: this.curNodeData.id,
|
|
|
+ };
|
|
|
if (!this.curNodeData.children) {
|
|
|
this.$set(this.curNodeData, "children", []);
|
|
|
}
|
|
|
this.curNodeData.children.push(newChild);
|
|
|
- this.modalForm = { name: "" };
|
|
|
+ this.modalForm = { ...newChild };
|
|
|
},
|
|
|
async toCreateFolder() {
|
|
|
const valid = await this.$refs.modalFormComp.validate().catch(() => {});
|
|
|
if (!valid) return;
|
|
|
+
|
|
|
+ if (this.loading) return;
|
|
|
+ this.loading = true;
|
|
|
+ const res = await updateClassifyApi({ ...this.modalForm }).catch(
|
|
|
+ () => {}
|
|
|
+ );
|
|
|
+ this.loading = false;
|
|
|
+ if (!res) return;
|
|
|
+ this.$message.success("操作成功");
|
|
|
+ const newChild = this.curNodeData.find((item) => item.id === null);
|
|
|
+ newChild.id = res.data;
|
|
|
},
|
|
|
toRemoveFolder(node, data) {
|
|
|
const parent = node.parent;
|
|
@@ -222,7 +239,7 @@ export default {
|
|
|
children.splice(index, 1);
|
|
|
},
|
|
|
confirm() {
|
|
|
- if (!this.curNodeData.id) {
|
|
|
+ if (!this.curNodeData.id && this.curNodeData.id !== 0) {
|
|
|
this.$message.error("请选择文件夹!");
|
|
|
return;
|
|
|
}
|