usent_ref.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. var _usent_buffer;
  2. class USentResult {
  3. constructor(filter = {}) {
  4. this.filter = filter;
  5. this.sentList = new Array();
  6. this.buffer = new Array();
  7. }
  8. pushSent(book, para, start, end) {
  9. for (const iterator of this.sentList) {
  10. if (
  11. iterator.book == book &&
  12. iterator.para == para &&
  13. iterator.start == start &&
  14. iterator.end == end
  15. ) {
  16. return;
  17. }
  18. }
  19. this.sentList.push({ book: book, para: para, start: start, end: end });
  20. }
  21. newSent(sent) {
  22. this.buffer.push(sent);
  23. }
  24. queryCallback(data, status) {
  25. switch (status) {
  26. case "success":
  27. try {
  28. let arrSent = JSON.parse(data);
  29. _usent_buffer = arrSent;
  30. } catch (e) {}
  31. break;
  32. case "":
  33. break;
  34. }
  35. }
  36. refresh() {
  37. $.post(
  38. "../usent/sent_query.php",
  39. {
  40. sent: JSON.stringify(this.sentList),
  41. filter: JSON.stringify(this.filter),
  42. },
  43. this.queryCallback
  44. );
  45. }
  46. getSentNum(book, para, start, end) {
  47. for (const iterator of _usent_buffer) {
  48. if (
  49. iterator.info.book == book &&
  50. iterator.info.para == para &&
  51. iterator.info.start == start &&
  52. iterator.info.end == end
  53. ) {
  54. return iterator.count;
  55. }
  56. }
  57. return 0;
  58. }
  59. getSentText(book, para, start, end, channal = 0) {
  60. for (const iterator of _usent_buffer) {
  61. if (
  62. iterator.info.book == book &&
  63. iterator.info.para == para &&
  64. iterator.info.start == start &&
  65. iterator.info.end == end
  66. ) {
  67. if (channal == 0) {
  68. return iterator.data;
  69. } else {
  70. for (const sent of iterator.data) {
  71. if (sent.channal == channal) {
  72. return sent;
  73. } else {
  74. return false;
  75. }
  76. }
  77. }
  78. }
  79. }
  80. return null;
  81. }
  82. }
  83. var _user_sent_buffer = new USentResult(); //数据库中的全部参考译文句子