portal html css js resource

resourceList.js 4.3KB

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