|
@@ -8,74 +8,15 @@
|
|
|
:close-on-click-modal="false"
|
|
|
:close-on-press-escape="false"
|
|
|
append-to-body
|
|
|
- @open="visibleChange"
|
|
|
>
|
|
|
- <el-tree
|
|
|
- class="folder-tree"
|
|
|
- :data="classifyTree"
|
|
|
- node-key="questionClassifyId"
|
|
|
- default-expand-all
|
|
|
- :expand-on-click-node="false"
|
|
|
- :props="defaultProps"
|
|
|
- @node-click="nodeClick"
|
|
|
- >
|
|
|
- <span slot-scope="{ node, data }">
|
|
|
- <i class="icon icon-files-act node-icon"></i>
|
|
|
- <span v-if="data.id === null" class="node-form">
|
|
|
- <el-form
|
|
|
- ref="modalFormComp"
|
|
|
- :model="modalForm"
|
|
|
- :rules="rules"
|
|
|
- size="mini"
|
|
|
- :show-message="false"
|
|
|
- inline
|
|
|
- >
|
|
|
- <el-form-item prop="name">
|
|
|
- <el-input
|
|
|
- v-model="modalForm.name"
|
|
|
- placeholder="请输入文件夹名称"
|
|
|
- clearable
|
|
|
- ></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item>
|
|
|
- <el-button
|
|
|
- type="primary"
|
|
|
- icon="el-icon-check"
|
|
|
- :disabled="loading"
|
|
|
- @click="toCreateFolder"
|
|
|
- ></el-button>
|
|
|
- <el-button
|
|
|
- type="danger"
|
|
|
- icon="el-icon-close"
|
|
|
- :disabled="loading"
|
|
|
- @click="toRemoveFolder(node, data)"
|
|
|
- ></el-button>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
- </span>
|
|
|
- <span
|
|
|
- v-else
|
|
|
- :class="['node-cont', { 'is-active': curNodeData.id === data.id }]"
|
|
|
- >{{ node.label }}</span
|
|
|
- >
|
|
|
- </span>
|
|
|
- </el-tree>
|
|
|
-
|
|
|
+ <question-folder
|
|
|
+ v-if="modalIsShow"
|
|
|
+ ref="QuestionFolder"
|
|
|
+ :is-edit="isEdit"
|
|
|
+ @selected="nodeSelected"
|
|
|
+ ></question-folder>
|
|
|
<div slot="footer" class="box-justify">
|
|
|
- <div v-if="isEdit">
|
|
|
- <el-button
|
|
|
- type="primary"
|
|
|
- :disabled="curNodeData.level >= MAX_FOLDER_LEVEL"
|
|
|
- @click="toAddFolder"
|
|
|
- >新建文件夹</el-button
|
|
|
- >
|
|
|
- <el-button
|
|
|
- type="danger"
|
|
|
- :disabled="curNodeData.level >= MAX_FOLDER_LEVEL"
|
|
|
- @click="toDeleteFolder"
|
|
|
- >删除文件夹</el-button
|
|
|
- >
|
|
|
- </div>
|
|
|
+ <div></div>
|
|
|
<div>
|
|
|
<el-button v-if="!isEdit" type="primary" @click="confirm"
|
|
|
>确定</el-button
|
|
@@ -87,16 +28,11 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import { classifyTreeApi, updateClassifyApi, deleteClassifyApi } from "../api";
|
|
|
+import QuestionFolder from "./QuestionFolder.vue";
|
|
|
|
|
|
-const initModalForm = {
|
|
|
- id: null,
|
|
|
- parentId: null,
|
|
|
- name: "",
|
|
|
- remark: "",
|
|
|
-};
|
|
|
export default {
|
|
|
name: "QuestionFolderDialog",
|
|
|
+ components: { QuestionFolder },
|
|
|
props: {
|
|
|
isEdit: {
|
|
|
type: Boolean,
|
|
@@ -106,32 +42,7 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
modalIsShow: false,
|
|
|
- MAX_FOLDER_LEVEL: 3,
|
|
|
- classifyTree: [
|
|
|
- {
|
|
|
- id: 0,
|
|
|
- parent: null,
|
|
|
- name: "根目录",
|
|
|
- children: [],
|
|
|
- },
|
|
|
- ],
|
|
|
- defaultProps: {
|
|
|
- label: "questionClassifyName",
|
|
|
- },
|
|
|
curNodeData: {},
|
|
|
- loading: false,
|
|
|
- modalForm: {
|
|
|
- ...initModalForm,
|
|
|
- },
|
|
|
- rules: {
|
|
|
- name: [
|
|
|
- {
|
|
|
- required: true,
|
|
|
- message: "请输入文件夹名称",
|
|
|
- trigger: "change",
|
|
|
- },
|
|
|
- ],
|
|
|
- },
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -140,123 +51,14 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- async visibleChange() {
|
|
|
- await this.getClassifyTree();
|
|
|
- if (this.folderId && !this.isEdit) {
|
|
|
- this.curNodeData = this.findNodeById(this.folderId);
|
|
|
- }
|
|
|
- },
|
|
|
cancel() {
|
|
|
this.modalIsShow = false;
|
|
|
},
|
|
|
open() {
|
|
|
this.modalIsShow = true;
|
|
|
},
|
|
|
- async getClassifyTree() {
|
|
|
- const res = await classifyTreeApi();
|
|
|
- this.classifyTree[0].children = res.data || [];
|
|
|
- },
|
|
|
- nodeClick(data) {
|
|
|
- if (data.id === null || data.id === this.curNodeData.id) return;
|
|
|
- this.clearPreNewNode();
|
|
|
- this.$nextTick(() => {
|
|
|
- this.curNodeData = this.findNodeById(data.id);
|
|
|
- });
|
|
|
- },
|
|
|
- findNodeById(id) {
|
|
|
- let curNode = null;
|
|
|
- const findNode = (data, level) => {
|
|
|
- if (curNode) return;
|
|
|
- level++;
|
|
|
- data.forEach((item) => {
|
|
|
- if (curNode) return;
|
|
|
-
|
|
|
- if (item.id === id) {
|
|
|
- curNode = item;
|
|
|
- curNode.level = level;
|
|
|
- return;
|
|
|
- }
|
|
|
- if (item.children && item.children.length)
|
|
|
- findNode(item.children, level);
|
|
|
- });
|
|
|
- };
|
|
|
- findNode(this.classifyTree, 0);
|
|
|
-
|
|
|
- return curNode || {};
|
|
|
- },
|
|
|
- clearPreNewNode() {
|
|
|
- const removePreNewChild = (data) => {
|
|
|
- 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.classifyTree = removePreNewChild(this.classifyTree);
|
|
|
- },
|
|
|
- toAddFolder() {
|
|
|
- if (!this.curNodeData.id) {
|
|
|
- this.$message.error("请先选择文件夹!");
|
|
|
- return;
|
|
|
- }
|
|
|
- if (this.curNodeData.level >= this.MAX_FOLDER_LEVEL) {
|
|
|
- this.$message.error(`最多允许${this.MAX_FOLDER_LEVEL}级目录`);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (
|
|
|
- this.curNodeData.children &&
|
|
|
- this.curNodeData.children.find((item) => item.id === null)
|
|
|
- ) {
|
|
|
- this.$message.closeAll();
|
|
|
- this.$message.error("有未创建完成的目录!");
|
|
|
- return;
|
|
|
- }
|
|
|
- const newChild = {
|
|
|
- ...initModalForm,
|
|
|
- parentId: this.curNodeData.id,
|
|
|
- };
|
|
|
- if (!this.curNodeData.children) {
|
|
|
- this.$set(this.curNodeData, "children", []);
|
|
|
- }
|
|
|
- this.curNodeData.children.push(newChild);
|
|
|
- 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;
|
|
|
- const children = parent.data.children || parent.data;
|
|
|
- const index = children.findIndex((d) => d.id === data.id);
|
|
|
- children.splice(index, 1);
|
|
|
- },
|
|
|
- async toDeleteFolder() {
|
|
|
- if (!this.curNodeData.id) return;
|
|
|
- const confirm = await this.$confirm(`确定要删除选中的文件夹吗?`, "提示", {
|
|
|
- type: "warning",
|
|
|
- }).catch(() => {});
|
|
|
- if (confirm !== "confirm") return;
|
|
|
-
|
|
|
- if (this.loading) return;
|
|
|
- this.loading = true;
|
|
|
- const res = await deleteClassifyApi(this.curNodeData.id).catch(() => {});
|
|
|
- this.loading = false;
|
|
|
- if (!res) return;
|
|
|
- this.$message.success("操作成功");
|
|
|
- await this.getClassifyTree();
|
|
|
+ nodeSelected(node) {
|
|
|
+ this.curNodeData = node || {};
|
|
|
},
|
|
|
confirm() {
|
|
|
if (!this.curNodeData.id && this.curNodeData.id !== 0) {
|