123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- function ajax(options) {
- var options = options || {};
- options.type = (options.type || 'GET').toUpperCase();
- options.dataType = options.dataType || 'json';
- params = formatParams(options.data);
- //创建-第一步
- var xhr;
- //非IE6
- if (window.XMLHttpRequest) {
- xhr = new XMLHttpRequest();
- } else {
- //ie6及其以下版本浏览器
- xhr = ActiveXObject('Microsoft.XMLHTTP');
- }
- //接收-第三步
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4) {
- var status = xhr.status;
- if (status >= 200 && status < 300) {
- options.success && options.success(xhr.responseText, xhr.responseXML);
- } else {
- options.error && options.error(status);
- }
- }
- }
- //连接和发送-第二步
- if (options.type == 'GET') {
- xhr.open('GET', options.url + '?' + params, true);
- xhr.send(null);
- } else if (options.type == 'POST') {
- xhr.open('POST', options.url, true);
- //设置表单提交时的内容类型
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xhr.send(params);
- }else if (options.type == 'HEAD') {
- xhr.open('Head', options.url + '?' + params, true);
- xhr.send(null);
- }
- }
- //格式化参数
- function formatParams(data) {
- var arr = [];
- for (var name in data) {
- arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name]));
- }
- // arr.push(('v='+Math.random()).replace('.',''));
- return arr.join('&');
- }
- function OpenDwSource() {
- var host = "http://localhost:19882"
- var xsource = '<div style="width:300px;position: absolute;border:1px solid #dddddd;background: #eeeeee;left:0; right:0;top:89px;margin:auto;box-shadow:0 1px 5px rgb(0 0 0 / 5%);border-radius:6px;z-index:10000000;">';
- xsource += '<div id="xcanner-content" style="padding: 15px 20px 0px 20px;">';
- xsource += '<h4 style="margin:0px;">请选择扫描仪:</h4>';
- xsource += '<div id="xscanner-sourcelist">';
- xsource += '<ul style="background: #fff;list-style: none;margin:0px;padding:0px;border-left:2px solid #777777;border-top:2px solid #777777;">';
- xsource += '</ul></div>';
- xsource += '<div><button id="xscanner-confirm-btn" style="margin:10px 10px 20px 0px;min-width: 80px;">确定</button><button id="xscanner-cancel-btn" style="margin:10px 10px 20px 0px;min-width: 80px;">取消</button></div>';
- var sourcediv = document.createElement("div")
- sourcediv.id = "xscanner-model"
- sourcediv.innerHTML = xsource;
- document.getElementsByTagName("body")[0].appendChild(sourcediv)
- //
- ajax({
- url: host + '/xscanSourceList.aspx',
- type: 'get',
- dataType: 'json',
- data: {},
- success: function (response, xml) {
- var listr = ""
- JSON.parse(response).forEach((item, index) => {
- if (index == 0) {
- listr += "<li style='background:rgb(199, 222, 252);'>" + item + "</li>";
- } else {
- listr += "<li>" + item + "</li>";
- }
- })
- document.getElementById("xscanner-sourcelist").children[0].innerHTML = listr;
- },
- error: function (status) {
- //失败后执行的代码
- }
- });
- // 确定
- document.getElementById("xscanner-confirm-btn").addEventListener("click", function () {
- ajax({
- url: host + '/xscanAction.aspx',
- type: 'GET',
- dataType: 'json',
- data:{tid:123},
- success: function (response, xml) {
- if (response) {
- }
- },
- error: function (status) {
- //失败后执行的代码
- }
- });
- var last = null;
- var counter = "15982"
- var i = 0;
- var timer = window.setInterval(function () {
- i += 1
- var xscannercontainer = document.getElementById("XScannerContainer")
- xscannercontainer.style = "overflow:scroll;padding:10px 20px 20px 20px;"
- last = xscannercontainer.firstChild;
- ajax({
- url: host + '/xscanImgUri.aspx',
- type: 'GET',
- dataType: 'json',
- data: {t:new Date().getTime()},
- success: function (response, xml) {
- console.log(response)
- if (response) {
- response.split(",").forEach((item,index)=>{
- var img = document.createElement("img")
- img.src = host + "/xscanImgReview.aspx?imgid="+item
- img.style = "width:100%;margin-bottom:10px;"
- if (last) {
- xscannercontainer.insertBefore(img, last)
- } else {
- xscannercontainer.append(img)
- }
- })
- }
- },
- error: function (status) {
- //失败后执行的代码
- }
- });
- }, 1000)
- document.getElementById("xscanner-model").remove();
- })
- // 取消
- document.getElementById("xscanner-cancel-btn").addEventListener("click", function () {
- document.getElementById("xscanner-model").remove();
- })
- }
|