portal html css js resource

resourceList.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. $(document).ready(function(){
  2. $(".onlogin .headnavbtn li").eq(0).addClass("navcurrent");
  3. loginStatus(); //判断个人是否登录
  4. var userid = $.cookie("userid");
  5. var resourceId;
  6. /*资源列表查询*/
  7. function getRecourceMe(n,isbind,num) {
  8. var resourceNameVa=$("#resouceName").val();
  9. var $info={};
  10. $info.professorId=userid;
  11. $info.pageSize=10;
  12. if(resourceNameVa !="") {
  13. $info.key=resourceNameVa;
  14. }
  15. $info.pageNo=n;
  16. $.ajax({
  17. "url": "/ajax/resource/pqSelf",
  18. "type": "GET",
  19. "success": function(data) {
  20. console.log(data)
  21. if(data.success) {
  22. $("#resourceList").html("");
  23. if(num==1) {
  24. if(data.data.data.length==0) {
  25. $("#noresource").removeClass("displayNone");
  26. $(".noContip").text("您还未发布任何资源");
  27. return;
  28. }else{
  29. $("#noresource").addClass("displayNone");
  30. }
  31. }else{
  32. if(data.data.data.length==0) {
  33. $("#noresource").removeClass("displayNone");
  34. $(".noContip").text("没有符合该搜索条件的内容");
  35. return;
  36. }else{
  37. $("#noresource").addClass("displayNone");
  38. }
  39. }
  40. resourceHtml(data.data.data);
  41. if(isbind == true) {
  42. $(".tcdPageCode").createPage({
  43. pageCount: Math.ceil(data.data.total / data.data.pageSize),
  44. current: data.data.pageNo,
  45. backFn: function(p) {
  46. getRecourceMe(p,false);
  47. }
  48. });
  49. }
  50. }
  51. },
  52. "data": $info,
  53. dataType: "json",
  54. 'error': function() {
  55. $.MsgBox.Alert('提示', '服务器连接超时!');
  56. }
  57. });
  58. }
  59. getRecourceMe(1,true,1);
  60. function resourceHtml($data) {
  61. for(var i=0;i<$data.length;i++) {
  62. var imgSrc="../images/default-resource.jpg";
  63. var oTime,pageview="",draftLable="",oHtml,oLi='';
  64. if($data[i].images.length) {
  65. imgSrc="/data/resource/"+$data[i].images[0].imageSrc
  66. }
  67. console.log($data[i].status)
  68. if($data[i].status==0) {
  69. oTime="修改于 "+timeTran($data[i].modifyTime);
  70. draftLable='<span class="draftLable">草稿</span>';
  71. oHtml="resourceIssue.html";
  72. oLi="class='draftList'"
  73. }else{
  74. oTime="发布于 "+timeTran($data[i].publishTime);
  75. pageview='<li><span>阅读量 '+$data[i].pageViews+'</span></li>';
  76. oHtml="resourceShow.html"
  77. }
  78. var oStr='<li '+oLi+'>'+
  79. '<a href="'+oHtml+'?resourceId='+$data[i].resourceId+'" target="_blank">'+
  80. '<div class="madiaHead resouseHead" style="background-image: url('+imgSrc+');"></div>' +
  81. '<div class="madiaInfo">'+
  82. '<p class="h1Font ellipsisSty">'+$data[i].resourceName+'</p>'+
  83. '<ul class="h2Font clearfix">'+
  84. '<li><span>'+oTime+'</span></li>'+pageview+
  85. '</ul>'+draftLable+
  86. '</div>'+
  87. '</a>'+
  88. '<ul class="madiaEdit">'+
  89. '<li><span class="deteleThis2" data-id="'+$data[i].resourceId+'"></span></li>'+
  90. '<li><span class="editThis" data-id="'+$data[i].resourceId+'"></span></li>'+
  91. '</ul>'+
  92. '</li>'
  93. $("#resourceList").append(oStr);
  94. }
  95. }
  96. /*时间格式转换*/
  97. function timeTran(otm) {
  98. var month, day, hour, minu;
  99. var monFirst = otm.substring(4, 5);
  100. var dayFirst = otm.substring(6, 7);
  101. if(monFirst == "0") {
  102. month = otm.substring(5, 6)
  103. } else {
  104. month = otm.substring(4, 6)
  105. }
  106. if(dayFirst == "0") {
  107. day = otm.substring(7, 8);
  108. } else {
  109. day = otm.substring(6, 8);
  110. }
  111. hour = otm.substring(8, 10);
  112. minu = otm.substring(10, 12);
  113. return month + "月" + day + "日 " + hour + ":" + minu;
  114. }
  115. /*点击修改跳转修改页面*/
  116. $("#resourceList").on("click",".editThis",function(){
  117. location.href="resourceIssue.html?resourceId="+$(this).attr("data-id")
  118. })
  119. /*点击删除跳转修改页面*/
  120. $("#resourceList").on("click",".deteleThis2",function(){
  121. resourceId=$(this).attr("data-id");
  122. $.MsgBox.Confirm("提示", "确认删除该资源?",deleResource);
  123. })
  124. /*删除函数*/
  125. function deleResource() {
  126. $.ajax({
  127. "url": "/ajax/resource/delete",
  128. "type": "POST",
  129. "success": function(data) {
  130. if(data.success) {
  131. getRecourceMe(1,false);
  132. }
  133. },
  134. "data": {"resourceId":resourceId},
  135. "beforeSend": function() { /*console.log(this.data)*/ },
  136. "contentType": "application/x-www-form-urlencoded",
  137. dataType: "json"
  138. });
  139. }
  140. /*输入资源名称限制字数*/
  141. $("#resouceName").bind({
  142. keyup: function() {
  143. if($(this).val().length > 30) {
  144. $(this).val($(this).val().substr(0, 30));
  145. }
  146. }
  147. });
  148. /*点击搜索*/
  149. $(".searchSpan").click(function(){
  150. $(".tcdPageCode").remove();
  151. $(".aboutRes").append('<div class="tcdPageCode"></div>');
  152. getRecourceMe(1,true);
  153. })
  154. })