qiyunfeng-create
3 天以前 5f00696dfb25bc90034448ceb634ed1ef256681a
src/views/classManage/teachingPlan.vue
@@ -12,7 +12,11 @@
        <div class="titleBox">
          <div class="titleOptions">
            <span>教学计划</span>
            <el-button v-if="userInfo?.role == 'Teacher'" @click="openPlan()" type="primary" round
            <el-button
              v-if="userInfo?.role == 'Teacher'"
              @click="openPlan()"
              type="primary"
              round
              >新建 <el-icon style="margin-left: 3px"><Plus /></el-icon
            ></el-button>
          </div>
@@ -25,7 +29,12 @@
              @keydown.enter="searchData()"
            >
              <template #append>
                <el-button type="primary" @click="searchData()" class="searchBtn" :icon="Search" />
                <el-button
                  type="primary"
                  @click="searchData()"
                  class="searchBtn"
                  :icon="Search"
                />
              </template>
            </el-input>
          </div>
@@ -71,7 +80,7 @@
                    v-for="(item, index) in scope.row.datas.uploadResources"
                    :key="index"
                  >
                    {{ item.FileName + '.' + item.Extension }}
                    {{ item.FileName + "." + item.Extension }}
                  </span>
                </div>
              </template>
@@ -131,7 +140,12 @@
            </el-col>
            <el-col :span="20">
              <div class="grid-content ep-bg-purple-light" />
              <el-input v-model="taskItem.title" placeholder="请填写名称" size="large" clearable />
              <el-input
                v-model="taskItem.title"
                placeholder="请填写名称"
                size="large"
                clearable
              />
            </el-col>
          </el-row>
          <el-row>
@@ -160,7 +174,12 @@
                </el-cascader>
              </div>
              <div class="btngroup">
                <el-button type="primary" @click="addGroup" style="height: 40px" :icon="Plus" />
                <el-button
                  type="primary"
                  @click="addGroup"
                  style="height: 40px"
                  :icon="Plus"
                />
                <el-button
                  type="warning"
                  :disabled="dynamicList.length == 1"
@@ -192,7 +211,12 @@
                  ></el-input>
                </div>
                <div class="btngroup">
                  <el-button type="primary" @click="addGroup" style="height: 40px" :icon="Plus" />
                  <el-button
                    type="primary"
                    @click="addGroup"
                    style="height: 40px"
                    :icon="Plus"
                  />
                  <el-button
                    type="warning"
                    :disabled="dynamicList.length == 1"
@@ -222,7 +246,13 @@
                  >上传</el-button
                >
              </el-upload> -->
              <el-upload class="upload" drag action="#" multiple :http-request="fileUpload">
              <el-upload
                class="upload"
                drag
                action="#"
                multiple
                :http-request="fileUpload"
              >
                <el-icon class="el-icon--upload"><upload-filled /></el-icon>
                <div class="el-upload__text">拖拽或点击文件上传</div>
              </el-upload>
