index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. type: 'POST',
  83. data: JSON.stringify(data),
  84. dataType: 'json',
  85. contentType: 'application/json;charset=utf-8',
  86. success: function (data) {
  87. if (data.code != 0) {
  88. return alert(data.msg)
  89. }
  90. $('.search-page').hide()
  91. if (data.data.length <= 0) {
  92. $('.result-page').fadeIn()
  93. $('.result-page ul').hide()
  94. $('.no-result').fadeIn()
  95. } else {
  96. $('.no-result').hide()
  97. $('.result-page').fadeIn()
  98. $('.result-page ul').fadeIn()
  99. let html = ``
  100. data.data.forEach(item => {
  101. html += `<li data-id="${item.id}">
  102. <img src="${item.pic}" data-id="${item.id}" alt="">
  103. <span data-id="${item.id}">${item.name}</span>
  104. </li>`
  105. })
  106. $('.result-page ul').html(html)
  107. let arr = Array.from(document.querySelectorAll('.result-page ul li'))
  108. arr.forEach(function (dom) {
  109. dom.addEventListener('mouseup', function (e) {
  110. let id = e.target.dataset.id
  111. setTimeout(function () {
  112. (window.resultCallback && !stopClick) && window.resultCallback(parseInt(id))
  113. })
  114. })
  115. })
  116. }
  117. }
  118. })
  119. }
  120. // function init () {
  121. // QQShuru.HWPanel({
  122. // canvasId: '#canvas',
  123. // lineColor: '#EA9649',
  124. // clearBtnId: '#clear',
  125. // callback: callbackfunc
  126. // })
  127. // }
  128. })