tasklib_book.js 34 KB

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