123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- $(function () {
- var request = getRequest();
- if (
- JSON.stringify(request) == "{}" ||
- request.id === undefined ||
- request.q === undefined ||
- request.t === undefined
- ) {
- console.log("argument error.");
- return;
- }
- var keywordControl = $("#keyword");
- if (request.q !== undefined) keywordControl.val(request.q);
- $("#search").on("click", function (e) {
- e.preventDefault();
- var inputValue = keywordControl.val().trim();
- if (inputValue === "" || inputValue.replace(/[-_—]/g, "") === "") {
- keywordControl.focus();
- return;
- }
- var keylist = encodeURIComponent(inputValue);
- window.location.href = "list_index.html?q=" + keylist + (request.t === undefined ? "" : "&t=" + request.t);
- });
- $("#keyword").on("keyup", function (e) {
- e.preventDefault();
- if (e.keyCode === 13) {
- $("#search").click();
- }
- });
- $('#loading').modal('show');
- fetchJSON("/api/resource/up/view?id=" + request.id, {}, "get", function (ret) {
- if (ret.code !== 0) console.log(ret.msg);
- });
- fetchJSON("/api/resource/info?id=" + request.id, {}, "get", function (ret) {
- if (ret.code === 0) {
- var resource = ret.data;
- $('#loading').modal('hide');
- fetchJSON(
- "/api/query/query",
- {keyword: combineKeysToArray(resource.resourceName), type: request.t, page: 0, size: 10},
- "post",
- function (ret) {
- if (ret.code === 0) {
- if (ret.data.resources.length != 0) {
- $("#relatedResourcesWrapper").css("display", "block");
- fillRelatedResourceList(ret.data.resources, request.t, $("#relatedResources"), request.q);
- }
- } else console.log(ret.msg);
- }
- );
- $("#title").html(resource.resourceName);
- $("#department").html(resource.submitDepartment);
- $("#author").html(resource.resourceAuthor);
- $("#submitDate").html(toDateString(resource.resourceCompletionDate));
- $("#format").html(getFileExt(resource.resourceUrl));
- var starWrapper = $("<div>", {class: "star pull-left"});
- var starSpan = $("<span>", {text: "满意度:"});
- starWrapper.append(starSpan);
- var b = parseInt(resource.satisfaction / 20);
- var c = resource.satisfaction % 20 == 0 ? 0 : 1;
- var rank = b + c;
- for (var j = 0; j < 5; j++) {
- if (j < rank)
- starWrapper.append(
- $("<span>", {
- id: "star" + j,
- class: "satisfaction icon cur",
- style: "cursor: pointer;",
- html: " "
- })
- );
- else
- starWrapper.append(
- $("<span>", {
- id: "star" + j,
- class: "satisfaction icon",
- style: "cursor: pointer;",
- html: " "
- })
- );
- }
- var video = $("<video>", {id: "player", controls: ""});
- video.append(
- $("<source>", {id: "videoSource", src: urlBase + "/file/" + resource.resourceUrl, type: "video/mp4"})
- );
- video.append(
- $("<source>", {id: "videoSource", src: urlBase + "/file/" + resource.resourceUrl, type: "video/ogg"})
- );
- $("#playerWrapper").append(video);
- $("#playerWrapper")
- .append($("<br>"))
- .append($("<h4>", {text: "可用操作", style: "margin-top: 40px; color: blue;"}))
- .append($("<hr>"))
- .append(starWrapper);
- fetchJSON("/api/resource/downloadPermission" +
- "", {}, "get", function (ret) {
- if (ret.code === 0) {
- if (ret.data === true) {
- $("#playerWrapper").append(
- $("<button>", {
- id: "download",
- class: "btn btn-primary icon pull-right",
- download: "",
- html: " 点击下载 (已下载" + resource.downloadTimes + "次)"
- })
- );
- var times = resource.downloadTimes;
- $("#download").on("click", function (e) {
- downloadResource("/api/resource/download?id=" + request.id);
- times++;
- $("#download").html(" 点击下载 (已下载" + times + "次)");
- });
- }
- } else {
- console.log(ret.msg);
- }
- });
- fetchJSON("/api/user/isCollected?id="+resource.id,{}, "get", function (ret) {
- if (ret.code === 0) {
- $("#playerWrapper").prepend(
- $("<button>", {
- id: "collect",
- class: "btn btn-primary icon pull-right",
- style:"margin-right :10px;margin-bottom :10px",
- html: " 点击收藏"
- })
- );
- $("#collect").on("click", function (e) {
- collectResource(resource.id,1);
- $("#collect").hide();
- $("#collect1").show();
- });
- $("#playerWrapper").prepend(
- $("<button>", {
- id: "collect1",
- class: "btn btn-danger icon pull-right",
- style:"margin-right :10px;margin-bottom :10px",
- html: " 取消收藏"
- })
- );
- $("#collect1").on("click", function (e) {
- collectResource(resource.id,0);
- $("#collect").show();
- $("#collect1").hide();
- });
- if (ret.data === false) {
- $("#collect1").hide();
- }else
- {
- $("#collect").hide();
- }
- $("#playerWrapper").prepend(
- $("<button>", {
- id: "reloadVideo",
- class: "btn btn-warm icon pull-right",
- style:"margin-right :10px;margin-bottom :10px",
- html: " 重新加载"
- })
- );
- $("#reloadVideo").on("click", function (e) {
- reConvertResource(resource.id);
- });
- $("#playerWrapper").prepend(
- $("<button>", {
- id: "reportError",
- class: "btn btn-danger icon pull-right",
- style:"margin-right :10px ;margin-bottom :10px",
- html: " 报告资源失效"
- })
- );
- $("#reportError").on("click", function (e) {
- reportError(resource.id);
- layer.msg('已提交!');
- });
- } else {
- console.log(ret.msg);
- }
- });
- $(".satisfaction").hover(
- function (e) {
- var id = this.id.replace("star", "");
- for (var i = 0; i <= id; i++) $("#star" + i).addClass("cur");
- },
- function (e) {
- for (var i = 0; i < 5; i++) if (i > rank - 1) $("#star" + i).removeClass("cur");
- }
- );
- $(".satisfaction").on("click", function (e) {
- var id = parseInt(this.id.replace("star", ""));
- rank = parseInt(id + 1);
- fetchJSON(
- "/api/resource/satisfaction?id=" + resource.id + "&satisfaction=" + (parseInt(id) + 1) * 20,
- {},
- "post",
- function (ret) {
- if (ret.code !== 0) console.log(ret.msg);
- }
- );
- });
- } else {
- console.log(ret.msg);
- }
- });
- fetchJSON("/api/query/related", {keyword: combineKeysToArray(request.q)}, "post", function (ret) {
- if (ret.code === 0) {
- if (ret.data.length != 0) {
- $("#relatedKeywordsWrapper").css("display", "block");
- fillRelatedKeywordList(ret.data, request.t, $("#relatedKeywords"));
- }
- } else {
- console.log(ret.msg);
- }
- });
- });
|