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
import { LightningElement, api } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import  lexUploadCss from '@salesforce/resourceUrl/lexUploadCss';
import {loadStyle} from 'lightning/platformResourceLoader';
export default class lexUplodTest extends LightningElement {
    @api myRecordId;
    returnUrl;
    get acceptedFormats() {
        return ['.pdf', '.png','.*'];
    }
    connectedCallback() { 
        Promise.all([
            loadStyle(this, lexUploadCss)
        ]);
        var queryParams = new URLSearchParams(window.location.search); 
        const param1 = queryParams.get('backgroundContext');
        this.returnUrl=param1;
        this.myRecordId=queryParams.get('0.recordId');
        console.log(queryParams.get('0.recordId'));
        console.log(this.returnUrl);
        const up = this.template.querySelectorAll('lightning-file-upload');
        if (up) {
            up.forEach(field => {
                console.log(field.value);
            });
        }
        console.log(up);
        // const deleteText = fileUploadEl[0].querySelectorAll('.slds-file-selector__text');
        // deleteText[0].style.display = 'none';
        // debugger
    }
    handleUploadFinished(event) {
        // debugger
        const uploadedFiles = event.detail.files;
        if (uploadedFiles.length) {
            let fileNames="";
            uploadedFiles.forEach(file => {fileNames+=file.name+";";} );
            const event = new ShowToastEvent({
                title: '上传成功!',
                message:"已上传附件:"+fileNames,
                variant:'success'
            });
            this.dispatchEvent(event);
        }
        // debugger
    }
    doIt(){
        // window.location.replace(this.returnUrl);
        if(this.returnUrl!=null&&this.returnUrl!=''){
            console.log("returnUrl:");
            console.log(this.returnUrl);
            window.location.replace(''+this.returnUrl);
        }else{
            console.log('no url');
            console.log(this.returnUrl);
            // window.history.back();
            console.log(window.history.length);
            if(window.history.length>1){
                window.history.back();
            }else{
                window.close();
            }
            // window.close();
        }
 
    }
 
}