|
@@ -1,4 +1,4 @@
|
|
|
-<!-- 角色创建/修改 -->
|
|
|
+<!-- 课程创建/修改 -->
|
|
|
|
|
|
<template>
|
|
|
<div class="pjc">
|
|
@@ -6,76 +6,56 @@
|
|
|
<h3>{{ title }}</h3>
|
|
|
<el-form :model="courseDeail" label-width="110px">
|
|
|
<el-form-item label="课程名称:">
|
|
|
- <el-input v-model.trim="courseDeail.name"></el-input>
|
|
|
+ <el-input v-model.trim="courseDeail.name" style="width: 40%"></el-input>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="预览图:">
|
|
|
- <div style="width: 68px;" @click="showSelectImg()">
|
|
|
+ <div style="width: 68px" @click="showSelectImg(1)">
|
|
|
<userImage
|
|
|
v-if="courseDeail.thumb"
|
|
|
width="68px"
|
|
|
height="68px"
|
|
|
+ radius="5px"
|
|
|
:img_url="courseDeail.thumb"
|
|
|
:user_name="courseDeail.name"
|
|
|
+ style="cursor: pointer"
|
|
|
></userImage>
|
|
|
<div v-else class="cursor">
|
|
|
- <div>
|
|
|
- +
|
|
|
- </div>
|
|
|
- <!-- <div>上传预览图</div> -->
|
|
|
+ <div>+</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="价格:">
|
|
|
<el-input-number
|
|
|
v-model="courseDeail.price"
|
|
|
- @change="this.courseDeail.price = !courseDeail.price"
|
|
|
- :min="1"
|
|
|
+ :min="0"
|
|
|
:max="10000000"
|
|
|
label="课程价格"
|
|
|
></el-input-number>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="是否上架:">
|
|
|
<el-switch
|
|
|
- v-model="courseDeail.isShelf"
|
|
|
+ v-model="courseDeail.enable"
|
|
|
active-color="#13ce66"
|
|
|
inactive-color="#999"
|
|
|
>
|
|
|
</el-switch>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="课程介绍:">
|
|
|
- <el-upload
|
|
|
- action="#"
|
|
|
- list-type="picture-card"
|
|
|
- :auto-upload="false"
|
|
|
- :file-list="courseDeail.images"
|
|
|
- :limit="20"
|
|
|
- multiple
|
|
|
- :on-change="uploadChange2"
|
|
|
- :on-error="uploadErr"
|
|
|
- >
|
|
|
- <i slot="default" class="el-icon-plus"></i>
|
|
|
- <div slot="file" slot-scope="{ file }">
|
|
|
- <img
|
|
|
- class="el-upload-list__item-thumbnail"
|
|
|
- :src="file.url"
|
|
|
- alt=""
|
|
|
- />
|
|
|
- <span class="el-upload-list__item-actions">
|
|
|
- <span
|
|
|
- class="el-upload-list__item-preview"
|
|
|
- @click="handlePictureCardPreview(file)"
|
|
|
- >
|
|
|
- <i class="el-icon-zoom-in"></i>
|
|
|
- </span>
|
|
|
- <span
|
|
|
- class="el-upload-list__item-delete"
|
|
|
- @click="handleRemove2(file)"
|
|
|
- >
|
|
|
- <i class="el-icon-delete"></i>
|
|
|
- </span>
|
|
|
- </span>
|
|
|
+ <div style="display: flex">
|
|
|
+ <div class="img_all">
|
|
|
+ <template v-for="(item, index) in courseImages">
|
|
|
+ <userImage
|
|
|
+ width="68px"
|
|
|
+ radius="5px"
|
|
|
+ height="68px"
|
|
|
+ :img_url="item"
|
|
|
+ ></userImage>
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+ <div class="cursor" @click="showSelectImg(2)">
|
|
|
+ <div>+</div>
|
|
|
</div>
|
|
|
- </el-upload>
|
|
|
+ </div>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="课程章节" size="normal">
|
|
|
<div class="sectionout">
|
|
@@ -85,10 +65,10 @@
|
|
|
:key="index"
|
|
|
>
|
|
|
<div class="sectionName">
|
|
|
- <el-input v-model.trim="item.name"></el-input>
|
|
|
+ <el-input v-model.trim="item.name" placeholder="请输入章节名..."></el-input>
|
|
|
</div>
|
|
|
<div class="sectionUrl">
|
|
|
- <el-input v-model.trim="item.link"></el-input>
|
|
|
+ <el-input v-model.trim="item.link" placeholder="请输入章节链接..."></el-input>
|
|
|
</div>
|
|
|
<div class="del">
|
|
|
<el-button
|
|
@@ -130,13 +110,16 @@
|
|
|
</template>
|
|
|
<script>
|
|
|
import ImageCropper from "@/components/ImageCropper";
|
|
|
+import { validateURL } from "@/utils/validate";
|
|
|
+import {createCourse,updataCourse,getCourseDetail} from '../api'
|
|
|
export default {
|
|
|
name: "courseEdit",
|
|
|
components: { ImageCropper },
|
|
|
data() {
|
|
|
return {
|
|
|
+ curId: 0,
|
|
|
title: "",
|
|
|
- company_img_show:false,
|
|
|
+ company_img_show: false,
|
|
|
company_img_loading: false,
|
|
|
alterCreate: "保存",
|
|
|
imgIndex: 1,
|
|
@@ -144,46 +127,78 @@ export default {
|
|
|
imgHeight: 300,
|
|
|
// 个人信息
|
|
|
courseDeail: {
|
|
|
- id: 0,
|
|
|
name: "",
|
|
|
price: 0,
|
|
|
thumb: "",
|
|
|
- images: [],
|
|
|
- sections: [
|
|
|
- {
|
|
|
- name: "精讲1",
|
|
|
- link: "http:sasdsada.com",
|
|
|
- },
|
|
|
- {
|
|
|
- name: "精讲1",
|
|
|
- link: "http:sasdsada.com",
|
|
|
- },
|
|
|
- {
|
|
|
- name: "精讲1",
|
|
|
- link: "http:sasdsada.com",
|
|
|
- },
|
|
|
- {
|
|
|
- name: "精讲1",
|
|
|
- link: "http:sasdsada.com",
|
|
|
- },
|
|
|
- ],
|
|
|
+ enable: false,
|
|
|
+ images: "",
|
|
|
+ sections: [],
|
|
|
},
|
|
|
dialogVisible: false,
|
|
|
dialogImageUrl: "",
|
|
|
};
|
|
|
},
|
|
|
- computed: {},
|
|
|
+ computed: {
|
|
|
+ courseImages() {
|
|
|
+ if (this.courseDeail.images) {
|
|
|
+ return this.courseDeail.images.split(",");
|
|
|
+ } else {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
methods: {
|
|
|
- //预览图上传成功
|
|
|
+ //章节信息校验
|
|
|
+ validateURL() {
|
|
|
+ let result = false;
|
|
|
+ result = this.courseDeail.sections.every((item) => {
|
|
|
+ return validateURL(item.link) && item.name !== "";
|
|
|
+ });
|
|
|
+ return result;
|
|
|
+ },
|
|
|
+ // 获取课程详情
|
|
|
+ getCourseDetail() {
|
|
|
+ getCourseDetail(this.curId).then((res) => {
|
|
|
+ this.courseDeail = this.uploadToData(res);
|
|
|
+ }).catch(err=>{
|
|
|
+ console.error(err)
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //课程详情数据转换展示
|
|
|
+ uploadToData(data) {
|
|
|
+ data.enable = data.enable == 1 ? true : false;
|
|
|
+ data.price = Number(data.price);
|
|
|
+ data.images = data.images.join(",");
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+ //图片上传成功回调
|
|
|
company_img_success(resData) {
|
|
|
- console.log(resData)
|
|
|
- this.courseDeail.thumb = resData.url;
|
|
|
+ if (this.imgIndex == 1) {
|
|
|
+ this.courseDeail.thumb = resData.url;
|
|
|
+ } else {
|
|
|
+ if (
|
|
|
+ this.courseDeail.images.split(",").length == 1 &&
|
|
|
+ this.courseDeail.images.split(",")[0] == ""
|
|
|
+ ) {
|
|
|
+ this.courseDeail.images = resData.url;
|
|
|
+ } else {
|
|
|
+ this.courseDeail.images = `${this.courseDeail.images},${resData.url}`;
|
|
|
+ }
|
|
|
+ }
|
|
|
this.company_img_show = false;
|
|
|
},
|
|
|
- //图片放大
|
|
|
- showSelectImg() {
|
|
|
+ //打开上传图片组件
|
|
|
+ showSelectImg(type) {
|
|
|
+ this.imgIndex = type;
|
|
|
this.company_img_show = true;
|
|
|
},
|
|
|
+ //展示数据转换成上传数据
|
|
|
+ toUpdata() {
|
|
|
+ let data = JSON.parse(JSON.stringify(this.courseDeail));
|
|
|
+ data.enable = data.enable ? 1 : 0;
|
|
|
+ data.sections = JSON.stringify(data.sections);
|
|
|
+ return data;
|
|
|
+ },
|
|
|
// 添加课程
|
|
|
addSection() {
|
|
|
let section = {
|
|
@@ -192,7 +207,7 @@ export default {
|
|
|
};
|
|
|
this.courseDeail.sections.push(section);
|
|
|
},
|
|
|
- // 删除课程
|
|
|
+ // 删除章节
|
|
|
sectionDel(index, item) {
|
|
|
this.$confirm("确定删除当前章节?", "提示", {
|
|
|
confirmButtonText: "确定",
|
|
@@ -209,35 +224,6 @@ export default {
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
- suceessChange(res) {
|
|
|
- console.log(res);
|
|
|
- },
|
|
|
- // 上传图片失败
|
|
|
- uploadErr(err, file, fileList) {
|
|
|
- console.log(err);
|
|
|
- console.log(file);
|
|
|
- },
|
|
|
- //上传预览图
|
|
|
- uploadChange(file, fileList) {
|
|
|
- this.courseDeail.thumb.push(file);
|
|
|
- },
|
|
|
- // 上传介绍图组
|
|
|
- uploadChange2(file, fileList) {
|
|
|
- this.courseDeail.images.push(file);
|
|
|
- },
|
|
|
- // 删除预览图
|
|
|
- handleRemove(file) {
|
|
|
- this.deleteImage(file.url);
|
|
|
- },
|
|
|
- // 删除介绍图
|
|
|
- handleRemove2(file) {
|
|
|
- this.deleteImage(file.url, 1);
|
|
|
- },
|
|
|
- // 图片放大查看
|
|
|
- handlePictureCardPreview(file) {
|
|
|
- this.dialogImageUrl = file.url;
|
|
|
- this.dialogVisible = true;
|
|
|
- },
|
|
|
// 删除图片
|
|
|
deleteImage(url, type) {
|
|
|
this.$confirm("确定删除图片?", "提示", {
|
|
@@ -252,7 +238,6 @@ export default {
|
|
|
});
|
|
|
this.courseDeail.images = newList;
|
|
|
} else {
|
|
|
- console.log(123);
|
|
|
this.courseDeail.thumb = [];
|
|
|
}
|
|
|
})
|
|
@@ -263,13 +248,14 @@ export default {
|
|
|
});
|
|
|
});
|
|
|
},
|
|
|
- //保存修改
|
|
|
+ //保存
|
|
|
iffirm() {
|
|
|
if (
|
|
|
!this.courseDeail.name == "" &&
|
|
|
- !this.courseDeail.images.length == 0 &&
|
|
|
+ !this.courseDeail.images == "" &&
|
|
|
!this.courseDeail.thumb == "" &&
|
|
|
- !this.courseDeail.price !== 0
|
|
|
+ !this.courseDeail.price !== 0 &&
|
|
|
+ this.validateURL()
|
|
|
) {
|
|
|
this.$confirm("确定保存当前页面信息?", "提示", {
|
|
|
confirmButtonText: "确定",
|
|
@@ -289,51 +275,69 @@ export default {
|
|
|
message: "已取消",
|
|
|
});
|
|
|
});
|
|
|
+ } else if (!this.validateURL()) {
|
|
|
+ this.$message({
|
|
|
+ type: "warning",
|
|
|
+ message: "章节列表未填写正确",
|
|
|
+ });
|
|
|
} else {
|
|
|
this.$message({
|
|
|
type: "warning",
|
|
|
- message: "用户信息未填写完整!",
|
|
|
+ message: "用户信息未填写完整",
|
|
|
});
|
|
|
}
|
|
|
},
|
|
|
//修改保存
|
|
|
saveAlter() {
|
|
|
- this.$message({
|
|
|
- message: "修改成功!",
|
|
|
- type: "success",
|
|
|
- showClose: true,
|
|
|
- duration: 2000,
|
|
|
- });
|
|
|
+ let data = this.toUpdata();
|
|
|
+ updataCourse(this.curId,data).then(res=>{
|
|
|
+ this.$message({
|
|
|
+ message: "修改成功!",
|
|
|
+ type: "success",
|
|
|
+ showClose: true,
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
+ this.$router.push("/course/courseManage");
|
|
|
+ }).catch(err=>{
|
|
|
+ console.error(err)
|
|
|
+ })
|
|
|
},
|
|
|
- //新建角色保存post
|
|
|
+ //新建课程
|
|
|
saveCreate() {
|
|
|
- this.$message({
|
|
|
- message: "新建课程成功!",
|
|
|
- type: "success",
|
|
|
- showClose: true,
|
|
|
- duration: 2000,
|
|
|
- });
|
|
|
+ let data = this.toUpdata();
|
|
|
+ createCourse(data).then(res=>{
|
|
|
+ this.$message({
|
|
|
+ message: "新建成功!",
|
|
|
+ type: "success",
|
|
|
+ showClose: true,
|
|
|
+ duration: 2000,
|
|
|
+ });
|
|
|
+ this.$router.push("/course/courseManage");
|
|
|
+ }).catch(err=>{
|
|
|
+ console.error(err)
|
|
|
+ })
|
|
|
},
|
|
|
//判断新建/修改
|
|
|
- judge() {
|
|
|
+ init() {
|
|
|
if (this.$route.params.id == undefined) {
|
|
|
this.title = "创建课程";
|
|
|
+ this.courseDeail = {
|
|
|
+ name: "",
|
|
|
+ price: 0,
|
|
|
+ thumb: "",
|
|
|
+ enable: false,
|
|
|
+ images: "",
|
|
|
+ sections: [],
|
|
|
+ };
|
|
|
} else {
|
|
|
+ this.curId = this.$route.params.id;
|
|
|
this.title = "编辑课程";
|
|
|
+ this.getCourseDetail();
|
|
|
}
|
|
|
},
|
|
|
- //获取单个角色信息
|
|
|
- getOneAccount() {
|
|
|
- // this.$api.role
|
|
|
- // .getOne(this.$route.params.id)
|
|
|
- // .then((res) => {
|
|
|
- // this.toRole(res.data.result);
|
|
|
- // })
|
|
|
- // .catch((error) => {});
|
|
|
- },
|
|
|
},
|
|
|
created() {
|
|
|
- this.judge();
|
|
|
+ this.init();
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
@@ -385,8 +389,14 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-.cursor{
|
|
|
- &>div{
|
|
|
+.img_all {
|
|
|
+ display: flex;
|
|
|
+ & > div {
|
|
|
+ margin-right: 10px;
|
|
|
+ }
|
|
|
+}
|
|
|
+.cursor {
|
|
|
+ & > div {
|
|
|
height: 68px;
|
|
|
width: 68px;
|
|
|
border: 2px dashed #f1f1f1;
|