homeStatic.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require('./../css/homeStatic.less');
  2. const $ = require("jquery");
  3. const {post, config,} = require('./promise.js');
  4. const {toggleWarnBox} = require('./util.js');
  5. let searchType = 0;
  6. require('./../images/staticBgS.png').replace(/^undefined/g, '')
  7. require('./../images/staticLogo.png').replace(/^undefined/g, '')
  8. require('./../images/staticBg.png').replace(/^undefined/g, '')
  9. require('./../images/word.png').replace(/^undefined/g, '')
  10. $(function(){
  11. getAllTypes()
  12. goSearchList()
  13. });
  14. //tab
  15. function renderTab(data){
  16. let str = '';
  17. for (let i = 0; i < data.length; i++) {
  18. const element = data[i];
  19. str += `<li class="${i==0?'tabFst':''}" data-id="${element.val}">${element.name}</li>`
  20. }
  21. $('.staticTopTab ul').html(str)
  22. $(".staticTopTab li").click(function(){
  23. searchType = $(this).attr('data-id')
  24. $(this).css({borderColor:'#fff'}).siblings().css({borderColor:'#2A9BD5'})
  25. })
  26. }
  27. //搜索跳转
  28. function goSearchList(){
  29. $(".searchBtn").click(function(){
  30. let vals = $('.searchStr').val().replace(/(^\s*)|(\s*$)/g, "")
  31. if (!vals) {
  32. $(".staticResult .loading").hide();
  33. toggleWarnBox('检索词不能为空!');
  34. return;
  35. }
  36. window.location.href = './searchStaticList.html?type='+searchType+'&inputStr='+vals
  37. })
  38. }
  39. //获取字典信息
  40. function getAllTypes(){
  41. const allTypes = localStorage.getItem('allTypes')&&JSON.parse(localStorage.getItem('allTypes'))||[];
  42. if(allTypes.length>0){
  43. renderTab(allTypes)
  44. return
  45. }
  46. post(config.dictionaryInfo, {}).then((res) => {
  47. const result = res.data
  48. if(result.code==='0'){
  49. const data = result.data[7]||[];
  50. localStorage.setItem('allTypes',JSON.stringify(data))
  51. renderTab(data)
  52. }
  53. })
  54. }
  55. $(function () {
  56. $(".warning-box .confirm,.warning-box .close").click(function () {
  57. toggleWarnBox();
  58. })
  59. });