保誠-保戶業務員媒合平台
Tomas
2022-01-03 88fdbfab7ef87ff01938529454222895bf43513e
update: [editConsultantAvatar] add reset img button
修改1個檔案
59 ■■■■ 已變更過的檔案
PAMapp/components/editConsultantAvatar.vue 59 ●●●● 修補檔 | 檢視 | 原始 | 究查 | 歷程
PAMapp/components/editConsultantAvatar.vue
@@ -1,18 +1,29 @@
<template>
  <div>
     <el-avatar
        :size="150"
        :src="imgSrc"
        class="pam-avatar cursor--pointer fix-chrome-click--issue"
    ></el-avatar>
    <el-upload
      class="pam-avatar-uploader"
      action=""
      ref="upload"
      action="#"
      :auto-upload="false"
      :on-change="handleAvatarSuccess"
      :show-file-list="false">
      <div class="pam-avatar-uploader--title">更換大頭貼照</div>
      :show-file-list="false"
      accept="image/png, image/jpeg, image/jpg">
        <el-avatar
          :size="150"
          :src="imgSrc"
          class="pam-avatar cursor--pointer fix-chrome-click--issue"
        ></el-avatar>
        <div  class="pam-avatar-uploader__action-label mt-10 cursor--pointer" >設定相片</div>
    </el-upload>
      <div
        v-if="showResetAvatarBtn"
        class="pam-avatar-uploader__action-label text--center mt-10 cursor--pointer"
        @click="resetAvatar">
        取消上傳相片
      </div>
  </div>
</template>
@@ -25,13 +36,15 @@
  @Component
  export default class editConsultantAvatar extends Vue {
    @Prop({type:String, default:""})
    agentNo!:string;
    @PropSync('photoBase64',{type:String, default:""})
    syncPhotoBase64!:string;
    imgSrc:string='';
    _imgSrc: string = '';
    imgSrc: string='';
    //////////////////////////////////////////////////////////////////////
@@ -39,26 +52,30 @@
      if(this.agentNo) this.initConsultantAvatar()
    }
    //////////////////////////////////////////////////////////////////////
    initConsultantAvatar():void{
    initConsultantAvatar(): void {
      myConsultantService.getConsultantAvatar(this.agentNo)
      .then(base64=>
       this.splitbase64WithCommon(base64)
       this.splitBase64WithCommon(base64)
      )
    }
    handleAvatarSuccess(file:any, fileList:any) {
      const isFollowUploadRule =_.includes(file.raw.type,'image/');
      isFollowUploadRule ? this.getImgSrc(file) : this.showErrorMsg()
    }
    getImgSrc(file:any):void{
      const blob = file.raw;
      this.blobToBase64(blob).then(base64=>{
        this.splitbase64WithCommon(base64 as string);
        this.splitBase64WithCommon(base64 as string);
      });
    }
    //////////////////////////////////////////////////////////////////////
    resetAvatar(): void {
      this.imgSrc = this._imgSrc;
    }
    private blobToBase64(blob:File):Promise<string | ArrayBuffer | null> {
      return new Promise((resolve,reject) => {
@@ -70,9 +87,14 @@
      });
    }
    private splitbase64WithCommon(base64:string):void{
    private splitBase64WithCommon(base64: string): void {
      const splitBase64=_.split(base64, ','); // 為了把 data:image , base64 解析分開;
      this.syncPhotoBase64 = splitBase64[1];
      // NOTE: 因為目前以 agentNO 取得 avatar 會失敗,
      // 故加上此判斷來防範不預期顯示'取消按鈕'的狀況。 [Tomas, 2022/1/3]
      if (!this._imgSrc) {
        this._imgSrc = base64;
      }
      this.imgSrc = base64;
    }
@@ -88,6 +110,13 @@
          closeOnClickModal:false,
        });
    }
    get showResetAvatarBtn(): boolean {
      // NOTE: 因為目前以 agentNO 取得 avatar 會失敗,
      // 故加上此判斷來防範不預期顯示'取消按鈕'的狀況。 [Tomas, 2022/1/3]
      if (!this._imgSrc && !this.imgSrc) return false;
      return this._imgSrc !== this.imgSrc;
    }
  }
</script>