ww 5 months ago
commit 3fad5889db
  1. 5
      generated/core/OpenAPI.ts
  2. 2
      generated/services/CourseResourceControllerService.ts
  3. 212
      src/views/courseResources/componse/resourceAdd.vue
  4. 38
      src/views/courseResources/index.vue

@ -21,7 +21,8 @@ export type OpenAPIConfig = {
export const OpenAPI: OpenAPIConfig = {
BASE: 'http://39.106.16.162:8080',
//BASE: 'http://39.106.16.162:8080',
BASE: 'http://127.0.0.1:8080',
VERSION: '1.0.0',
WITH_CREDENTIALS: false,
CREDENTIALS: 'include',
@ -33,7 +34,7 @@ export const OpenAPI: OpenAPIConfig = {
};
// BASE: 'http://39.106.16.162:8080',
// BASE: 'http://127.0.0.1:8080/api',
// VERSION: '1.0.0',
// WITH_CREDENTIALS: false,
// CREDENTIALS: 'include',

@ -85,7 +85,7 @@ export class CourseResourceControllerService {
courseResources: CourseResources,
): CancelablePromise<BaseResponse_string_> {
return __request(OpenAPI, {
method: 'GET',
method: 'POST',
url: '/api/courses/save',
body: courseResources,
errors: {

@ -1,69 +1,53 @@
<script setup>
import { ref } from 'vue'
import { CourseResourceControllerService } from '../../../../generated/services/CourseResourceControllerService'
const props = defineProps(['dafulIndex'])
import tool from '@/utils/oss.js'
const visibilerDrawer = ref(false)
import { ElMessage } from 'element-plus'
const emit = defineEmits(['getpptresourceList'])
const getresourceList = () => {
emit('getpptresourceList', 'type')
}
//
const visibleDramwer = ref(false)
import { CourseResourceControllerService } from '../../../../generated/services/CourseResourceControllerService'
//
const defaultForm = {
description: '',
id: '',
img: '',
img: '', //
name: '',
type: '',
type: '', //
path: '',
}
const imageUrl = ref('')
const onSelectFile = (uploadFile) => {
// console.log(uploadFile)
//
imageUrl.value = URL.createObjectURL(uploadFile.raw)
//
formModel.value.img = uploadFile.raw
}
//
const formModel = ref({
...defaultForm,
})
//
const rules = {
name: [
{ 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' },
],
}
//open
const open = async (row) => {
visibleDramwer.value = true
const open = (row) => {
visibilerDrawer.value = true
// console.log(row)
if (row.id) {
//row.id
const res = await CourseResourceControllerService.getAllUsingGet1(row.id)
//
formModel.value = res.data.records
console.log(res)
//
//row.id
console.log('编辑回显')
} else {
//
formModel.value = {
...defaultForm,
}
} //form
//
imageUrl.value = ''
console.log('添加')
}
}
defineExpose({
open,
})
const selectVal = ref(props.dafulIndex)
//
const rules = {
name: [
{ required: true, message: '请输入资源名称', trigger: 'blur' },
{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' },
],
type: [{ required: true, trigger: 'blur' }],
}
const selectOp = ref([
{ label: 'ppt', value: '1' },
{ label: '图片', value: '2' },
@ -72,52 +56,18 @@ const selectOp = ref([
{ label: '文件', value: '5' },
{ 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 clearFileList = () => {
console.log(fileList)
fileList.value.length = 0
fileList.value = []
}
const handleSel = () => {
fileList.value.length = 0
}
const formRef = ref()
const isSubmit = async () => {
formRef.value.validate(async (valid, fields) => {
if (valid) {
const params = {
name: formModel.value.name,
type: selectVal.value,
img: formModel.value.img,
description: formModel.value.description,
path: formModel.value.img,
}
console.log(params)
await CourseResourceControllerService.saveCourseResourceUsingGet1(params)
visibleDramwer.value = false
clearFileList()
ElMessage.success('添加成功')
getresourceList()
} else {
console.log('error submit!', fields)
}
})
}
// upd
const beforeAvatarUpload = (rawFile) => {
console.log('执行了')
switch (+selectVal.value) {
switch (+formModel.value.type.value) {
case 1:
if (rawFile.type !== 'application/vnd.ms-powerpoint') {
if (rawFile.type !== 'applicationnd.ms-powerpoint') {
clearFileList()
ElMessage.error('必须是ppt文件!')
} else {
@ -143,7 +93,7 @@ const beforeAvatarUpload = (rawFile) => {
}
break
case 4:
if (!rawFile.type.startsWith('application/pdf')) {
if (!rawFile.type.startsWith('applicationf')) {
clearFileList()
ElMessage.error('必须是pdf文件!')
} else {
@ -154,7 +104,7 @@ const beforeAvatarUpload = (rawFile) => {
case 5:
if (
!rawFile.type.startsWith(
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'applicationnd.openxmlformats-officedocument.wordprocessingml.document',
) &&
!rawFile.type.startsWith('application/msword')
) {
@ -176,36 +126,45 @@ const beforeAvatarUpload = (rawFile) => {
break
}
}
//
const emit = defineEmits('success')
const isSubmit = async () => {
//
if (formModel.value.id) {
console.log('编辑')
} else {
console.log(formModel.value)
await CourseResourceControllerService.saveCourseResourceUsingGet1(
formModel.value,
)
ElMessage.success('添加成功')
visibilerDrawer.value = false
//
emit('success', 'add')
}
}
const isabolish = () => {
clearFileList()
visibleDramwer.value = false
visibilerDrawer.value = false
formModel.value = []
imageUrl.value = ''
// console.log(formModel.value)
}
defineExpose({
open,
})
</script>
<template>
<el-drawer
v-model="visibleDramwer"
:title="formModel.id ? '编辑资源' : '添加资源'"
direction="rtl"
size="50%"
>
<!-- 添加资源表单 -->
<el-form
class="resourceformModel"
:model="formModel"
ref="formRef"
:rules="rules"
label-width="100px"
>
<el-drawer v-model="visibilerDrawer" title="标题" direction="rtl" size="50%">
<el-form :model="formModel" ref="fromRef" :rules="rules">
<el-form-item label="资源名称" prop="name">
<el-input
v-model="formModel.name"
placeholder="请输入资源名称"
></el-input>
</el-form-item>
<el-form-item label="资源类型">
<el-form-item label="资源类型" prop="type">
<el-select
@change="handleSel"
v-model="selectVal"
v-model="formModel.type"
placeholder="请选择资源类型"
size="large"
style="width: 100%"
@ -218,18 +177,17 @@ const isabolish = () => {
/>
</el-select>
</el-form-item>
<el-form-item label="上传资源" prop="fileList">
<el-form-item label="资源封面" prop="img">
<!-- 此处需要关闭自动上传 -->
<el-upload
v-model:file-list="fileList"
:http-request="upload"
:limit="1"
class="upload-demo"
action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
list-type="picture"
class="avatar-uploader"
:show-file-list="false"
:auto-upload="false"
:before-upload="beforeAvatarUpload"
:on-change="onSelectFile"
>
<el-button type="primary">点击上传资源</el-button>
<template #file></template>
<img v-if="imageUrl" :src="imageUrl" class="avatar" />
<el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
</el-upload>
</el-form-item>
<el-form-item label="资源简介" prop="description">
@ -246,11 +204,31 @@ const isabolish = () => {
</el-drawer>
</template>
<style lang="scss" scoped>
.editor {
width: 100%;
:deep(.ql-editor) {
min-height: 200px;
.avatar-uploader {
:deep() {
.avatar {
width: 178px;
height: 178px;
display: block;
}
.el-upload {
border: 1px dashed var(--el-border-color);
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
transition: var(--el-transition-duration-fast);
}
.el-upload:hover {
border-color: var(--el-color-primary);
}
.el-icon.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
text-align: center;
}
}
}
</style>

@ -19,8 +19,8 @@ const total = ref(0)
const pptresourceList = ref([])
const loading = ref(false)
const params = ref({
// pagesize: '10',
// pagenum: '1',
pagesize: '10',
pagenum: '1',
type: '1', //ppt
})
@ -85,7 +85,7 @@ const param = ref({
download: '0',
content: '',
address: '/portal',
type: '4',
type: '1',
})
//
const generateRecords = async (rescource) => {
@ -95,20 +95,32 @@ const generateRecords = async (rescource) => {
// console.log(param)
}
const resourceAddRef = ref()
//
const rescourceRef = ref()
//
const onAddResource = () => {
resourceAddRef.value.open({})
rescourceRef.value.open({})
}
//
const onEditResource = (row) => {
resourceAddRef.value.open(row)
rescourceRef.value.open(row)
}
//
const onsuccess = (state) => {
if (state == 'add') {
//
const lastPage = Math.ceil((total.value + 1) / params.value.pagesize)
//
params.value.pagenum = lastPage
getpptresourceList()
} else {
//
getpptresourceList()
}
}
</script>
<template>
<div>
<div class="top">
<el-button @click="onAddResource">添加资源</el-button>
<el-button @click="onAddResource()">添加资源</el-button>
</div>
<div class="body">
<div class="nav">
@ -184,7 +196,7 @@ const onEditResource = (row) => {
<el-icon @click="onDeleteResource(resource.id)">
<Delete />
</el-icon>
<el-icon @click="onEditResource(row)">
<el-icon @click="onEditResource(resource)">
<Edit />
</el-icon>
</div>
@ -219,11 +231,7 @@ const onEditResource = (row) => {
/>
</div>
<!-- 添加编辑的抽屉 -->
<resource-add
:dafulIndex="params.type"
ref="resourceAddRef"
@getpptresourceList="getpptresourceList"
></resource-add>
<resource-add ref="rescourceRef" @success="onsuccess"></resource-add>
<!-- -->
</div>
</div>

Loading…
Cancel
Save