Commit 6814a5f6 authored by 杨培's avatar 杨培

课程发布与编辑页面独立,共用部分组件调整

parent e081db4e
......@@ -31,4 +31,10 @@ class CourseTeacher extends \yii\db\ActiveRecord
];
}
public static function getTeachersIdsByCourseId($courseId)
{
$list = self::find()->select('teacher_id')->where(['course_id'=>$courseId])->asArray()->all();
return array_column($list, 'teacher_id');
}
}
......@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"hash": "479a584a432c765bda14b8e45493291a",
"content-hash": "b2a9e1b6aa19ba113948022d2525b40b",
"hash": "4454b16ac08c05c643766291ce0b6335",
"content-hash": "7cd14e3280f6fcccf735c7641fab4a28",
"packages": [
{
"name": "2amigos/yii2-qrcode-helper",
......@@ -357,16 +357,16 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.1",
"version": "6.2.2",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "3f808fba627f2c5b69e2501217bf31af349c1427"
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/guzzle/guzzle/3f808fba627f2c5b69e2501217bf31af349c1427.zip",
"reference": "3f808fba627f2c5b69e2501217bf31af349c1427",
"url": "https://packagist.phpcomposer.com/files/guzzle/guzzle/ebf29dee597f02f09f4d5bbecc68230ea9b08f60.zip",
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
"shasum": ""
},
"require": {
......@@ -415,7 +415,7 @@
"rest",
"web service"
],
"time": "2016-07-15 17:22:37"
"time": "2016-10-08 15:01:37"
},
{
"name": "guzzlehttp/promises",
......@@ -572,6 +572,60 @@
],
"time": "2015-08-15 16:07:34"
},
{
"name": "mobiledetect/mobiledetectlib",
"version": "2.8.22",
"source": {
"type": "git",
"url": "https://github.com/serbanghita/Mobile-Detect.git",
"reference": "53cddae0c272a478b24a4b5fb60d0f838caf70b6"
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/serbanghita/Mobile-Detect/53cddae0c272a478b24a4b5fb60d0f838caf70b6.zip",
"reference": "53cddae0c272a478b24a4b5fb60d0f838caf70b6",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"codeclimate/php-test-reporter": "dev-master",
"johnkary/phpunit-speedtrap": "~1.0@dev",
"phpunit/phpunit": "*"
},
"type": "library",
"autoload": {
"classmap": [
"Mobile_Detect.php"
],
"psr-0": {
"Detection": "namespaced/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Serban Ghita",
"email": "serbanghita@gmail.com",
"homepage": "http://mobiledetect.net",
"role": "Developer"
}
],
"description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
"homepage": "https://github.com/serbanghita/Mobile-Detect",
"keywords": [
"detect mobile devices",
"mobile",
"mobile detect",
"mobile detector",
"php mobile detect"
],
"time": "2016-04-24 09:47:16"
},
{
"name": "psr/http-message",
"version": "1.0.1",
......
......@@ -95,7 +95,7 @@ class MyCourseController extends \yii\web\Controller
}
$lesson = Courseware::findOne(['course_id'=>$course->id]);
$teacherIds = CourseTeacher::findAll(['course_id'=>$course->id]);
$teacherIds = CourseTeacher::getTeachersIdsByCourseId($course->id);
$thumbToken = '';
......@@ -112,8 +112,6 @@ class MyCourseController extends \yii\web\Controller
$userId = Yii::$app->user->identity->getId();
$classId = $this->classStatus['id'];
//验证临时ID
$tmpId = $request->post('tmp');
......@@ -310,9 +308,4 @@ class MyCourseController extends \yii\web\Controller
return ['success'=>true, 'msg'=>'', 'file_path'=>$result['src'], 'key'=>$result['key'], 'uuid'=>$result['uuid']];
}
public function actionTest()
{
print_r(UploadPools::claimFile('2ade5751-8fae-11e6-a1b1-1242ac110005'));
}
}
......@@ -11,13 +11,13 @@ use frontend\assets\AppAsset;
$this->title = '编辑课程信息';
//AppAsset::addScript($this, '@web/assets/single-lib/plupload/plupload.full.min.js');
AppAsset::addScript($this, '@web/assets/course_publish.js');
AppAsset::addScript($this, '@web/assets/course_edit.js');
AppAsset::addCss($this, '@web/assets/css/course_publish.css');
?>
<div class="send-class" id="publishMain" xmlns:v-el="http://www.w3.org/1999/xhtml">
<div class="tit">编辑课程信息</div>
<form method="post" name="coursePublish">
<form method="post" name="courseEdit">
<div class="cls-part">
<div class="tit">标题</div>
<input type="text" name="name" class="input-r-control" placeholder="请输入课程标题,20 个汉字以内..." value="<?=$course->name?>">
......@@ -25,21 +25,7 @@ AppAsset::addCss($this, '@web/assets/css/course_publish.css');
<div class="cls-part teacher-list">
<div class="tit">讲师</div>
<div class="checkbox" v-cloak>
<label v-for="(index, item) in teachers" :class="{'m-l-10':index!=0}">
<input name="teacher[]" type="checkbox" value="{{item.id}}" v-model="checkedTeachers">{{item.name}}
</label>
<div class="d-i-b" v-if="atState">
<input type="text" class="input-r-control reset-input" placeholder="请输入讲师名称" v-model="addTeacherName" v-el:tni>
<button type="button" class="btn btn-nobg" @click="addTeacher">保存</button>
</div>
<span class="m-l-10" v-if="!atState"><a href="javascript:;" @click="addTeacher">+ 添加讲师</a></span>
</div>
</div>
<div class="cls-part">
<div class="tit">上传视频</div>
<teachers init-teachers="<?=join(',', $teacherIds)?>"></teachers>
</div>
<div class="cls-part">
......@@ -48,13 +34,13 @@ AppAsset::addCss($this, '@web/assets/css/course_publish.css');
<div class="checkbox rules-set fl">
<label class="clearfix">
<!--<input name="vip_price" type="checkbox" class="fl" value="1">--><span>会员价</span> <input type="text" name="price" class="input-r-control text-center" value="0"> <span>元</span>
<span>会员价</span> <input type="text" name="price" class="input-r-control text-center" value="<?=$course->price?>"> <span>元</span>
</label>
</div>
<div class="checkbox rules-set m-l-20 fl">
<label class="clearfix">
<!--<input name="free_time" type="checkbox" class="fl">--><span>免费试看</span> <input type="text" name="free_time" class="input-r-control text-center" value="0"> <span>分钟</span>
<span>免费试看</span> <input type="text" name="free_time" class="input-r-control text-center" value="<?=$course->free_time?>"> <span>分钟</span>
</label>
</div>
</div>
......@@ -76,14 +62,14 @@ AppAsset::addCss($this, '@web/assets/css/course_publish.css');
<div class="tit">课程属性</div>
<div class="checkbox">
<label>
<input type="checkbox" name="recommend" value="1">推荐课程
<input type="checkbox" name="recommend" value="1"<?php if ($course->recommend) { ?> checked<?php } ?>>推荐课程
</label>
</div>
</div>
<input type="hidden" name="tmp" value="{{tmp}}" />
<input type="hidden" name="vuid" value="{{vuid}}" />
<input type="hidden" name="preview" value="{{previewKey}}" />
<input type="hidden" name="vuid" value="@orig" v-model="vuid" />
<input type="hidden" name="preview" value="@orig" v-model="previewKey" />
<div class="btn-box text-center" style="border-top: 1px solid #e7e7e7; margin-top: 10px; ">
<button type="button" class="btn btn-nobg">取消</button>
......
......@@ -24,17 +24,7 @@ AppAsset::addCss($this, '@web/assets/css/course_publish.css');
<div class="cls-part teacher-list">
<div class="tit">讲师</div>
<div class="checkbox" v-cloak>
<label v-for="(index, item) in teachers" :class="{'m-l-10':index!=0}">
<input name="teacher[]" type="checkbox" value="{{item.id}}" v-model="checkedTeachers">{{item.name}}
</label>
<div class="d-i-b" v-if="atState">
<input type="text" class="input-r-control reset-input" placeholder="请输入讲师名称" v-model="addTeacherName" v-el:tni>
<button type="button" class="btn btn-nobg" @click="addTeacher">保存</button>
</div>
<span class="m-l-10" v-if="!atState"><a href="javascript:;" @click="addTeacher">+ 添加讲师</a></span>
</div>
<teachers></teachers>
</div>
<div class="cls-part">
......
......@@ -6,7 +6,14 @@
$.ajaxSetup({
beforeSend: function () {
if (this.type == "POST") {
this.data += "&_csrf-frontend=" + encodeURIComponent($("meta[name='csrf-token']").attr("content"));
var name = "_csrf-frontend";
var token = $("meta[name='csrf-token']").attr("content");
if (this.data instanceof FormData) {
this.data.append(name, token);
} else {
this.data += (this.data ? "&" : "") + name + "=" + encodeURIComponent(token);
}
}
}
});
\ No newline at end of file
<template xmlns:v-el="http://www.w3.org/1999/xhtml">
<div class="checkbox">
<label v-for="(index, item) in teachers" :class="{'m-l-10':index!=0}">
<input name="teacher[]" type="checkbox" value="{{item.id}}" v-model="checkedTeachers">{{item.name}}
</label>
<div class="d-i-b" v-if="addFormShow">
<input type="text" class="input-r-control reset-input" placeholder="请输入讲师名称" v-model="newName" v-el:nameInput>
<button type="button" class="btn btn-nobg" @click="addTeacher">保存</button>
</div>
<span class="m-l-10" v-else><a href="javascript:;" @click="showAddForm">+ 添加讲师</a></span>
</div>
</template>
<script>
import layer from 'layer-js';
export default{
data() {
return {
teachers: [],
checkedTeachers: [],
addFormShow: false,
newName: ""
}
},
props: {
initTeachers: String
},
methods: {
showAddForm() {
this.addFormShow = true;
this.$nextTick(function() {
this.$els.nameInput.focus();
});
},
addTeacher(e) {
if ($.trim(this.newName) == "") {
this.$els.nameInput.focus();
return;
}
var self = this;
//添加讲师
$.post("/teacher-manager/save", {
name: self.newName
}, function(t) {
if (!t.error) {
self.loadTeacherList();
self.newName = "";
self.addFormShow = false;
self.checkedTeachers.push(t.teacher_id.toString());
} else {
layer.alert("添加讲师失败!\n" + t.error, {icon:5, title:"上传失败"});
}
}, "json");
},
loadTeacherList() {
var self = this;
$.getJSON("/teacher-manager/simple-teacher-list", function(t) {
self.teachers = t;
});
}
},
watch: {
checkedTeachers(val) {
this.$dispatch("teacher-quick-list-checked", val);
}
},
ready() {
this.loadTeacherList();
if (this.initTeachers) {
this.checkedTeachers = this.initTeachers.split(",");
}
}
}
</script>
/**
* Created by pader on 16/10/21.
*/
var Vue = require('vue');
var thumbUpload = require('../components/uploader/thumb-upload.vue');
var teacherQuickList = require('./components/teacher-quick-list.vue');
var richText = require('./rich-text');
var layer = require("layer-js");
var str = require("../utils/string");
require('jquery-validation');
var form = document.forms["courseEdit"];
var vm = new Vue({
el: "#publishMain",
data: {
vuid: "",
previewKey: "",
tmp: str.rand(20)
},
components: {
thumbUpload: thumbUpload,
teachers: teacherQuickList
},
ready: function() {
var self = this;
this.$on("thumb-uploaded", function(name, data) {
self.previewKey = data.uuid;
});
var validator = $(form).validate({
//debug: true,
//errorClass: "",
//validClass: "",
ignore: "",
rules: {
name: {
required: true
},
preview: {
required: true
}
},
messages: {
name: {
required: "请填写标题"
},
preview: {
required: "必须上传缩略图"
}
},
errorPlacement: function(error, element) {
var text = error.text();
var org = element.get(0);
var to = null;
if (org == form.preview) {
to = $(".upload-video-screen").get(0);
} else {
to = org;
}
//绑定提示到元素上
if (text) {
if (to.tipIndex) {
layer.close(to.tipIndex);
}
to.tipIndex = layer.tips(text, to, {
tips: org == form.name ? 3 : 2,
time: 0,
tipsMore: true
});
} else if (to.tipIndex) {
layer.close(to.tipIndex);
to.tipIndex = null;
}
},
success: function() {}, //添加 success 后,当表单验证成功时才会触发 errorPlacement,否则验证成功不触发
submitHandler: function() {
var data = $(form).serialize();
var idx = layer.msg("正在提交..", {icon:16, shade: [0.2,'#000'], time:0});
$.post("/my-course/submit", data, function(t) {
layer.close(idx);
if (t.status) {
location.replace("/my-course/result?id=" + t.data.course_id + "&action=publish");
} else {
layer.alert(t.message, {icon:5, title:"提示"});
}
}, "json");
return false;
}
});
var doValidate = function() { validator.form(); };
this.$watch("vuid", doValidate);
this.$watch("previewKey", doValidate);
richText.createEditor($("#introEditor"), this.tmp);
}
});
\ No newline at end of file
......@@ -4,21 +4,13 @@
var Vue = require('vue');
var videoUpload = require('../components/uploader/video-upload.vue');
var thumbUpload = require('../components/uploader/thumb-upload.vue');
var teacherQuickList = require('./components/teacher-quick-list.vue');
var richText = require('./rich-text');
var layer = require("layer-js");
var Simditor = require("../utils/simditor");
var str = require("../utils/string");
require('jquery-validation');
//$.ajaxSetup({
// beforeSend: function() {
// if (this.type == "POST") {
// this.data += "&_csrf-frontend=" + encodeURIComponent($("meta[name='csrf-token']").attr("content"));
// }
// }
//});
var form = document.forms["coursePublish"];
var vm = new Vue({
......@@ -26,54 +18,15 @@ var vm = new Vue({
data: {
vuid: "",
previewKey: "",
teachers: [],
atState: 0,
addTeacherName: "",
checkedTeachers: [],
tmp: str.rand(20)
},
components: {
videoUpload: videoUpload,
thumbUpload: thumbUpload
},
methods: {
addTeacher: function(e) {
if (e.target.tagName.toLowerCase() == "a") {
this.atState = 1;
return;
}
if ($.trim(this.addTeacherName) == "") {
this.$els.tni.focus();
return;
}
var self = this;
//添加讲师
$.post("/teacher-manager/save", {
name: self.addTeacherName
}, function(t) {
if (!t.error) {
self.loadTeacherList();
self.addTeacherName = "";
self.atState = 0;
self.checkedTeachers.push(t.teacher_id.toString());
} else {
layer.alert("添加讲师失败!\n" + t.error, {icon:5, title:"上传失败"});
}
}, "json");
},
loadTeacherList: function() {
$.getJSON("/teacher-manager/simple-teacher-list", function(t) {
vm.teachers = t;
});
}
thumbUpload: thumbUpload,
teachers: teacherQuickList
},
ready: function() {
var self = this;
this.loadTeacherList();
this.$on("video-uploaded", function(name, data) {
self.vuid = data.uuid;
......@@ -161,22 +114,6 @@ var vm = new Vue({
this.$watch("vuid", doValidate);
this.$watch("previewKey", doValidate);
var editor = new Simditor({
textarea: $("#introEditor"),
toolbarFloat: false,
defaultImage: "/assets/img/placeholder.jpg",
upload: {
url : '/my-course/upload', //文件上传的接口地址
params: {
"_csrf-frontend": $("meta[name='csrf-token']").attr("content"),
"tmp": self.tmp
},
fileKey: 'file', //服务器端获取文件数据的参数名
connectionCount: 3,
leaveConfirm: '正在上传文件'
}
});
editor;
richText.createEditor($("#introEditor"), this.tmp);
}
});
\ No newline at end of file
/**
* Created by pader on 2016/10/21.
*/
var Simditor = require("../utils/simditor");
module.exports = {
createEditor: function(container, tmp) {
return new Simditor({
textarea: container,
toolbarFloat: false,
defaultImage: "/assets/img/placeholder.jpg",
upload: {
url : '/my-course/upload', //文件上传的接口地址
params: {
"_csrf-frontend": $("meta[name='csrf-token']").attr("content"),
"tmp": tmp
},
fileKey: 'file', //服务器端获取文件数据的参数名
connectionCount: 3,
leaveConfirm: '正在上传文件'
}
});
}
};
\ No newline at end of file
......@@ -24,6 +24,7 @@ var entry = {
home_index: [js_dir + '/home/index.js'],
home_video: [js_dir + '/home/video.js'],
course_publish: [js_dir + '/my-course/publish.js'],
course_edit: [js_dir + '/my-course/edit.js'],
teacher_form: [js_dir + '/teacher-manager/form.js'],
my_income: [js_dir + '/my-income/index.js']
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment