From c7cc2210fba81f39c86916945d0e120e40072139 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Thu, 18 Jun 2020 19:52:14 +0800 Subject: [PATCH] =?UTF-8?q?layui=E8=BF=98=E6=98=AF=E6=9C=89=E5=BE=88?= =?UTF-8?q?=E5=A4=9A=E9=97=AE=E9=A2=98=E7=9A=84=EF=BC=8C=E7=BB=95=E5=BC=80?= =?UTF-8?q?=E5=85=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Web/Controllers/LiveController.php | 39 ++-- .../Web/Controllers/MessengerController.php | 18 +- .../Web/Controllers/TeacherController.php | 2 + app/Http/Web/Services/Live.php | 75 +++++++- app/Http/Web/Services/Messenger.php | 65 +++++++ app/Http/Web/Views/chapter/live_stats.volt | 17 ++ app/Http/Web/Views/chapter/show_live.volt | 24 ++- app/Http/Web/Views/course/show.volt | 85 ++++----- app/Http/Web/Views/partials/macro_course.volt | 62 ++++--- app/Http/Web/Views/templates/full.volt | 19 +- app/Services/Frontend/Teacher/TeacherList.php | 2 + public/static/web/css/common.css | 40 ++++- public/static/web/js/captcha.login.js | 27 +-- public/static/web/js/captcha.verify.js | 149 ++++++++-------- public/static/web/js/common.js | 126 ++++++------- public/static/web/js/course.show.js | 30 ++++ public/static/web/js/fixbar.js | 12 ++ public/static/web/js/live.im.js | 20 ++- public/static/web/js/live.player.js | 168 +++++++++--------- 19 files changed, 595 insertions(+), 385 deletions(-) create mode 100644 app/Http/Web/Services/Messenger.php create mode 100644 app/Http/Web/Views/chapter/live_stats.volt create mode 100644 public/static/web/js/course.show.js create mode 100644 public/static/web/js/fixbar.js diff --git a/app/Http/Web/Controllers/LiveController.php b/app/Http/Web/Controllers/LiveController.php index 2c3b8816..b4ab59ed 100644 --- a/app/Http/Web/Controllers/LiveController.php +++ b/app/Http/Web/Controllers/LiveController.php @@ -4,6 +4,7 @@ namespace App\Http\Web\Controllers; use App\Http\Web\Services\Live as LiveService; use App\Traits\Response as ResponseTrait; +use Phalcon\Mvc\View; /** * @RoutePrefix("/live") @@ -18,33 +19,21 @@ class LiveController extends \Phalcon\Mvc\Controller */ public function membersAction($id) { - $list = [ - [ - 'username' => '直飞机', - 'avatar' => 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1', - 'status' => 'online', - 'sign' => '高舍炮打的准', - 'id' => 1, - ], - [ - 'username' => '直飞机2', - 'avatar' => 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1', - 'status' => 'online', - 'sign' => '高舍炮打的准', - 'id' => 2, - ], - [ - 'username' => '直飞机3', - 'avatar' => 'http://tp1.sinaimg.cn/5619439268/180/40030060651/1', - 'status' => 'online', - 'sign' => '高舍炮打的准', - 'id' => 3, - ], - ]; + return $this->jsonSuccess(); + } - $content = ['data' => ['list' => $list]]; + /** + * @Get("/{id:[0-9]+}/stats", name="web.live.stats") + */ + public function statsAction($id) + { + $service = new LiveService(); - return $this->jsonSuccess($content); + $stats = $service->getStats($id); + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('chapter/live_stats'); + $this->view->setVar('stats', $stats); } /** diff --git a/app/Http/Web/Controllers/MessengerController.php b/app/Http/Web/Controllers/MessengerController.php index 940df23a..a5883dcb 100644 --- a/app/Http/Web/Controllers/MessengerController.php +++ b/app/Http/Web/Controllers/MessengerController.php @@ -2,26 +2,18 @@ namespace App\Http\Web\Controllers; -use App\Http\Web\Services\Index as IndexService; - +/** + * @RoutePrefix("/im") + */ class MessengerController extends Controller { /** - * @Get("/", name="web.index") + * @Get("/init", name="web.index") */ - public function indexAction() + public function initAction() { - $this->siteSeo->setKeywords($this->siteSettings['keywords']); - $this->siteSeo->setDescription($this->siteSettings['description']); - $indexService = new IndexService(); - - $this->view->setVar('slides', $indexService->getSlides()); - $this->view->setVar('lives', $indexService->getLives()); - $this->view->setVar('new_courses', $indexService->getNewCourses()); - $this->view->setVar('free_courses', $indexService->getFreeCourses()); - $this->view->setVar('vip_courses', $indexService->getVipCourses()); } } diff --git a/app/Http/Web/Controllers/TeacherController.php b/app/Http/Web/Controllers/TeacherController.php index f15ee64e..18382713 100644 --- a/app/Http/Web/Controllers/TeacherController.php +++ b/app/Http/Web/Controllers/TeacherController.php @@ -15,6 +15,8 @@ class TeacherController extends Controller */ public function listAction() { + $_REQUEST['limit'] = 12; + $service = new TeacherListService(); $pager = $service->handle(); diff --git a/app/Http/Web/Services/Live.php b/app/Http/Web/Services/Live.php index a3373c34..c6b98007 100644 --- a/app/Http/Web/Services/Live.php +++ b/app/Http/Web/Services/Live.php @@ -2,6 +2,7 @@ namespace App\Http\Web\Services; +use App\Repos\User as UserRepo; use App\Services\Frontend\ChapterTrait; use GatewayClient\Gateway; @@ -10,21 +11,44 @@ class Live extends Service use ChapterTrait; - public function bindUser($id) + public function getStats($id) { $chapter = $this->checkChapterCache($id); - $user = $this->getCurrentUser(); + Gateway::$registerAddress = '127.0.0.1:1238'; - $userId = $user->id > 0 ?: $this->session->getId(); + $groupName = $this->getGroupName($chapter->id); + $clientCount = Gateway::getClientIdCountByGroup($groupName); + $userCount = Gateway::getUidCountByGroup($groupName); + $guestCount = $clientCount - $userCount; + + $userIds = Gateway::getUidListByGroup($groupName); + + $users = $this->handleUsers($userIds); + + return [ + 'user_count' => $userCount, + 'guest_count' => $guestCount, + 'users' => $users, + ]; + } + + public function bindUser($id) + { $clientId = $this->request->getPost('client_id'); + $chapter = $this->checkChapterCache($id); + + $user = $this->getCurrentUser(); + $groupName = $this->getGroupName($chapter->id); Gateway::$registerAddress = '127.0.0.1:1238'; - Gateway::bindUid($clientId, $userId); + if ($user->id > 0) { + Gateway::bindUid($clientId, $user->id); + } Gateway::joinGroup($clientId, $groupName); } @@ -33,9 +57,21 @@ class Live extends Service { $chapter = $this->checkChapterCache($id); + $user = $this->getLoginUser(); + $from = $this->request->getPost('from'); $to = $this->request->getPost('to'); + Gateway::$registerAddress = '127.0.0.1:1238'; + + $groupName = $this->getGroupName($chapter->id); + + $excludeClientId = null; + + if ($user->id == $from['id']) { + $excludeClientId = Gateway::getClientIdByUid($user->id); + } + $content = [ 'username' => $from['username'], 'avatar' => $from['avatar'], @@ -52,11 +88,36 @@ class Live extends Service 'content' => $content, ]); - $groupName = $this->getGroupName($chapter->id); - Gateway::$registerAddress = '127.0.0.1:1238'; + Gateway::sendToGroup($groupName, $message, $excludeClientId); + } - Gateway::sendToGroup($groupName, $message); + protected function handleUsers($userIds) + { + if (!$userIds) return []; + + $userRepo = new UserRepo(); + + $users = $userRepo->findByIds($userIds); + + $baseUrl = kg_ci_base_url(); + + $result = []; + + foreach ($users->toArray() as $key => $user) { + + $user['avatar'] = $baseUrl . $user['avatar']; + + $result[] = [ + 'id' => $user['id'], + 'name' => $user['name'], + 'title' => $user['title'], + 'vip' => $user['vip'], + 'avatar' => $user['avatar'], + ]; + } + + return $result; } protected function getGroupName($groupId) diff --git a/app/Http/Web/Services/Messenger.php b/app/Http/Web/Services/Messenger.php new file mode 100644 index 00000000..3417fe33 --- /dev/null +++ b/app/Http/Web/Services/Messenger.php @@ -0,0 +1,65 @@ +getCurrentUser(); + + $userId = $user->id > 0 ?: $this->session->getId(); + + $clientId = $this->request->getPost('client_id'); + + $groupName = $this->getGroupName($id); + + Gateway::$registerAddress = '127.0.0.1:1238'; + + Gateway::bindUid($clientId, $userId); + + Gateway::joinGroup($clientId, $groupName); + } + + public function sendMessage($id) + { + $chapter = $this->checkChapterCache($id); + + $from = $this->request->getPost('from'); + $to = $this->request->getPost('to'); + + $content = [ + 'username' => $from['username'], + 'avatar' => $from['avatar'], + 'content' => $from['content'], + 'fromid' => $from['id'], + 'id' => $to['id'], + 'type' => $to['type'], + 'timestamp' => 1000 * time(), + 'mine' => false, + ]; + + $message = json_encode([ + 'type' => 'show_message', + 'content' => $content, + ]); + + $groupName = $this->getGroupName($chapter->id); + + Gateway::$registerAddress = '127.0.0.1:1238'; + + Gateway::sendToGroup($groupName, $message); + } + + protected function getGroupName($groupId) + { + return "group_{$groupId}"; + } + +} diff --git a/app/Http/Web/Views/chapter/live_stats.volt b/app/Http/Web/Views/chapter/live_stats.volt new file mode 100644 index 00000000..80924165 --- /dev/null +++ b/app/Http/Web/Views/chapter/live_stats.volt @@ -0,0 +1,17 @@ +
+
在线成员
+
+
+ 用户:{{ stats.user_count }} + 游客:{{ stats.guest_count }} +
+
+ {% for user in stats.users %} + {% set vip_flag = user.vip ? 'vip' : '' %} +
+
{{ user.name }} {{ vip_flag }}
+
+ {% endfor %} +
+
+
diff --git a/app/Http/Web/Views/chapter/show_live.volt b/app/Http/Web/Views/chapter/show_live.volt index 575f2150..c9441a5b 100644 --- a/app/Http/Web/Views/chapter/show_live.volt +++ b/app/Http/Web/Views/chapter/show_live.volt @@ -9,8 +9,15 @@ {{ chapter.title }} -
-
+
+
+
+
+
+
+
+ +
@@ -40,4 +47,17 @@ {% block inline_js %} + + {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/course/show.volt b/app/Http/Web/Views/course/show.volt index 5ec0e504..4ca62994 100644 --- a/app/Http/Web/Views/course/show.volt +++ b/app/Http/Web/Views/course/show.volt @@ -32,35 +32,35 @@
  • 详情
  • 目录
  • {% if show_tab_packages == 1 %} -
  • 套餐
  • - {% endif %} - {% if show_tab_consults == 1 %} -
  • 咨询
  • - {% endif %} - {% if show_tab_reviews == 1 %} -
  • 评价
  • - {% endif %} - -
    -
    -
    {{ course.details }}
    +
  • 套餐
  • + {% endif %} + {% if show_tab_consults == 1 %} +
  • 咨询
  • + {% endif %} + {% if show_tab_reviews == 1 %} +
  • 评价
  • + {% endif %} + +
    +
    +
    {{ course.details }}
    +
    +
    + {{ partial('course/chapters') }} +
    + {% if show_tab_packages == 1 %} + {% set packages_url = url({'for':'web.course.packages','id':course.id}) %} +
    + {% endif %} + {% if show_tab_consults == 1 %} + {% set consults_url = url({'for':'web.course.consults','id':course.id}) %} +
    + {% endif %} + {% if show_tab_reviews == 1 %} + {% set reviews_url = url({'for':'web.course.reviews','id':course.id}) %} +
    + {% endif %}
    -
    - {{ partial('course/chapters') }} -
    - {% if show_tab_packages == 1 %} - {% set packages_url = url({'for':'web.course.packages','id':course.id}) %} -
    - {% endif %} - {% if show_tab_consults == 1 %} - {% set consults_url = url({'for':'web.course.consults','id':course.id}) %} -
    - {% endif %} - {% if show_tab_reviews == 1 %} - {% set reviews_url = url({'for':'web.course.reviews','id':course.id}) %} -
    - {% endif %} -
    @@ -91,33 +91,8 @@ {% endblock %} -{% block inline_js %} +{% block include_js %} - + {{ js_include('web/js/course.show.js') }} {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/partials/macro_course.volt b/app/Http/Web/Views/partials/macro_course.volt index a68a62fd..6b567a73 100644 --- a/app/Http/Web/Views/partials/macro_course.volt +++ b/app/Http/Web/Views/partials/macro_course.volt @@ -28,30 +28,32 @@ {{ course.title|e }} -
    - {{ course.title }} -
    -
    - {% if course.market_price > course.vip_price %} - {{ '¥%0.2f'|format(course.market_price) }} - {% if course.vip_price > 0 %} - {{ '会员¥%0.2f'|format(course.vip_price) }} +
    + +
    + {% if course.market_price > course.vip_price %} + {{ '¥%0.2f'|format(course.market_price) }} + {% if course.vip_price > 0 %} + {{ '会员¥%0.2f'|format(course.vip_price) }} + {% else %} + 会员免费 + {% endif %} + {{ level_info(course.level) }} + {{ course.user_count }}人购买 + {% elseif course.market_price > 0 %} + {{ '¥%0.2f'|format(course.market_price) }} + {{ level_info(course.level) }} + {{ course.lesson_count }}节课 + {{ course.user_count }}人购买 {% else %} - 会员免费 + 免费 + {{ level_info(course.level) }} + {{ course.lesson_count }}节课 + {{ course.user_count }}人报名 {% endif %} - {{ level_info(course.level) }} - {{ course.user_count }}人购买 - {% elseif course.market_price > 0 %} - {{ '¥%0.2f'|format(course.market_price) }} - {{ level_info(course.level) }} - {{ course.lesson_count }}节课 - {{ course.user_count }}人购买 - {% else %} - 免费 - {{ level_info(course.level) }} - {{ course.lesson_count }}节课 - {{ course.user_count }}人报名 - {% endif %} +
    {%- endmacro %} @@ -90,14 +92,16 @@ {{ course_title }} -
    - {{ course_title }} -
    -
    -
    -
    +
    + +
    +
    +
    +
    +
    +
    已学习 {{ item.duration|total_duration }}
    -
    已学习 {{ item.duration|total_duration }}
    {%- endmacro %} \ No newline at end of file diff --git a/app/Http/Web/Views/templates/full.volt b/app/Http/Web/Views/templates/full.volt index 0a5df51a..35b3eaf5 100644 --- a/app/Http/Web/Views/templates/full.volt +++ b/app/Http/Web/Views/templates/full.volt @@ -14,28 +14,23 @@ {% block inline_css %}{% endblock %} + +
    {% block content %}{% endblock %}
    + -{{ js_include('lib/layui/layui.all.js') }} + +{{ js_include('lib/layui/layui.js') }} {{ js_include('web/js/common.js') }} - +{{ js_include('web/js/fixbar.js') }} + {% block include_js %}{% endblock %} {% block inline_js %}{% endblock %} diff --git a/app/Services/Frontend/Teacher/TeacherList.php b/app/Services/Frontend/Teacher/TeacherList.php index 2df7bcdb..9213a0bc 100644 --- a/app/Services/Frontend/Teacher/TeacherList.php +++ b/app/Services/Frontend/Teacher/TeacherList.php @@ -3,6 +3,7 @@ namespace App\Services\Frontend\Teacher; use App\Library\Paginator\Query as PagerQuery; +use App\Models\User; use App\Repos\User as UserRepo; use App\Services\Frontend\Service as FrontendService; @@ -15,6 +16,7 @@ class TeacherList extends FrontendService $params = $pagerQuery->getParams(); + $params['edu_role'] = User::EDU_ROLE_TEACHER; $params['deleted'] = 0; $sort = $pagerQuery->getSort(); diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css index 57eedb98..f2a54b36 100644 --- a/public/static/web/css/common.css +++ b/public/static/web/css/common.css @@ -174,7 +174,11 @@ } .index-course-list .course-card { - box-shadow: 0 1px 2px 1px rgba(0, 0, 0, 0.05); + box-shadow: none; +} + +.index-course-list .course-card .info { + border: 1px solid #eee; } .index-carousel { @@ -285,7 +289,6 @@ } .course-card .cover { - margin-bottom: 10px; overflow: hidden; } @@ -299,15 +302,17 @@ transform: scale(1.2); } +.course-card .info { + padding: 10px 5px; +} + .course-card .title { - padding: 0 5px; margin-bottom: 10px; } .course-card .meta { color: #666; font-size: 12px; - padding: 0 5px; } .course-card .meta span { @@ -728,8 +733,31 @@ } .live-player { - width: 800px; - height: 450px; + width: 760px; + height: 428px; +} + +.live-stats { + color: #666; +} + +.live-stats .stats { + margin-bottom: 15px; +} + +.live-stats .count { + margin-right: 10px; +} + +.live-user-card { + line-height: 30px; +} + +.chat-login-tips { + padding-top: 20px; + text-align: center; + font-size: 12px; + color: #999; } .chapter-bg { diff --git a/public/static/web/js/captcha.login.js b/public/static/web/js/captcha.login.js index d8b85745..945d2d19 100644 --- a/public/static/web/js/captcha.login.js +++ b/public/static/web/js/captcha.login.js @@ -1,14 +1,15 @@ -var $ = layui.jquery; -var layer = layui.layer; -var captcha = new TencentCaptcha( - $('#captcha-btn')[0], - $('#captcha-btn').attr('data-app-id'), - function (res) { - if (res.ret === 0) { - $('#ticket').val(res.ticket); - $('#rand').val(res.randstr); - $('#captcha-block').hide(); - $('#submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); +layui.use(['jquery'], function () { + var $ = layui.jquery; + var captcha = new TencentCaptcha( + $('#captcha-btn')[0], + $('#captcha-btn').attr('data-app-id'), + function (res) { + if (res.ret === 0) { + $('#ticket').val(res.ticket); + $('#rand').val(res.randstr); + $('#captcha-block').hide(); + $('#submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); + } } - } -); \ No newline at end of file + ); +}); \ No newline at end of file diff --git a/public/static/web/js/captcha.verify.js b/public/static/web/js/captcha.verify.js index 6b30bb06..d65737b3 100644 --- a/public/static/web/js/captcha.verify.js +++ b/public/static/web/js/captcha.verify.js @@ -1,87 +1,84 @@ -var $ = layui.jquery; -var layer = layui.layer; +layui.use(['jquery', 'util'], function () { -var timeCounting = false; -var $account = $('#cv-account'); -var $emit = $('#cv-verify-emit'); + var $ = layui.jquery; + var util = layui.util; -var captcha = new TencentCaptcha( - $emit[0], - $('#cv-app-id').val(), - function (res) { - if (res.ret === 0) { - $('#cv-ticket').val(res.ticket); - $('#cv-rand').val(res.randstr); - if (isEmail($account.val()) || isPhone($account.val())) { - var postUrl = null; - var postData = { - ticket: $('#cv-ticket').val(), - rand: $('#cv-rand').val(), - }; - if (isPhone($account.val())) { - postData.phone = $account.val(); - postUrl = '/verify/sms/code'; - } else if (isEmail($account.val())) { - postData.email = $account.val(); - postUrl = '/verify/email/code'; - } - $.ajax({ - type: 'POST', - url: postUrl, - data: postData, - success: function (res) { + var timeCounting = false; + var $account = $('#cv-account'); + var $emit = $('#cv-verify-emit'); - }, - error: function (xhr) { - var json = JSON.parse(xhr.responseText); - layer.msg(json.msg, {icon: 2}); + var captcha = new TencentCaptcha( + $emit[0], + $('#cv-app-id').val(), + function (res) { + if (res.ret === 0) { + $('#cv-ticket').val(res.ticket); + $('#cv-rand').val(res.randstr); + if (isEmail($account.val()) || isPhone($account.val())) { + var postUrl; + var postData = { + ticket: $('#cv-ticket').val(), + rand: $('#cv-rand').val(), + }; + if (isPhone($account.val())) { + postData.phone = $account.val(); + postUrl = '/verify/sms/code'; + } else if (isEmail($account.val())) { + postData.email = $account.val(); + postUrl = '/verify/email/code'; } - }); - $('#cv-submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); - $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled'); - showCountDown($emit); + $.ajax({ + type: 'POST', + url: postUrl, + data: postData + }); + $('#cv-submit-btn').removeClass('layui-btn-disabled').removeAttr('disabled'); + $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled'); + showCountDown($emit); + } } } - } -); + ); -$account.on('keyup', function () { - var accountOk; - var type = $(this).attr('data-type'); - var account = $(this).val(); - if (type === 'phone') { - accountOk = isPhone(account); - } else if (type === 'email') { - accountOk = isEmail(account); - } else { - accountOk = isPhone(account) || isEmail(account); - } - if (accountOk && !timeCounting) { - $emit.removeClass('layui-btn-disabled').removeAttr('disabled'); - } else { - $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled'); - } -}); - -function showCountDown(obj) { - var serverTime = new Date().getTime(); - var endTime = serverTime + 60 * 1000; - layui.util.countdown(endTime, serverTime, function (date, serverTime, timer) { - var left = date[0] * 86400 + date[1] * 3600 + date[2] * 60 + date[3]; - obj.text(left + '秒'); - if (left === 0) { - obj.removeClass('layui-btn-disabled').removeAttr('disabled').text('重新发送'); - clearInterval(timer); - timeCounting = false; + $account.on('keyup', function () { + var accountOk; + var type = $(this).attr('data-type'); + var account = $(this).val(); + if (type === 'phone') { + accountOk = isPhone(account); + } else if (type === 'email') { + accountOk = isEmail(account); + } else { + accountOk = isPhone(account) || isEmail(account); + } + if (accountOk && !timeCounting) { + $emit.removeClass('layui-btn-disabled').removeAttr('disabled'); + } else { + $emit.addClass('layui-btn-disabled').attr('disabled', 'disabled'); } }); - timeCounting = true; -} -function isEmail(email) { - return /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email); -} + function showCountDown(obj) { + var serverTime = new Date().getTime(); + var endTime = serverTime + 60 * 1000; + util.countdown(endTime, serverTime, function (date, serverTime, timer) { + var left = date[0] * 86400 + date[1] * 3600 + date[2] * 60 + date[3]; + obj.text(left + '秒'); + if (left === 0) { + obj.removeClass('layui-btn-disabled').removeAttr('disabled').text('重新发送'); + clearInterval(timer); + timeCounting = false; + } + }); + timeCounting = true; + } -function isPhone(phone) { - return /^1(3|4|5|6|7|8|9)\d{9}$/.test(phone); -} \ No newline at end of file + function isEmail(email) { + return /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(email); + } + + function isPhone(phone) { + return /^1(3|4|5|6|7|8|9)\d{9}$/.test(phone); + } + +}); \ No newline at end of file diff --git a/public/static/web/js/common.js b/public/static/web/js/common.js index 6eb9f697..987c57fd 100644 --- a/public/static/web/js/common.js +++ b/public/static/web/js/common.js @@ -1,86 +1,92 @@ -var $ = layui.jquery; -var element = layui.element; -var form = layui.form; -var layer = layui.layer; - -$.ajaxSetup({ - beforeSend: function (xhr) { - xhr.setRequestHeader('X-Csrf-Token', $('meta[name="csrf-token"]').attr('content')); - } +layui.define(['jquery', 'element'], function (exports) { + exports('ajaxLoadHtml', function (url, target) { + var $ = layui.jquery; + var element = layui.element; + var $target = $('#' + target); + var html = '
    '; + $target.html(html); + $.get(url, function (html) { + $target.html(html); + element.init(); + }); + }); }); -var helper = {}; +layui.use(['jquery', 'form', 'element', 'layer'], function () { -helper.ajaxLoadHtml = function (url, target) { - var $target = $('#' + target); - var html = '
    '; - $target.html(html); - $.get(url, function (html) { - $target.html(html); - element.init(); - }); -} + var $ = layui.jquery; + var element = layui.element; + var form = layui.form; + var layer = layui.layer; -form.on('submit(go)', function (data) { - var submit = $(this); - submit.attr('disabled', 'disabled').addClass('layui-btn-disabled'); - $.ajax({ - type: 'POST', - url: data.form.action, - data: data.field, - success: function (res) { - var icon = res.code === 0 ? 1 : 2; - if (res.msg) { - layer.msg(res.msg, {icon: icon}); - } - if (res.location) { - setTimeout(function () { - window.location.href = res.location; - }, 1500); - } else { - submit.removeAttr('disabled').removeClass('layui-btn-disabled'); - } - }, - error: function (xhr) { - var json = JSON.parse(xhr.responseText); - layer.msg(json.msg, {icon: 2}); - submit.removeAttr('disabled').removeClass('layui-btn-disabled'); + $.ajaxSetup({ + beforeSend: function (xhr) { + xhr.setRequestHeader('X-Csrf-Token', $('meta[name="csrf-token"]').attr('content')); } }); - return false; -}); -$('.kg-delete').on('click', function () { - var url = $(this).attr('data-url'); - var tips = '确定要删除吗?'; - layer.confirm(tips, function () { + form.on('submit(go)', function (data) { + var submit = $(this); + submit.attr('disabled', 'disabled').addClass('layui-btn-disabled'); $.ajax({ type: 'POST', - url: url, + url: data.form.action, + data: data.field, success: function (res) { - layer.msg(res.msg, {icon: 1}); + var icon = res.code === 0 ? 1 : 2; + if (res.msg) { + layer.msg(res.msg, {icon: icon}); + } if (res.location) { setTimeout(function () { window.location.href = res.location; }, 1500); } else { - window.location.reload(); + submit.removeAttr('disabled').removeClass('layui-btn-disabled'); } }, error: function (xhr) { var json = JSON.parse(xhr.responseText); layer.msg(json.msg, {icon: 2}); + submit.removeAttr('disabled').removeClass('layui-btn-disabled'); } }); + return false; }); -}); -$('.kg-back').on('click', function () { - window.history.back(); -}); + $('.kg-delete').on('click', function () { + var url = $(this).attr('data-url'); + var tips = '确定要删除吗?'; + layer.confirm(tips, function () { + $.ajax({ + type: 'POST', + url: url, + success: function (res) { + layer.msg(res.msg, {icon: 1}); + if (res.location) { + setTimeout(function () { + window.location.href = res.location; + }, 1500); + } else { + window.location.reload(); + } + }, + error: function (xhr) { + var json = JSON.parse(xhr.responseText); + layer.msg(json.msg, {icon: 2}); + } + }); + }); + }); + + $('.kg-back').on('click', function () { + window.history.back(); + }); + + $('body').on('click', '.layui-laypage > a', function () { + var url = $(this).attr('data-url'); + var target = $(this).attr('data-target'); + layui.ajaxLoadHtml(url, target); + }); -$('body').on('click', '.layui-laypage > a', function () { - var url = $(this).attr('data-url'); - var target = $(this).attr('data-target'); - helper.ajaxLoadHtml(url, target); }); \ No newline at end of file diff --git a/public/static/web/js/course.show.js b/public/static/web/js/course.show.js new file mode 100644 index 00000000..3441694e --- /dev/null +++ b/public/static/web/js/course.show.js @@ -0,0 +1,30 @@ +layui.use(['jquery', 'element'], function () { + + var $ = layui.jquery; + + if ($('#tab-packages').length > 0) { + var $tabPackages = $('#tab-packages'); + layui.ajaxLoadHtml($tabPackages.attr('data-url'), $tabPackages.attr('id')); + } + if ($('#tab-consults').length > 0) { + var $tabConsults = $('#tab-consults'); + layui.ajaxLoadHtml($tabConsults.attr('data-url'), $tabConsults.attr('id')); + } + if ($('#tab-reviews').length > 0) { + var $tabReviews = $('#tab-reviews'); + layui.ajaxLoadHtml($tabReviews.attr('data-url'), $tabReviews.attr('id')); + } + if ($('#sidebar-topics').length > 0) { + var $sdTopics = $('#sidebar-topics'); + layui.ajaxLoadHtml($sdTopics.attr('data-url'), $sdTopics.attr('id')); + } + if ($('#sidebar-recommended').length > 0) { + var $sdRecommended = $('#sidebar-recommended'); + layui.ajaxLoadHtml($sdRecommended.attr('data-url'), $sdRecommended.attr('id')); + } + if ($('#sidebar-related').length > 0) { + var $sdRelated = $('#sidebar-related'); + layui.ajaxLoadHtml($sdRelated.attr('data-url'), $sdRelated.attr('id')); + } + +}); \ No newline at end of file diff --git a/public/static/web/js/fixbar.js b/public/static/web/js/fixbar.js new file mode 100644 index 00000000..f734a076 --- /dev/null +++ b/public/static/web/js/fixbar.js @@ -0,0 +1,12 @@ +layui.use(['util'], function () { + var util = layui.util; + util.fixbar({ + bar1: true, + click: function (type) { + console.log(type); + if (type === 'bar1') { + alert('点击了bar1'); + } + } + }); +}); \ No newline at end of file diff --git a/public/static/web/js/live.im.js b/public/static/web/js/live.im.js index 255778f1..19d5e589 100644 --- a/public/static/web/js/live.im.js +++ b/public/static/web/js/live.im.js @@ -2,7 +2,6 @@ layui.use(['jquery', 'layim'], function () { var $ = layui.jquery; var layim = layui.layim; - var socket = new WebSocket('ws://127.0.0.1:8282'); var membersUrl = $('input[name="im.members_url"]').val(); @@ -34,9 +33,7 @@ layui.use(['jquery', 'layim'], function () { 'sign': user.sign } }, - members: { - url: membersUrl - } + members: {url: membersUrl} }).chat({ type: 'group', name: group.name, @@ -44,6 +41,8 @@ layui.use(['jquery', 'layim'], function () { id: group.id }); + layim.setChatMin(); + layim.on('sendMessage', function (res) { sendMessage(res.mine, res.to); }); @@ -72,6 +71,8 @@ layui.use(['jquery', 'layim'], function () { } }; + showOrHidePoster(); + function bindUser(clientId) { $.ajax({ type: 'POST', @@ -90,7 +91,16 @@ layui.use(['jquery', 'layim'], function () { } function showMessage(message) { - layim.getMessage(message); + if (message.fromid !== user.id) { + layim.getMessage(message); + } + } + + function showOrHidePoster() { + if (user.id === '0') { + var html = ''; + $('.layim-chat-footer').hide().after(html); + } } }); \ No newline at end of file diff --git a/public/static/web/js/live.player.js b/public/static/web/js/live.player.js index 7fe8f0d0..1d761435 100644 --- a/public/static/web/js/live.player.js +++ b/public/static/web/js/live.player.js @@ -1,104 +1,108 @@ -var interval = null; -var intervalTime = 5000; -var position = 0; -var chapterId = $('input[name="chapter.id"]').val(); -var planId = $('input[name="chapter.plan_id"]').val(); -var userId = $('input[name="user.id"]').val(); -var learningUrl = $('input[name="chapter.learning_url"]').val(); -var playUrls = JSON.parse($('input[name="chapter.play_urls"]').val()); -var requestId = getRequestId(); +layui.use(['jquery'], function () { -var options = { - live: true, - autoplay: true, - h5_flv: true, - width: 800, - height: 450 -}; + var interval = null; + var intervalTime = 5000; + var position = 0; + var chapterId = $('input[name="chapter.id"]').val(); + var planId = $('input[name="chapter.plan_id"]').val(); + var userId = $('input[name="user.id"]').val(); + var learningUrl = $('input[name="chapter.learning_url"]').val(); + var playUrls = JSON.parse($('input[name="chapter.play_urls"]').val()); + var requestId = getRequestId(); -if (playUrls.rtmp && playUrls.rtmp.od) { - options.rtmp = playUrls.rtmp.od; -} + var options = { + live: true, + autoplay: true, + h5_flv: true, + width: 760, + height: 428 + }; -if (playUrls.rtmp && playUrls.rtmp.hd) { - options.rtmp_hd = playUrls.rtmp.hd; -} + if (playUrls.rtmp && playUrls.rtmp.od) { + options.rtmp = playUrls.rtmp.od; + } -if (playUrls.rtmp && playUrls.rtmp.sd) { - options.rtmp_sd = playUrls.rtmp.sd; -} + if (playUrls.rtmp && playUrls.rtmp.hd) { + options.rtmp_hd = playUrls.rtmp.hd; + } -if (playUrls.flv && playUrls.flv.od) { - options.flv = playUrls.flv.od; -} + if (playUrls.rtmp && playUrls.rtmp.sd) { + options.rtmp_sd = playUrls.rtmp.sd; + } -if (playUrls.flv && playUrls.flv.hd) { - options.flv_hd = playUrls.flv.hd; -} + if (playUrls.flv && playUrls.flv.od) { + options.flv = playUrls.flv.od; + } -if (playUrls.flv && playUrls.flv.sd) { - options.flv_sd = playUrls.flv.sd; -} + if (playUrls.flv && playUrls.flv.hd) { + options.flv_hd = playUrls.flv.hd; + } -if (playUrls.m3u8 && playUrls.m3u8.od) { - options.m3u8 = playUrls.m3u8.od; -} + if (playUrls.flv && playUrls.flv.sd) { + options.flv_sd = playUrls.flv.sd; + } -if (playUrls.m3u8 && playUrls.m3u8.hd) { - options.m3u8_hd = playUrls.m3u8.hd; -} + if (playUrls.m3u8 && playUrls.m3u8.od) { + options.m3u8 = playUrls.m3u8.od; + } -if (playUrls.m3u8 && playUrls.m3u8.sd) { - options.m3u8_sd = playUrls.m3u8.sd; -} + if (playUrls.m3u8 && playUrls.m3u8.hd) { + options.m3u8_hd = playUrls.m3u8.hd; + } -if (userId !== '0' && planId !== '0') { - options.listener = function (msg) { - if (msg.type === 'play') { - start(); - } else if (msg.type === 'pause') { - stop(); - } else if (msg.type === 'end') { - stop(); + if (playUrls.m3u8 && playUrls.m3u8.sd) { + options.m3u8_sd = playUrls.m3u8.sd; + } + + if (userId !== '0' && planId !== '0') { + options.listener = function (msg) { + if (msg.type === 'play') { + start(); + } else if (msg.type === 'pause') { + stop(); + } else if (msg.type === 'end') { + stop(); + } } } -} -var player = new TcPlayer('player', options); + var player = new TcPlayer('player', options); -if (position > 0) { - player.currentTime(position); -} + if (position > 0) { + player.currentTime(position); + } -function start() { - if (interval != null) { + function start() { + if (interval != null) { + clearInterval(interval); + interval = null; + } + interval = setInterval(learning, intervalTime); + } + + function stop() { clearInterval(interval); interval = null; } - interval = setInterval(learning, intervalTime); -} -function stop() { - clearInterval(interval); - interval = null; -} + function learning() { + $.ajax({ + type: 'POST', + url: learningUrl, + data: { + request_id: requestId, + chapter_id: chapterId, + plan_id: planId, + interval: intervalTime, + position: player.currentTime(), + } + }); + } -function learning() { - $.ajax({ - type: 'POST', - url: learningUrl, - data: { - request_id: requestId, - chapter_id: chapterId, - plan_id: planId, - interval: intervalTime, - position: player.currentTime(), - } - }); -} + function getRequestId() { + var id = Date.now().toString(36); + id += Math.random().toString(36).substr(3); + return id; + } -function getRequestId() { - var id = Date.now().toString(36); - id += Math.random().toString(36).substr(3); - return id; -} \ No newline at end of file +}); \ No newline at end of file