lyc-dev #19

Merged
lyc merged 2 commits from lyc-dev into main 2024-07-15 10:58:30 +08:00
2 changed files with 81 additions and 17 deletions

View File

@ -5,7 +5,9 @@
<i class="iconfont icon-xiangyou"></i>
</div>
<div class="book-list">
<el-tree :data="treeData" :props="defaultProps" highlight-current @node-click="handleNodeClick">
<el-tree ref="treeref" :data="treeData" :props="defaultProps" node-key="id"
:default-expanded-keys="defaultExpandedKeys"
:current-node-key="currentNode" highlight-current @node-click="handleNodeClick">
<template #default="{ node }">
<span :title="node.label" class="tree-label">{{ node.label }}</span>
</template>
@ -35,7 +37,7 @@
</template>
<script setup>
import { onMounted, ref } from 'vue';
import { onMounted, ref, nextTick } from 'vue';
import useUserStore from '@/store/modules/user'
import { listEvaluation } from '@/api/subject'
@ -63,6 +65,12 @@ const curBookName = ref('')
const volumeOne = ref([])
//
const volumeTwo = ref([])
//
const currentNode = ref(0)
//
const defaultExpandedKeys = ref([])
// tree
const treeref = ref(null)
//
@ -101,6 +109,33 @@ const getTreeData = () => {
let upData = transData(volumeOne.value)
let downData = transData(volumeTwo.value)
treeData.value = upData.length ? upData : downData
defaultExpandedKeys.value = [treeData.value[0].id]
nextTick(() => {
currentNode.value = getLastLevelData(treeData.value)[0].id
})
}
const getLastLevelData = (tree) => {
let lastLevelData = [];
//
function traverseTree(nodes) {
nodes.forEach((node) => {
//
if (node.children && node.children.length > 0) {
traverseTree(node.children);
} else {
//
lastLevelData.push(node);
}
});
}
//
traverseTree(tree);
//
return lastLevelData;
}
@ -146,9 +181,6 @@ const isHaveUnit = (id) => {
})
}
const renderContent = (h, { node, data }) => {
console.log(node, data)
}
const handleNodeClick = (data) => {
emit('nodeClick', data)

View File

@ -4,7 +4,8 @@
<el-form>
<el-form-item label="文件">
<div class="create-item file-item flex">
<el-upload action="" multiple :before-upload="hanleFileBefore" :auto-upload="true">
<el-upload :file-list="fileList" :show-file-list="false" :auto-upload="false" multiple
:on-change="hanleFileChange">
<el-button slot="trigger">选择文件</el-button>
</el-upload>
<span class="upload-desc">说明一次最多上传5个文件单个文件大小不能大于100M</span>
@ -22,7 +23,7 @@
</div>
<div class="flex-type flex">
<span class="name">类别</span>
<el-select v-model="item.fileType" placeholder="Select" style="width: 100px">
<el-select v-model="item.fileData.fileFlag" placeholder="Select" style="width: 100px">
<el-option v-for="item in resourceType" :key="item.alue" :label="item.label" :value="item.value" />
</el-select>
@ -78,10 +79,14 @@ const resourceType = ref([
])
watch(() => props.modelValue, (newVal) => {
dialogValue.value = newVal
})
const hanleFileBefore = (rawFile) => {
const hanleFileChange = (file) => {
//
const audioTypes = ['audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/aac']
@ -94,27 +99,47 @@ const hanleFileBefore = (rawFile) => {
// pdf
const pdfTypes = ['application/pdf']
const fileType = rawFile.type
const fileType = file.raw.type
if (!(audioTypes.includes(fileType) || videoTypes.includes(fileType) || wordTypes.includes(fileType) || pptTypes.includes(fileType) || pdfTypes.includes(fileType))) {
ElMessage.error('文件格式错误! 请上传音频、视频、word、ppt、pdf文件!')
return false
}
//
const fileSize = rawFile.size / 1024 / 1024 > 100
const fileSize = file.raw.size / 1024 / 1024 > 100
if (fileSize) {
ElMessage.error('文件大小错误! 请上传小于100M的文件!')
return false
}
console.log(rawFile)
rawFile.fileType = 1
fileList.value.push(rawFile)
if (file.status === 'ready') {
file.fileData = {
textbookId: '123',
levelFirstId: '123',
levelSecondId: '123',
fileSource: '平台',
fileFlag: 1,
fileRoot: '资源'
}
file.callback = successFile
fileList.value.push(file)
}
return false
}
const getFileTypeIcon = (fileName)=>{
let fileSuccessAry = []
let fileNums = 0;
const successFile = (res) => {
fileSuccessAry.push(res)
if(fileSuccessAry.length == fileNums){
let flag = fileSuccessAry.every(item => item.code == 200)
if(flag){
ElMessage.success('上传成功!')
fileNums = 0
}
}
}
const getFileTypeIcon = (fileName) => {
const name = fileName.substr(fileName.lastIndexOf('.') + 1);
console.log(name)
const iconObj = {
pdf: 'icon-pdf',
ppt: 'icon-ppt',
@ -132,18 +157,21 @@ const delFile = (index) => {
//
const beforeClose = (done) => {
fileNums = fileList.value.length
fileList.value = []
emit('update:modelValue', false)
done()
}
//
const closeDialog = () => {
fileNums = fileList.value.length
fileList.value = []
emit('update:modelValue', false)
}
//
const submitFile = () => {
emit('submitFile', fileList.value)
closeDialog()
}
@ -172,15 +200,18 @@ const submitFile = () => {
width: 100%;
justify-content: space-between;
margin-bottom: 15px;
.file-name {
width: 50%;
margin-right: 20px;
display: flex;
align-items: center
}
.icon{
.icon {
font-size: 30px;
}
.flex-type {
align-items: center;
margin-right: 20px;
@ -192,6 +223,7 @@ const submitFile = () => {
.name {
position: relative;
flex-shrink: 0;
&::after {
content: '*';
position: absolute;