黄千龙
2023-03-08 962519811b7c4be07f30d09e791798b0ea79d3ae
force-app/main/default/aura/eSignHospitalPage/eSignHospitalPageHelper.js
@@ -869,45 +869,58 @@
            //用于判断上传同一个文件提示
            component.set("v.messageFlag",false);
            messageFlag = component.get("v.messageFlag");
            var action = component.get("c.saveChunk");
            action.setParams({
              parentId: component.get("v.parentId"),
              fileName: file.name,
              base64Data: encodeURIComponent(getchunk),
              contentType: file.type,
              fileId: attachId
            });
            // set call back
            action.setCallback(this, function(response) {
              // store the response / Attachment Id
              attachId = response.getReturnValue();
              //增加文件列表删除功能  精琢技术 thh 2021-09-02 start
              //关联附件ID和附件名
              var attachmentID = component.get("v.attachmentID");
              attachmentID[file.name] = attachId;
              component.set("v.attachmentID", attachmentID);
              //增加文件列表删除功能  精琢技术 thh 2021-09-02 end
              var state = response.getState();
              if (state === "SUCCESS") {
                // update the start position with end postion
            //zhj 不使用分批上传的功能,等该文件累计完成之后再上传到AWS然后存在sf的FileAddress__c start
            debugger
                startPosition = endPosition;
                endPosition = Math.min(
                  fileContents.length,
                  startPosition + this.CHUNK_SIZE
                );
                // check if the start postion is still less then end postion
                // then call again 'uploadInChunk' method ,
                // else, diaply alert msg and hide the loading spinner
                if (startPosition < endPosition) {
                  this.uploadInChunk(
                    component,
                    file,
                    fileContents,
                    startPosition,
                    endPosition,
                    attachId
                  );
                } else {
            // if (startPosition < endPosition) {
            //     this.uploadInChunk(
            //         component,
            //         file,
            //         fileContents,
            //         startPosition,
            //         endPosition,
            //         ''
            //     );
            // }
            let staticResource = component.get('v.staticResource');
            var reader = new FileReader();
            reader.readAsDataURL(file);
            var that = this;
            reader.onloadend = function(evt){
                if(evt.target.readyState == FileReader.DONE){
                    var base64value = evt.target.result;
                    var Base64 = {};
                    Base64.file = base64value;
                    Base64.fileName = file.name;
                    Base64.size = fileContents.length;
                    //调用AWS 保存文件v.staticResource
                    that.awsPushData(staticResource.newUrl,JSON.stringify(Base64), function(result){
                        console.log('result = ' + result);
                            if(result.status == '0'){
                                that.CallBackAction(component,'saveFile',{
                                    fileName: file.name,
                                    key : result.object,
                                    transId : result.txId,
                                    parentId: component.get("v.parentId")
                                },function(response){
                                    //增加文件列表删除功能  精琢技术 thh 2021-09-02 end
                                    var state = response.getState();
                                    if (state === "SUCCESS") {
                                        //执行trans方法,进行确认成功
                                        that.awsPushData(staticResource.updateUrl,JSON.stringify({ 'txId': result.txId, "isSuccess": 1 }), function(result){
                                            console('确认事务 =' + json.stringify(result));
                                        },staticResource.token,'POST');
                                        // store the response / Attachment Id
                                        attachId = response.getReturnValue();       //attachId改造之后变成了是File_Address__c的Id deloitte-zhj 2023-01-11
                                        //增加文件列表删除功能  精琢技术 thh 2021-09-02 start
                                        //关联附件ID和附件名
                                        var attachmentID = component.get("v.attachmentID");
                                        attachmentID[file.name] = attachId;
                                        component.set("v.attachmentID", attachmentID);
                  //判断上传文件内容 提示一次信息
                  var base = component.get("v.getchunk");
                  if(!base || (base&&base!=getchunk)){
@@ -975,7 +988,8 @@
                    }
                  }
                  //上传成功后文件列表的文件名变色  精琢技术 thh 2021-09-26 end
                }
                                    //}
                                    //zhj 不使用分批上传的功能,等该文件累计完成之后再上传到AWS然后存在sf的FileAddress__c end
                // handel the response errors
              } else if (state === "INCOMPLETE") {
                alert("From server: " + response.getReturnValue());
@@ -994,9 +1008,11 @@
                  console.log("Unknown error");
                }
              }
            });
            // enqueue the action
            $A.enqueueAction(action);
                                })
                            }
                    })
                }
            }
        }
@@ -1007,52 +1023,77 @@
    //用于判断上传同一个文件提示
    component.set("v.messageFlag",false);
    messageFlag = component.get("v.messageFlag");
    var action = component.get("c.saveChunk");
    action.setParams({
      parentId: component.get("v.parentId"),
      fileName: file.name,
      base64Data: encodeURIComponent(getchunk),
      contentType: file.type,
      fileId: attachId
    });
    // set call back
    action.setCallback(this, function(response) {
      // store the response / Attachment Id
      attachId = response.getReturnValue();
      //增加文件列表删除功能  精琢技术 thh 2021-09-02 start
      //关联附件ID和附件名
      var attachmentID = component.get("v.attachmentID");
      attachmentID[file.name] = attachId;
      component.set("v.attachmentID", attachmentID);
      //增加文件列表删除功能  精琢技术 thh 2021-09-02 end
      var state = response.getState();
      if (state === "SUCCESS") {
        // update the start position with end postion
    //zhj 不使用分批上传的功能,等该文件累计完成之后再上传到AWS然后存在sf的FileAddress__c start
    debugger
        startPosition = endPosition;
        endPosition = Math.min(
          fileContents.length,
          startPosition + this.CHUNK_SIZE
        );
        // check if the start postion is still less then end postion
        // then call again 'uploadInChunk' method ,
        // else, diaply alert msg and hide the loading spinner
        if (startPosition < endPosition) {
          this.uploadInChunk(
            component,
            file,
            fileContents,
            startPosition,
            endPosition,
            attachId
          );
        } else {
    // if (startPosition < endPosition) {
    //     this.uploadInChunk(
    //         component,
    //         file,
    //         fileContents,
    //         startPosition,
    //         endPosition,
    //         ''
    //     );
    // }
    let staticResource = component.get('v.staticResource');
    var reader = new FileReader();
    reader.readAsDataURL(file);
    var that = this;
    reader.onloadend = function(evt){
        if(evt.target.readyState == FileReader.DONE){
            var base64value = evt.target.result;
            var Base64 = {};
            Base64.file = base64value;
            Base64.fileName = file.name;
            Base64.size = fileContents.length;
            //调用AWS 保存文件v.staticResource
            that.awsPushData(staticResource.newUrl,JSON.stringify(Base64), function(result){
                console.log('result = ' + result);
                if(result.status == '0'){
                    //sf去保存
                    // var action = component.get("c.saveFile");
                    // action.setParams({
                    //     fileName: file.name,
                    //     key : result.object,
                    //     transId : result.txId,
                    //     parentId: component.get("v.parentId")
                    // });
                    that.CallBackAction(component,'saveFile',{
                        fileName: file.name,
                        key : result.object,
                        transId : result.txId,
                        parentId: component.get("v.parentId")
                    },function(response){
                    // });
                    // action.setCallback(that, function(response) {
                        //增加文件列表删除功能  精琢技术 thh 2021-09-02 end
                        var state = response.getState();
                        if (state === "SUCCESS") {
                            //执行trans方法,进行确认成功
                            that.awsPushData(staticResource.updateUrl,JSON.stringify({ 'txId': result.txId, "isSuccess": 1 }), function(result){
                                console('确认事务 =' + JSON.stringify(result));
                            },staticResource.token,'POST');
                            // store the response / Attachment Id
                            attachId = response.getReturnValue();       //attachId改造之后变成了是File_Address__c的Id deloitte-zhj 2023-01-11
                            //增加文件列表删除功能  精琢技术 thh 2021-09-02 start
                            //关联附件ID和附件名
                            var attachmentID = component.get("v.attachmentID");
                            attachmentID[file.name] = attachId;
                            component.set("v.attachmentID", attachmentID);
          //判断上传文件内容 提示一次信息
          var base = component.get("v.getchunk");
          if(!base || (base&&base!=getchunk)){
            // alert("您已经成功上传文件。");
            component.set("v.getchunk",getchunk );
          }
          alert("您已经成功上传文件。\n请点击提交后退出。");
          //用于提交按钮判断是否有已上传的文件
          component.set('v.IsUpLoad',true);
@@ -1113,12 +1154,13 @@
            }
          }
          //上传成功后文件列表的文件名变色  精琢技术 thh 2021-09-26 end
        }
                            //zhj 不使用分批上传的功能,等该文件累计完成之后再上传到AWS然后存在sf的FileAddress__c end
        // handel the response errors
      } else if (state === "INCOMPLETE") {
        alert("From server: " + response.getReturnValue());
        component.set("v.showLoadingSpinner", false);
        component.set("v.errorFlag", true);
      } else if (state === "ERROR") {
        var errors = response.getError();
        component.set("v.showLoadingSpinner", false);
@@ -1133,7 +1175,13 @@
      }
    });
    // enqueue the action
    $A.enqueueAction(action);
                    //$A.enqueueAction(action);
                }
            },staticResource.token,'POST');
        }else{
            alert('Could not read file');
        }
    }
    }else{
     if(messageFlag){
          alert("您已经上传过该文件了!")
@@ -1222,5 +1270,54 @@
    }
    
    return imgScale;
},
},CallBackAction  : function(component,action_name,para,callback) {  //调用后台方法 zhj 2022-01-03
    var action = component.get("c." + action_name.trimStart().replace("c.",""));
    if(para){
        action.setParams(para);
    }
    if(callback){
        action.setCallback(this,function(data){
            callback(data);
        });
    }
    $A.enqueueAction(action);
},trans : function (fileName,txId,isSuccess){       //确认事务 AWS zhj 2022-01-03
    let transParameters = {
        txId: txId,
        isSuccess: isSuccess
    };
    console.log('txId = ' + txId);
    AWSService.confirmTrans(staticResource.updateUrl,JSON.stringify(transParameters),function(result){
        console.log(fileName);
        console.log(JSON.stringify(result))
    },staticResource.token)
},awsPushData : function(destUrl, payloadForNewPI, callback, token,type) {  //确认事务 AWS zhj 2022-01-03
   console.log('enter '+type);
   let payloadstr= null;
   if (payloadForNewPI) {
       if (typeof payloadForNewPI == 'string') {
           payloadstr = payloadForNewPI;
       }else{
           payloadstr = JSON.stringify(payloadForNewPI);
       }
   }
   console.log(payloadstr);
   fetch(destUrl, {
        method: type,
        body: payloadstr,
        headers: {
            'Content-Type': 'application/json',
            'pi-token': token
        }
    }).then((data) => {
        return data.json();
    }).then((result) => {
        console.log(result);
        callback(result);
    }).catch(error => {
        console.log(error);
        callback(0);
    });
}
})