liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<apex:page standardController="FileAddress__c" extensions="ImgPreviewVFController" showHeader="false">
    <head>
        <apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
        <!-- <apex:includeScript value="{! URLFOR($Resource.AWSService, 'AWSService.js') }" /> -->
        <style type="text/css">
            img{
                max-width: 800px;
                max-height: 800px;
                height:auto;
                zoom:expression( function(e) {
                if(e.width>e.height) {if (e.width>128) { e.height = e.height*(128 /e.width); e.width=128; }}
                else {if (e.height>128) { e.width = e.width*(128 /e.height); e.height=128; }}
                e.style.zoom = '1';     }(this));
                overflow:hidden; 
            }
        </style>
        <script>
            window.onload = function(){ 
                var current = 0;
                document.getElementById('rotate').onclick = function(){
                    current = (current+90)%360;
                    this.style.transform = 'rotate('+current+'deg)';
                }
            };
            /* var staticResources = JSON.parse('{!staticResource}'); */
            /* var fileKey = '{!fileKey}'; */
            /* var fileName = '{!fileName}'; */
            var type = '{!type}';
            var hostUrl = '{!hostUrl}';
 
            /* var PARAMS = {};
            PARAMS.fileKey = fileKey; 
            PARAMS.fileName = fileName;
            PARAMS.token = staticResources.token;
            console.log('PARAMS = ' + JSON.stringify(PARAMS)); */
            setTimeout(function() {
                console.log('This is an anonymous function called after a delay.');
                if(type == 'preview'){
                    /* postAWS(hostUrl + '/api/file/cacheFileKey',PARAMS,'preview'); */
                    postAWS(hostUrl);
                }
            }, 3000);
            //调用AWS进行预览或下载
            /* function postAWS(url,PARAMS,preDown){ */
            function postAWS(url){
                debugger
                /* console.log('filekey = ' + PARAMS.fileKey);
                console.log('url = ' + url);
                var cacheType = 0;
                if(preDown == 'preview'){
                    cacheType = 1;
                }
                fetch(url, {
                    method: 'POST',
                    body: JSON.stringify({ 'fileKey': PARAMS.fileKey, "fileName": PARAMS.fileName, 'token': PARAMS.token,'cacheType':cacheType }),
                    headers: {
                        'Content-Type': 'application/json',
                        'pi-token': PARAMS.token
                    }
                }).then((data) => {
                    return data.json();
                }).then(result => {
                    console.log(result);
                    if(preDown == 'preview'){ */
                        /* //window.location.href = hostUrl + '/api/file/previewV3?key=' + result.object; */
                        var img = document.getElementsByTagName("img")[0];
                        /* var src = hostUrl + '/api/file/previewV3?key=' + result.object; */
                        var src = hostUrl;
                        /* console.log('src = ' + hostUrl + '/api/file/previewV3?key=' + result.object); */
                        console.log('src = ' + src);
                        img.src = src;
                        console.log('width = ' + img.style.width);
                        console.log('height = ' + img.style.height);
                    /* }
                }) */
            }
            
        </script>
    </head>
 
    <body id='body' style="text-align: center">
        <p style="font-size:20px">点击图片进行旋转</p>
        <img id ="rotate" src=""/>
    </body>
</apex:page>