portal html css js resource

my-attention.js 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. $(function(){
  2. /*设置全局变量*/
  3. var professorId = GetQueryString("professorId");
  4. var resourceId = GetQueryString("resourceId");
  5. var userid=$.cookie("userid");
  6. var returnId;
  7. var ifurl = window.location.href;
  8. ifCollection();
  9. $('.attentBtn').click(function(){
  10. if (userid && userid != "null" && userid != null) {
  11. if($(this).is('.attented')){
  12. cancelCollectionExpert();
  13. }else{
  14. collectionExpert();
  15. }
  16. }else{
  17. $.MsgBox.Alert('提示',"请先登录再进行关注");
  18. $("#mb_btn_ok").val("去登录");
  19. var aele = document.createElement('a');
  20. $("#mb_btnbox").append(aele);
  21. $("#mb_btnbox a").css({
  22. 'display': "block",
  23. 'width': '100%',
  24. 'height': '40px',
  25. 'position': 'absolute',
  26. 'bottom': '-6px',
  27. 'left': '0'
  28. });
  29. aele.setAttribute('href', '../login.html');
  30. }
  31. })
  32. /*判断是非关注专家*/
  33. function ifCollection() {
  34. if(ifurl.indexOf("professorId") >= 0){
  35. var data = {"professorId": userid,"watchObject": professorId}
  36. }else{
  37. var data = {"professorId": userid,"watchObject": resourceId}
  38. }
  39. //alert(JSON.stringify(data))
  40. $.ajax({
  41. url:"/ajax/watch/hasWatch",
  42. data:data,
  43. dataType: 'json', //数据格式类型
  44. type: 'get', //http请求类型
  45. timeout: 10000,
  46. async: false,
  47. success: function(data) {
  48. if(data.success && data.data != null) {
  49. $(".attentBtn").addClass('attented');
  50. $('.attentBtn i').text('已关注');
  51. returnId = data.data.watchObject;
  52. } else {
  53. $(".attentBtn").removeClass('attented');
  54. $('.attentBtn i').text('关注');
  55. }
  56. },
  57. error: function() {
  58. $.MsgBox.Alert('提示',"服务器链接超时");
  59. }
  60. });
  61. }
  62. /*关注专家*/
  63. function collectionExpert() {
  64. if(ifurl.indexOf("professorId") >= 0){
  65. var data = {"professorId": userid,"watchObject": professorId,"watchType": 1}
  66. }else{
  67. var data = {"professorId": userid,"watchObject": resourceId,"watchType": 2}
  68. }
  69. data.uname=$.cookie("userName");
  70. $.ajax({
  71. url:"/ajax/watch",
  72. data:data,
  73. dataType: 'json', //数据格式类型
  74. type: 'POST', //http请求类型
  75. timeout: 10000,
  76. async: false,
  77. success: function(data) {
  78. //console.log(data.success)
  79. if(data.success) {
  80. returnId = data.data;
  81. $(".attentBtn").addClass('attented');
  82. $('.attentBtn i').text('已关注');
  83. //$.MsgBox.Alert('提示',"专家关注成功");
  84. }
  85. },
  86. error: function() {
  87. $.MsgBox.Alert('提示',"服务器链接超时");
  88. }
  89. });
  90. }
  91. /*取消收藏专家*/
  92. function cancelCollectionExpert() {
  93. $.ajax({
  94. url:"/ajax/watch/delete",
  95. data: {
  96. professorId: userid,
  97. watchObject: returnId
  98. },
  99. dataType: 'json', //数据格式类型
  100. type: 'post', //http请求类型
  101. timeout: 10000,
  102. async: true,
  103. success: function(data) {
  104. //console.log(data.success)
  105. if(data.success) {
  106. $(".attentBtn").removeClass('attented');
  107. $('.attentBtn i').text('关注');
  108. //$.MsgBox.Alert('提示',"取消关注成功");
  109. }
  110. },
  111. error: function(data) {
  112. $.MsgBox.Alert('提示',"服务器链接超时");
  113. }
  114. });
  115. }
  116. })