show_document.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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. $('#loading').modal('hide');
  33. if (ret.code !== 0) console.log(ret.msg);
  34. });
  35. fetchJSON("/api/resource/info?id=" + request.id, {}, "get", function (ret) {
  36. if (ret.code === 0) {
  37. var resource = ret.data;
  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", style: "margin-bottom: 50px;"});
  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 url = resource.resourceUrl.toLowerCase();
  83. var player = $("<textarea>", {
  84. id: "player",
  85. class: "form-control",
  86. rows: 15,
  87. style: "resize: none; background-color:transparent; border: 0;"
  88. });
  89. $("#playerWrapper")
  90. .append($("<h4>", {text: "简要内容", style: "color: blue;"}))
  91. .append($("<br>"))
  92. .append(player);
  93. if (url.endsWith(".doc") || url.endsWith(".docx") || url.endsWith(".xls") || url.endsWith(".xlsx") || url.endsWith(".ppt")
  94. || url.endsWith(".pptx") || url.endsWith(".txt") || url.endsWith(".rtf") || url.endsWith(".wps")){
  95. $("#playerWrapper").append($('<p>', {
  96. id: "loadTips",
  97. text: "正在加载预览文件,请稍候...",
  98. style: "margin-top: -300px"
  99. }));
  100. fetchJSON("/api/resource/onlineView?id=" + resource.id, {}, "get", function (ret) {
  101. if (ret.code === 0) {
  102. $('#load' +
  103. 'Tips').css('display', 'none');
  104. $("#playerWrapper")
  105. .removeClass("col-md-10")
  106. .removeClass("col-md-offset-1")
  107. .addClass("col-md-12");
  108. $("#playerWrapper h4").html("内容预览");
  109. $("#playerWrapper h4").css('padding-left', '30px');
  110. $("#player").css('display', 'none');
  111. /* $("#playerWrapper")
  112. .append($("<iframe>", {
  113. width: $('#playerWrapper').width(),
  114. height: 800,
  115. src: ret.data
  116. }));*/
  117. $('#playerWrapper')
  118. .append($("<iframe>", {
  119. width: $("#playerWrapper").width(),
  120. height: 800,
  121. src: "/pdfjs/web/viewer.html?file=/" +ret.data
  122. }));
  123. } else {
  124. console.log(ret.msg);
  125. $('#loadTips').text('预览文件加载失败,显示默认文件概要信息');
  126. player.html(resource.description);
  127. }
  128. $("#playerWrapper")
  129. .append($("<h4>", {text: "可用操作", style: "margin-top: 40px; color: blue;"}))
  130. .append($("<hr>"))
  131. .append(starWrapper);
  132. $(".satisfaction").hover(
  133. function (e) {
  134. var id = this.id.replace("star", "");
  135. for (var i = 0; i <= id; i++) $("#star" + i).addClass("cur");
  136. },
  137. function (e) {
  138. for (var i = 0; i < 5; i++) if (i > rank - 1) $("#star" + i).removeClass("cur");
  139. }
  140. );
  141. $(".satisfaction").on("click", function (e) {
  142. var id = parseInt(this.id.replace("star", ""));
  143. rank = parseInt(id + 1);
  144. fetchJSON(
  145. "/api/resource/satisfaction?id=" + resource.id + "&satisfaction=" + (parseInt(id) + 1) * 20,
  146. {},
  147. "post",
  148. function (ret) {
  149. if (ret.code !== 0) console.log(ret.msg);
  150. }
  151. );
  152. });
  153. fetchJSON("/api/resource/downloadPermission", {}, "get", function (ret) {
  154. if (ret.code === 0) {
  155. if (ret.data === true) {
  156. $("#playerWrapper").append(
  157. $("<button>", {
  158. id: "download",
  159. class: "btn btn-primary icon pull-right",
  160. download: "",
  161. html: "&#xe6fe; 点击下载 (已下载" + resource.downloadTimes + "次)"
  162. })
  163. );
  164. var times = resource.downloadTimes;
  165. $("#download").on("click", function (e) {
  166. downloadResource("/api/resource/download?id=" + request.id);
  167. times++;
  168. $("#download").html("&#xe6fe; 点击下载 (已下载" + times + "次)");
  169. });
  170. $("#playerWrapper").append(
  171. $("<button>", {
  172. id: "download1",
  173. class: "btn btn-primary icon pull-right",
  174. style:"margin-right :10px",
  175. html: "&#xe6fe; 点击打印"
  176. })
  177. );
  178. $("#download1").on("click", function (e) {
  179. $('iframe:last').contents().find("#secondaryPrint").click();
  180. });
  181. }
  182. } else {
  183. console.log(ret.msg);
  184. }
  185. });
  186. fetchJSON("/api/user/isCollected?id="+resource.id,{}, "get", function (ret) {
  187. if (ret.code === 0) {
  188. $("#playerWrapper").prepend(
  189. $("<button>", {
  190. id: "collect",
  191. class: "btn btn-primary icon pull-right",
  192. style:"margin-right :10px",
  193. html: "&#xe6fe; 点击收藏"
  194. })
  195. );
  196. $("#collect").on("click", function (e) {
  197. collectResource(resource.id,1);
  198. $("#collect").hide();
  199. $("#collect1").show();
  200. });
  201. $("#playerWrapper").prepend(
  202. $("<button>", {
  203. id: "collect1",
  204. class: "btn btn-danger icon pull-right",
  205. style:"margin-right :10px",
  206. html: "&#xe6fe; 取消收藏"
  207. })
  208. );
  209. $("#collect1").on("click", function (e) {
  210. collectResource(resource.id,0);
  211. $("#collect").show();
  212. $("#collect1").hide();
  213. });
  214. if (ret.data === false) {
  215. $("#collect1").hide();
  216. }else
  217. {
  218. $("#collect").hide();
  219. }
  220. } else {
  221. console.log(ret.msg);
  222. }
  223. });
  224. });
  225. } else if (url.endsWith(".pdf")) {
  226. $("#playerWrapper")
  227. .removeClass("col-md-10")
  228. .removeClass("col-md-offset-1")
  229. .removeClass("col-md-12");
  230. $("#playerWrapper h4").html("内容预览");
  231. $("#playerWrapper h4").css("padding-left", '30px');
  232. $("#player").css('display', 'none');
  233. /*$('#playerWrapper')
  234. .append($("<iframe>", {
  235. width: $("#playerWrapper").width(),
  236. height: 800,
  237. src: urlBase + "/file/" + resource.resourceUrl
  238. }));*/
  239. $('#playerWrapper')
  240. .append($("<iframe>", {
  241. width: $("#playerWrapper").width(),
  242. height: 800,
  243. src: "/pdfjs/web/viewer.html?file=" + "/file/" + resource.resourceUrl
  244. }));
  245. $("#playerWrapper")
  246. .append($("<h4>", {text: "可用操作", style: "margin-top: 40px; color: blue;"}))
  247. .append($("<hr>"))
  248. .append(starWrapper);
  249. fetchJSON("/api/resource/downloadPermission", {}, "get", function (ret) {
  250. if (ret.code === 0) {
  251. if (ret.data === true) {
  252. $("#playerWrapper").append(
  253. $("<button>", {
  254. id: "download",
  255. class: "btn btn-primary icon pull-right",
  256. download: "",
  257. html: "&#xe6fe; 点击下载 (已下载" + resource.downloadTimes + "次)"
  258. })
  259. );
  260. var times = resource.downloadTimes;
  261. $("#download").on("click", function (e) {
  262. downloadResource("/api/resource/download?id=" + request.id);
  263. times++;
  264. $("#download").html("&#xe6fe; 点击下载 (已下载" + times + "次)");
  265. });
  266. $("#playerWrapper").append(
  267. $("<button>", {
  268. id: "download1",
  269. class: "btn btn-primary icon pull-right",
  270. style:"margin-right :10px",
  271. html: "&#xe6fe; 点击打印"
  272. })
  273. );
  274. $("#download1").on("click", function (e) {
  275. $('iframe:last').contents().find("#secondaryPrint").click();
  276. });
  277. }
  278. } else {
  279. console.log(ret.msg);
  280. }
  281. });
  282. fetchJSON("/api/user/isCollected?id="+resource.id,{}, "get", function (ret) {
  283. if (ret.code === 0) {
  284. $("#playerWrapper").prepend(
  285. $("<button>", {
  286. id: "collect",
  287. class: "btn btn-primary icon pull-right",
  288. style:"margin-right :10px",
  289. html: "&#xe6fe; 点击收藏"
  290. })
  291. );
  292. $("#collect").on("click", function (e) {
  293. collectResource(resource.id,1);
  294. $("#collect").hide();
  295. $("#collect1").show();
  296. });
  297. $("#playerWrapper").prepend(
  298. $("<button>", {
  299. id: "collect1",
  300. class: "btn btn-danger icon pull-right",
  301. style:"margin-right :10px",
  302. html: "&#xe6fe; 取消收藏"
  303. })
  304. );
  305. $("#collect1").on("click", function (e) {
  306. collectResource(resource.id,0);
  307. $("#collect").show();
  308. $("#collect1").hide();
  309. });
  310. if (ret.data === false) {
  311. $("#collect1").hide();
  312. }else
  313. {
  314. $("#collect").hide();
  315. }
  316. } else {
  317. console.log(ret.msg);
  318. }
  319. });
  320. } else {
  321. player.html(resource.description);
  322. $("#playerWrapper")
  323. .append($("<h4>", {text: "可用操作", style: "margin-top: 40px; color: blue;"}))
  324. .append($("<hr>"))
  325. .append(starWrapper);
  326. fetchJSON("/api/resource/downloadPermission", {}, "get", function (ret) {
  327. if (ret.code === 0) {
  328. if (ret.data === true) {
  329. $("#playerWrapper").append(
  330. $("<button>", {
  331. id: "download",
  332. class: "btn btn-primary icon pull-right",
  333. download: "",
  334. html: "&#xe6fe; 点击下载 (已下载" + resource.downloadTimes + "次)"
  335. })
  336. );
  337. var times = resource.downloadTimes;
  338. $("#download").on("click", function (e) {
  339. downloadResource("/api/resource/download?id=" + request.id);
  340. times++;
  341. $("#download").html("&#xe6fe; 点击下载 (已下载" + times + "次)");
  342. });
  343. }
  344. } else {
  345. console.log(ret.msg);
  346. }
  347. });
  348. fetchJSON("/api/user/isCollected?id="+resource.id,{}, "get", function (ret) {
  349. if (ret.code === 0) {
  350. $("#playerWrapper").prepend(
  351. $("<button>", {
  352. id: "collect",
  353. class: "btn btn-primary icon pull-right",
  354. style:"margin-right :10px",
  355. html: "&#xe6fe; 点击收藏"
  356. })
  357. );
  358. $("#collect").on("click", function (e) {
  359. collectResource(resource.id,1);
  360. $("#collect").hide();
  361. $("#collect1").show();
  362. });
  363. $("#playerWrapper").prepend(
  364. $("<button>", {
  365. id: "collect1",
  366. class: "btn btn-danger icon pull-right",
  367. style:"margin-right :10px",
  368. html: "&#xe6fe; 取消收藏"
  369. })
  370. );
  371. $("#collect1").on("click", function (e) {
  372. collectResource(resource.id,0);
  373. $("#collect").show();
  374. $("#collect1").hide();
  375. });
  376. if (ret.data === false) {
  377. $("#collect1").hide();
  378. }else
  379. {
  380. $("#collect").hide();
  381. }
  382. } else {
  383. console.log(ret.msg);
  384. }
  385. });
  386. }
  387. $(".satisfaction").hover(
  388. function (e) {
  389. var id = this.id.replace("star", "");
  390. for (var i = 0; i <= id; i++) $("#star" + i).addClass("cur");
  391. },
  392. function (e) {
  393. for (var i = 0; i < 5; i++) if (i > rank - 1) $("#star" + i).removeClass("cur");
  394. }
  395. );
  396. $(".satisfaction").on("click", function (e) {
  397. var id = parseInt(this.id.replace("star", ""));
  398. rank = parseInt(id + 1);
  399. fetchJSON(
  400. "/api/resource/satisfaction?id=" + resource.id + "&satisfaction=" + (parseInt(id) + 1) * 20,
  401. {},
  402. "post",
  403. function (ret) {
  404. if (ret.code !== 0) console.log(ret.msg);
  405. }
  406. );
  407. });
  408. } else {
  409. console.log(ret.msg);
  410. }
  411. });
  412. fetchJSON("/api/query/related", {keyword: combineKeysToArray(request.q)}, "post", function (ret) {
  413. if (ret.code === 0) {
  414. if (ret.data.length != 0) {
  415. $("#relatedKeywordsWrapper").css("display", "block");
  416. fillRelatedKeywordList(ret.data, request.t, $("#relatedKeywords"));
  417. }
  418. } else {
  419. console.log(ret.msg);
  420. }
  421. });
  422. });