/* * @Description: * @version: * @Author: chen jing wu * @Date: 2023-12-04 10:55:42 * @LastEditors: chen jing wu * @LastEditTime: 2023-12-08 11:16:26 */ import { LightningElement, wire,api,track } from 'lwc'; import getFiles from '@salesforce/apex/MassFileDownloaderController.getFiles'; import searchFiles from '@salesforce/apex/MassFileDownloaderController.searchFiles'; const COLUMNS = [ { label: 'Title', fieldName: 'Id', type: 'url', typeAttributes: { label: { fieldName: 'Title' }, target : '_blank' } }, { label: 'Type', fieldName: 'FileExtension', type: 'text' }, { label: 'Owner', fieldName: 'Description', type: 'text' }, { label: 'CreatedDate', fieldName: 'CreatedDate', type: 'date' }, ]; const BASE_DOWNLOAD_PATH = '/sfc/servlet.shepherd/version/download'; export default class MassFileDownloader extends LightningElement { value = ""; offset = 0; columns = COLUMNS; @track files; connectedCallback(){ getFiles({ offset:this.offset }).then(result=>{ this.files = result; console.log(this.files); }); } downloadFiles() { let selectedFiles = this.files; if(selectedFiles.length === 0) { return; } this.initDownloading( this.getDownloadString(selectedFiles) ); } setSelect(event){ var index = event.target.name; this.files[index].isSelect = event.target.checked; } getDownloadString(files) { let downloadString = ''; files.forEach(item => { if(item.isSelect){ downloadString += '/' + item.con.LatestPublishedVersionId } }); return downloadString; } initDownloading(downloadString) { if(0 == downloadString.length){ return; } // alert(BASE_DOWNLOAD_PATH + downloadString); window.open(BASE_DOWNLOAD_PATH + downloadString, '_blank'); } cancel(){ if(this.offset >= 50){ this.offset = this.offset - 50; searchFiles({ title: this.value, offset: this.offset }).then(result=>{ this.files = result; }); } } next(){ this.offset = this.offset + 50; searchFiles({ title: this.value, offset: this.offset }).then(result=>{ this.files = result; }); } allSelect(event){ var value = event.target.checked; for(var i = 0;i < this.files.length;i++){ this.files[i].isSelect = value; } var elements = this.template.querySelectorAll('.options'); elements.forEach(element=>{ element.checked = value; }); console.log('123'); console.log(this.files); } search(event){ var element = this.template.querySelector('[data-id="search"]'); this.value = element.value; console.log(element); this.offset = 0; if(this.value){ searchFiles({ title: this.value, offset: 0 }).then(result=>{ this.files = result; }); }else{ getFiles({ offset:this.offset }).then(result=>{ this.files = result; console.log(this.files); }); } } }