完成上传后处理来自 Array <BehaviorSubject 更新页面的返回

问题描述

如果可能,我想在完成上传后隐藏该项目并在完成后不久更新页面视图。我不想使用拉刷新来更新,我希望它是自动的 我必须记住,在同一页面上,我还有另一个列表,我也想在每次发送结束后更新它,所以我认为通过更新整个页面调用 ionViewWillEnter 会更容易,但我不知道该怎么做。

因此,每次上传完成后,发送列表中的项目将消失,服务器返回的列表将更新。

如果不可能,我想至少通过将最新的放在第一个位置来更改数组

服务:

private percent: Array<BehaviorSubject<{ id: string,aux: number,percent: string,name: string,date:string,savedId: string,status: number }>> = []

salvarMalote(payload){
    console.log(payload)
    
    var filePath = payload.imageURI;
    var filename = filePath.split("/").pop();
    var extencao = filename.split(".").pop();
    var paramsEnvio = {
      discclient: payload.discription,code: this.client.code,email:this.email,nameFile: filename,chaveappmury: this.date 
    }
    let params = JSON.stringify(paramsEnvio)
    console.log(paramsEnvio)
    console.log(params)
    let server
    var options : FileUploadOptions;

    server = 'my URL'
    //server = this.urlSPE + 'salvarMalote'
    options = {
    fileKey: "file",fileName: filename,chunkedMode: false,headers: {
        Connecection: "close"
    },params: {
        parametrosJson : params
    }
    }
    
    let id = Date.Now()
    //Verificação de progresso 

    this.fileTransfer.onProgress((progressEvent) => {
      let perc
      if (progressEvent.lengthComputable) {
          perc = Math.floor((progressEvent.loaded / progressEvent.total) * 100);
          this.setPorcentagem(perc,id,payload.discription,0)
      } else {
          perc++
      }
    });

    //upload

    console.log(filePath,server,options)

    return this.fileTransfer.upload(filePath,options).then((data) => {
        let returned = JSON.parse(data.response)
        if (retorno.sucesso) {
          let savedId = returned.return.id              //Terá valor apenas quando malote for salvo np servidor
          console.log('Id Malote Salov: ' + savedId)
          this.setPorcentagem(100,savedId,0)
        } else if (!retorno.sucesso) {
            console.log('erro')
            this.setPorcentagem(100,1)
            this.fileTransfer.abort()
        }
    },(error) => {
        console.log(error)
        this.setPorcentagem(100,1)
        this.fileTransfer.abort()
    });
  }

  //Metodos Observable

  setPorcentagem(perc,discription,status) {
    let dataEnv
    let percent;
    let aux;
    let already = this.percent.findindex(i => {
        return i.value.id == id
    })
    dataEnv = this.datePipe.transform(Date.Now(),'dd/MM/yyyy HH:mm')
    if (perc == 1) {
        percent = perc / 100
        aux = perc
        this.ref.tick();
    } else if (perc == 100) {
        percent = 0
        aux = 0
        this.ref.tick();
    } else {
        percent = perc / 100
        aux = perc
        this.ref.tick();
    }
    console.log(status)
    if (already != -1) {
        let value = this.percent[already].value;
        value.percent = percent;
        value.aux = aux;
        value.date = date,value.savedId = savedId
        value.status = status
        this.percent[already].next(value)
        this.ref.tick();
    } else {
        this.percent.push(new BehaviorSubject({ id: id,aux: aux,percent: percent,name: discription,date: date,savedId:savedId,status:status}))
    }
  }


  getPercentObservable(): Array<BehaviorSubject<{ id: string,percent: string }>> {
    return this.percent;
  }

HTML:

<ion-item *ngFor="let item of apiService.getPercentObservable()" (click)="detalharItem(item)">
    <ion-grid *ngIf="item|async">
      <ion-row>
        <ion-col size="6">
          <ion-label class="discription" text-wrap>{{item.value.name}}</ion-label>
        </ion-col>
        <ion-col></ion-col>
        <ion-col size="5">
          <ion-text class="hour" *ngIf="item.value.percent != 0">Uploading...</ion-text>
          <ion-progress-bar  type="indeterminate" class="hour" color="secondary" *ngIf="item.value.percent != 0"> </ion-progress-bar>
          <!-- <ion-progress-bar class="horario" color="secondary" [value]="item.value.porcentagem" *ngIf="item.value.porcentagem != 0"></ion-progress-bar> -->
          <ion-label class="discription"  *ngIf="item.value.percent == 0 && item.value.status == 0" text-wrap>{{item.value.date}}</ion-label>
          <ion-label *ngIf="item.value.status == 1"><ion-icon [src]="personalizado"></ion-icon></ion-label>
        </ion-col>
      </ion-row>
    </ion-grid>
  </ion-item>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)