index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. $(function(){
  2. // let base = 'http://119.23.129.199:8100/'
  3. let base = '/'
  4. var stopClick = false
  5. $('#canvas').attr('width',$('#canvasWrap').width())
  6. $('#canvas').attr('height',$('#canvasWrap').height())
  7. init()
  8. $('#clear').click(function () {
  9. $('#clear').css('opacity',0)
  10. $('#result').html('')
  11. })
  12. $('#clsipt').click(function () {
  13. $('#input').val('')
  14. $('#clsipt').css('opacity',0)
  15. $('.search-page').show()
  16. $('.result-page').hide()
  17. })
  18. $('#input').on('input propertychange', function() {
  19. var count = $(this).val().length;
  20. $('#clsipt').css('opacity',count?1:0)
  21. });
  22. $('#search').click(function () {
  23. search()
  24. })
  25. $('#reload').click(function () {
  26. (window.clickReload) && window.clickReload();
  27. location.reload()
  28. })
  29. let startY = ''
  30. let lastY = ''
  31. let mMove = function (event) {
  32. event.stopPropagation()
  33. event.preventDefault()
  34. let deltaY = event.clientY - startY
  35. stopClick = true
  36. if (lastY == deltaY) {
  37. return
  38. }
  39. let de = document.documentElement.scrollTop||document.body.scrollTop
  40. dic = lastY>deltaY? 1:-1
  41. let to = de + dic * 15
  42. window.scrollTo(0,to)
  43. // lastY>deltaY?window.scrollTo(deltaY):'下'
  44. lastY = deltaY
  45. }
  46. $('.body').mousedown(function (e) {
  47. startY = e.clientY
  48. stopClick = false
  49. $('.body').mousemove(mMove)
  50. })
  51. $('.body').mouseup(function (e) {
  52. $('.body').off('mousemove',mMove)
  53. })
  54. function callbackfunc(ret){
  55. let html = ''
  56. ret.cand.forEach(item => {
  57. html+=`<li>${item}</li>`
  58. });
  59. $('#clear').css('opacity',1)
  60. $('#result').html(html)
  61. $('#result').undelegate()
  62. $('#result').delegate('li','click',function (e) {
  63. e.stopPropagation()
  64. e.preventDefault()
  65. let target = e.target
  66. $('#input').val($('#input').val() + $(target).text())
  67. $('#clsipt').css('opacity',1)
  68. $('#clear').click()
  69. })
  70. }
  71. function search() {
  72. let data = {
  73. id: '',
  74. name: $('#input').val(),
  75. }
  76. $.ajax({
  77. url: base + 'api/searchCollection',
  78. type: "POST",
  79. data: JSON.stringify(data),
  80. dataType: "json",
  81. contentType: "application/json;charset=utf-8",
  82. success: function (data) {
  83. if (data.code!=0) {
  84. return alert(data.msg)
  85. }
  86. $('.search-page').hide()
  87. if (data.data.length<=0) {
  88. $('.result-page').fadeIn()
  89. $('.result-page ul').hide()
  90. $('.no-result').fadeIn()
  91. }
  92. else{
  93. $('.no-result').hide()
  94. $('.result-page').fadeIn()
  95. $('.result-page ul').fadeIn()
  96. let html = ``
  97. data.data.forEach(item=>{
  98. html += `<li data-id="${item.id}">
  99. <img src="${item.pic}" data-id="${item.id}" alt="">
  100. <span data-id="${item.id}">${item.name}</span>
  101. </li>`
  102. })
  103. $('.result-page ul').html(html)
  104. let arr = Array.from(document.querySelectorAll(".result-page ul li"))
  105. arr.forEach(function(dom) {
  106. dom.addEventListener("mouseup", function(e) {
  107. let id = e.target.dataset.id
  108. setTimeout(function() {
  109. (window.resultCallback&&!stopClick) && window.resultCallback(parseInt(id));
  110. });
  111. $.ajax({
  112. url: base + 'api/addSearchNum',
  113. type: "POST",
  114. data: JSON.stringify({
  115. id:id
  116. }),
  117. dataType: "json",
  118. contentType: "application/json;charset=utf-8",
  119. success: function (data) {
  120. }
  121. });
  122. });
  123. });
  124. }
  125. }
  126. })
  127. }
  128. function init() {
  129. QQShuru.HWPanel({
  130. canvasId:"#canvas",
  131. lineColor:"#D7EBF9",
  132. clearBtnId:"#clear",
  133. callback:callbackfunc
  134. });
  135. }
  136. })