ui.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. (function () {
  2. let baseUrl = '' //打包
  3. // let baseUrl = 'http://hnbwg.4dage.com' //本地测试
  4. let arr = []
  5. const getList = function (searchKey) {
  6. fetch(`${baseUrl}/api/show/goods/list`, {
  7. method: 'post',
  8. body: JSON.stringify({
  9. type: 'model',
  10. searchKey,
  11. pageSize:99999
  12. }),
  13. headers: {
  14. 'Content-Type': 'application/json'
  15. }
  16. }).then(res => res.text()) //请求得到的数据转换为text
  17. .then(res => {
  18. let ul = document.querySelector('.con');
  19. ul.innerHTML = ''
  20. let res2 = JSON.parse(res)
  21. arr = res2.data.records
  22. // 如果没有数据
  23. if (arr.length === 0) {
  24. $('.none').css({ opacity: 1, pointerEvents: 'auto' })
  25. } else {
  26. $('.none').css({ opacity: 0, pointerEvents: 'none' })
  27. let fragment = document.createDocumentFragment();
  28. arr.forEach(v => {
  29. let li = document.createElement('li');
  30. let divWrap = document.createElement('div');
  31. let a = document.createElement('a');
  32. let div = document.createElement('div');
  33. let p = document.createElement("p");
  34. divWrap.classList.add('case');
  35. a.classList.add('link-a');
  36. a.href = `Model.html?m=${v.fileName}`;
  37. div.classList.add('card-img');
  38. div.style = `background-image: url(${v.thumb})`;
  39. p.innerHTML = v.name;
  40. a.appendChild(div);
  41. divWrap.appendChild(a);
  42. li.appendChild(divWrap);
  43. li.appendChild(p);
  44. fragment.appendChild(li);
  45. })
  46. ul.appendChild(fragment);
  47. }
  48. })
  49. }
  50. getList('')
  51. $('.search').keyup(function (e) {
  52. if (e.key === 'Enter') {
  53. let txt = $('.myInp').val().trim()
  54. getList(txt)
  55. }
  56. })
  57. $('.searImg').click(function () {
  58. let txt = $('.myInp').val().trim()
  59. getList(txt)
  60. })
  61. })()