Browse Source

文章收藏及点赞

jack 8 years ago
parent
commit
36aa45638a
2 changed files with 194 additions and 6 deletions
  1. 8 2
      articalInfo.html
  2. 186 4
      js/articalInfo.js

+ 8 - 2
articalInfo.html

@ -50,7 +50,7 @@
50 50
				<!--分享操作栏-->
51 51
				<div class="share-nav">
52 52
					<div class="clearfix">		
53
						<a class="proinfor floatL" style="display:block;width:64%;" id="lineId">
53
						<a class="proinfor ellipsisSty floatL" style="display:block;width:55%;" id="lineId">
54 54
							<div class="headblock floatL" style="width:40px"><img id="proHead" class="headimg headRadius" src="../images/default-photo.jpg" width="100%"></div>
55 55
							<div class="listtit2 floatL"><span style="color: #ff9900;" id="proName"></span><span style="margin-left:10px;" id="proTitle"></span><span id="proOffice"></span><span id="proOrg"></span><span id="proAddress"></span></div>
56 56
						</a>
@ -68,7 +68,13 @@
68 68
							</span>
69 69
						</div>
70 70
						<div class="navOperate floatR">
71
							<span class="wrapicon wordHave"></span><span class="message" style="position:relative;top:-7px;left:2px;">24</span>
71
							<span id="attention" style="background: url(../images/favoricon.png) 0 -50px no-repeat;background-size: 100% auto;margin-top: -4px; display: inline-block;width: 26px;height: 26px;cursor:pointer"></span>
72
						</div>
73
						<div class="navOperate floatR">
74
							<span class="wrapicon wordHave"></span><span class="message" style="position:relative;top:-7px;left:2px;"></span>
75
						</div>
76
						<div class="navOperate floatR">
77
							<span class="plus" style="display:inline-block;float: none;"></span><span class="message1" style="position:relative;top:-7px;left:2px;"></span>
72 78
						</div>
73 79
					</div>
74 80
				</div>

+ 186 - 4
js/articalInfo.js

@ -40,10 +40,12 @@ $(document).ready(function() {
40 40
			success: function(data) {
41 41
				var $info = data.data || {};
42 42
				if(data.success && data.data) {
43
					console.log(data);
43 44
					//var oTime = $info.createTime.substring(0, 4) + "." + $info.createTime.substring(4, 6) + "." + $info.createTime.substring(6, 8) 
44 45
					var oTime=timeGeshi($info.createTime);
45 46
					$("#creTime").text(oTime);
46 47
					$("#articleName").text($info.articleTitle);
48
					$(".message1").text($info.articleAgree);
47 49
					if($info.subject) {
48 50
						industryShow($info.subject, "subjectList");
49 51
					} else {
@ -330,7 +332,7 @@ $(document).ready(function() {
330 332
				}
331 333
			},
332 334
			error: function(XMLHttpRequest) {
333
				console.log(XMLHttpRequest)
335
				$.MsgBox.Alert('提示', '服务器请求失败')
334 336
			}
335 337
		});
336 338
		}
@ -378,7 +380,7 @@ $(document).ready(function() {
378 380
				}
379 381
			},
380 382
			error: function() {
381
				return;
383
				$.MsgBox.Alert('提示', '服务器请求失败')
382 384
			}
383 385
		});
384 386
	}
@ -415,7 +417,7 @@ $(document).ready(function() {
415 417
				}
416 418
			},
417 419
			error: function(XMLHttpRequest) {
418
				console.log(XMLHttpRequest)
420
				$.MsgBox.Alert('提示', '服务器请求失败');
419 421
			}
420 422
		});
421 423
	}
@ -444,7 +446,7 @@ $(document).ready(function() {
444 446
				}
445 447
			},
446 448
			error: function(XMLHttpRequest) {
447
				console.log(XMLHttpRequest)
449
				$.MsgBox.Alert('提示', '服务器请求失败')
448 450
			}
449 451
		});
450 452
	})
@ -457,4 +459,184 @@ $(document).ready(function() {
457 459
		}
458 460
		
459 461
	})
462
	/*点赞模块*/
