Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

二级分类 #14

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
/src/template/
/src/js/tmpl/*.js
/src/asset/font/**/*.js

14 changes: 14 additions & 0 deletions src/js/Controller/student/getParamWithURL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
define(function(url) {
var args = url.split('?');
if (args[0] === url) {
return '';
}
var arr = args[1].split('&');
var obj = [];
for (var i = 0; i < arr.length; i++) {
var arg = arr[i].split('=');
obj[arg[0]] = arg[1];
return obj;
}
console.log('xiongwenchengdashabi');
});
74 changes: 0 additions & 74 deletions src/js/Controller/student/login.js

This file was deleted.

93 changes: 90 additions & 3 deletions src/js/Controller/student/s_course.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@ require.config({
jquery: '/lib/jquery.min-1.11.3',
tpl: '../../tmpl/student',
cookies: '../../../lib/js.cookie',
common: '../student/s_common'
common: '../student/s_common',
pagination: '../../../lib/jquery.simplePagination'

},
shim: {
pagination: {
deps: ['jquery']
}
}
});
require(['jquery', 'tpl', 'cookies', 'common'], function($, tpl, Cookies, common) {
require(['jquery', 'tpl', 'cookies', 'common', 'pagination'], function($, tpl, Cookies, common, pagination) {
$(function() {
//头部可以进行封装,复用
var userData = {};
$.ajaxSetup({headers: {
'Authorization': Cookies.get('Authorization')
}});
var id = Cookies.get('userID');
var childID;
$.ajax({
url: 'http://n.hamkd.com/api/user/' + id,
type: 'GET',
Expand All @@ -38,18 +45,98 @@ require(['jquery', 'tpl', 'cookies', 'common'], function($, tpl, Cookies, common
dataType: 'json',
success: function(response) {
console.log('courseCat', response);
courseCat = response;
for (var i = 0; i < response.length; i++) {
response[i].children = [];
for (var j = 0; j < response.length; j++) {
if (response[j].pid === response[i].id) {
response[i].children.push(response[j]);
}
}
if (response[i].children.length > 0) {
courseCat.push(response[i]);
}
};

console.log(courseCat);
$('.s-c-item').html(tpl('CourseCat', {courseCat: courseCat}));

$('.accordion').on('click', '.accordion-control', function(e) {
e.preventDefault();
var $span = $(this).next('span');
$span.next('.accordion-panel').not(':animated').slideToggle();
$span.html() === '+' ? $span.html('-') : $span.html('+');
var catIdString = $(this).text();
$('.course-nav').html(catIdString);
});
$('.accordion-panel').on('click', 'li', function(e) {
var childText = $(this).text();

document.querySelector('.left_span').style.opacity = 1;
$('.child_text').html(childText);
childID = $(this).attr('name');
$.ajax({
url: 'http://n.hamkd.com/api/student/courses?_limit=20&_order=id&catId=' + childID,
type: 'GET',
data: '',
dataType: 'json'
}).done(function(response) {
console.log('catId', response);
catCourseList = response;
$('.content_main').html(tpl('CatCourseList', {catCourseList: catCourseList}));
// $('#pagination').pagination({
// items: 100,
// itemsOnPage: 20,
// cssStyle: 'light-theme'});
});
});
},
error: function() {
console.log('获取失败');
}
});

$.ajax({
url: 'http://n.hamkd.com/api/student/course_category?pid=1',
type: 'GET',
data: '',
dataType: 'json',
success: function(response) {
console.log('test', response);
},
error: function() {
console.log('获取失败');
}
});
// $.ajax({
// url: 'http://n.hamkd.com/api/student/courses?catId=6&_limit=20&_order=id',
// type: 'GET',
// data: '',
// dataType: 'json',
// success: function(response) {
// console.log('test2', response);
// },
// error: function() {
// console.log('获取失败');
// }
// });

// var catCourseList = [];
// $.ajax({
// url: 'http://n.hamkd.com/api/student/courses?catId=6&_limit=20&_order=id',
// type: 'GET',
// data: '',
// dataType: 'json'
// }).done(function(response) {
// console.log('catId', response);
// catCourseList = response;
// $('.content_main').html(tpl('CatCourseList', {catCourseList: catCourseList}));
// });

$('.pagination').pagination({
items: 100,
itemsOnPage: 20,
cssStyle: 'light-theme'
});
$('.pagination').pagination('getPagesCount');
});
});
58 changes: 52 additions & 6 deletions src/js/Controller/student/s_course_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ require.config({
jquery: '/lib/jquery.min-1.11.3',
tpl: '../../tmpl/student',
cookies: '../../../lib/js.cookie',
common: '../student/s_common'
common: '../student/s_common',

}
});
require(['jquery', 'tpl', 'cookies', 'common'], function($, tpl, Cookies, common) {
$(function() {
require(['jquery', 'tpl', 'cookies', 'common'], function ($, tpl, Cookies, common) {
$(function () {
//头部可以进行封装,复用
var userData = {};
$.ajaxSetup({headers: {
'Authorization': Cookies.get('Authorization')
}});
$.ajaxSetup({
headers: {
'Authorization': Cookies.get('Authorization')
}
});
var id = Cookies.get('userID');
$.ajax({
url: 'http://n.hamkd.com/api/user/' + id,
Expand All @@ -26,5 +28,49 @@ require(['jquery', 'tpl', 'cookies', 'common'], function($, tpl, Cookies, common
$('#s_header').html(tpl('Header', userData));
}
});

$.ajax({
url: 'http://n.hamkd.com/api/user/' + id,
type: 'GET',
data: '',
dataType: 'json',
success: function(response) {
userData.name = response.name;
userData.avatar = response.avatar;
$('#s_header').html(tpl('Header', userData));
}
});
//定义从url上获取参数
function getParamWithURL(url) {
var args = url.split('?');
if (args[0] === url) {
return '';
}
var arr = args[1].split('&');
var obj = [];
for (var i = 0; i < arr.length; i++) {
var arg = arr[i].split('=');
obj[arg[0]] = arg[1];
}
return obj;
}

//获取id参数值并get详情信息
var urlID = window.location.href;
console.log(urlID);
var id_ = getParamWithURL(urlID).id;
var courseDetail = [];
$.ajax({
url: 'http://n.hamkd.com/api/student/courses?id=' + id_,
type: 'GET',
data: '',
dataType: 'json',
success: function(response) {
courseDetail = response[0];
console.log(courseDetail);
// $('.courseDetail').html('xiongwencheng');
$('.courseDetail').html(tpl('CourseDetail', {courseDetail: courseDetail}));
}
});
});
});
36 changes: 27 additions & 9 deletions src/js/Controller/student/s_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ require.config({
//进行入口处理
require(['jquery', 'swiper', 'tpl', 'cookies'], function($, Swiper, tpl, Cookies) {
$(function() {
var mySwiper = new Swiper('.swiper-container', {
autoplay: true, //可选选项,自动滑动
parallax: true,
speed: 2000,
loop: true,
pagination: {
el: '.swiper-pagination'
}
});
//用户信息
var userData = {};
$.ajaxSetup({headers: {
'Authorization': Cookies.get('Authorization')
Expand All @@ -40,6 +32,32 @@ require(['jquery', 'swiper', 'tpl', 'cookies'], function($, Swiper, tpl, Cookies
console.log('获取失败');
}
});
//轮播图
var swiperList = [];
$.ajax({
url: 'http://n.hamkd.com/api/student/carousel',
type: 'GET',
data: '',
dataType: 'json',
success: function(response) {
console.log('swiper:', response);
swiperList = response;
// $('#s_banner').html(tpl('Swiper', {swiperList: swiperList}));
var mySwiper = new Swiper('.swiper-container', {
autoplay: true, //可选选项,自动滑动
parallax: true,
speed: 2000,
loop: true,
pagination: {
el: '.swiper-pagination'
}
});
},
error: function() {
console.log('获取失败');
}
});

//推荐课程列表请求 --- 可以封装在js文件中
var courseList = [];
$.ajax({
Expand Down
29 changes: 23 additions & 6 deletions src/js/Controller/student/s_login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,33 @@
require.config({
paths: {
jquery: '/lib/jquery.min-1.11.3',
sha1: '../../../lib/sha1',
ajaxSetup: '../../../js/student/ajaxSetup',
cookie: '../../../lib/js.cookie'

sha1: '/lib/sha1',
cookie: '/lib/js.cookie',
validate: '/lib/jquery.validate.min'
}
});
//进行入口处理
require(['jquery', 'cookie', 'sha1'], function($, Cookies, sha1) {
require(['jquery', 'cookie', 'sha1', 'validate'], function($, Cookies, sha1, validate) {
$(function() {
//未写表单验证
//表单验证未完善
$('#login').validate({
rules: {
userName: {
required: true, // 必填
minlength: 3
},
password: {
required: true,
minlength: 3
}
},
messages: {
username: {
},
password: {
}
}
});
$('#submitBtn').on('click', function(e) {
e.preventDefault();
var dataArr = [];
Expand Down
Loading