@@ -276,112 +306,112 @@
</template>
<script setup lang="ts">
import { Search, ArrowRight, Plus, Minus } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { reactive, ref, onMounted, inject, watch } from 'vue'
import { useRoute } from 'vue-router'
import axios from 'axios'
import { Search, ArrowRight, Plus, Minus } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
import { reactive, ref, onMounted, inject, watch } from "vue";
import { useRoute } from "vue-router";
import axios from "axios";
const route: any = useRoute()
const MG: any = inject('MG')
const config: any = inject('config')
const tool: any = inject('toolClass')
const classInfo = JSON.parse(route.query.classInfo)
const userInfo = ref()
const searchKey = ref('')
const visible = ref(false)
const dynamicList: any = ref([])
const tableData: any = ref([])
const classItem = ref([])
const fileList: any = ref([])
const chapterList: any = ref([])
const childrenList: any = ref([])
const taskData: any = ref()
const route: any = useRoute();
const MG: any = inject("MG");
const config: any = inject("config");
const tool: any = inject("toolClass");
const classInfo = JSON.parse(route.query.classInfo);
const userInfo = ref();
const searchKey = ref("");
const visible = ref(false);
const dynamicList: any = ref([]);
const tableData: any = ref([]);
const classItem = ref([]);
const fileList: any = ref([]);
const chapterList: any = ref([]);
const childrenList: any = ref([]);
const taskData: any = ref();
// 新建教学计划防抖
const newLoading = ref(false)
const teachPlanvalue = ref('')
const newLoading = ref(false);
const teachPlanvalue = ref("");
const taskItem = reactive({
  title: '',
  selectChapter: '',
  referenceMaterial: '',
  explain: '',
  uploadResources: ''
})
  title: "",
  selectChapter: "",
  referenceMaterial: "",
  explain: "",
  uploadResources: "",
});
let pages = reactive({
  page: 1,
  pageSize: 13,
  count: 0,
  loading: false
})
  loading: false,
});
onMounted(() => {
  const list = [{ key: 1, parentVal: '', childVal: '' }]
  dynamicList.value = list
  const userCache: any = localStorage.getItem('jesk-userInfo')
  const list = [{ key: 1, parentVal: "", childVal: "" }];
  dynamicList.value = list;
  const userCache: any = localStorage.getItem(config.userInfoKey);
  if (userCache) {
    userInfo.value = JSON.parse(userCache)
    userInfo.value = JSON.parse(userCache);
  }
  pages.loading = true
  getTaskList()
})
  pages.loading = true;
  getTaskList();
});
const searchData = () => {
  pages.page = 1
  getTaskCmsList()
}
  pages.page = 1;
  getTaskCmsList();
};
const openPlan = () => {
  visible.value = true
  taskItem.title = ''
  taskItem.selectChapter = ''
  taskItem.referenceMaterial = ''
  taskItem.explain = ''
  taskItem.uploadResources = ''
  dynamicList.value = [{ key: 1, parentVal: '', childVal: '' }]
  fileList.value = []
}
  visible.value = true;
  taskItem.title = "";
  taskItem.selectChapter = "";
  taskItem.referenceMaterial = "";
  taskItem.explain = "";
  taskItem.uploadResources = "";
  dynamicList.value = [{ key: 1, parentVal: "", childVal: "" }];
  fileList.value = [];
};
const reduceGroup = () => {
  dynamicList.value.pop()
}
  dynamicList.value.pop();
};
const addGroup = () => {
  const source = dynamicList.value[dynamicList.value.length - 1]
  const obj = { key: source.key++, parentVal: '', childVal: '' }
  dynamicList.value.push(obj)
}
  const source = dynamicList.value[dynamicList.value.length - 1];
  const obj = { key: source.key++, parentVal: "", childVal: "" };
  dynamicList.value.push(obj);
};
const handleSizeChange = (val: number) => {
  pages.pageSize = val
  getTaskCmsList()
}
  pages.pageSize = val;
  getTaskCmsList();
};
const handleCurrentChange = (val: number) => {
  pages.page = val
  getTaskCmsList()
}
  pages.page = val;
  getTaskCmsList();
};
// 新建任务
const newTask = () => {
  const data = {
    name: classInfo?.name + '教学计划',
    description: '',
    icon: '',
    name: classInfo?.name + "教学计划",
    description: "",
    icon: "",
    type: config.taskType.teachingPlan,
    state: 'Normal',
    state: "Normal",
    groupId: classInfo?.id,
    order: 0,
    beginDate: '2024-09-09T03:38:07.167Z',
    endDate: '2024-09-09T03:38:07.167Z',
    duration: 0
  }
    beginDate: "2024-09-09T03:38:07.167Z",
    endDate: "2024-09-09T03:38:07.167Z",
    duration: 0,
  };
  MG.edu
    .newTask(data)
    .then((res: any) => {})
    .catch((e: any) => {
      console.log(e)
    })
}
      console.log(e);
    });
};
// 获取任务列表
const getTaskList = () => {
@@ -391,33 +421,33 @@
    filterList: [
      {
        value: config.taskType.teachingPlan,
        field: 'Type',
        subFilters: []
      }
        field: "Type",
        subFilters: [],
      },
    ],
    searchList: [],
    groupId: classInfo?.id
  }
    groupId: classInfo?.id,
  };
  MG.edu
    .getTaskList(data)
    .then((res: any) => {
      if (res.datas.length == 0 && userInfo.value.role == 'Teacher') {
        newTask()
      if (res.datas.length == 0 && userInfo.value.role == "Teacher") {
        newTask();
      }
      if (res.datas.length > 0) {
        taskData.value = res.datas[0]
        classInfo.taskId = taskData.value?.id
        classInfo.rootTaskCmsId = taskData.value?.rootCmsItemId
        taskData.value = res.datas[0];
        classInfo.taskId = taskData.value?.id;
        classInfo.rootTaskCmsId = taskData.value?.rootCmsItemId;
      }
      getTypeByCode()
      getTypeByCode();
      if (classInfo.bookRefCode) {
        getCatalogueList()
        getCatalogueList();
      }
    })
    .catch((e: any) => {
      console.log(e)
    })
}
      console.log(e);
    });
};
// 前往阅读器
const toRead = (item: any) => {
@@ -426,35 +456,35 @@
  if (classInfo.bookRefCode) {
    const url =
      config.textReaderUrl +
      '?bookId=' +
      "?bookId=" +
      classInfo?.bookRefCode +
      '&token=' +
      localStorage.getItem('jsek-token') +
      '&chapter=' +
      "&token=" +
      localStorage.getItem(config.tokenKey) +
      "&chapter=" +
      item.parentVal +
      '&startPage=' +
      item.childVal
    window.open(url, '_blank')
      "&startPage=" +
      item.childVal;
    window.open(url, "_blank");
  } else {
    ElMessage.warning('当前章节无法跳转')
    ElMessage.warning("当前章节无法跳转");
  }
}
};
// 下载上传资源
const downloadRes = (item: any) => {
  const url = config.requestCtx + '/file/api/ApiDownload?md5=' + item.Md5
  window.open(url, '_blank')
}
  const url = config.requestCtx + "/file/api/ApiDownload?md5=" + item.Md5;
  window.open(url, "_blank");
};
// 选择器
const parentSelect = (val: any, item: any) => {
  if (val?.length) {
    const str = val[2]
    const obj = findObj(chapterList.value, str)
    item.parentVal = obj.chapter
    item.childVal = obj.start
    const str = val[2];
    const obj = findObj(chapterList.value, str);
    item.parentVal = obj.chapter;
    item.childVal = obj.start;
  }
}
};
// 文件上传
const fileUpload = (file: any) => {
@@ -469,104 +499,105 @@
    //   ElMessage.error('上传文件大小不能超过 300KB!')
    //   return reject()
    // }
    const FileName = file.file.name.split('.')[0]
    const Extension = file.file.name.split('.')[1]
    const FileType = file.file.type
    let size = 1024
    const FileName = file.file.name.split(".")[0];
    const Extension = file.file.name.split(".")[1];
    const FileType = file.file.type;
    let size = 1024;
    tool
      .getFileMd5(file.file, size * 1024)
      .then((e: string) => {
        if (!fileList.value.find((item: any) => item.md5 == e)) {
          const imgData = new FormData()
          imgData.append('Md5', e)
          imgData.append('FileName', FileName)
          imgData.append('Extension', Extension)
          imgData.append('FileType', FileType)
          imgData.append('MetaData', null)
          imgData.append('file', file.file)
          const imgData = new FormData();
          imgData.append("Md5", e);
          imgData.append("FileName", FileName);
          imgData.append("Extension", Extension);
          imgData.append("FileType", FileType);
          imgData.append("MetaData", null);
          imgData.append("file", file.file);
          MG.file.upload(imgData).then(() => {
            fileList.value.push({
              md5: e,
              linkType: 'LinkFile',
              linkProtectType: 'Public',
              linkType: "LinkFile",
              linkProtectType: "Public",
              fileName: FileName,
              extension: Extension,
              url: config.requestCtx + `​/file​/api​/ApiDownload?md5=` + e
            })
          })
              url: config.requestCtx + `​/file​/api​/ApiDownload?md5=` + e,
            });
          });
        } else {
          ElMessage.warning('当前文件已上传,请勿重复操作!')
          ElMessage.warning("当前文件已上传,请勿重复操作!");
        }
      })
      .catch((e: any) => {
        console.error(e)
      })
  })
}
        console.error(e);
      });
  });
};
// 获取章节目录
const getCatalogueList = () => {
  const url = config.requestCtx + '/books/resource/' + classInfo?.bookRefCode + '/information.json'
  const url =
    config.requestCtx + "/books/resource/" + classInfo?.bookRefCode + "/information.json";
  axios
    .get(url)
    .then((res) => {
      if (res.data?.data.length > 0) {
        const datas = res.data.data
        const list = datas?.filter((item: any) => item.children?.length > 0)
        chapterList.value = changeCascaderData(list)
        const datas = res.data.data;
        const list = datas?.filter((item: any) => item.children?.length > 0);
        chapterList.value = changeCascaderData(list);
      }
    })
    .catch((e) => {
      console.log(e)
    })
}
      console.log(e);
    });
};
// 递归更数组
const changeCascaderData = (data: any) => {
  for (const item of data) {
    item.value = item.start
    item.value = item.start;
    if (item.children?.length > 0) {
      changeCascaderData(item.children)
      changeCascaderData(item.children);
    }
  }
  return data
}
  return data;
};
// 递归查找
const findObj = (arr: any, val: any) => {
  for (let i = 0; i < arr.length; i++) {
    const obj = arr[i]
    const obj = arr[i];
    if (obj.start === val) {
      return obj // 找到目标对象,直接返回
      return obj; // 找到目标对象,直接返回
    }
    if (obj.children && obj.children.length > 0) {
      // 如果当前对象有子对象,递归查找子对象
      const found: any = findObj(obj.children, val)
      const found: any = findObj(obj.children, val);
      if (found) {
        return found // 在子对象中找到目标对象,返回
        return found; // 在子对象中找到目标对象,返回
      }
    }
  }
  return null
}
  return null;
};
// 获取类型字段
const getTypeByCode = () => {
  MG.resource
    .getCmsTypeByRefCode({
      refCodes: [config.refCodes.teachingPlan]
      refCodes: [config.refCodes.teachingPlan],
    })
    .then((res: any) => {
      const data = res[0]?.cmsTypeLinks[0]?.children
      const data = res[0]?.cmsTypeLinks[0]?.children;
      if (data?.length) {
        classItem.value = data
        classItem.value = data;
      }
      getTaskCmsList()
      getTaskCmsList();
    })
    .catch((err: any) => {
      console.log(err)
    })
}
      console.log(err);
    });
};
// 获取任务下的资源列表
const getTaskCmsList = () => {
@@ -577,80 +608,81 @@
      ? [
          {
            keywords: searchKey.value,
            field: 'Name',
            compareType: 'Contains'
          }
            field: "Name",
            compareType: "Contains",
          },
        ]
      : [],
    taskId: classInfo?.taskId,
    path: String(classInfo?.rootTaskCmsId),
    type: '*',
    keys: ['referenceMaterial', 'Name', 'selectChapter', 'uploadResources', 'explain']
  }
    type: "*",
    keys: ["referenceMaterial", "Name", "selectChapter", "uploadResources", "explain"],
  };
  MG.edu
    .getTaskCmsItem(data)
    .then((res: any) => {
      pages.loading = false
      pages.count = res.totalSize
      pages.loading = false;
      pages.count = res.totalSize;
      for (let i = 0; i < res.datas.length; i++) {
        const item = res.datas[i]
        const item = res.datas[i];
        // 处理字段
        if (taskItem != null) {
          for (let fieldKey in taskItem) {
            if (item.datas[fieldKey]) {
              const values = JSON.parse(item.datas[fieldKey])
              const values = JSON.parse(item.datas[fieldKey]);
              if (values.length > 0) {
                // 用字段名处理返回的字段值
                if (values[0].Value) {
                  item.datas[fieldKey] = values[0].Value
                  item.datas[fieldKey] = values[0].Value;
                } else if (values[0].Data) {
                  item.datas[fieldKey] = values[0].Data.Value
                  item.datas[fieldKey] = values[0].Data.Value;
                } else if (!values[0].Value && values[0].FileList?.length > 0) {
                  item.datas[fieldKey] = values[0].FileList
                  item.datas[fieldKey] = values[0].FileList;
                } else {
                  item.datas[fieldKey] = '-'
                  item.datas[fieldKey] = "-";
                }
                if (fieldKey == 'selectChapter' && values[0].Value) {
                  const data = JSON.parse(values[0].Value)
                  item.datas['selectChapter'] = data.map((citem: any) => {
                if (fieldKey == "selectChapter" && values[0].Value) {
                  const data = JSON.parse(values[0].Value);
                  item.datas["selectChapter"] = data.map((citem: any) => {
                    if (classInfo.bookRefCode) {
                      const dataS = findObj(chapterList.value, citem.childVal)
                      const dataS = findObj(chapterList.value, citem.childVal);
                      return {
                        ...citem,
                        parentName:
                          chapterList.value.find((sitem: any) => sitem.chapter == citem.parentVal)
                            ?.label +
                          '---' +
                          dataS?.label
                      }
                          chapterList.value.find(
                            (sitem: any) => sitem.chapter == citem.parentVal
                          )?.label +
                          "---" +
                          dataS?.label,
                      };
                    } else {
                      return {
                        ...citem,
                        parentName: citem.parentVal + '---' + citem.childVal
                      }
                        parentName: citem.parentVal + "---" + citem.childVal,
                      };
                    }
                  })
                  });
                }
                if (fieldKey == 'selectChapter' && !values[0].Value) {
                  item.datas['selectChapter'] = []
                if (fieldKey == "selectChapter" && !values[0].Value) {
                  item.datas["selectChapter"] = [];
                }
              }
              const index = i
              item.datas['index'] = index + 1
              const index = i;
              item.datas["index"] = index + 1;
            }
          }
        }
      }
      tableData.value = res.datas
      tableData.value = res.datas;
    })
    .catch((e: any) => {
      ElMessage({
        message: '列表获取失败',
        type: 'error'
      })
      console.log(e)
    })
}
        message: "列表获取失败",
        type: "error",
      });
      console.log(e);
    });
};
// 删除资源
const removeTaskItem = (item: any) => {
@@ -659,56 +691,56 @@
    requests: [
      {
        cmsItemId: item.id,
        path: String(classInfo?.rootTaskCmsId)
      }
    ]
  }
        path: String(classInfo?.rootTaskCmsId),
      },
    ],
  };
  MG.edu
    .removeTaskCmsItemList(data)
    .then((res: any) => {
      if (res) {
        ElMessage({
          message: '删除成功',
          type: 'success'
        })
        getTaskCmsList()
          message: "删除成功",
          type: "success",
        });
        getTaskCmsList();
      }
    })
    .catch((e: any) => {
      ElMessage({
        message: '删除失败',
        type: 'error'
      })
    })
}
        message: "删除失败",
        type: "error",
      });
    });
};
// 为任务新建资源
const newTaskCmsItems = () => {
  newLoading.value = true
  taskItem.selectChapter = JSON.stringify(dynamicList.value)
  newLoading.value = true;
  taskItem.selectChapter = JSON.stringify(dynamicList.value);
  if (!taskItem.title) {
    ElMessage({
      message: '请填写教学名称',
      type: 'warning'
    })
    newLoading.value = false
    return false
      message: "请填写教学名称",
      type: "warning",
    });
    newLoading.value = false;
    return false;
  }
  if (dynamicList.value[0]?.parentVal == '') {
  if (dynamicList.value[0]?.parentVal == "") {
    ElMessage({
      message: '请选择教学章节',
      type: 'warning'
    })
    newLoading.value = false
    return false
      message: "请选择教学章节",
      type: "warning",
    });
    newLoading.value = false;
    return false;
  }
  if (fileList.value.length == 0) {
    ElMessage({
      message: '请上传教学文件',
      type: 'warning'
    })
    newLoading.value = false
    return false
      message: "请上传教学文件",
      type: "warning",
    });
    newLoading.value = false;
    return false;
  }
  const data = {
    groupId: classInfo?.id,
@@ -717,29 +749,33 @@
    newGroupCmsItemRequests: [
      {
        name: taskItem.title,
        description: '',
        icon: '',
        description: "",
        icon: "",
        type: config.refCodes.teachingPlan,
        state: 'Normal',
        state: "Normal",
        order: 0,
        newDataListRequest: tool.worksDataBytool(classItem.value, taskItem, fileList.value),
        newDataListRequest: tool.worksDataBytool(
          classItem.value,
          taskItem,
          fileList.value
        ),
        newCmsItemAndFileLinkListRequest: [],
        newChildrenListRequest: []
      }
    ]
  }
        newChildrenListRequest: [],
      },
    ],
  };
  MG.edu.newTaskCmsItem(data).then((res: any) => {
    newLoading.value = false
    newLoading.value = false;
    if (res) {
      ElMessage({
        message: '新建成功',
        type: 'success'
      })
      visible.value = false
      getTaskCmsList()
        message: "新建成功",
        type: "success",
      });
      visible.value = false;
      getTaskCmsList();
    }
  })
}
  });
};
// // 编辑资源
// const editOpen = (item: any) => {