var num = 0 let arr = [{ id: 0, name: "故障记录", English: 'faultRecord' }, { id: 1, name: "故障案例", English: 'repairManual' }, { id: 2, name: "技术资料", English: 'article' }, ] $(function() { var storage = window.localStorage; let user = window.localStorage.getItem('user'); let userInfo = JSON.parse(user); let type = ''; var momEle = document.getElementById("search-box"); $('.search-type span').click((e) => { console.log(e.target.id) type = e.target.id; $('.search-type span').css({ color: 'black', // borderBottom: 'black' }); e.target.style.color = '#09c' // e.target.style.borderBottom = '1px solid #09c' }) $('#logOut').click(() => { const data = { id: userInfo.id }; $.ajax({ type: "post", url: urlBase + "api/common/login", async: true, data: JSON.stringify(data), success: res => { if (res.status == 0) { window.location.href = '../index.html'; } else { alert(res.msg); } }, error: xhr => { console.log(xhr) } }); }) $("input[id='add']").click(add); function add() { num++; var divEle = document.createElement("div"); divEle.setAttribute("class", "form"); divEle.setAttribute("id", `${num}`); var inner = '
' divEle.innerHTML = inner; // alert(divEle.innerHTML); if (num >= 4) { alert("最多四条") } else { momEle.appendChild(divEle); } } $("input[id='pop']").click(pop); function pop() { if (num != 0) { var current_dom = document.getElementById(`${num}`); momEle.removeChild(current_dom); num-- } else { alert('最少有一个字段') } } $('#searchBtn').click(() => { if ($('.searchInput').val() == "") {} else { $('.search-box').addClass('search-box-toLeft'); $('.search-data').css({ 'display': 'block' }); const data = { type: type, keyword: $('.searchInput').val() }; $.ajax({ type: "get", url: urlBase + "api/common/find", async: true, data: data, headers: { // token:"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxIn0.Oik3R7IxeUi9v9d0C7kvFd2gF_xSu4WjspKKeXy3dGw" token: sessionStorage.getItem('token') }, success: res => { if (res.status == 0) { $('.search-data-list').html(); let data = res.data; let str = ''; var name, path; let allData = []; for (var index in data) { for (var i = 0; i < data[index].length; i++) { cData = data[index]; if (index == 'repairManual') { name = cData[i].device_type; // console.log(name) } else if (index == 'faultRecord') { name = cData[i].device_name + cData[i].equipment_name + cData[i].fault_content; // console.log(name) } else if (index == 'article') { name = cData[i].keywords; // console.log(name) } var fileType; if (cData[i].file_path) { fileType = cData[i].file_path.split('.')[1]; path = urlBase + cData[i].file_path; } str += '
  • ' + name + '
  • ' // console.log(str) } } $('.search-data-list').html(str) } else { alert(res.msg); } }, error: xhr => { console.log(xhr) } }); } }); function getAll() { // $("#all").append($("