463
var oIsGree = {
464
	/*查询登陆者是否为文章点赞*/
465
	inquiry: function() {
466
		$.ajax({
467
			url: "/ajax/article/isAgree",
468
			dataType: 'json', //数据格式类型
469
			type: 'GET', //http请求类型
470
			timeout: 10000, //超时设置
471
			data: {
472
				operateId:userid,
473
				articleId:articleId
474
			},
475
			success: function(data) {
476
				if(data.success) {
477
					if(data.data==null){
478
						$(".plus").attr("data-flag","0");
479
					}else{
480
						$(".plus").attr("data-flag","1");
481
						$(".plus").css("background-position-y","-26px");
482
					}
483
				}
484
			},
485
			error: function(XMLHttpRequest) {
486
				$.MsgBox.Alert('提示', '服务器请求失败');
487
			}
488
		});
489
	},
490
	/*点赞及取消点赞*/
491
	favour:function() {
492
		$(".plus").click(function(){
493
			if(userid == "null"||userid==undefined){
494
				location.href="login.html";
495
				return;
496
			}
497
			var isgree=$(this).attr("data-flag");
498
			if(isgree==0){
499
				oIsGree.articleIsAgree();
500
			}else{
501
				oIsGree.articleNoIsAgree();
502
			}
503
		});
504
	},
505
	/*为文章点赞*/
506
	articleIsAgree:function(){
507
		$.ajax({
508
			url: "/ajax/article/agree",
509
			dataType: 'json', //数据格式类型
510
			type: 'POST', //http请求类型
511
			timeout: 10000, //超时设置
512
			data: {
513
				operateId:userid,
514
				articleId:articleId
515
			},
516
			success: function(data) {
517
				if(data.success) {					
518
						$(".plus").attr("data-flag","1");
519
						$(".plus").css("background-position-y","-26px");
520
						$(".message1").text(parseInt($(".message1").html())+1);
521
				}
522
			},
523
			error: function(XMLHttpRequest) {
524
				$.MsgBox.Alert('提示', '服务器请求失败');
525
			}
526
		});
527
	},
528
	/*为文章取消点赞*/
529
	articleNoIsAgree:function(){
530
		$.ajax({
531
			url: "/ajax/article/unAgree",
532
			dataType: 'json', //数据格式类型
533
			type: 'POST', //http请求类型
534
			timeout: 10000, //超时设置
535
			data: {
536
				operateId:userid,
537
				articleId:articleId
538
			},
539
			success: function(data) {
540
				if(data.success) {				
541
						$(".plus").attr("data-flag","0");
542
						$(".plus").css("background-position-y","0px");
543
						$(".message1").text(parseInt($(".message1").html())-1);
544
				}
545
			},
546
			error: function(XMLHttpRequest) {
547
				$.MsgBox.Alert('提示', '服务器请求失败');
548
			}
549
		});
550
	}
551
}
552
oIsGree.inquiry();
553
oIsGree.favour();
554
/*收藏模块*/
555
var collection={
556
	/*查询是否收藏文章*/
557
	inquiry:function(){
558
		$.ajax({
559
			url: "/ajax/watch/hasWatch",
560
			dataType: 'json', //数据格式类型
561
			type: 'GET', //http请求类型
562
			timeout: 10000, //超时设置
563
			data: {
564
				professorId:userid,
565
				watchObject:articleId
566
			},
567
			success: function(data) {
568
				if(data.success) {				
569
					if(data.data==null){
570
						$("#attention").attr("data-flag","0");
571
					}else{
572
						$("#attention").attr("data-flag","1").css({"background":"url(../images/favoricon.png) 0 -26px no-repeat","background-size": "100% auto"});
573
					}
574
				}
575
			},
576
			error: function(XMLHttpRequest) {
577
				$.MsgBox.Alert('提示', '服务器请求失败');
578
			}
579
		});
580
	},
581
	/*收藏及取消收藏*/
582
	attention:function() {
583
		$("#attention").click(function(){
584
			if(userid == "null"||userid==undefined){
585
				location.href="login.html";
586
				return;
587
			}
588
			var attFlag=$(this).attr("data-flag");
589
			if(attFlag==0){
590
				collection.attentionYes();
591
			}else{
592
				collection.attentionNo();
593
			}
594
		});
595
	},
596
	/*收藏文章*/
597
	attentionYes:function(){
598
		$.ajax({
599
			url: "/ajax/watch",
600
			dataType: 'json', //数据格式类型
601
			type: 'POST', //http请求类型
602
			timeout: 10000, //超时设置
603
			data: {
604
				professorId:userid,
605
				watchObject:articleId,
606
				watchType:3
607
			},
608
			success: function(data) {
609
				if(data.success) {				
610
						$("#attention").attr("data-flag","1").css({"background":"url(../images/favoricon.png) 0 -26px no-repeat","background-size": "100% auto"});
611
				}
612
			},
613
			error: function(XMLHttpRequest) {
614
				$.MsgBox.Alert('提示', '服务器请求失败');
615
			}
616
		});
617
	},
618
	/*取消收藏文章*/
619
	attentionNo:function(){
620
		$.ajax({
621
			url: "/ajax/watch/delete",
622
			dataType: 'json', //数据格式类型
623
			type: 'POST', //http请求类型
624
			timeout: 10000, //超时设置
625
			data: {
626
				professorId:userid,
627
				watchObject:articleId
628
			},
629
			success: function(data) {
630
				if(data.success) {				
631
						$("#attention").attr("data-flag","0").css({"background":"url(../images/favoricon.png) 0 -50px no-repeat","background-size": "100% auto"});
632
				}
633
			},
634
			error: function(XMLHttpRequest) {
635
				$.MsgBox.Alert('提示', '服务器请求失败');
636
			}
637
		});
638
	}
639
};
640
collection.inquiry();
641
collection.attention();
460 642
})