diff --git a/safesite/static/safesite/mystatic/js/conversion.js b/safesite/static/safesite/mystatic/js/conversion.js new file mode 100644 index 00000000..1d598b03 --- /dev/null +++ b/safesite/static/safesite/mystatic/js/conversion.js @@ -0,0 +1 @@ +"use strict";var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):window.imageConversion=t()}(function(){var t={};function e(t){return["image/png","image/jpeg","image/gif"].some(function(e){return e===t})}return t.urltoImage=function(t){return new Promise(function(e,a){var n=new Image;n.onload=function(){return e(n)},n.onerror=function(){return a(new Error("urltoImage(): Image failed to load, please check the image URL"))},n.src=t})},t.urltoBlob=function(t){return fetch(t).then(function(t){return t.blob()})},t.imagetoCanvas=async function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=document.createElement("canvas"),n=a.getContext("2d"),i=void 0,r=void 0;for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(e[o]=Number(e[o]));if(e.scale){var c=e.scale>0&&e.scale<10?e.scale:1;r=t.width*c,i=t.height*c}else r=e.width||e.height*t.width/t.height||t.width,i=e.height||e.width*t.height/t.width||t.height;switch([5,6,7,8].some(function(t){return t===e.orientation})?(a.height=r,a.width=i):(a.height=i,a.width=r),e.orientation){case 3:n.rotate(180*Math.PI/180),n.drawImage(t,-a.width,-a.height,a.width,a.height);break;case 6:n.rotate(90*Math.PI/180),n.drawImage(t,0,-a.width,a.height,a.width);break;case 8:n.rotate(270*Math.PI/180),n.drawImage(t,-a.height,0,a.height,a.width);break;case 2:n.translate(a.width,0),n.scale(-1,1),n.drawImage(t,0,0,a.width,a.height);break;case 4:n.translate(a.width,0),n.scale(-1,1),n.rotate(180*Math.PI/180),n.drawImage(t,-a.width,-a.height,a.width,a.height);break;case 5:n.translate(a.width,0),n.scale(-1,1),n.rotate(90*Math.PI/180),n.drawImage(t,0,-a.width,a.height,a.width);break;case 7:n.translate(a.width,0),n.scale(-1,1),n.rotate(270*Math.PI/180),n.drawImage(t,-a.height,0,a.height,a.width);break;default:n.drawImage(t,0,0,a.width,a.height)}return a},t.canvastoFile=function(t,e){var a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"image/jpeg";return new Promise(function(n){return t.toBlob(function(t){return n(t)},a,e)})},t.canvastoDataURL=async function(t,a,n){return e(n)||(n="image/jpeg"),t.toDataURL(n,a)},t.filetoDataURL=function(t){return new Promise(function(e){var a=new FileReader;a.onloadend=function(t){return e(t.target.result)},a.readAsDataURL(t)})},t.dataURLtoImage=function(t){return new Promise(function(e,a){var n=new Image;n.onload=function(){return e(n)},n.onerror=function(){return a(new Error("dataURLtoImage(): dataURL is illegal"))},n.src=t})},t.dataURLtoFile=async function(t,a){for(var n=t.split(","),i=n[0].match(/:(.*?);/)[1],r=atob(n[1]),o=r.length,c=new Uint8Array(o);o--;)c[o]=r.charCodeAt(o);return e(a)&&(i=a),new Blob([c],{type:i})},t.downloadFile=function(t,e){var a=document.createElement("a");a.href=window.URL.createObjectURL(t),a.download=e||Date.now().toString(36),document.body.appendChild(a);var n=document.createEvent("MouseEvents");n.initEvent("click",!1,!1),a.dispatchEvent(n),document.body.removeChild(a)},t.compress=async function(a){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(a instanceof Blob))throw new Error("compress(): First arg must be a Blob object or a File object.");if("object"!==(void 0===n?"undefined":_typeof(n))&&(n=Object.assign({quality:n})),n.quality=Number(n.quality),Number.isNaN(n.quality))return a;var i=await t.filetoDataURL(a),r=i.split(",")[0].match(/:(.*?);/)[1],o="image/jpeg";e(n.type)&&(o=n.type,r=n.type);var c=await t.dataURLtoImage(i),u=await t.imagetoCanvas(c,Object.assign({},n)),s=await t.canvastoDataURL(u,n.quality,o);return await t.dataURLtoFile(s,r)},t.compressAccurately=async function(a){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!(a instanceof Blob))throw new Error("compressAccurately(): First arg must be a Blob object or a File object.");if("object"!==(void 0===n?"undefined":_typeof(n))&&(n=Object.assign({size:n})),n.size=Number(n.size),Number.isNaN(n.size))return a;if(1024*n.size>a.size)return a;n.accuracy=Number(n.accuracy),(!n.accuracy||n.accuracy<.8||n.accuracy>.99)&&(n.accuracy=.95);var i=n.size*(2-n.accuracy)*1024,r=1024*n.size,o=n.size*n.accuracy*1024,c=await t.filetoDataURL(a),u=c.split(",")[0].match(/:(.*?);/)[1],s="image/jpeg";e(n.type)&&(s=n.type,u=n.type);for(var h=await t.dataURLtoImage(c),d=await t.imagetoCanvas(h,Object.assign({},n)),l=.5,f=void 0,g=[null,null],m=1;m<=7;m++){var w=.75*(f=await t.canvastoDataURL(d,l,s)).length;if(7===m){(iw)&&(f=[f].concat(g).filter(function(t){return t}).sort(function(t,e){return Math.abs(.75*t.length-r)-Math.abs(.75*e.length-r)})[0]);break}if(iw))break;g[0]=f,l+=.5**(m+1)}}var y=await t.dataURLtoFile(f,u);return y.size>a.size?a:y},t}); \ No newline at end of file diff --git a/safesite/static/safesite/mystatic/js/util.js b/safesite/static/safesite/mystatic/js/util.js index 35f76255..982a2f67 100644 --- a/safesite/static/safesite/mystatic/js/util.js +++ b/safesite/static/safesite/mystatic/js/util.js @@ -32,6 +32,17 @@ function canvasDataURL(path, obj, callback) { scale = w / h; w = obj.width || w; h = obj.height || (w / scale); + if(w <= h ){ + if(w>640){ + w = 640 + h = w/scale + } + }else{ + if(h>640){ + h=640 + w = h*scale + } + } var quality = 0.7; // 默认图片质量为0.7 //生成canvas var canvas = document.createElement('canvas'); @@ -45,9 +56,9 @@ function canvasDataURL(path, obj, callback) { canvas.setAttributeNode(anh); ctx.drawImage(that, 0, 0, w, h); // 图像质量 - if (obj.quality && obj.quality <= 1 && obj.quality > 0) { - quality = obj.quality; - } + // if (obj.quality && obj.quality <= 1 && obj.quality > 0) { + // quality = obj.quality; + // } // quality值越小,所绘制出的图像越模糊 var base64 = canvas.toDataURL('image/jpeg', quality); // 回调函数返回base64的值 @@ -62,7 +73,6 @@ function convertBase64UrlToBlob(urlData) { } return new Blob([u8arr], { type: mime }); } - //取消上传 function cancleUploadFile() { diff --git a/safesite/templates/accesstrouble.html b/safesite/templates/accesstrouble.html index 317c97f1..90c14740 100644 --- a/safesite/templates/accesstrouble.html +++ b/safesite/templates/accesstrouble.html @@ -301,7 +301,16 @@ $("#yhms").textbox('disable'); $('#fcyjdiv,#file2,#zgxq,#shyjdiv,#csyj,#reject').hide(); $('#jxpg').show(); $("#yhpg").combobox({ url: 'getdickey?dicclass=19&a=combobox', }); - $("#zgbm").combotree({ url: 'parthandle?a=tree3', onSelect: function (node) { $('#zgr').combobox({ url: 'getuser?partid=' + node.id + '&a=combobox', }); } }); + $("#zgbm").combotree({ url: 'parthandle?a=tree3', onSelect: function (node) { + $('#zgr').combobox({ + url: 'getuser?partid=' + node.id + '&a=combobox', + editable: false, + filter: function (q, row) { + var opts = $(this).combobox('options'); + return row[opts.textField].indexOf(q) >= 0;//这里改成>=即可在任意地方匹配 + }, + }); + } }); // if (data.yhpg__dickeyname != '' & data.yhpg__dickeyname != null) { // $("#yhpg").combobox('setValue', data.yhpg__dickeyid).combobox('readonly'); // $("#yhlx").combobox({ url: 'getdicclass?dicid=15' }).combobox('setValue', data.yhlx__dicid).combobox('readonly'); diff --git a/safesite/templates/addtrouble.html b/safesite/templates/addtrouble.html index 7e02d19d..0f3b607c 100644 --- a/safesite/templates/addtrouble.html +++ b/safesite/templates/addtrouble.html @@ -219,9 +219,7 @@ var form = new FormData(); if (fileObj.size / 1024 > 500) { //大于500k,进行压缩上传 $("#file").after('图片大于500k,正在压缩...'); - photoCompress(fileObj, { - quality: 0.2 - }, function (base64Codes) { + photoCompress(fileObj, {}, function (base64Codes) { //console.log("压缩后:" + base.length / 1024 + " " + base); var bl = convertBase64UrlToBlob(base64Codes); form.append("upfile", bl, fileObj.name); // 文件对象 @@ -310,9 +308,7 @@ var form = new FormData(); if (fileObj.size / 1024 > 500) { //大于500k,进行压缩上传 $("#file2").after('图片大于500k,正在压缩...'); - photoCompress(fileObj, { - quality: 0.2 - }, function (base64Codes) { + photoCompress(fileObj, {}, function (base64Codes) {//quality: 0.2 //console.log("压缩后:" + base.length / 1024 + " " + base); var bl = convertBase64UrlToBlob(base64Codes); form.append("upfile", bl, fileObj.name); // 文件对象 diff --git a/safesite/templates/main.html b/safesite/templates/main.html index 784daf6a..680a4ab7 100644 --- a/safesite/templates/main.html +++ b/safesite/templates/main.html @@ -263,7 +263,7 @@ float: left;">
-
@@ -326,6 +326,12 @@ float: left;">
+
+
+ +
+
+