Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Z
zuiketang
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏彬
zuiketang
Commits
0062bbcf
Commit
0062bbcf
authored
Oct 22, 2016
by
杨培
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善修改课程:富文本编辑器工具栏跟随屏幕,缩略图风格修改,修改缩略图自动删除老图片。
parent
2c0c033a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
233 additions
and
16 deletions
+233
-16
MyCourseController.php
src/frontend/controllers/MyCourseController.php
+9
-3
CoursePublishForm.php
src/frontend/models/CoursePublishForm.php
+193
-0
edit.php
src/frontend/views/my-course/edit.php
+2
-3
thumb-upload.vue
src/frontend/web/js/components/uploader/thumb-upload.vue
+27
-9
rich-text.js
src/frontend/web/js/my-course/rich-text.js
+2
-1
No files found.
src/frontend/controllers/MyCourseController.php
View file @
0062bbcf
...
@@ -157,7 +157,7 @@ class MyCourseController extends \yii\web\Controller
...
@@ -157,7 +157,7 @@ class MyCourseController extends \yii\web\Controller
if
(
!
$courseware
->
validate
())
{
if
(
!
$courseware
->
validate
())
{
Utils
::
ajaxResponse
(
false
,
Utils
::
fetchErrorFirst
(
$courseware
->
errors
));
Utils
::
ajaxResponse
(
false
,
Utils
::
fetchErrorFirst
(
$courseware
->
errors
));
}
}
//保存课程数据
//保存课程数据
if
(
!
$course
->
save
())
{
if
(
!
$course
->
save
())
{
Utils
::
ajaxResponse
(
false
,
Utils
::
fetchErrorFirst
(
$course
->
errors
));
Utils
::
ajaxResponse
(
false
,
Utils
::
fetchErrorFirst
(
$course
->
errors
));
...
@@ -212,6 +212,8 @@ class MyCourseController extends \yii\web\Controller
...
@@ -212,6 +212,8 @@ class MyCourseController extends \yii\web\Controller
throw
new
ForbiddenHttpException
();
throw
new
ForbiddenHttpException
();
}
}
$oldPreview
=
$course
->
preview_pic
;
//修改课程数据
//修改课程数据
$course
->
name
=
$form
->
name
;
$course
->
name
=
$form
->
name
;
$course
->
price
=
$form
->
price
;
$course
->
price
=
$form
->
price
;
...
@@ -233,8 +235,12 @@ class MyCourseController extends \yii\web\Controller
...
@@ -233,8 +235,12 @@ class MyCourseController extends \yii\web\Controller
//保存讲师与课程关联数据
//保存讲师与课程关联数据
CourseTeacher
::
autoSaveRelations
(
$course
->
id
,
$form
->
teacher
);
CourseTeacher
::
autoSaveRelations
(
$course
->
id
,
$form
->
teacher
);
//认领文件与附件
//认领文件与附件,删除老文件
UploadPools
::
claimFile
(
$course
->
preview_pic
);
if
(
$form
->
preview
)
{
UploadPools
::
claimFile
(
$form
->
preview
[
'key'
]);
UploadPools
::
deleteFile
(
'public:'
.
$oldPreview
);
}
AttachUpload
::
claimTmpAttachs
(
$form
->
tmp
,
'course:'
.
$course
->
id
);
AttachUpload
::
claimTmpAttachs
(
$form
->
tmp
,
'course:'
.
$course
->
id
);
Utils
::
ajaxResponse
(
true
,
null
,
[
'course_id'
=>
$course
->
id
]);
Utils
::
ajaxResponse
(
true
,
null
,
[
'course_id'
=>
$course
->
id
]);
...
...
src/frontend/models/CoursePublishForm.php
0 → 100644
View file @
0062bbcf
<?php
/**
* Created by PhpStorm.
* User: pader
* Date: 2016/10/21
* Time: 16:17
*/
namespace
frontend\models
;
use
common\libs\Utils
;
use
common\models\Teacher
;
use
common\models\UploadPools
;
use
Qiniu\Storage\BucketManager
;
use
yii\base\Model
;
/**
* 课件发布辅助表单类
*
* 这不是一个常规的Yii表单类,仅用于处理提交数据后缀的辅助验证等
*
* @property $id int
* @property $tmp string
* @property $class_id int
* @property $user_id int
* @property $preview string|array
* @property $vuid string|array
* @property $name string
* @property $price float
* @property $free_time int
* @property $intro string
* @property $recommend int
* @package frontend\models
*/
class
CoursePublishForm
extends
Model
{
public
$id
;
public
$tmp
;
public
$class_id
;
public
$user_id
;
public
$vuid
;
public
$preview
;
public
$name
;
/**
* 选择的讲师ID数组
* @var array
*/
public
$teacher
;
public
$price
;
public
$free_time
;
public
$intro
;
public
$recommend
;
private
$createMode
;
public
function
__construct
(
$create
=
false
)
{
parent
::
__construct
();
$this
->
createMode
=
$create
;
}
public
function
formName
()
{
return
''
;
}
/**
* @inheritdoc
*/
public
function
attributeLabels
()
{
return
[
'id'
=>
'ID'
,
'tmp'
=>
'Tmp'
,
'user_id'
=>
'User ID'
,
'class_id'
=>
'Class ID'
,
'name'
=>
'标题'
,
'teacher'
=>
'讲师'
,
'price'
=>
'价格'
,
'free_time'
=>
'免费观看时间'
,
'intro'
=>
'简介'
,
'vuid'
=>
'视频'
,
'preview'
=>
'预览图'
,
'recommend'
=>
'推荐课程'
];
}
public
function
rules
()
{
$requiredFields
=
[
'tmp'
,
'class_id'
,
'user_id'
,
'name'
,
'price'
,
'free_time'
,
'preview'
];
//创建模式下将验证视频文件
if
(
$this
->
createMode
)
{
$requiredFields
[]
=
'vuid'
;
}
$rules
=
[
[
$requiredFields
,
'required'
],
[[
'id'
,
'class_id'
,
'user_id'
,
'free_time'
],
'integer'
],
[[
'tmp'
,
'name'
,
'preview'
,
'intro'
],
'string'
],
[
'tmp'
,
'match'
,
'pattern'
=>
'/^\w{20}$/i'
],
[
'teacher'
,
'validateTeachers'
],
[
'teacher'
,
'default'
,
'value'
=>
[]],
[
'free_time'
,
'integer'
,
'min'
=>
0
,
'max'
=>
15
],
[
'preview'
,
'validateUploadKey'
],
[
'recommend'
,
'boolean'
]
];
if
(
$this
->
createMode
)
{
$rules
[]
=
[
'vuid'
,
'validateUploadKey'
];
}
return
$rules
;
}
/**
* 检查上传七牛云文件是否可领取是否可领取
*
* @param string $attr
* @param $params
*/
public
function
validateUploadKey
(
$attr
,
$params
)
{
//值 @orig 代表保持原文件,不做验证和修改,此时将值改为false
if
(
$this
->
$attr
==
'@orig'
)
{
$this
->
$attr
=
false
;
return
;
}
//验证成功后值将被修改为文件信息数组
$file
=
UploadPools
::
getFileInfo
(
$this
->
$attr
);
if
(
$file
)
{
$this
->
$attr
=
$file
;
}
else
{
$labels
=
$this
->
attributeLabels
();
$name
=
isset
(
$labels
[
$attr
])
?
$labels
[
$attr
]
:
''
;
$this
->
addError
(
$attr
,
$name
.
'文件不存在'
);
}
}
/**
* 过滤已拥有的讲师列表
*
* @param string $attr
* @param $params
*/
public
function
validateTeachers
(
$attr
,
$params
)
{
$ids
=
is_array
(
$this
->
$attr
)
?
$this
->
$attr
:
[];
$this
->
$attr
=
Teacher
::
filterOwnTeacherIds
(
$this
->
class_id
,
$ids
);
}
/**
* 获取已验证的视频文件信息
*
* @param array $poolFile 由 UploadPools::getFileInfo 返回的文件信息
* @return array ['file'=>文件stat信息, 'av'=>文件avInfo流媒体信息]
* @throws \yii\base\ExitException
*/
public
static
function
getVerifyVideoInfo
(
$poolFile
)
{
/* @var $qiniu \common\components\Qiniu; */
$qiniu
=
\Yii
::
$app
->
qiniu
;
$bucket
=
$qiniu
->
getStorageConfig
(
$poolFile
[
'storage'
],
'bucket'
);
$auth
=
$qiniu
->
getAuthInstance
();
$bucketMgr
=
new
BucketManager
(
$auth
);
$return
=
[];
/* @var $err \Qiniu\Http\Error */
list
(
$ret
,
$err
)
=
$bucketMgr
->
stat
(
$bucket
,
$poolFile
[
'key'
]);
if
(
$err
!==
null
)
{
Utils
::
ajaxResponse
(
false
,
$err
->
message
());
}
else
{
$return
[
'file'
]
=
$ret
;
}
//读取视频信息
$avUrl
=
$auth
->
privateDownloadUrl
(
$poolFile
[
'url'
]
.
'?avinfo'
);
$response
=
(
new
\GuzzleHttp\Client
())
->
get
(
$avUrl
);
$avInfo
=
$response
->
getBody
();
if
(
$avInfo
)
{
$return
[
'av'
]
=
\GuzzleHttp\json_decode
(
$avInfo
,
true
);
}
else
{
Utils
::
ajaxResponse
(
false
,
'读取视频信息失败'
);
}
return
$return
;
}
}
\ No newline at end of file
src/frontend/views/my-course/edit.php
View file @
0062bbcf
...
@@ -48,14 +48,13 @@ AppAsset::addCss($this, '@web/assets/css/course_publish.css');
...
@@ -48,14 +48,13 @@ AppAsset::addCss($this, '@web/assets/css/course_publish.css');
<div
class=
"cls-part"
>
<div
class=
"cls-part"
>
<div
class=
"tit"
>
课程介绍
</div>
<div
class=
"tit"
>
课程介绍
</div>
<div
class=
"cls-intro-textarea"
>
<div
class=
"cls-intro-textarea"
>
<textarea
name=
"intro"
class=
"input-r-control"
placeholder=
"请输入课程介绍..."
id=
"introEditor"
>
<?=
\yii\helpers\Html
::
encode
(
$course
->
intro
)
?>
</textarea>
<textarea
name=
"intro"
class=
"input-r-control"
placeholder=
"请输入课程介绍..."
id=
"introEditor"
style=
"height:300px;"
>
<?=
\yii\helpers\Html
::
encode
(
$course
->
intro
)
?>
</textarea>
</div>
</div>
</div>
</div>
<div
class=
"cls-part"
>
<div
class=
"cls-part"
>
<div
class=
"tit"
>
缩略图
<small>
建议尺寸:900像素 * 500像素
</small></div>
<div
class=
"tit"
>
缩略图
<small>
建议尺寸:900像素 * 500像素
</small></div>
<thumb-upload
uptoken=
"
<?=
$thumbToken
?>
"
></thumb-upload>
<thumb-upload
uptoken=
"
<?=
$thumbToken
?>
"
init-img=
"
<?=
\Yii
::
$app
->
qiniu
->
getUrl
(
'public'
,
$course
->
preview_pic
)
?>
-m.preview"
></thumb-upload>
<img
src=
"
<?=
\Yii
::
$app
->
qiniu
->
getUrl
(
'public'
,
$course
->
preview_pic
)
?>
-s.preview"
/>
</div>
</div>
<div
class=
"cls-part p-b-20"
>
<div
class=
"cls-part p-b-20"
>
...
...
src/frontend/web/js/components/uploader/thumb-upload.vue
View file @
0062bbcf
<
template
xmlns:v-bind=
"http://www.w3.org/1999/xhtml"
>
<
template
xmlns:v-bind=
"http://www.w3.org/1999/xhtml"
>
<div
class=
"upload-video-screen"
v-bind:id=
"uploaderId"
>
<div
class=
"upload-video-screen"
v-bind:id=
"uploaderId"
>
<i
class=
"icon-image"
></i>
{{
text
}}
<!--
<img
src=
"img/avatar.jpg"
>
-->
<span>
<i
class=
"icon-image"
></i>
{{
text
}}
</span>
</div>
</div>
</
template
>
</
template
>
<
style
>
<
style
>
.upload-video-screen
{
cursor
:
pointer
;
white-space
:
nowrap
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
padding
:
0
10px
;}
.upload-video-screen
{
cursor
:
pointer
;
white-space
:
nowrap
;
overflow
:
hidden
;
text-overflow
:
ellipsis
;
padding
:
0
10px
;}
.upload-video-screen.uploaded
span
{
color
:
#FFF
;
text-shadow
:
0
0
8px
#555
;}
</
style
>
</
style
>
<
script
>
<
script
>
import
layer
from
"layer-js"
;
import
layer
from
"layer-js"
;
...
@@ -22,11 +26,18 @@ export default{
...
@@ -22,11 +26,18 @@ export default{
}
}
},
},
props
:
{
props
:
{
uptoken
:
String
uptoken
:
String
,
initImg
:
String
},
},
ready
()
{
ready
()
{
this
.
text
=
defaultText
;
var
container
=
$
(
this
.
$el
);
if
(
this
.
initImg
)
{
container
.
addClass
(
'uploaded'
).
prepend
(
'<img src="'
+
this
.
initImg
+
'">'
);
defaultText
=
"更换缩略图"
;
}
this
.
text
=
defaultText
;
var
self
=
this
;
var
self
=
this
;
var
uploader
=
new
qiniu
.
Uploader
({
var
uploader
=
new
qiniu
.
Uploader
({
...
@@ -45,18 +56,20 @@ export default{
...
@@ -45,18 +56,20 @@ export default{
auto_start
:
true
,
auto_start
:
true
,
init
:
{
init
:
{
'FilesAdded'
:
function
(
up
,
files
)
{
'FilesAdded'
:
function
(
up
,
files
)
{
plupload
.
each
(
files
,
function
(
file
)
{
//
plupload.each(files, function(file) {
// self.videoSize = filesize(file.origSize, {fixed:2, spacer:' '}).human('si');
// self.videoSize = filesize(file.origSize, {fixed:2, spacer:' '}).human('si');
// self.videoName = file.name;
// self.videoName = file.name;
});
//
});
self
.
state
=
'uploading'
;
up
.
start
();
up
.
start
();
self
.
state
=
'uploading'
;
self
.
text
=
"上传中.."
;
self
.
text
=
"上传中.."
;
container
.
addClass
(
'uploading'
);
},
},
//每个文件上传前
//每个文件上传前
'BeforeUpload'
:
function
(
up
,
file
)
{
//
'BeforeUpload': function(up, file) {
},
//
},
'UploadProgress'
:
function
(
up
,
file
)
{
'UploadProgress'
:
function
(
up
,
file
)
{
self
.
text
=
"上传中.."
+
file
.
percent
+
"%"
;
self
.
text
=
"上传中.."
+
file
.
percent
+
"%"
;
},
},
...
@@ -66,9 +79,13 @@ export default{
...
@@ -66,9 +79,13 @@ export default{
setTimeout
(
function
()
{
setTimeout
(
function
()
{
self
.
text
=
file
.
name
;
self
.
text
=
file
.
name
;
},
10
00
);
},
7
00
);
var
response
=
$
.
parseJSON
(
info
.
response
);
var
response
=
$
.
parseJSON
(
info
.
response
);
container
.
addClass
(
"uploaded"
).
find
(
"img"
).
remove
();
container
.
prepend
(
'<img src="'
+
response
.
src
+
'-m.preview">'
);
self
.
$dispatch
(
"thumb-uploaded"
,
file
.
name
,
response
);
self
.
$dispatch
(
"thumb-uploaded"
,
file
.
name
,
response
);
},
},
'Error'
:
function
(
up
,
err
)
{
'Error'
:
function
(
up
,
err
)
{
...
@@ -85,6 +102,7 @@ export default{
...
@@ -85,6 +102,7 @@ export default{
//队列文件处理完毕后
//队列文件处理完毕后
'UploadComplete'
:
function
()
{
'UploadComplete'
:
function
()
{
self
.
state
=
'completed'
;
self
.
state
=
'completed'
;
container
.
removeClass
(
'uploading'
);
}
}
}
}
});
});
...
...
src/frontend/web/js/my-course/rich-text.js
View file @
0062bbcf
...
@@ -7,7 +7,8 @@ module.exports = {
...
@@ -7,7 +7,8 @@ module.exports = {
createEditor
:
function
(
container
,
tmp
)
{
createEditor
:
function
(
container
,
tmp
)
{
return
new
Simditor
({
return
new
Simditor
({
textarea
:
container
,
textarea
:
container
,
toolbarFloat
:
false
,
toolbarFloat
:
true
,
toolbarFloatOffset
:
60
,
defaultImage
:
"/assets/img/placeholder.jpg"
,
defaultImage
:
"/assets/img/placeholder.jpg"
,
upload
:
{
upload
:
{
url
:
'/my-course/upload'
,
//文件上传的接口地址
url
:
'/my-course/upload'
,
//文件上传的接口地址
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment