圖片和文件上傳js剖析

/**
* 商戶資質信息模塊js
*
* 涉及頁面組件 {
* 上傳組件(UploadFileComponent)
* }
*
*
* 初始化工具(init)
*
* @Author:Waver
*/
var qualificationInfoModule = (function() {

// 上傳文件類型
var UPLOAD_FILE_TYPE = {
BUSSINESS_LICENSE: 'BUSSINESS_LICENSE',
ORGANIZATION_CODE: 'ORGANIZATION_CODE',
TAX_REGISTRATION: 'TAX_REGISTRATION',
BANK_ACCOUNT_LICENCE: 'BANK_ACCOUNT_LICENCE',
ID_CARD_FRONT: 'ID_CARD_FRONT',
ID_CARD_BACK: 'ID_CARD_BACK',
PAYMENT_BUSINESS_LICENSE: 'PAYMENT_BUSINESS_LICENSE',
SHOP_PLACE: 'SHOP_PLACE',
SHOP_FRONT: 'SHOP_FRONT',
SHOP_CASHIER: 'SHOP_CASHIER',
APPLY: 'APPLY',
OPTIONAL: 'OPTIONAL'
}

var fileTypeMap = new Map([
[UPLOAD_FILE_TYPE.BUSSINESS_LICENSE , 'imgBusinessLicense'],
[UPLOAD_FILE_TYPE.ORGANIZATION_CODE , 'imgOrganizationCode'],
[UPLOAD_FILE_TYPE.TAX_REGISTRATION , 'imgTaxRegistration'],
[UPLOAD_FILE_TYPE.BANK_ACCOUNT_LICENCE , 'imgBankAccountLicence'],
[UPLOAD_FILE_TYPE.ID_CARD_FRONT , 'imgIdCardFront'],
[UPLOAD_FILE_TYPE.ID_CARD_BACK , 'imgIdCardBack'],
[UPLOAD_FILE_TYPE.PAYMENT_BUSINESS_LICENSE , ''],
[UPLOAD_FILE_TYPE.SHOP_PLACE , 'imgShopPlace'],
[UPLOAD_FILE_TYPE.SHOP_FRONT , 'imgShopFront'],
[UPLOAD_FILE_TYPE.SHOP_CASHIER , 'imgShopCashier'],
[UPLOAD_FILE_TYPE.APPLY , 'imgApply'],
[UPLOAD_FILE_TYPE.OPTIONAL , 'optional']
]);

var uploadFileComponentMap = new Map();
// 申請表資質上傳組件列表
var applyUploadFileComponent = new Array();
// 其他資質上傳組件列表
var optionalUploadFileComponent = new Array();

//ajaxuploadfile插件input[type='file']對應的id屬性的number
var uploadFileNum = 0
function UploadFileComponent(uploadFileDiv) {

var uploadFileObj = null;
// 上傳文件類型
var uploadFileType = null;
// 文件上傳后對應路徑的隱藏域ID
var filePathHiddenId = null;

+function(uploadFileDiv) {
uploadFileObj = $(uploadFileDiv);
uploadFileType = uploadFileObj.attr('file-type');
}(uploadFileDiv);

// 為上傳組件添加表單
var addForm = function() {
uploadFileNum ++
var text = '<form id="' + uploadFileObj.attr('file-type') + 'FORM" action="register/upload" enctype="multipart/form-data" method="post">'
+ '<input type="file" class="upload-file-input" id="uploadFile_'+uploadFileNum+'" name="uploadFile" aria-invalid="false">'
+ '<img src="" class="upload-img-file upload-file-show" data-src="" style="z-index: 999; display: none;">'
+ '<a class="delete-image-btn" style="display: none;"></a>'// 刪除按鈕
+ '<a class="change-image-btn" style="display: none;"></a>'// 點擊查看放大圖片
+ '<p class="validation-error"><p/>'
+ '</form>';
uploadFileObj.find('.upload-photo-name').after(text);

bind_change_event_for_file_input();

// 添加點擊刪除事件
bind_click_event_for_delete_btn();
return uploadFileNum
}

var bind_change_event_for_file_input = function() {
uploadFileObj.find('.upload-file-input').change(function() {
uploadFile(this);
});

// 點擊按鈕重新上傳文件(優化點3)
uploadFileObj.find('.change-image-btn').click(function(){
$(this).parent().find(".upload-file-input").attr("disabled",false)
$(this).parent().find(".upload-file-input").eq(0).trigger("click")
uploadFile(this.previousSibling.previousSibling.previousSibling);
});
}



// 上傳文件
var uploadFile = function(inputFileObj) {
console.log(inputFileObj.files[0].name.split(".")[inputFileObj.files[0].name.split(".").length-1])
if(inputFileObj.files[0] == undefined){
return;
}
// 只允許上傳jpg jpeg gif png類型的圖片
var pattern=/\.(pdf|jpg|jpeg|gif|png)$/;
//上傳 pdf,zip,rar
var patternTwo = /\.(pdf|zip|rar)$/
// 只允許上傳zip pdf文件
var patternThree = /\.(zip|rar)$/
if($(inputFileObj).next().attr("src") == "" || $(inputFileObj).next().attr("src") == "undefined"){
console.log($(inputFileObj).next().attr("src") == "")
}else{
console.log($(inputFileObj).next().attr("src") == "undefined")
}
if(pattern.test(inputFileObj.files[0].name) == false && patternTwo.test(inputFileObj.files[0].name) == false){// 上傳了非制定類型的圖片
$.alert({
title:"",
content:"文件格式錯誤,請重新選擇",
buttons:{
'確定':function(){
$("body").mLoading("hide");
}
}
});
return;
}

//在非資質信息區域上傳rar和zip文件
if(patternThree.test(inputFileObj.files[0].name) && !($(inputFileObj).parent().parent().parent().attr("file-type") == "OPTIONAL")){
console.log("只有資質照片才能上傳zip和rar")
YEEPAY.popTosure({
msg : "只有其他資質照片才可以傳zip或rar文件",
btnNumber: 'one'
})
}// 非圖片上傳和下載√
else if(patternTwo.test(inputFileObj.files[0].name)){
var qualificationType = uploadFileObj.attr('file-type');

var fileType = inputFileObj.files[0].name.split(".")[inputFileObj.files[0].name.split(".").length-1]

// 上傳文件前,禁用提交按鈕
if('CHAIN_HEAD_REGISTER' == opType) {
$('#submit_test').attr('disabled', true);
} else {
$('#registerSubmit').attr('disabled', true);
}

// 上傳非圖片(調用函數)
ajaxFileUpload(inputFileObj)
function ajaxFileUpload(inputFileObj){
$.ajaxFileUpload({
url:contextPath +"url",
type: "post",
data : {
fileType: fileType,
qualificationType: qualificationType || ""
},
dataType: 'json',
secureuri: false, //一StringToEnumConverterFactory般設置為false
fileElementId: $(inputFileObj).attr("id"), // 上傳文件的id屬性名
success: function(data, status){
console.log(data)
removeUploadFile();

if(fileType == "zip" || fileType == "rar"){
uploadFileObj.find('.upload-img-file').attr("data-src", data.filepath);
uploadFileObj.find('.upload-img-file').attr("src", contextPath + "/dist/images/zip.png");
}
if(fileType == "pdf"){
uploadFileObj.find('.upload-img-file').attr("data-src", data.filepath);
uploadFileObj.find('.upload-img-file').attr("src", contextPath + "/dist/images/pdf.png");
}

// 添加圖片路徑隱藏域(后臺需要)
$('#opRegisterForm').append('<input type="hidden" id="' + getFilePathHiddenId() + '" name="' + fileTypeMap.get(qualificationType) + '" value="' + data.filepath + '" />');


//顯示圖片 顯示button
uploadFileObj.find('.upload-img-file').show();
uploadFileObj.find('.delete-image-btn').show();
uploadFileObj.find('.change-image-btn').show();

//下載zip和pdf
var downFunc = uploadFileObj.find('.upload-img-file').click(function(){
var _this = this
var downObj = $(_this)
YEEPAY.popTosure()
$(".sureDownload").click(function(){
window.location.href = contextPath + 'url?fileRelativePath=' + downObj.attr("data-src")
})
});
//downFun = null

// 上傳文件成功后,恢復提交按鈕
if('CHAIN_HEAD_REGISTER' == opType) {
$('#submit_test').attr('disabled', false);
} else {
$('#registerSubmit').attr('disabled', false);
}
},
error: function(data, status, e){
alert(e);
// 上傳文件失敗后,恢復提交按鈕
if('CHAIN_HEAD_REGISTER' == opType) {
$('#submit_test').attr('disabled', false);
} else {
$('#registerSubmit').attr('disabled', false);
}
}
});
}
return
}
else {

//lrz實現本地壓縮后上傳圖片
lrz(inputFileObj.files[0], {width: 1024, quality: 0.8}).then(function (rst) {
sourceSize = toFixed2(inputFileObj.files[0].size / 1024);
resultSize = toFixed2(rst.fileLen / 1024);// fielLen返回的是文件的長度
scale = parseInt(100 - (resultSize / sourceSize * 100));
//alert(sourceSize+"->"+resultSize+",scale:"+scale);
var form = $(inputFileObj).parent();
//資質文件類型
var qualificationType = uploadFileObj.attr('file-type');
//上傳文件類型
var fileType = inputFileObj.files[0].name.split(".")[inputFileObj.files[0].name.split(".").length - 1]

// 上傳文件前,禁用提交按鈕
if('CHAIN_HEAD_REGISTER' == opType) {
$('#submit_test').attr('disabled', true);
} else {
$('#registerSubmit').attr('disabled', true);
}

Common.ajax(contextPath + 'url/register/uploadImg', 'POST',
{
fileData: rst.base64,
fileType: fileType,
qualificationType: qualificationType || ""
}, function (response) {
removeUploadFile()

//顯示縮略圖 換路徑
uploadFileObj.find('.upload-img-file').attr("src", rst.base64);//這里顯示的就是縮略圖
//顯示圖片 顯示button
uploadFileObj.find('.upload-img-file').show();
uploadFileObj.find('.delete-image-btn').show();
uploadFileObj.find('.change-image-btn').show();

// 這個是顯示大圖的
uploadFileObj.find('.upload-img-file').click(function () {
// 這個是彈出新窗口
window.open('url/showImage?filePath=' + response.filepath, '_blank', "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes,height=600,width=800");
});

// 添加圖片路徑隱藏域(后臺需要)
$('#opRegisterForm').append('<input type="hidden" id="' + getFilePathHiddenId() + '" name="' + fileTypeMap.get(qualificationType) + '" value="' + response.filepath + '" />');

// 禁用上傳功能(每次點擊都會調用這個方法,所以下次就仍舊可以上傳)
uploadFileObj.find('.upload-file-input').attr('disabled', true); // 點擊切換圖片

// 上傳文件成功后,恢復提交按鈕
if('CHAIN_HEAD_REGISTER' == opType) {
$('#submit_test').attr('disabled', false);
} else {
$('#registerSubmit').attr('disabled', false);
}
}, function () {
uploadFileObj.find('.upload-file-input').val('');
// 上傳文件失敗后,恢復提交按鈕
if('CHAIN_HEAD_REGISTER' == opType) {
$('#submit_test').attr('disabled', false);
} else {
$('#registerSubmit').attr('disabled', false);
}

$.alert({
title: "",
content: "圖片上傳失敗或超時,請重試",
buttons: {
'確定': function () {
$("body").mLoading("hide");
}
}
});
}, {
timeout: 180000,
async: true
});

return rst;
}).catch(function (err) {
// 處理失敗會執行
}).always(function () {
// 不管是成功失敗,都會執行
});
}
}


var toFixed2 = function(num) {
return parseFloat(+num.toFixed(2));
}

var getUploadFileType = function() {
return uploadFileType;
}

var setImage = function(imageFilePath) {

var uploadFileType = getOrigUploadFileType(imageFilePath);

if(!uploadFileType) {
return;
}

// 先刪除了一個,又添加了一個img
uploadFileObj.find('.upload-img-file').remove();

if(uploadFileType == 'pdf') {
uploadFileObj.find('.upload-file-input').after('<img src="' + contextPath + '/dist/images/pdf.png" class="upload-img-file upload-file-show" style="z-index: 999;">');
} else if(uploadFileType == 'zip' || uploadFileType == 'rar') {
uploadFileObj.find('.upload-file-input').after('<img src="' + contextPath + '/dist/images/zip.png" class="upload-img-file upload-file-show" style="z-index: 999;">');
} else {
uploadFileObj.find('.upload-file-input').after('<img src="' + imageFilePath + '" class="upload-img-file upload-file-show" style="z-index: 999;">');
}

// 顯示刪除按鈕
uploadFileObj.find('.delete-image-btn').show();
uploadFileObj.find('.change-image-btn').show();
}

// 獲取上傳文件類型
var getOrigUploadFileType = function(imageFilePath) {
if(!imageFilePath || imageFilePath.length == 0) {
return null;
}
var fileTypePos = imageFilePath.lastIndexOf('.');
if(fileTypePos > -1) {
return imageFilePath.substring(fileTypePos + 1);
} else {
return null;
}
}

// 是否支持下載
var isDownload = function(imageFilePath) {
var fileType = getOrigUploadFileType(imageFilePath);

if(!fileType) {
return false;
}

// pdf、zip、rar支持下載
var pattern = /^(pdf|zip|rar)$/;

return pattern.test(fileType);
}

// 禁用上傳功能
var disableUploading = function() {
uploadFileObj.find('.upload-file-input').attr('disabled', true);
}
//使用上傳功能
var enableUploading = function() {
//控制disable屬性
uploadFileObj.find('.upload-file-input').attr('disabled', false);
uploadFileObj.find('.upload-file-input').val('');
}

// 為刪除按鈕綁定click事件
var bind_click_event_for_delete_btn = function() {
uploadFileObj.find('.delete-image-btn').click(function() {
removeUploadFile();
});
}

// 刪除已經上傳的圖片
var removeUploadFile = function() {

var uploadFileHidden = $('#opRegisterForm').find('input[id="' + getFilePathHiddenId() + '"]');
var uploadFilePath;
if(uploadFileHidden) {
//獲取上傳文件路徑
uploadFilePath = uploadFileHidden.val();
// 刪除增加上傳文件路徑對應的hidden
uploadFileHidden.remove();
}

if(uploadFilePath) {
// 增加待刪除文件路徑對應的hidden
$('#opRegisterForm').append('<input type="hidden" name="delete_op_img" value="' + uploadFilePath + '">');
}
// 移除圖片顯示
removeImage();
// 啟用上傳功能
enableUploading();
}

var removeImage = function() {
uploadFileObj.find('.upload-img-file').hide();
uploadFileObj.find('.delete-image-btn').hide();
uploadFileObj.find('.change-image-btn').hide();
uploadFileObj.find('.upload-img-file').off('click',null)
}


var getFilePathHiddenId = function() {
return filePathHiddenId;
}

var setFilePathHiddenId = function(hiddenId) {
filePathHiddenId = hiddenId;
}

var getUploadFileObj = function() {
return uploadFileObj;
}


return {
addForm : addForm,
getUploadFileType : getUploadFileType,
setImage : setImage,
disableUploading : disableUploading,
getFilePathHiddenId : getFilePathHiddenId,
setFilePathHiddenId : setFilePathHiddenId,
getUploadFileObj : getUploadFileObj,
removeUploadFile : removeUploadFile,
getOrigUploadFileType : getOrigUploadFileType,
isDownload : isDownload
}
}



//
var getUploadFileComponentMap = function() {
return uploadFileComponentMap;
}

// 校驗必傳資質文件是否上傳
var validateUploadingFile = function() {

var result = true; // 校驗結果

$.each(UPLOAD_FILE_TYPE, function(key, value) {

if(UPLOAD_FILE_TYPE.BUSSINESS_LICENSE == value) {
// 檢查營業執照號是否填寫,如果填寫,營業執照資質必須上傳
if($('#businessLicence').val() != null && $('#businessLicence').val().trim() != '') {
if(!_validate(value)) {
result = false;
}
} else {
// 清除原有校驗提示信息
var uploadFileComponent = uploadFileComponentMap.get(value);
uploadFileComponent.getUploadFileObj().find('.validation-error').text('');
}
} else if(UPLOAD_FILE_TYPE.ORGANIZATION_CODE == value) {
// 檢查組織機構代碼證是否填寫,如果填寫,組織機構代碼證資質必須上傳
if($('#orgCode').val() != null && $('#orgCode').val().trim() != '') {
if(!_validate(value)) {
result = false;
}
} else {
// 清除原有校驗提示信息
var uploadFileComponent = uploadFileComponentMap.get(value);
uploadFileComponent.getUploadFileObj().find('.validation-error').text('');
}
} else if(UPLOAD_FILE_TYPE.TAX_REGISTRATION == value) {
// 檢查稅務登記證是否填寫,如果填寫,稅務登記證資質必須上傳
if($('#taxCode').val() != null && $('#taxCode').val().trim() != '') {
if(!_validate(value)) {
result = false;
}
} else {
// 清除原有校驗提示信息
var uploadFileComponent = uploadFileComponentMap.get(value);
uploadFileComponent.getUploadFileObj().find('.validation-error').text('');
}
} else if(UPLOAD_FILE_TYPE.ID_CARD_FRONT == value) {
if(!_validate(value)) {
result = false;
}
} else if(UPLOAD_FILE_TYPE.ID_CARD_BACK == value) {
if(!_validate(value)) {
result =false;
}
} else if(UPLOAD_FILE_TYPE.APPLY == value) {
if(!_validate(value)) {
result = false;
}
} else if(UPLOAD_FILE_TYPE.PAYMENT_BUSINESS_LICENSE == value) {
// 代理商類型為支付機構時,支付許可證必須上傳
if($('input[name="oPOperatorParam[\'agentType\']"]:checked').val()) {
if('AGENT_PAYMENT' == $('input[name="oPOperatorParam[\'agentType\']"]:checked').val()) {
if(!_validate(value)) {
result = false;
}
} else {
// 清除原有校驗提示信息
var uploadFileComponent = uploadFileComponentMap.get(value);
uploadFileComponent.getUploadFileObj().find('.validation-error').text('');
}
}
}

});

return result;
}

// 門店入網頁,校驗必傳資質文件是否上傳
var validateUploadingFileForChain = function() {

var result = true; // 校驗結果

$.each(UPLOAD_FILE_TYPE, function(key, value) {

if(UPLOAD_FILE_TYPE.APPLY == value) {
if(!_validate(value)) {
result = false;
}
}
});

return result;
}

var _validate = function(uploadFileType) {

var result = true; // 校驗結果

if(UPLOAD_FILE_TYPE.APPLY == uploadFileType) {// 上傳文件類型

var flag = true;

$.each(applyUploadFileComponent, function (index, component) {
var inputFileObj = component.getUploadFileObj().find('input[type=file]');

if($('#opRegisterForm').find('input[id=' + uploadFileType + '_' + (index + 1) +']')[0]) {
flag = false;
}
});

if(flag) {
applyUploadFileComponent[0].getUploadFileObj().find('.validation-error').text('請上傳文件!');
result = false;
} else {
applyUploadFileComponent[0].getUploadFileObj().find('.validation-error').text('');
}
} else if(UPLOAD_FILE_TYPE.OPTIONAL == uploadFileType) {

} else if(UPLOAD_FILE_TYPE.ID_CARD_FRONT == uploadFileType || UPLOAD_FILE_TYPE.ID_CARD_BACK == uploadFileType) {

var uploadFileComponent = uploadFileComponentMap.get(UPLOAD_FILE_TYPE.ID_CARD_FRONT);

if($('#opRegisterForm').find('input[id='+ UPLOAD_FILE_TYPE.ID_CARD_FRONT + ']')[0] || $('#opRegisterForm').find('input[id='+ UPLOAD_FILE_TYPE.ID_CARD_BACK + ']')[0]) {
// 清除校驗信息
uploadFileComponent.getUploadFileObj().find('.validation-error').text('');
} else {
// 提示校驗信息
uploadFileComponent.getUploadFileObj().find('.validation-error').text('請上傳文件!');
result = false;
}
}else {
var uploadFileComponent = uploadFileComponentMap.get(uploadFileType);

if($('#opRegisterForm').find('input[id='+ uploadFileType + ']')[0]) {
// 清除校驗信息
uploadFileComponent.getUploadFileObj().find('.validation-error').text('');
} else {
// 提示校驗信息
uploadFileComponent.getUploadFileObj().find('.validation-error').text('請上傳文件!');
result = false;
}
}

return result;
}

// 初始化組件
var init = (function() {
return {
initialize : function() {

uploadFileComponentMap.set(UPLOAD_FILE_TYPE.APPLY, applyUploadFileComponent);
uploadFileComponentMap.set(UPLOAD_FILE_TYPE.OPTIONAL, optionalUploadFileComponent);

$('.pic-module .upload-photo').each(function(index, uploadPhotoDiv) {
var uploadFileComponent = new UploadFileComponent(uploadPhotoDiv);
uploadFileComponent.addForm();

// 將上傳組件添加到map中
if(UPLOAD_FILE_TYPE.APPLY == uploadFileComponent.getUploadFileType()) {
applyUploadFileComponent.push(uploadFileComponent);
uploadFileComponent.setFilePathHiddenId(UPLOAD_FILE_TYPE.APPLY + '_' + applyUploadFileComponent.length);
} else if(UPLOAD_FILE_TYPE.OPTIONAL == uploadFileComponent.getUploadFileType()) {
optionalUploadFileComponent.push(uploadFileComponent);
uploadFileComponent.setFilePathHiddenId(UPLOAD_FILE_TYPE.OPTIONAL + '_' + optionalUploadFileComponent.length);
} else {
uploadFileComponentMap.set(uploadFileComponent.getUploadFileType(), uploadFileComponent);
uploadFileComponent.setFilePathHiddenId(uploadFileComponent.getUploadFileType());
}
});

// 添加按鈕綁定事件
$('.pic-module .add-upload-photo').each(function(index, addUploadPhotoLi) {
var fileType = $(addUploadPhotoLi).attr('file-type');
// 申請表資質信息添加按鈕事件
if(UPLOAD_FILE_TYPE.APPLY == fileType) {
$(addUploadPhotoLi).click(function() {
if(applyUploadFileComponent.length < 2) {
var text = '<li class="upload-photo" file-type="APPLY"><div class="upload-block">'
+ '<div class="upload-photo-name">'
+ '<span class="iconfont icon-tianjiatupian"></span>'
+ '<p>申請表</p></div></div></li>';

$(addUploadPhotoLi).before(text);

var uploadPhotoLi = $('.pic-module .apply-frame').find('.upload-photo:last');

var uploadFileComponent = new UploadFileComponent(uploadPhotoLi);
uploadFileComponent.addForm();

applyUploadFileComponent.push(uploadFileComponent);

uploadFileComponent.setFilePathHiddenId(UPLOAD_FILE_TYPE.APPLY + '_' + applyUploadFileComponent.length);
}
if (applyUploadFileComponent.length == 2) {
$(addUploadPhotoLi).hide();
}
});
// 其他資質信息添加按鈕事件
} else if(UPLOAD_FILE_TYPE.OPTIONAL == fileType) {
$(addUploadPhotoLi).click(function () {
if (optionalUploadFileComponent.length < 10) {
var text = '<li class="upload-photo" file-type="OPTIONAL"><div class="upload-block">'
+ '<div class="upload-photo-name">'
+ '<span class="iconfont icon-tianjiatupian"></span>'
+ '<p>其他</p></div></div></li>';

$(addUploadPhotoLi).before(text);

var uploadPhotoLi = $('.pic-module .optional-frame').find('.upload-photo:last');

var uploadFileComponent = new UploadFileComponent(uploadPhotoLi);
uploadFileComponent.addForm();

optionalUploadFileComponent.push(uploadFileComponent);

uploadFileComponent.setFilePathHiddenId(UPLOAD_FILE_TYPE.OPTIONAL + '_' + optionalUploadFileComponent.length);
}
if (optionalUploadFileComponent.length == 10) {
$(addUploadPhotoLi).hide();
}
});
}
});

// 加載已經上傳的資質圖片
if(initData.qualification) {

$.each(UPLOAD_FILE_TYPE, function(key, value) {

if(initData.qualification[value]) {

if (UPLOAD_FILE_TYPE.APPLY == value) { // 這個的應用信息
$.each(applyUploadFileComponent, function (index, component) {
if(initData.qualification[value][index]) {
component.setImage('url/showImage?filePath=' + initData.qualification[value][index]);
component.disableUploading();

var uploadFileObj = component.getUploadFileObj();

if(component.isDownload(initData.qualification[value][index])) {
uploadFileObj.find('.upload-img-file').click(function () {
window.location.href = contextPath + 'url/download?fileRelativePath=' + initData.qualification[value][index];
})
} else {
uploadFileObj.find('.upload-img-file').click(function () {
window.open('url/manage/showImage?filePath=' + initData.qualification[value][index], '_blank',"scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes,height=600,width=800");
})
}

// 添加圖片路徑隱藏域
$('#opRegisterForm').append('<input type="hidden" id="' + component.getFilePathHiddenId() + '" name="' + fileTypeMap.get(value) + '" value="' + initData.qualification[value][index] + '" />');
}
});
} else if (UPLOAD_FILE_TYPE.OPTIONAL == value) {// 這個是資質信息
$.each(optionalUploadFileComponent, function (index, component) {
if(initData.qualification[value][index]) {
component.setImage('url/merchant/manage/showImage?filePath=' + initData.qualification[value][index]);
component.disableUploading();


//$('.upload-file-show').click(function(){
// window.open('url/manage/showImage?filePath=' + initData.qualification[value][index], '_blank',"scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes,height=600,width=800");
//
//})

var uploadFileObj = component.getUploadFileObj();

if(component.isDownload(initData.qualification[value][index])) {
uploadFileObj.find('.upload-img-file').click(function () {
window.location.href = contextPath + 'url/download?fileRelativePath=' + initData.qualification[value][index];
})
} else {
uploadFileObj.find('.upload-img-file').click(function () {
window.open('url/merchant/manage/showImage?filePath=' + initData.qualification[value][index], '_blank',"scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes,height=600,width=800");
})
}

// 添加圖片路徑隱藏域
$('#opRegisterForm').append('<input type="hidden" id="' + component.getFilePathHiddenId() + '" name="' + fileTypeMap.get(value) + '" value="' + initData.qualification[value][index] + '" />');
}
});
} else {
// 得到對應的hidden的name值
//var hidden = fileTypeMap.get(fileType)
var uploadFileComponent = uploadFileComponentMap.get(value);
uploadFileComponent.setImage('url/showImage?filePath=' + initData.qualification[value]);
uploadFileComponent.disableUploading();

// 添加圖片路徑隱藏域
$('#opRegisterForm').append('<input type="hidden" id="' + uploadFileComponent.getFilePathHiddenId() + '" name="' + fileTypeMap.get(value) + '" value="' + initData.qualification[value] + '" />');
var uploadFileObj = uploadFileComponent.getUploadFileObj();

if(uploadFileComponent.isDownload(initData.qualification[value])) {
uploadFileObj.find('.upload-img-file').click(function () {
window.location.href = contextPath + 'url/register/download?fileRelativePath=' + initData.qualification[value];
})
} else {
uploadFileObj.find('.upload-img-file').click(function () {
window.open('url/merchant/manage/showImage?filePath=' + initData.qualification[value], '_blank', "scrollbars=yes,resizable=1,modal=false,alwaysRaised=yes,height=600,width=800");
})
}

}
}

});
}
}
}
})();

+function () {
init.initialize();
}();

return {
UPLOAD_FILE_TYPE : UPLOAD_FILE_TYPE,
validateUploadingFile : validateUploadingFile,
validateUploadingFileForChain : validateUploadingFileForChain,
getUploadFileComponentMap : getUploadFileComponentMap
}
})();


以上的js代碼實現了圖片的上傳,下載,點擊換圖和點擊查看大圖(實現方法是打開一個新頁面),重點應用了倆個jq插件lrz(用來上傳圖片)和ajaxuploadfile(上傳非圖片,具體上傳了rar,zip和pdf文件)插件
上傳圖片涉及的區域比較多,分類復雜,需要根據具體的頁面來進行理解,但是具體的邏輯是適用的,包含了初始化,validate插件的校驗。寫的比較糙,以后來完善

轉載于:https://www.cnblogs.com/wyliunan/p/7688187.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/370902.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/370902.shtml
英文地址,請注明出處:http://en.pswp.cn/news/370902.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

研究僵局–第1部分

我敢肯定我們都去過那里&#xff1a;太晚了&#xff0c;您餓了&#xff0c;服務器已掛起&#xff0c;或者應用程序正在以蝸牛的速度運行&#xff0c;并且有人喘著氣想要您解決問題&#xff0c;然后再去解決。 您的應用程序意外掛起的可能原因之一是稱為死鎖的線程問題。 無需贅…

前端的學習之旅

Html學習筆記1 特殊符號&#xff1a;html中對換行縮進空格不敏感&#xff0c;都只會解析成一個空格 空格&#xff1a; < : < > :$gt; 版權符號&#xff1a;&copy&#xff1b; 表格&#xff1a;1 表示表格&#xff1a;table表示表格 tr&#xff1a;…

使用Vue.js和Axios從第三方API獲取數據 — SitePoint

更多的往往不是&#xff0c;建立你的JavaScript應用程序時&#xff0c;你會想把數據從遠程源或消耗一個[ API ]&#xff08;https&#xff1a;/ /恩。維基百科。org /維基/ application_programming_interface&#xff09;。我最近看了一些[公開]&#xff08;https://github.co…

區位碼怎么知道點陣里的起始點_自身免疫疾病的GAPS起始飲食改良版

寫這篇文章的原因如果您已經關注我的博客一段時間&#xff0c;您知道我開始使用GAPS飲食&#xff0c;然后轉換到AIP飲食&#xff0c;因為我仍在努力治療炎癥和自身免疫的發作。 Katy Haldiman 有同樣的經歷&#xff0c;我們并不孤單。許多患有自身免疫性疾病的人在 GAPS 上掙扎…

Linux存儲保護,談談Linux中的存儲保護

談談Linux中的存儲保護以下討論的內容是以i386平臺為基礎的Linux將4G的地址劃分為用戶空間和內核空間兩部分。在Linux內核的低版本中(2。0。X)&#xff0c;通常0-3G為用戶空間&#xff0c;3G-4G為內核空間。這個分界點是可以可以改動的。正是這個分界點的存在&#xff0c;限制了…

004-JQuery屬性

添加與刪除屬性CSS類HTML代碼/文本/值添加與刪除屬性 attr(name|properties|key,value|fn) &#xff1a;設置或返回被選元素的屬性值 removeAttr(name) &#xff1a;從每一個匹配的元素中刪除name屬性 prop(name|properties|key,value|fn) &#xff1a;獲取在匹配的元素集中的第…

預熱您的JVM –超快速生產服務器和IDE

幾個月前&#xff0c;我正在閱讀Java中的復雜事件處理以及實現低延遲的方法。 在我長達一個小時的研究結束時&#xff0c;我發現即使您的應用程序編寫正確并且您的方法主要在0&#xff08;log n&#xff09;的時間內運行&#xff0c;并且您正在使用某些前沿的硬件解決方案&…

微信小程序APP(商超營銷類)經驗總結

項目介紹 這是一款主打門店營銷的小程序。包括首頁、門店、營銷、個人設置、登錄、數據統計展示、營銷設置等。 本來要獨立完成整個項目&#xff0c;包括前后端一套的&#xff0c;有些意外因素&#xff0c;項目臨時收尾&#xff08;說明&#xff1a;只完成了前端的部分&#…

excel不顯示0_Excel數字過長不能完整顯示?超長數字變為0

Excel中計算規則和限制設定數值精確度為15位&#xff01;超過15位后&#xff0c;數字會顯示為0excel數字超過15位&#xff0c;會顯示為0&#xff0c;超過10位&#xff0c;默認采用科學計數法顯示1、如何解決超長數字輸入&#xff0c;全部顯示問題&#xff1f;&#xff08;單元格…

Android天氣預報設計

——嵌入式軟件開發 名字功能模塊代碼行數備注謝燦輝Widget200桌面小程序李楊敏GPS定位&#xff0c;百度地圖API100-150獲取當前所在城市丁小芳城市選擇Activity&#xff0c;天氣API獲取天氣100-200包括數據庫交互本軟件是一個天氣類應用軟件&#xff0c;帶有widget&#xff0c…

linux vi后不保存退出,linux下退出VI的方法:不保存退出

當編輯完文件&#xff0c;準備退出Vi返回到shell時&#xff0c;可以使用以下幾種方法之一。在命令模式中&#xff0c;連按兩次大寫字母Z&#xff0c;若當前編輯的文件曾被修改過&#xff0c;則Vi保存該文件后退出&#xff0c;返回到shell&#xff1b;若當前編輯的文件沒被修改過…

算法筆記_164:算法提高 最小方差生成樹(Java)

目錄 1 問題描述 2 解決方案 1 問題描述 問題描述給定帶權無向圖&#xff0c;求出一顆方差最小的生成樹。輸入格式輸入多組測試數據。第一行為N,M&#xff0c;依次是點數和邊數。接下來M行&#xff0c;每行三個整數U,V,W&#xff0c;代表連接U,V的邊&#xff0c;和權值W。保證圖…

番石榴分配器vs StringUtils

因此&#xff0c;我最近寫了一篇有關舊的&#xff0c;可靠的Apache Commons StringUtils的文章 &#xff0c;該文章引起了一些評論&#xff0c;其中之一是Google Guava提供了更好的連接和拆分字符串的機制。 我必須承認&#xff0c;這是我尚未探索的番石榴的一個角落。 因此&am…

layui數據表格(一:基礎篇,數據展示、分頁組件、表格內嵌表單和圖片)

表格展示神器之一&#xff1a;layui表格 前言&#xff1a;在寫后臺管理系統中使用最多的就是表格數據展示了&#xff0c;使用表格組件能提高大量的開發效率&#xff0c;目前主流的數據表格組件有bootstrap table、layui table、easyUI table等.... 博主個人比較傾向于layui&am…

算法設計與分析_算法設計與分析(第2版)第2章分治策略回顧

YI時間&#xff5c;外刊&#xff5c;MM-DFW&#xff5c;機器學習系列點擊上方藍字&#xff0c;關注給你寫干貨的松子茶分治策略是通用算法設計技術之一&#xff0c;很多有效的算法是它的特殊實現,顧名思義就是分而治之。一個問題能夠用分治法求解的要素是問題能夠按照某種方式分…

2017-2018-1 Java演繹法 第三周 作業

團隊任務&#xff1a;團隊展示與選題團隊展示 隊員學號及姓名 學號  姓名  主要負責工作  20162315  馬軍  日常統計&#xff0c;項目部分代碼  20162316  劉誠昊  項目部分代碼&#xff0c;代碼質量測試  20162317  袁逸灝  組長 項目 主要 代碼  201…

linux開機啟動roscore,樹莓派ubuntuMate系統中開機自啟動ROS的launch文件

0x00 為何需要開機自啟動launch文件在ROS開發后期階段由于功能已經趨于穩定&#xff0c;因此就需要系統在一上電啟動后就自動把ROS下的各節點程序加載運行&#xff0c;這樣就省去了我們還得手動輸入roslaunch命令來加載bringup的launch文件的操作。經過我的實際測試目前有兩種方…

Oracle ADF移動世界! 你好!

您好&#xff0c;ADF Mobile&#xff0c;世界&#xff01; 您可能已經知道... ADF Mobile在這里&#xff01; 以下是一些鏈接&#xff0c;這些鏈接會讓您有賓至如歸的感覺。 ADF Mobile主頁&#xff1a; http://www.oracle.com/technetwork/developer-tools/adf/overview/ad…

Bootstrap里的文件分別代表什么意思及其引用方法

關于Bootstrap打包的文件分別代表什么意思&#xff0c;官網也沒有給出一個明確的解釋&#xff0c;在網上查了一些資料&#xff0c;總價歸納了如下&#xff1a; bootstrap/ <!--主目錄--> ├── css/ <!--CSS樣式文件--> │ ├── bootstrap.css <!…

css 小知識點:inline/inline-block/line-height

inline: 此元素會被顯示為內聯元素&#xff0c;元素前后沒有換行符。因此&#xff1a;無法設置寬度和高度&#xff5e; inline-block: 行內塊元素。元素前后沒有換行符&#xff08;CSS2.1 新增的值&#xff09; 用通俗的話講&#xff0c;就是不獨占一行的塊級元素。然后擁有…