From 8073fa3ddc967635ba77e51d3294654e831a4f44 Mon Sep 17 00:00:00 2001
From: unknown <sunxia@prec-tech.com>
Date: 星期三, 26 四月 2023 15:46:42 +0800
Subject: [PATCH] 备品出借 备品上传附件
---
force-app/main/default/pages/RentalApplyUploadPdf.page | 190 +++++++++++++++++++++++++++++++++++++++++++++++
force-app/main/default/pages/RentalApplyUploadPdf.page-meta.xml | 7 +
2 files changed, 197 insertions(+), 0 deletions(-)
diff --git a/force-app/main/default/pages/RentalApplyUploadPdf.page b/force-app/main/default/pages/RentalApplyUploadPdf.page
new file mode 100644
index 0000000..c749a53
--- /dev/null
+++ b/force-app/main/default/pages/RentalApplyUploadPdf.page
@@ -0,0 +1,190 @@
+<!-- 璇ラ〉闈㈢敤浜嶭ead瀵硅薄涓婁紶PDF锛屾湭鏉ュ鏋滆娣诲姞鍏朵粬瀵硅薄鐨勪笂浼燩DF鍔熻兘锛屽鍒惰椤甸潰锛屽皢**standardController**淇敼涓哄叾浠栧璞PI鍚嶇О鍗冲彲 -->
+<apex:page standardController="Rental_Apply__c" extensions="FileUploadController" id="page" lightningStyleSheets="true">
+ <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" />
+ <script>
+ var staticResources = JSON.parse('{!staticResource}');
+ var parentId = '{!parentId}';
+ var uploadUrl = staticResources.newUrl;
+ var key;
+
+ function alertErrorMessage(errorMsg) {
+ let errorMsgNode = document.getElementById("page:theForm:block:msgContent");
+ errorMsgNode.innerText = errorMsg;
+ errorMsgNode.className = 'message errorM3';
+ }
+
+ function hiddenErrorMsgNode() {
+ let errorMsgNode = document.getElementById("page:theForm:block:msgContent");
+ errorMsgNode.innerText = '';
+ errorMsgNode.className = '';
+ }
+ function getFileContent(event) {
+ var fileObject = document.getElementById("page:theForm:block:uploadSection:file");
+ var reader = new FileReader();
+ var data = reader.readAsDataURL(fileObject.files[0]);
+ debugger
+ console.log(event);
+ }
+ function getBase64(file) {
+ return new Promise((resolve, reject) => {
+ const reader = new FileReader();
+ reader.readAsDataURL(file);
+ reader.onload = () => resolve(reader.result);
+ reader.onerror = error => reject(error);
+ });
+ }
+ function disableButtonStatus() {
+ let btnNode = document.getElementById('uploadFileId');
+ btnNode.classList.add("btnDisabled");
+ }
+
+ function enableButtonStatus() {
+ let btnNode = document.getElementById('uploadFileId');
+ btnNode.classList.remove("btnDisabled");
+ }
+
+ function uploadFile() {
+ disableButtonStatus();
+ var fileObject = document.getElementById("file").files[0];
+ getBase64(fileObject).then(
+ data => {
+ console.log(data);
+ uploadFileToAWS(data, (fileObject.size).toString(), fileObject.name);
+
+ }
+ );
+ }
+ function confirmTrans(transId, isSuccess) {
+
+ fetch(staticResources.updateUrl, {
+ method: 'POST',
+ body: JSON.stringify({ 'txId': transId, "isSuccess": isSuccess }),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'pi-token': staticResources.token
+ }
+ }).then((data) => {
+ return data.json();
+ }).then(data => {
+ console.log("confirmTrans-" + JSON.stringify(data));
+ document.getElementById("file").files[0].name = '';
+ enableButtonStatus();
+ refreshFiles();
+ return data.status;
+ })
+
+ }
+ function calculateFileSize(fileObject) {
+ if (fileObject.size > 20971520) {
+ alertErrorMessage('鏂囦欢杩囧ぇ锛岃閫夋嫨灏忎簬20mb鐨勬枃浠�');
+ }
+ }
+ function uploadFileToAWS(data, size, fileName) {
+ console.log("body=" + JSON.stringify({ 'file': data, "size": size, 'fileName': fileName }));
+
+ fetch(uploadUrl, {
+ method: 'POST',
+ body: JSON.stringify({ 'file': data, "size": size, 'fileName': fileName }),
+ headers: {
+ 'Content-Type': 'application/json',
+ 'pi-token': staticResources.token
+ }
+ }).then((data) => {
+ return data.json();
+ }).then(result => {
+
+ console.log("result" + JSON.stringify(result));
+
+ if (result.success == true) {
+ key = result.object;
+
+ Visualforce.remoting.Manager.invokeAction(
+ '{!$RemoteAction.FileUploadController.saveFile}',
+ fileName, key, result.txId, parentId,
+ function (resultvalue, event) {
+
+
+
+ //2. show file list
+ if (resultvalue.status == 'fail') {
+ alertErrorMessage(resultvalue.message);
+ //1. Confirm trans
+ confirmTrans(result.txId, 0);
+ } else {
+ alertErrorMessage('涓婁紶鎴愬姛');
+ confirmTrans(result.txId, 1);
+ }
+
+ // window.location.reload();
+ },
+ { escape: true }
+ );
+
+ console.log('key' + key);
+ } else {
+ alertErrorMessage('涓婁紶澶辫触璇风◢鍚庡啀璇曪紒');
+ }
+ }).catch((error) => {
+ console.error('Error:', error);
+ })
+ debugger
+ }
+ function downPdf(fileUrl) {
+ window.open(fileUrl,'_blank');
+ }
+
+ </script>
+ <style>
+ .pdf .num {
+ width: 30%;
+ }
+
+ .pdf.name {
+ width: 30%
+ }
+
+ .pdf.downLink {
+ width: 40%
+ }
+ </style>
+ <apex:form id="theForm">
+ <apex:actionFunction name="refreshFiles" action="{!refreshFiles}" reRender="pdf,uploadSection"/>
+ <br/>
+ <br/>
+ <apex:pageBlock id="block">
+ <div style="text-align: center;">
+ <apex:outputPanel id="errorMsg">
+ <apex:pageMessages id="msgContent" escape="false" />
+ </apex:outputPanel>
+ </div>
+ <apex:pageBlockSection id="uploadSection">
+ <!-- <apex:inputFile id="file" value="{!documentData.body}" filename="{!documentData.name}" /> -->
+ <input type="file" id="file" name="filename"/>
+ <input class="btn" id='uploadFileId' type="Button" value="纭涓婁紶" onclick="uploadFile()" />
+ </apex:pageBlockSection>
+ </apex:pageBlock>
+ <apex:pageBlock title="PDF鍒楄〃" id="pdf">
+ <!-- <apex:pageBlockSection > -->
+ <!-- show uploated file list -->
+ <apex:pageBlockTable value="{!fileList}" var="file" align="center" columns="3" columnsWidth="30%,30%,40%">
+ <apex:column id="name" headerValue="鏂囦欢鍚嶇О">
+ <apex:outputLink value="/{!file.Id}" target="_blank">{!file.FileName__c}</apex:outputLink>
+ </apex:column>
+ <!-- <apex:column id="num" headerValue="鐖惰褰曢摼鎺�">
+ <apex:outputLink value="/{!file.ParentRecordId__c}" target="_blank">{!file.ParentRecordId__c}</apex:outputLink>
+ </apex:column> -->
+ <apex:column id="previewLink" headerValue="棰勮閾炬帴">
+ <apex:outputLink value="{!file.ViewLink__c}" target="{!file.ViewLink__c}">棰勮閾炬帴
+ </apex:outputLink>
+ </apex:column>
+ <apex:column id="downLink" headerValue="涓嬭浇閾炬帴">
+ <!-- <apex:outputLink value= "{!file.DownloadLink__c}" target="{!file.DownloadLink__c}">涓嬭浇閾炬帴
+ </apex:outputLink> -->
+ <input class="btn" id='downloadFileButton' type="Button" value="涓嬭浇" onclick="downPdf('{!file.DownloadLink__c}')" />
+ </apex:column>
+ </apex:pageBlockTable>
+ <!-- </apex:pageBlockSection> -->
+ </apex:pageBlock>
+ </apex:form>
+
+</apex:page>
\ No newline at end of file
diff --git a/force-app/main/default/pages/RentalApplyUploadPdf.page-meta.xml b/force-app/main/default/pages/RentalApplyUploadPdf.page-meta.xml
new file mode 100644
index 0000000..b5f6910
--- /dev/null
+++ b/force-app/main/default/pages/RentalApplyUploadPdf.page-meta.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
+ <apiVersion>52.0</apiVersion>
+ <availableInTouch>false</availableInTouch>
+ <confirmationTokenRequired>false</confirmationTokenRequired>
+ <label>RentalApplyUploadPdf</label>
+</ApexPage>
--
Gitblit v1.9.1