index.js 3.8 KB

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