let baseurl = window.location.protocol + "//" + window.location.host + "/en"; let rsa; $(function () { //初始化公钥 post("/ajax/getkey","", function (res){ rsa = new jsencrypt(); rsa.setpublickey(res.publickey) }) $(".submit").click(function (e) { const $input = $('#search-content'); const value = $input.val(); if(!value){ alert("please fill in") return } const menulistid = $input.attr("data-menu-list-id") const pagesize = $input.attr("data-page-size") getlist(value, menulistid, 1, pagesize) }) $('.yearbox-notice dd p').click(function (e) { e.stoppropagation(); const $input = $('#search-content'); const value = $input.val(); const menulistid = $input.attr("data-menu-list-id") const pagesize = $input.attr("data-page-size") getlist(value, menulistid, 1, pagesize, $(this).text()) }) $('.news_search-notice input').keyup(function (event) { if (event.keycode == 13) { const $input = $('#search-content'); const value = $input.val(); if(!value){ alert("please fill in") return } const menulistid = $input.attr("data-menu-list-id") const pagesize = $input.attr("data-page-size") const year = $('.yearbox-notice dt input').val(); getlist(value, menulistid, 1, pagesize, year) } event.stoppropagation(); }) $('.new_index input').keyup(function (event) { if (event.keycode == 13) { const $input = $('#search-content'); const value = $input.val(); if(!value){ alert("please fill in") return } const menulistid = $input.attr("data-menu-list-id") const pagesize = $input.attr("data-page-size") getlist(value, menulistid, 1, pagesize) } event.stoppropagation(); }) $(".form_button").click(function (e) { let data= { checkbox1: $(".checkbox1").val(), single1: $(".single1").val(), select1: $(".select1").val(), select2: $(".select2").val(), note1: $(".note1").val(), note2: $(".note2").val(), single2: $(".single2").val(), single3: $(".single3").val(), single4: $(".single4").val(), single5: $(".single5").val(), single6: $(".single6").val(), uuid: $('#img-code').attr("uuid"), code: $('.code').val(), file1: $('#previewfile').attr("href") } post("/ajax/report", data, function (response) { if(response.code && response.code == 500){ window.alert(response.msg); return } window.alert("提交成功!") }, function (err) { window.alert(err.msg) }) }) }) function getlist(queryvalue, menulistid, pagenum, pagesize, year){ let data = { queryvalue: queryvalue, menulistid: menulistid, pagenum: pagenum, pagesize: pagesize } if(menulistid == 333 || menulistid == 334){ if(year){ data.year = year }else{ const year = $('.yearbox-notice dt input').val() if(year){ data.year = year } } } post("/ajax/content/list", data, function (response) { let respdata = decrypt(response) if(data.year){ $('.yearbox-notice dt input').val(data.year); } $('#ajaxpagehtml').html(respdata.ajaxpagehtml) $('#ajaxlisthtml').html(respdata.ajaxlisthtml) imgratio(); }) } function post(url, data, successcallback, errorcallback) { newrequest(url, "post", encrypt(data), successcallback, errorcallback) } function uploadfile(url, data, successcallback, errorcallback) { newuploadrequest(url, "post", data, successcallback, errorcallback) } function newuploadrequest(url, type, data, successcallback, errorcallback) { $.ajax({ url: baseurl + url, type: type, data: data, processdata: false, // 不要对data进行序列化处理,因为我们在formdata中已经处理了 contenttype: false, success: successcallback, error: errorcallback }); } function encrypt(data){ if(!data){ return } const jsondata = json.stringify(data) const key = cryptojs.lib.wordarray.random(128 / 8); const keyhex = cryptojs.enc.hex.parse(key.tostring()); const ivhex = cryptojs.enc.utf8.parse("0000000000000000"); const enc = cryptojs.aes.encrypt(cryptojs.enc.utf8.parse(jsondata), keyhex, {iv: ivhex, mode: cryptojs.mode.cbc, padding: cryptojs.pad.pkcs7}) return { key: rsa.encrypt(key.tostring()), value: enc.tostring() }; } function newrequest(url, type, data, successcallback, errorcallback) { $.ajax({ contenttype: 'application/json', url: baseurl + url, type: type, data: json.stringify(data), success: successcallback, error: errorcallback }); } function decrypt(response){ const text = response.data.value const texthex = cryptojs.enc.base64.parse(text) const key = response.data.key1; const key2 = response.data.key2; const deckey = rsa.decrypt(key2.tostring()); const keyhex = cryptojs.enc.hex.parse(key); const ivhex = cryptojs.enc.utf8.parse("0000000000000000"); const decrypteddata = cryptojs.aes.decrypt({ ciphertext: texthex }, keyhex, { iv: ivhex, mode: cryptojs.mode.cbc, padding: cryptojs.pad.pkcs7 }); const dec = hexstringtoutf8string(decrypteddata.tostring()) return json.parse(dec); } function hexstringtoutf8string(hexstring) { const buffer = new arraybuffer(hexstring.length / 2); const view = new uint8array(buffer); for (let i = 0; i < hexstring.length; i += 2) { const hex = hexstring.substr(i, 2); view[i / 2] = parseint(hex, 16); } const decoder = new textdecoder('utf-8'); return decoder.decode(buffer); }