tasklib_book.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. //播放音频图片地址
  2. var PicInfo = {
  3. yaoshiShowImgUrl: "file:///android_asset/js/yaoshi-show.png",
  4. yaoshiHideImgUrl: "file:///android_asset/js/yaoshi-hide.png",
  5. recordPlayImgUrl: "file:///android_asset/js/play.png",
  6. recordPauseImgUrl: "file:///android_asset/js/pause.png",
  7. audioPlayImgUrl: "file:///android_asset/js/dynaiselaba.gif",
  8. audioPauseImgUrl: "file:///android_asset/js/dynaiselaba.png"
  9. }
  10. //显示、隐藏答案
  11. function showHideAnswer(flag) {
  12. if (flag) {
  13. //$(".underlineContent").show();
  14. $(".underlineContent").css("color", "#92D050");
  15. $(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
  16. }
  17. else {
  18. //$(".underlineContent").hide();
  19. $(".underlineContent").css("color", "#ffffff");
  20. $(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
  21. }
  22. }
  23. ///显示、隐藏钥匙及答案 isShowYX:显示和隐藏钥匙,isShowAS:显示和隐藏答案
  24. function showHideAnswerEx(isShowYX, isShowAS) {
  25. if (isShowYX) {
  26. $(".yaoshi").show();
  27. }
  28. else {
  29. $(".yaoshi").hide();
  30. }
  31. if (isShowAS) {
  32. $.each($(".underlineContent"), function (index, item) {
  33. //$(item).html($(item).attr("data-text"));
  34. $(item).css("color", "#92D050");
  35. });
  36. $(".yaoshi").data("status", "1");
  37. $(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
  38. }
  39. else {
  40. $.each($(".underlineContent,.underlineContent.no-answer"), function (index, item) {
  41. $(item).css("color", "#ffffff");
  42. });
  43. $(".yaoshi").data("status", "0");
  44. $(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
  45. }
  46. }
  47. //页面加载完,原文 绑定事件
  48. function bindEventTeaOrignalYS() {
  49. var bodyWidth = $(document.body).width();
  50. //显示/隐藏习题答案
  51. $(".yaoshi").on("click", function () {
  52. var curDisplay = $(this).nextUntil(".yaoshi").find(".underlineContent").eq(0).css("display");
  53. if (curDisplay == "undefined" || curDisplay == undefined) return;
  54. if (curDisplay == "none" || $(this).data("status") == "0") {
  55. $(this).data("status", "1");
  56. $(this).attr("src", PicInfo.yaoshiShowImgUrl);
  57. //$(this).nextUntil(".yaoshi").find(".underlineContent").show();
  58. $(this).nextUntil(".yaoshi").find(".underlineContent").css("color", "#92D050");
  59. } else {
  60. $(this).data("status", "0");
  61. $(this).attr("src", PicInfo.yaoshiHideImgUrl);
  62. //$(this).nextUntil(".yaoshi").find(".underlineContent").hide();
  63. $(this).nextUntil(".yaoshi").find(".underlineContent").css("color", "#ffffff");
  64. }
  65. });
  66. //处理答题点
  67. $.each($(".underlineContent"), function (index, item) {
  68. $(item).attr("data-text", $(item).html());
  69. });
  70. //给音频绑定一个ID
  71. $.each($(".audioImg"), function (index, item) {
  72. $(item).attr("audiourl", "");
  73. $(item).attr('audio-id', index);
  74. });
  75. //给视频图标处理
  76. $.each($(".videoImg"), function (index, item) {
  77. $(item).attr("audiourl", "");
  78. });
  79. //给口语图标处理
  80. $.each($(".oralLanguageImg"), function (index, item) {
  81. $(item).attr("audiourl", "");
  82. });
  83. //去除多余的U空标签
  84. $.each($("u"), function (index, item) {
  85. var text = $(item).text();
  86. text = text.replace(/\s+/g, "");
  87. if (text == "") {
  88. $(item).remove();
  89. }
  90. });
  91. //处理暂无参考答案
  92. $.each($(".yaoshi"), function (index, item) {
  93. var prev = $(item).nextUntil(".yaoshi").find(".underlineContent");
  94. if (prev.length == 0) {
  95. var uHtml = document.createElement("u");
  96. uHtml.className = "underlineContent no-answer";
  97. uHtml.innerText = "暂无参考答案";
  98. uHtml.setAttribute("data-text", uHtml.innerText);
  99. $(item).after(uHtml);
  100. }
  101. });
  102. //处理表格宽度
  103. $.each($(".wordTable"), function (index, item) {
  104. $(item).css("width", bodyWidth + "px");
  105. });
  106. //点击喇叭事件,音频播放
  107. $(".audioImg").on("click", function () {
  108. audioPlayClick(this);
  109. });
  110. //点击播放事件,视频播放
  111. $(".videoImg").on("click", function () {
  112. var curHtml = $(this).parent().find(".videoUrl").html();
  113. var curAlt = $(this).attr("alt");//播放视频地址
  114. playVisiableAudioCallBack(2, $(this).attr("alt"));
  115. });
  116. //处理表格样式
  117. $("td").attr("style", "");
  118. //处理文章标题的样式(目前资料源已处理)
  119. //$("p").eq(2).addClass("p-title-top");
  120. }
  121. //页面加载完,课件 绑定事件
  122. function bindEventYS() {
  123. var bodyWidth = $(document.body).width();
  124. //给每个答题点加上ID
  125. $.each($(".yaoshi"), function (index, item) {
  126. $(item).attr('answer-id', index);
  127. });
  128. //给音频绑定一个ID
  129. $.each($(".audioImg"), function (index, item) {
  130. $(item).attr("audiourl", "");
  131. $(item).attr('audio-id', index);
  132. });
  133. //给视频图标处理
  134. $.each($(".videoImg"), function (index, item) {
  135. $(item).attr("audiourl", "");
  136. });
  137. //给口语图标处理
  138. $.each($(".oralLanguageImg"), function (index, item) {
  139. $(item).attr("audiourl", "");
  140. });
  141. //去除多余的U空标签
  142. $.each($("u"), function (index, item) {
  143. var text = $(item).text();
  144. text = text.replace(/\s+/g, "");
  145. if (text == "") {
  146. $(item).remove();
  147. }
  148. });
  149. //处理暂无参考答案
  150. $.each($(".yaoshi"), function (index, item) {
  151. var prev = $(item).nextAll(".underlineContent");
  152. if (prev.length == 0) {
  153. var uHtml = document.createElement("u");
  154. uHtml.className = "underlineContent no-answer";
  155. uHtml.innerText = "暂无参考答案";
  156. uHtml.setAttribute("data-text", uHtml.innerText);
  157. $(item).after(uHtml);
  158. }
  159. });
  160. //处理表格宽度
  161. $.each($(".wordTable"), function (index, item) {
  162. $(item).css("width", bodyWidth + "px");
  163. });
  164. //显示/隐藏习题答案
  165. $(".yaoshi").on("click", function () {
  166. if ($(this).data("status") == "0") {
  167. $(this).data("status", "1");
  168. $(this).attr("src", PicInfo.yaoshiShowImgUrl);
  169. $(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#92D050");
  170. }
  171. else {
  172. $(this).data("status", "0");
  173. $(this).attr("src", PicInfo.yaoshiHideImgUrl);
  174. $(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#ffffff");
  175. }
  176. });
  177. //点击喇叭事件,音频播放
  178. $(".audioImg").on("click", function () {
  179. audioPlayClick(this);
  180. });
  181. //点击播放事件,视频播放
  182. $(".videoImg").on("click", function () {
  183. $(this).attr("audiourl", "");
  184. var curHtml = $(this).parent().find(".videoUrl").html();
  185. var curAlt = $(this).attr("alt");//播放视频地址
  186. playVisiableAudioCallBack(2, $(this).attr("alt"));
  187. });
  188. //处理表格样式
  189. $("td").attr("style", "");
  190. //处理文章标题的样式(目前资料源已处理)
  191. //$("p").eq(2).addClass("p-title-top");
  192. }
  193. //获取所有作答答案及参考答案
  194. function getAllAnswer() {
  195. return answerData;
  196. }
  197. //学生端 处理作答区域
  198. var answerData = new Array();
  199. function handleAnswerRange() {
  200. //规范文本格式
  201. var answerId = "";
  202. var tempJson = new Array();
  203. $.each($(".yaoshi").nextUntil(".yaoshi").filter(".underline"), function (index, item) {
  204. tempId = $(item).prevAll(".yaoshi").attr("answer-id");
  205. //记录上一次的ID
  206. if (tempId == undefined) {
  207. tempId = answerId;
  208. }
  209. else {
  210. answerId = tempId;
  211. }
  212. var prev = $(item).prev();
  213. if ((prev.length == 0 || $(prev).attr("class") != "tag-span") && $(prev).attr("class") != "underlineContent") {
  214. if ($("span[answer-id='" + tempId + "']").length == 0) {
  215. $(item).prop("outerHTML", "<span answer-id='" + tempId + "' class='tag-span' answer-isky='0'>_</span>");
  216. }
  217. }
  218. $(item).remove();
  219. });
  220. //提取参考答案并规范文本格式
  221. answerId = "";
  222. $.each($(".yaoshi").nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
  223. var info = new Object();
  224. info.Id = $(item).prevAll(".yaoshi").attr("answer-id");
  225. //记录上一次的ID
  226. if (info.Id == undefined) {
  227. info.Id = answerId;
  228. }
  229. else {
  230. answerId = info.Id;
  231. }
  232. info.AnsText = $(item).text();
  233. tempJson.push(info);
  234. var prev = $(item).prev();
  235. if (prev.length == 0 || $(prev).attr("class") != "tag-span") {
  236. //替换答案
  237. $(item).prop("outerHTML", "<span answer-id='" + info.Id + "' class='tag-span' answer-isky='0'>_</span>");
  238. }
  239. else {
  240. $(item).remove();
  241. }
  242. });
  243. //补充空钥匙的处理
  244. $.each($(".yaoshi"), function (index, item) {
  245. var Id = $(item).attr("answer-id");
  246. var prev = $(item).next();
  247. if (prev.length == 0 || $(prev).attr("class") != "tag-span") {
  248. if ($("span[answer-id='" + Id + "']").length == 0) {
  249. var uHtml = document.createElement("span");
  250. uHtml.className = "tag-span";
  251. uHtml.innerText = "_";
  252. uHtml.setAttribute("answer-id", Id);
  253. $(item).after(uHtml);
  254. }
  255. }
  256. });
  257. //处理口语试题
  258. $.each($(".oralLanguage").nextUntil(".oralLanguageDone"), function (num, part) {
  259. if ($(part).hasClass("underlinePart")) {
  260. $.each($(part).find(".tag-span"), function (index, item) {
  261. $(item).attr("answer-isky", "1");
  262. });
  263. }
  264. });
  265. //合并参考答案数据
  266. var tempid = "";
  267. var temptext = "";
  268. for (var i = 0; i < tempJson.length; i++) {
  269. if (tempid == tempJson[i].Id) {
  270. temptext = temptext + tempJson[i].AnsText;
  271. }
  272. else {
  273. if (tempid != "") {
  274. var info = new Object();
  275. info.Id = tempid;
  276. info.AnsText = temptext;
  277. answerData.push(info);
  278. //重置
  279. tempid = "";
  280. temptext = "";
  281. }
  282. tempid = tempJson[i].Id;
  283. temptext = tempJson[i].AnsText;
  284. //最后一个存入
  285. if (i == tempJson.length - 1) {
  286. var info = new Object();
  287. info.Id = tempid;
  288. info.AnsText = temptext;
  289. answerData.push(info);
  290. }
  291. }
  292. }
  293. //补全答题点
  294. var Num = 0;
  295. if (answerData.length > 0) {
  296. //Num = Number.parseInt(answerData[answerData.length - 1].Id);
  297. Num = Number.parseInt($(".yaoshi:last").attr('answer-id'));
  298. for (var i = 0; i < Num+1; i++) {
  299. if (i < answerData.length) {
  300. var index = Number(answerData[i].Id) - i;
  301. for (var j = 0; j < index; j++) {
  302. var info = new Object();
  303. info.Id = (i + j).toString();
  304. info.AnsText = "";
  305. answerData.splice(i, 0, info);
  306. }
  307. }
  308. else {
  309. var info = new Object();
  310. info.Id = (i).toString();
  311. info.AnsText = "";
  312. answerData.splice(i, 0, info);
  313. }
  314. }
  315. }
  316. //添加答题点的点击UI及交互
  317. $.each($(".tag-span"), function (index, item) {
  318. var answerText = "";
  319. var isky = $(item).attr('answer-isky');
  320. var answerid = $(item).attr('answer-id');
  321. for (var i = 0; i < answerData.length; i++) {
  322. if (answerid == answerData[i].Id) {
  323. answerText = answerData[i].AnsText;
  324. break;
  325. }
  326. }
  327. $(item).prop("outerHTML", "<buttom answer-id='" + answerid + "' answer-anstext='" + answerText + "' answer-isky='" + isky + "' class='answertext btn-bgimg'>点击作答</buttom>");
  328. //删除钥匙节点
  329. var prev = $("img[answer-id='" + answerid + "']");
  330. if (prev.length > 0) {
  331. $(prev).remove();
  332. }
  333. });
  334. //添加点击事件
  335. $(".answertext").on("click", function () {
  336. var curObj = new Object();
  337. curObj.Id = $(this).attr("answer-id");//答题点ID
  338. curObj.IsKY = $(this).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  339. curObj.Text = $(this).attr("answer-text");//用户作答内容
  340. curObj.Score = $(this).attr("answer-score");//作答评分
  341. curObj.AnsText = $(this).attr("answer-anstext");//参考答案
  342. curObj.Comment = $(this).attr("answer-comment");//评语
  343. //已作答,弹出作答答案
  344. if ($(this).data("ans-status") == "1") {
  345. //移动端添加外部处理
  346. onClickAnswerPoint(JSON.stringify(curObj));
  347. }
  348. else {
  349. //移动端添加外部处理,弹出作答操作
  350. onClickAnswerPoint(JSON.stringify(curObj));
  351. }
  352. });
  353. //去除多余的空格横线
  354. $.each($(".underline"), function (index, item) {
  355. var text = $(item).text();
  356. text = text.replace(/\s+/g, "");
  357. if (text == "") {
  358. $(item).remove();
  359. }
  360. });
  361. return answerData;
  362. }
  363. //接收学生的作答
  364. function reviewAnswer(answerJson) {
  365. //测试数据
  366. //answerJson = "{\"AudioLength\":0,\"Id\":\"2\",\"Text\":\"i am how i know\",\"Type\":1}";
  367. //answerJson = "{\"AudioLength\":3,\"AudioUrl\":\"http://172.16.41.241:10103/http_TBookEditor51/exerciseAnswerAudio/2020-11-06_09-31-19.wav\",\"Id\":\"4\",\"Text\":\"i know how i know \",\"Type\":3}";
  368. if (answerJson != "" && answerJson) {
  369. var answerObj = JSON.parse(answerJson);
  370. var selectElement = $(".answertext[answer-id='" + answerObj.Id + "']");
  371. var audioElement = $(".btn-play[answer-id='" + answerObj.Id + "']>span");
  372. answerObj.IsKY = $(selectElement).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  373. //有内容时,要动态处理单词长度
  374. if (answerObj.Text != "") {
  375. $(selectElement).addClass("break-word");
  376. }
  377. else {
  378. $(selectElement).removeClass("break-word");
  379. }
  380. //是否是音频作答
  381. if ((answerObj.Type == 3 || answerObj.Type == 4) && answerObj.AudioUrl != "") {
  382. answerObj.Text = answerObj.Text == "" ? answerObj.Text : "(" + answerObj.Text + ")";
  383. $(selectElement).text(answerObj.Text);
  384. $(selectElement).attr("answer-text", answerObj.Text);//填充作答内容
  385. //移除作答样式
  386. if ($(selectElement).hasClass("btn-bgimg")) {
  387. $(selectElement).removeClass("btn-bgimg");
  388. }
  389. //是否之前存在作答音频
  390. if (audioElement.length > 0) {
  391. $(audioElement).text("作答音频(" + answerObj.AudioLength + "s)");
  392. $(audioElement).parent().attr("answer-url", answerObj.AudioUrl);
  393. }
  394. else {
  395. var divHtml = document.createElement("div");
  396. divHtml.className = "btn-play";
  397. divHtml.innerHTML = "<img src='file:///android_asset/js/play.png'/><span>作答音频(" + answerObj.AudioLength + "s)</span>";
  398. divHtml.setAttribute("answer-id", answerObj.Id);
  399. divHtml.setAttribute("answer-url", answerObj.AudioUrl);
  400. divHtml.setAttribute("play-status", "0");
  401. //增加节点
  402. $(selectElement).before(divHtml);
  403. //独立绑定事件
  404. $(selectElement).prev().children("img").on("click", function () {
  405. recordAudioClick(this, answerObj.Id, answerObj.AudioUrl);
  406. });
  407. $(selectElement).prev().children("span").on("click", function () {
  408. //移动端的修改
  409. onClickAnswerPoint(JSON.stringify(answerObj));
  410. });
  411. }
  412. }
  413. else {
  414. answerObj.Text = answerObj.Text == "" ? "点击作答" : answerObj.Text;
  415. $(selectElement).text(answerObj.Text);
  416. $(selectElement).attr("answer-text", answerObj.Text);//填充作答内容
  417. //之前作答存在音频,但是现在没有音频传入,要删除音频节点
  418. if (audioElement.length > 0) {
  419. $(".btn-play[answer-id='" + answerObj.Id + "']").unbind('click');
  420. $(".btn-play[answer-id='" + answerObj.Id + "']").remove();
  421. }
  422. //增加作答样式
  423. if (!$(selectElement).hasClass("btn-bgimg")) {
  424. $(selectElement).addClass("btn-bgimg");
  425. }
  426. }
  427. }
  428. }
  429. //提交,获取所有作答答案及参考答案
  430. function getAllAnswer1() {
  431. //处理作答
  432. $.each($(".answertext"), function (index, item) {
  433. var mytext = $(item).text();
  434. if (mytext == "点击作答") {
  435. mytext = "未作答";
  436. $(item).text(mytext);
  437. $(item).addClass("no-answer");
  438. }
  439. //移除作答样式
  440. if ($(item).hasClass("btn-bgimg")) {
  441. $(item).removeClass("btn-bgimg");
  442. }
  443. });
  444. $(".answertext").unbind('click');//取消点击绑定事件
  445. $(".btn-play>span").unbind('click');//取消点击绑定事件
  446. return answerData;
  447. }
  448. //回填所有答案,answerJson:所有作答及参考答案List,statusType:0-可作答,1-已提交,2-查看评阅
  449. function backupAllAnswer(answerJson, statusType) {
  450. if (answerJson != "" && answerJson) {
  451. var answerList = JSON.parse(answerJson);
  452. //answerList = JSON.parse(answerList);
  453. //获取Dom一个个回填
  454. $.each($(".answertext"), function (index, item) {
  455. //提交直接还原作答现场
  456. var mytext = answerList[index].Text;//我的答案
  457. answerList[index].IsKY = $(item).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  458. //有内容时,要动态处理单词长度
  459. if (mytext != "") {
  460. $(item).addClass("break-word");
  461. }
  462. //可作答状态,作答还原
  463. if (statusType == 0) {
  464. //已作答过,还原作答,增加作答后的UI节点
  465. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  466. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  467. $(item).text(mytext);
  468. $(item).attr("answer-text", mytext);//填充作答内容
  469. //移除作答样式
  470. if ($(item).hasClass("btn-bgimg")) {
  471. $(item).removeClass("btn-bgimg");
  472. }
  473. //添加音频节点
  474. var divHtml = document.createElement("div");
  475. divHtml.className = "btn-play";
  476. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  477. divHtml.setAttribute("answer-id", answerList[index].Id);
  478. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  479. divHtml.setAttribute("play-status", "0");
  480. //增加节点
  481. $(item).before(divHtml);
  482. //独立绑定事件
  483. $(item).prev().children("img").on("click", function () {
  484. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  485. });
  486. $(item).prev().children("span").on("click", function () {
  487. onClickAnswerPoint(JSON.stringify(answerList[index]));
  488. });
  489. }
  490. else {
  491. //文本作答
  492. mytext = mytext == "" ? "点击作答" : mytext;//我的答案
  493. $(item).text(mytext);
  494. $(item).attr("answer-text", mytext);//填充作答内容
  495. }
  496. }
  497. //已提交,作答还原
  498. if (statusType == 1) {
  499. $(item).unbind('click');//取消点击绑定事件
  500. //添加音频控制
  501. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  502. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  503. $(item).text(mytext);
  504. $(item).attr("answer-text", mytext);//填充作答内容
  505. //移除作答样式
  506. if ($(item).hasClass("btn-bgimg")) {
  507. $(item).removeClass("btn-bgimg");
  508. }
  509. //添加音频节点
  510. var divHtml = document.createElement("div");
  511. divHtml.className = "btn-play";
  512. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  513. divHtml.setAttribute("answer-id", answerList[index].Id);
  514. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  515. divHtml.setAttribute("play-status", "0");
  516. //增加节点
  517. $(item).before(divHtml);
  518. //独立绑定事件
  519. $(item).prev().children("img").on("click", function () {
  520. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  521. });
  522. }
  523. else {
  524. if (mytext == "") {
  525. mytext = "未作答";
  526. $(item).addClass("no-answer");
  527. //移除作答样式
  528. if ($(item).hasClass("btn-bgimg")) {
  529. $(item).removeClass("btn-bgimg");
  530. }
  531. }
  532. $(item).text(mytext);
  533. $(item).attr("answer-text", mytext);//填充作答内容
  534. }
  535. }
  536. //已评阅,查看评阅详情
  537. if (statusType == 2) {
  538. //添加音频控制
  539. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  540. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  541. $(item).text(mytext);
  542. $(item).attr("answer-text", mytext);//填充作答内容
  543. //添加音频节点
  544. var divHtml = document.createElement("div");
  545. divHtml.className = "btn-play";
  546. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  547. divHtml.setAttribute("answer-id", answerList[index].Id);
  548. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  549. divHtml.setAttribute("play-status", "0");
  550. //增加节点
  551. $(item).before(divHtml);
  552. //独立绑定事件
  553. $(item).prev().children("img").on("click", function () {
  554. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  555. });
  556. $(item).prev().children("span").on("click", function () {
  557. onClickAnswerPoint(JSON.stringify(answerList[index]));
  558. });
  559. }
  560. else {
  561. if (mytext == "") {
  562. mytext = "未作答";
  563. $(item).addClass("no-answer");
  564. }
  565. $(item).text(mytext);
  566. $(item).attr("answer-text", mytext);//填充作答内容
  567. }
  568. //评阅样式
  569. if (answerList[index].Score == 0 && answerList[index].Text != "") {
  570. $(item).addClass("bad-answer");
  571. }
  572. if (answerList[index].Score > 0) {
  573. $(item).addClass("good-answer");
  574. }
  575. //移除作答样式
  576. if ($(item).hasClass("btn-bgimg")) {
  577. $(item).removeClass("btn-bgimg");
  578. }
  579. }
  580. });
  581. }
  582. }
  583. //老师评阅学生作答
  584. function reviewStuAnswer(answerJson) {
  585. if (answerJson != "" && answerJson) {
  586. var answerObj = JSON.parse(answerJson);
  587. var selectElement = $(".answertext[answer-id='" + answerObj.Id + "']");
  588. //$(selectElement).attr("answer-text", answerObj.Text);//用户作答内容
  589. $(selectElement).attr("answer-score", answerObj.Score);//作答评分
  590. $(selectElement).attr("answer-anstext ", answerObj.AnsText);//参考答案
  591. $(selectElement).attr("answer-comment", answerObj.Comment);//评语
  592. //评阅样式
  593. if (answerObj.Score == 0) {
  594. $(selectElement).removeClass("good-answer");
  595. $(selectElement).addClass("bad-answer");
  596. }
  597. if (answerObj.Score > 0) {
  598. $(selectElement).removeClass("bad-answer");
  599. $(selectElement).addClass("good-answer");
  600. }
  601. }
  602. }
  603. //回填所有评阅信息,answerJson:所有作答及参考答案评阅信息List
  604. function backupAllReview(answerJson) {
  605. //测试数据
  606. //answerJson = "[{\"AudioLength\":11,\"AudioUrl\":\"http://172.16.41.241:10103/http_TBookEditor51/exerciseAnswerAudio/2020-11-10_11-18-54.mp3\",\"Id\":\"2\",\"Text\":\"\",\"Type\":3}]";
  607. if (answerJson != "" && answerJson) {
  608. var answerList = JSON.parse(answerJson);
  609. //answerList = JSON.parse(answerList);
  610. //获取Dom一个个回填
  611. $.each($(".answertext"), function (index, item) {
  612. //$(item).attr("answer-id", answerList[index].Id);//答题点ID
  613. //$(item).attr("answer-text", answerList[index].Text);//用户作答内容
  614. $(item).attr("answer-score", answerList[index].Score);//作答评分
  615. $(item).attr("answer-anstext ", answerList[index].AnsText);//参考答案
  616. $(item).attr("answer-comment", answerList[index].Comment);//评语
  617. //提交直接还原作答现场
  618. var mytext = answerList[index].Text;//我的答案
  619. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  620. mytext = mytext == "" ? mytext : "(" + mytext + ")";
  621. $(item).text(mytext);
  622. //添加音频节点
  623. var divHtml = document.createElement("div");
  624. divHtml.className = "btn-play";
  625. divHtml.innerHTML = "<img src='" + PicInfo.recordPlayImgUrl + "'/><span>作答音频(" + answerList[index].AudioLength + "s)</span>";
  626. divHtml.setAttribute("answer-id", answerList[index].Id);
  627. divHtml.setAttribute("answer-url", answerList[index].AudioUrl);
  628. divHtml.setAttribute("play-status", "0");
  629. //增加节点
  630. $(item).before(divHtml);
  631. //独立绑定事件
  632. $(item).prev().children("img").on("click", function () {
  633. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  634. });
  635. $(item).prev().children("span").on("click", function () {
  636. onClickAnswerPoint(JSON.stringify(answerList[index]));//移动端的修改
  637. });
  638. }
  639. else {
  640. if (mytext == "") {
  641. mytext = "未作答";
  642. $(item).addClass("no-answer");
  643. }
  644. $(item).text(mytext);
  645. }
  646. //评阅样式
  647. if (answerList[index].Score == 0) {
  648. $(item).addClass("bad-answer");
  649. }
  650. if (answerList[index].Score > 0) {
  651. $(item).addClass("good-answer");
  652. }
  653. //移除作答样式
  654. if ($(item).hasClass("btn-bgimg")) {
  655. $(item).removeClass("btn-bgimg");
  656. }
  657. });
  658. }
  659. }
  660. //处理播放录音,answerid:答题点ID,isPlay:是否播放(0-暂停,1-播放)
  661. function playRecordAudio(answerid, isPlay) {
  662. //获取其他正在播放的音频
  663. var playing = $(".btn-play[answer-id='" + answerid + "']");
  664. if (playing.length > 0) {
  665. if (isPlay == "1") {
  666. $(playing).attr("play-status", "1");
  667. $(playing).find("img").attr("src", PicInfo.recordPauseImgUrl);//移动端要根据本地路径替换
  668. }
  669. else {
  670. $(playing).attr("play-status", "0");
  671. $(playing).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  672. }
  673. }
  674. }
  675. //滚动到相应DIV
  676. function scrollAnswer(answerid) {
  677. $(".answertext").removeClass("select-answer");
  678. var ansDom = $(".answertext[answer-id='" + answerid + "']");
  679. $(ansDom).addClass("select-answer");
  680. var scroll_offset = $(ansDom).offset(); //得到box这个div层的offset,包含两个值,top和left
  681. $("body,html").animate({
  682. scrollTop: scroll_offset.top //让body的scrollTop等于pos的top,就实现了滚动
  683. });
  684. }
  685. //暂停播放原文音频
  686. function pauseTextAudio(audioid) {
  687. //获取其他正在播放的音频
  688. var playing = $(".audioImg[audio-id='" + audioid + "']");
  689. if (playing.length > 0) {
  690. $(playing).attr("play-status", "0");
  691. $(playing).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  692. }
  693. }
  694. //原文音频播放按钮点击事件
  695. function audioPlayClick(myobj) {
  696. var curHtml = $(myobj).parent().find(".audioUrl").html();
  697. var curAlt = $(myobj).attr("alt");
  698. //处理当前按钮的状
  699. if ($(myobj).attr("play-status") == "1") {
  700. $(myobj).attr("play-status", "0");
  701. $(myobj).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  702. }
  703. else {
  704. //停止其他作答音频播放
  705. var isRecordPlaying = $(".btn-play[play-status='1']");
  706. if (isRecordPlaying.length > 0) {
  707. $(isRecordPlaying).attr("play-status", "0");
  708. $(isRecordPlaying).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  709. }
  710. //停止其他原文音频播放
  711. var audioPlaying = $(".audioImg[play-status='1']");
  712. if (audioPlaying.length > 0) {
  713. $(audioPlaying).attr("play-status", "0");
  714. $(audioPlaying).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  715. }
  716. //设置播放状态
  717. $(myobj).attr("play-status", "1");
  718. $(myobj).attr("src", PicInfo.audioPlayImgUrl);//移动端要根据本地 喇叭 路径替换
  719. }
  720. var info = new Object();
  721. info.Id = $(myobj).attr("audio-id");
  722. info.AudioUrl = curAlt;
  723. //移动端添加外部处理
  724. playVisiableAudioCallBack(1, JSON.stringify(info));
  725. }
  726. //作答录音播放按钮点击事件
  727. function recordAudioClick(myobj, id, url) {
  728. //处理当前按钮的状态
  729. if ($(myobj).parent().attr("play-status") == "0") {
  730. //停止其他作答音频播放
  731. var isRecordPlaying = $(".btn-play[play-status='1']");
  732. if (isRecordPlaying.length > 0) {
  733. $(isRecordPlaying).attr("play-status", "0");
  734. $(isRecordPlaying).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  735. }
  736. //停止其他原文音频播放
  737. var audioPlaying = $(".audioImg[play-status='1']");
  738. if (audioPlaying.length > 0) {
  739. $(audioPlaying).attr("play-status", "0");
  740. $(audioPlaying).attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地 喇叭 路径替换
  741. }
  742. //设置播放状态
  743. $(myobj).parent().attr("play-status", "1");
  744. $(myobj).attr("src", PicInfo.recordPauseImgUrl);//移动端要根据本地路径替换
  745. }
  746. else {
  747. $(myobj).parent().attr("play-status", "0");
  748. $(myobj).attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  749. }
  750. //移动端添加外部处理,播放录音
  751. var info = new Object();
  752. info.Id = id;
  753. info.AudioUrl = url;
  754. //移动端添加外部处理,播放录音
  755. playVisiableAudioCallBack(3, JSON.stringify(info));
  756. }
  757. function playVisiableAudioCallBack(type, url) {
  758. cancelBubble();
  759. plugin.startPlay(type, url);
  760. }
  761. function onClickAnswerPoint(data) {
  762. //alert(JSON.stringify(data));
  763. cancelBubble();
  764. plugin.onClickAnswerPoint(data);
  765. }
  766. function cancelBubble(e) {
  767. var evt = e ? e : window.event;
  768. if(evt.stopPropagation) { //W3C
  769. evt.stopPropagation();
  770. } else { //IE
  771. evt.cancelBubble = true;
  772. }
  773. }