show_video.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. $(function () {
  2. var request = getRequest();
  3. if (
  4. JSON.stringify(request) == "{}" ||
  5. request.id === undefined ||
  6. request.q === undefined ||
  7. request.t === undefined
  8. ) {
  9. console.log("argument error.");
  10. return;
  11. }
  12. var keywordControl = $("#keyword");
  13. if (request.q !== undefined) keywordControl.val(request.q);
  14. $("#search").on("click", function (e) {
  15. e.preventDefault();
  16. var inputValue = keywordControl.val().trim();
  17. if (inputValue === "" || inputValue.replace(/[-_—]/g, "") === "") {
  18. keywordControl.focus();
  19. return;
  20. }
  21. var keylist = encodeURIComponent(inputValue);
  22. window.location.href = "list_index.html?q=" + keylist + (request.t === undefined ? "" : "&t=" + request.t);
  23. });
  24. $("#keyword").on("keyup", function (e) {
  25. e.preventDefault();
  26. if (e.keyCode === 13) {
  27. $("#search").click();
  28. }
  29. });
  30. $('#loading').modal('show');
  31. fetchJSON("/api/resource/up/view?id=" + request.id, {}, "get", function (ret) {
  32. if (ret.code !== 0) console.log(ret.msg);
  33. });
  34. fetchJSON("/api/resource/info?id=" + request.id, {}, "get", function (ret) {
  35. if (ret.code === 0) {
  36. var resource = ret.data;
  37. $('#loading').modal('hide');
  38. fetchJSON(
  39. "/api/query/query",
  40. {keyword: combineKeysToArray(resource.resourceName), type: request.t, page: 0, size: 10},
  41. "post",
  42. function (ret) {
  43. if (ret.code === 0) {
  44. if (ret.data.resources.length != 0) {
  45. $("#relatedResourcesWrapper").css("display", "block");
  46. fillRelatedResourceList(ret.data.resources, request.t, $("#relatedResources"), request.q);
  47. }
  48. } else console.log(ret.msg);
  49. }
  50. );
  51. $("#title").html(resource.resourceName);
  52. $("#department").html(resource.submitDepartment);
  53. $("#author").html(resource.resourceAuthor);
  54. $("#submitDate").html(toDateString(resource.resourceCompletionDate));
  55. $("#format").html(getFileExt(resource.resourceUrl));
  56. var starWrapper = $("<div>", {class: "star pull-left"});
  57. var starSpan = $("<span>", {text: "满意度:"});
  58. starWrapper.append(starSpan);
  59. var b = parseInt(resource.satisfaction / 20);
  60. var c = resource.satisfaction % 20 == 0 ? 0 : 1;
  61. var rank = b + c;
  62. for (var j = 0; j < 5; j++) {
  63. if (j < rank)
  64. starWrapper.append(
  65. $("<span>", {
  66. id: "star" + j,
  67. class: "satisfaction icon cur",
  68. style: "cursor: pointer;",
  69. html: "&#xe644; &nbsp;"
  70. })
  71. );
  72. else
  73. starWrapper.append(
  74. $("<span>", {
  75. id: "star" + j,
  76. class: "satisfaction icon",
  77. style: "cursor: pointer;",
  78. html: "&#xe644; &nbsp;"
  79. })
  80. );
  81. }
  82. var video = $("<video>", {id: "player", controls: ""});
  83. video.append(
  84. $("<source>", {id: "videoSource", src: urlBase + "/file/" + resource.resourceUrl, type: "video/mp4"})
  85. );
  86. video.append(
  87. $("<source>", {id: "videoSource", src: urlBase + "/file/" + resource.resourceUrl, type: "video/ogg"})
  88. );
  89. $("#playerWrapper").append(video);
  90. $("#playerWrapper")
  91. .append($("<br>"))
  92. .append($("<h4>", {text: "可用操作", style: "margin-top: 40px; color: blue;"}))
  93. .append($("<hr>"))
  94. .append(starWrapper);
  95. fetchJSON("/api/resource/downloadPermission" +
  96. "", {}, "get", function (ret) {
  97. if (ret.code === 0) {
  98. if (ret.data === true) {
  99. $("#playerWrapper").append(
  100. $("<button>", {
  101. id: "download",
  102. class: "btn btn-primary icon pull-right",
  103. download: "",
  104. html: "&#xe6fe; 点击下载 (已下载" + resource.downloadTimes + "次)"
  105. })
  106. );
  107. var times = resource.downloadTimes;
  108. $("#download").on("click", function (e) {
  109. downloadResource("/api/resource/download?id=" + request.id);
  110. times++;
  111. $("#download").html("&#xe6fe; 点击下载 (已下载" + times + "次)");
  112. });
  113. }
  114. } else {
  115. console.log(ret.msg);
  116. }
  117. });
  118. fetchJSON("/api/user/isCollected?id="+resource.id,{}, "get", function (ret) {
  119. if (ret.code === 0) {
  120. $("#playerWrapper").prepend(
  121. $("<button>", {
  122. id: "collect",
  123. class: "btn btn-primary icon pull-right",
  124. style:"margin-right :10px;margin-bottom :10px",
  125. html: "&#xe6fe; 点击收藏"
  126. })
  127. );
  128. $("#collect").on("click", function (e) {
  129. collectResource(resource.id,1);
  130. $("#collect").hide();
  131. $("#collect1").show();
  132. });
  133. $("#playerWrapper").prepend(
  134. $("<button>", {
  135. id: "collect1",
  136. class: "btn btn-danger icon pull-right",
  137. style:"margin-right :10px;margin-bottom :10px",
  138. html: "&#xe6fe; 取消收藏"
  139. })
  140. );
  141. $("#collect1").on("click", function (e) {
  142. collectResource(resource.id,0);
  143. $("#collect").show();
  144. $("#collect1").hide();
  145. });
  146. if (ret.data === false) {
  147. $("#collect1").hide();
  148. }else
  149. {
  150. $("#collect").hide();
  151. }
  152. $("#playerWrapper").prepend(
  153. $("<button>", {
  154. id: "reloadVideo",
  155. class: "btn btn-warm icon pull-right",
  156. style:"margin-right :10px;margin-bottom :10px",
  157. html: "&#xe6fe; 重新加载"
  158. })
  159. );
  160. $("#reloadVideo").on("click", function (e) {
  161. reConvertResource(resource.id);
  162. });
  163. $("#playerWrapper").prepend(
  164. $("<button>", {
  165. id: "reportError",
  166. class: "btn btn-danger icon pull-right",
  167. style:"margin-right :10px ;margin-bottom :10px",
  168. html: "&#xe6fe; 报告资源失效"
  169. })
  170. );
  171. $("#reportError").on("click", function (e) {
  172. reportError(resource.id);
  173. layer.msg('已提交!');
  174. });
  175. } else {
  176. console.log(ret.msg);
  177. }
  178. });
  179. $(".satisfaction").hover(
  180. function (e) {
  181. var id = this.id.replace("star", "");
  182. for (var i = 0; i <= id; i++) $("#star" + i).addClass("cur");
  183. },
  184. function (e) {
  185. for (var i = 0; i < 5; i++) if (i > rank - 1) $("#star" + i).removeClass("cur");
  186. }
  187. );
  188. $(".satisfaction").on("click", function (e) {
  189. var id = parseInt(this.id.replace("star", ""));
  190. rank = parseInt(id + 1);
  191. fetchJSON(
  192. "/api/resource/satisfaction?id=" + resource.id + "&satisfaction=" + (parseInt(id) + 1) * 20,
  193. {},
  194. "post",
  195. function (ret) {
  196. if (ret.code !== 0) console.log(ret.msg);
  197. }
  198. );
  199. });
  200. } else {
  201. console.log(ret.msg);
  202. }
  203. });
  204. fetchJSON("/api/query/related", {keyword: combineKeysToArray(request.q)}, "post", function (ret) {
  205. if (ret.code === 0) {
  206. if (ret.data.length != 0) {
  207. $("#relatedKeywordsWrapper").css("display", "block");
  208. fillRelatedKeywordList(ret.data, request.t, $("#relatedKeywords"));
  209. }
  210. } else {
  211. console.log(ret.msg);
  212. }
  213. });
  214. });