|
|
@ -1,11 +1,15 @@ |
|
|
|
<script lang="ts" setup> |
|
|
|
<script setup> |
|
|
|
import { ref } from 'vue' |
|
|
|
import { ref } from 'vue' |
|
|
|
// import axios from 'axios' |
|
|
|
|
|
|
|
import { CourseResourceControllerService } from '../../../../generated/services/CourseResourceControllerService' |
|
|
|
import { CourseResourceControllerService } from '../../../../generated/services/CourseResourceControllerService' |
|
|
|
const props = defineProps(['dafulIndex']) |
|
|
|
const props = defineProps(['dafulIndex']) |
|
|
|
import { QuillEditor } from '@vueup/vue-quill' |
|
|
|
import tool from '@/utils/oss.js' |
|
|
|
import '@vueup/vue-quill/dist/vue-quill.snow.css' |
|
|
|
|
|
|
|
import { ElMessage } from 'element-plus' |
|
|
|
import { ElMessage } from 'element-plus' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['getpptresourceList']) |
|
|
|
|
|
|
|
const getresourceList = () => { |
|
|
|
|
|
|
|
emit('getpptresourceList', 'type') |
|
|
|
|
|
|
|
} |
|
|
|
//默认抽屉隐藏 |
|
|
|
//默认抽屉隐藏 |
|
|
|
const visibleDramwer = ref(false) |
|
|
|
const visibleDramwer = ref(false) |
|
|
|
//默认数据 |
|
|
|
//默认数据 |
|
|
@ -25,6 +29,10 @@ const formModel = ref({ |
|
|
|
const rules = { |
|
|
|
const rules = { |
|
|
|
name: [ |
|
|
|
name: [ |
|
|
|
{ required: true, message: '请输入资源名称', trigger: 'blur' }, |
|
|
|
{ required: true, message: '请输入资源名称', trigger: 'blur' }, |
|
|
|
|
|
|
|
{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }, |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
description: [ |
|
|
|
|
|
|
|
{ required: true, message: '请输入资源简介', trigger: 'blur' }, |
|
|
|
{ min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }, |
|
|
|
{ min: 3, max: 10, message: '长度在 3 到 10 个字符', trigger: 'blur' }, |
|
|
|
], |
|
|
|
], |
|
|
|
} |
|
|
|
} |
|
|
@ -32,8 +40,6 @@ const rules = { |
|
|
|
//组件对外暴露一个open 方法 根据传来的参数区分添加还是编辑 |
|
|
|
//组件对外暴露一个open 方法 根据传来的参数区分添加还是编辑 |
|
|
|
const open = async (row) => { |
|
|
|
const open = async (row) => { |
|
|
|
visibleDramwer.value = true |
|
|
|
visibleDramwer.value = true |
|
|
|
//console.log(row.id) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (row.id) { |
|
|
|
if (row.id) { |
|
|
|
//需要基于row.id 发送请求,获取编辑的详情数据,进行回显 |
|
|
|
//需要基于row.id 发送请求,获取编辑的详情数据,进行回显 |
|
|
|
const res = await CourseResourceControllerService.getAllUsingGet1(row.id) |
|
|
|
const res = await CourseResourceControllerService.getAllUsingGet1(row.id) |
|
|
@ -42,7 +48,7 @@ const open = async (row) => { |
|
|
|
console.log(res) |
|
|
|
console.log(res) |
|
|
|
|
|
|
|
|
|
|
|
//图片回显 |
|
|
|
//图片回显 |
|
|
|
//富文本框回显 |
|
|
|
|
|
|
|
console.log('编辑回显') |
|
|
|
console.log('编辑回显') |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
//重置表单数据 |
|
|
|
//重置表单数据 |
|
|
@ -57,6 +63,7 @@ defineExpose({ |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const selectVal = ref(props.dafulIndex) |
|
|
|
const selectVal = ref(props.dafulIndex) |
|
|
|
|
|
|
|
|
|
|
|
const selectOp = ref([ |
|
|
|
const selectOp = ref([ |
|
|
|
{ label: 'ppt', value: '1' }, |
|
|
|
{ label: 'ppt', value: '1' }, |
|
|
|
{ label: '图片', value: '2' }, |
|
|
|
{ label: '图片', value: '2' }, |
|
|
@ -66,35 +73,40 @@ const selectOp = ref([ |
|
|
|
{ label: '音频', value: '6' }, |
|
|
|
{ label: '音频', value: '6' }, |
|
|
|
]) |
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const upload = async (option) => { |
|
|
|
|
|
|
|
const res = await tool.oss.upload(option.file) |
|
|
|
|
|
|
|
const url = 'https://wenyu132.oss-cn-beijing.aliyuncs.com/' + res.name |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
formModel.value.img = url |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const fileList = ref([]) |
|
|
|
const fileList = ref([]) |
|
|
|
function clearFileList() { |
|
|
|
const clearFileList = () => { |
|
|
|
|
|
|
|
console.log(fileList) |
|
|
|
fileList.value.length = 0 |
|
|
|
fileList.value.length = 0 |
|
|
|
|
|
|
|
fileList.value = [] |
|
|
|
} |
|
|
|
} |
|
|
|
const handleSel = () => { |
|
|
|
const handleSel = () => { |
|
|
|
fileList.value.length = 0 |
|
|
|
fileList.value.length = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//上传图片 |
|
|
|
|
|
|
|
import type { UploadProps } from 'element-plus' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleRemove: UploadProps['onRemove'] = (uploadFile, uploadFiles) => { |
|
|
|
|
|
|
|
console.log(uploadFile, uploadFiles) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handlePreview: UploadProps['onPreview'] = (file) => { |
|
|
|
|
|
|
|
console.log(file) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const formRef = ref() |
|
|
|
const formRef = ref() |
|
|
|
function isSubmit() { |
|
|
|
const isSubmit = async () => { |
|
|
|
formRef.value.validate((valid, fields) => { |
|
|
|
formRef.value.validate(async (valid, fields) => { |
|
|
|
if (valid) { |
|
|
|
if (valid) { |
|
|
|
const params = { |
|
|
|
const params = { |
|
|
|
name: formModel.value.name, |
|
|
|
name: formModel.value.name, |
|
|
|
type: selectVal.value, |
|
|
|
type: selectVal.value, |
|
|
|
img: fileList.value[0]?.raw, |
|
|
|
img: formModel.value.img, |
|
|
|
description: formModel.value.description, |
|
|
|
description: formModel.value.description, |
|
|
|
|
|
|
|
path: formModel.value.img, |
|
|
|
} |
|
|
|
} |
|
|
|
console.log('根据参数:', params, '去调用接口???') |
|
|
|
console.log(params) |
|
|
|
|
|
|
|
await CourseResourceControllerService.saveCourseResourceUsingGet1(params) |
|
|
|
|
|
|
|
visibleDramwer.value = false |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
ElMessage.success('添加成功') |
|
|
|
|
|
|
|
getresourceList() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
console.log('error submit!', fields) |
|
|
|
console.log('error submit!', fields) |
|
|
|
} |
|
|
|
} |
|
|
@ -109,57 +121,65 @@ const beforeAvatarUpload = (rawFile) => { |
|
|
|
clearFileList() |
|
|
|
clearFileList() |
|
|
|
ElMessage.error('必须是ppt文件!') |
|
|
|
ElMessage.error('必须是ppt文件!') |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
clearFileList() |
|
|
|
|
|
|
|
fileList.value.push(rawFile) |
|
|
|
fileList.value.push(rawFile) |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
case 2: |
|
|
|
case 2: |
|
|
|
if (!rawFile.type.startsWith('image/')) { |
|
|
|
if (!rawFile.type.startsWith('image/')) { |
|
|
|
clearFileList() |
|
|
|
clearFileList() |
|
|
|
ElMessage.error('必须是??文件!') |
|
|
|
ElMessage.error('必须是图片文件!') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fileList.value.push(rawFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case 3: |
|
|
|
|
|
|
|
if (!rawFile.type.startsWith('video/')) { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
ElMessage.error('必须是视频文件!') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
fileList.value.push(rawFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
case 4: |
|
|
|
|
|
|
|
if (!rawFile.type.startsWith('application/pdf')) { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
ElMessage.error('必须是pdf文件!') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
fileList.value.push(rawFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
case 5: |
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
|
|
!rawFile.type.startsWith( |
|
|
|
|
|
|
|
'application/vnd.openxmlformats-officedocument.wordprocessingml.document', |
|
|
|
|
|
|
|
) && |
|
|
|
|
|
|
|
!rawFile.type.startsWith('application/msword') |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
ElMessage.error('必须是word文件!') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
fileList.value.push(rawFile) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break |
|
|
|
|
|
|
|
case 6: |
|
|
|
|
|
|
|
if (!rawFile.type.startsWith('audio/')) { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
ElMessage.error('必须是音频文件!') |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
clearFileList() |
|
|
|
clearFileList() |
|
|
|
fileList.value.push(rawFile) |
|
|
|
fileList.value.push(rawFile) |
|
|
|
} |
|
|
|
} |
|
|
|
break |
|
|
|
break |
|
|
|
// case 3: |
|
|
|
|
|
|
|
// if (false) { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// ElMessage.error('必须是??文件!') |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// fileList.value.push(rawFile) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// break |
|
|
|
|
|
|
|
// case 4: |
|
|
|
|
|
|
|
// if (false) { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// ElMessage.error('必须是??文件!') |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// fileList.value.push(rawFile) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// break |
|
|
|
|
|
|
|
// case 5: |
|
|
|
|
|
|
|
// if (false) { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// ElMessage.error('必须是??文件!') |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// fileList.value.push(rawFile) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// break |
|
|
|
|
|
|
|
// case 6: |
|
|
|
|
|
|
|
// if (false) { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// ElMessage.error('必须是??文件!') |
|
|
|
|
|
|
|
// } else { |
|
|
|
|
|
|
|
// clearFileList() |
|
|
|
|
|
|
|
// fileList.value.push(rawFile) |
|
|
|
|
|
|
|
// } |
|
|
|
|
|
|
|
// break |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const isabolish = () => { |
|
|
|
|
|
|
|
clearFileList() |
|
|
|
|
|
|
|
visibleDramwer.value = false |
|
|
|
|
|
|
|
} |
|
|
|
</script> |
|
|
|
</script> |
|
|
|
<template> |
|
|
|
<template> |
|
|
|
<el-drawer |
|
|
|
<el-drawer |
|
|
@ -201,33 +221,25 @@ const beforeAvatarUpload = (rawFile) => { |
|
|
|
<el-form-item label="上传资源" prop="fileList"> |
|
|
|
<el-form-item label="上传资源" prop="fileList"> |
|
|
|
<el-upload |
|
|
|
<el-upload |
|
|
|
v-model:file-list="fileList" |
|
|
|
v-model:file-list="fileList" |
|
|
|
|
|
|
|
:http-request="upload" |
|
|
|
:limit="1" |
|
|
|
:limit="1" |
|
|
|
class="upload-demo" |
|
|
|
class="upload-demo" |
|
|
|
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" |
|
|
|
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15" |
|
|
|
:on-preview="handlePreview" |
|
|
|
|
|
|
|
:on-remove="handleRemove" |
|
|
|
|
|
|
|
list-type="picture" |
|
|
|
list-type="picture" |
|
|
|
:before-upload="beforeAvatarUpload" |
|
|
|
:before-upload="beforeAvatarUpload" |
|
|
|
> |
|
|
|
> |
|
|
|
<el-button type="primary">点击上传资源</el-button> |
|
|
|
<el-button type="primary">点击上传资源</el-button> |
|
|
|
<template #tip> |
|
|
|
<template #file></template> |
|
|
|
<div class="el-upload__tip"> |
|
|
|
|
|
|
|
jpg/png files with a size less than 500kb |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</template> |
|
|
|
|
|
|
|
</el-upload> |
|
|
|
</el-upload> |
|
|
|
</el-form-item> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item label="资源简介" prop="description"> |
|
|
|
<el-form-item label="资源简介" prop="description"> |
|
|
|
<div class="editor"> |
|
|
|
<el-input |
|
|
|
<quill-editor |
|
|
|
v-model="formModel.description" |
|
|
|
v-model:content="formModel.description" |
|
|
|
placeholder="请输入资源简介" |
|
|
|
content-type="html" |
|
|
|
></el-input> |
|
|
|
theme="snow" |
|
|
|
|
|
|
|
></quill-editor> |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
</el-form-item> |
|
|
|
</el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-form-item> |
|
|
|
<el-button type="primary">取消</el-button> |
|
|
|
<el-button type="primary" @click="isabolish">取消</el-button> |
|
|
|
<el-button type="info" @click="isSubmit">确定</el-button> |
|
|
|
<el-button type="info" @click="isSubmit">确定</el-button> |
|
|
|
</el-form-item> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
</el-form> |
|
|
|