chapter_channel.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. //获取章节的channel列表
  2. /*
  3. param
  4. {
  5. book:book,
  6. para:para,
  7. target:target,
  8. topchannel:[1,2,3],
  9. showchannel:[1,2,3]
  10. }
  11. */
  12. function loadChapterChannel(param){
  13. $.getJSON(
  14. "/api/v2/progress?view=chapter_channels",
  15. {
  16. book: param.book,
  17. par: param.para,
  18. },
  19. function (data, status) {
  20. let arrChannelList = data.data.rows;
  21. if(typeof param.readonly != "undefined" && param.readonly == true){
  22. $(param.target).html(render_chapter_progress_list_readonly(arrChannelList,param));
  23. }else{
  24. $(param.target).html(render_chapter_progress_list(arrChannelList,param));
  25. Like();
  26. }
  27. }
  28. );
  29. }
  30. //章节已经有译文的channel 列表
  31. function render_chapter_progress_list(chapterList,param) {
  32. let html = "";
  33. html += "<ul class='chapter_info_list'>";
  34. for (const iterator of chapterList) {
  35. if(iterator.channel){
  36. if(param.showchannel){
  37. if(!param.showchannel.includes(iterator.channel.uid)){
  38. continue;
  39. }
  40. }
  41. html += "<li>";
  42. html += "<span class='channel_name' style='flex:2;'>";
  43. html += "<a href='../article/?view=chapter&book="+iterator.book+"&par="+iterator.para+"&channel="+iterator.channel.uid+"' target='_blanck'>";
  44. html += iterator.channel.name;
  45. html += "</a>";
  46. html += "</span>";
  47. html += "<span class='progress_bar'>";
  48. html += renderProgressBar(iterator.progress);
  49. html += "</span>";
  50. html += "<span class='views' >";
  51. html += iterator.views;
  52. html += "</span>";
  53. html += "<span class='likes' style='flex:5;'>";
  54. html += renderChannelLikes(iterator.likes,'progress_chapter',iterator.uid);
  55. html += "</span>";
  56. html += "<span class='updated_at' title='"+iterator.updated_at+"' >";
  57. html += getPassDataTime(new Date(iterator.updated_at));
  58. html += "</span>";
  59. html += "</li>";
  60. }
  61. }
  62. html += "</ul>";
  63. return html;
  64. }
  65. function render_chapter_progress_list_readonly(chapterList,param) {
  66. let html = "";
  67. html += "<ul class='chapter_info_list'>";
  68. html += "<li>";
  69. html += "<span class='channel_name' >版本</span>";
  70. html += "<span class='progress_bar' >进度</span>";
  71. html += "<span class='views' >阅读</span>";
  72. html += "<span class='likes' >点赞</span>";
  73. html += "<span class='updated_at' >更新于</span>";
  74. html += "</li>";
  75. for (const iterator of chapterList) {
  76. if(iterator.channel){
  77. if(param.showchannel){
  78. if(!param.showchannel.includes(iterator.channel.uid)){
  79. continue;
  80. }
  81. }
  82. html += "<li>";
  83. html += "<span class='channel_name' style='flex:3;'>";
  84. html += "<a href='../article/?view=chapter&book="+iterator.book+"&par="+iterator.para+"&channel="+iterator.channel.uid+"' target='_blanck'>";
  85. html += iterator.channel.name;
  86. html += "</a>";
  87. html += "</span>";
  88. html += "<span class='progress_bar'>";
  89. html += renderProgressBar(iterator.progress);
  90. html += "</span>";
  91. html += "<span class='views' >";
  92. html += iterator.views;
  93. html += "</span>";
  94. html += "<span class='likes' >";
  95. html += getChapterLikeCount(iterator.likes,'like');
  96. html += "</span>";
  97. html += "<span class='updated_at' title='"+iterator.updated_at+"' >";
  98. html += getPassDataTime(new Date(iterator.updated_at));
  99. html += "</span>";
  100. html += "</li>";
  101. }
  102. }
  103. html += "</ul>";
  104. return html;
  105. }
  106. function getChapterLikeCount(info,likeType){
  107. for (const item of info) {
  108. if(item.type==likeType){
  109. return item.count;
  110. }
  111. }
  112. return 0;
  113. }
  114. function renderChannelLikes(info,restype,resid){
  115. /*
  116. 点赞 like
  117. 收藏 favorite
  118. 关注 watch
  119. 书签 bookmark
  120. */
  121. let like_types = ["like",'favorite',"watch"];
  122. let html = "";
  123. for (const typs of like_types) {
  124. html += "<like ";
  125. html +="liketype='"+typs+"' ";
  126. let count = 0;
  127. for (const item of info) {
  128. if(item.type==typs){
  129. count = item.count;
  130. if(item.selected){
  131. html +=" mine='"+item.selected+"' ";
  132. }
  133. }
  134. }
  135. html +="count='"+count+"' ";
  136. html +="restype='"+restype+"' ";
  137. html += "resid='"+resid+"' ";
  138. html += ">"+count+"</like>";
  139. }
  140. return html;
  141. }
  142. function renderProgressBar(progress){
  143. let html = "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 100 25'>";
  144. let resulte = Math.round(progress*100);
  145. let clipPathId = "ClipPath_"+com_uuid();
  146. html += "<rect id='frontground' x='0' y='0' width='100' height='25' fill='#cccccc' ></rect>";
  147. html += "<text id='bg_text' x='5' y='19' fill='#006600' style='font-size:20px;'>"+resulte+"%</text>";
  148. html += "<rect id='background' x='0' y='0' width='100' height='25' fill='#006600' clip-path='url(#"+clipPathId+")'></rect>";
  149. html += "<text id='bg_text' x='5' y='19' fill='#ffffff' style='font-size:20px;' clip-path='url(#"+clipPathId+")'>"+resulte+"%</text>";
  150. html += "<clipPath id='"+clipPathId+"'>";
  151. html += " <rect x='0' y='0' width='"+resulte+"' height='25'></rect>";
  152. html += "</clipPath>";
  153. html += "</svg>";
  154. return html;
  155. }