很基礎(chǔ)的js(es6)啊~

數(shù)組轉(zhuǎn)成字符串 join(',')

let Arry= ['待簽收', '已簽收', '已退回', '未簽收', '已發(fā)送', '簽收中', '被退回', '以辦結(jié)', '已經(jīng)撤回']
let strName = ' '
retrun strName  = Arry.join(',')
//待簽收,已簽收,已退回,未簽收,已發(fā)送,簽收中,被退回,以辦結(jié),已經(jīng)撤回


處理ie問題要做的兼容

場(chǎng)景:上傳組件在ie的時(shí)候 會(huì)有點(diǎn)擊穿透的效果。 做法就是干掉默認(rèn)事件

        /* 處理ie 點(diǎn)擊查看會(huì)調(diào)上傳文件的問題  */
        if(!!window.ActiveXObject || "ActiveXObject" in window){
          console.log('這家伙是IE啊')
          window.event.cancelBubble = true
        }


格式化時(shí)間

場(chǎng)景:后臺(tái)傳給你的時(shí)間戳 你要做對(duì)應(yīng)的業(yè)務(wù)處理 例如當(dāng)天時(shí)間要顯示當(dāng)天。 (剛剛,之前多少分鐘前發(fā)送一樣的原理)
image.png

代碼如下(rawTime目的時(shí)間,sysTime當(dāng)前時(shí)間):

    /*格式化時(shí)間*/
    getCustomTime(rawTime, sysTime){
      if (!rawTime) {
        return "";
      }
      sysTime = sysTime || unifiedOfficeLib.moment.formatTime(Date.now(), "YYYY-MM-DD hh:mm");
      let timeInfo = "";
      let tempRawTime = rawTime.split(" ");
      let tempSysTime = sysTime.split(" ");
      if (tempRawTime.length !== 2 && tempSysTime.length !== 2) {
        return "";
      }
      /*同一天*/
      if (tempRawTime[0] === tempSysTime[0]) {
        timeInfo = "今天" + tempRawTime[1].substring(0, 5);
      } else {
        let year = tempRawTime[0].substring(0, 4);
        let month = tempRawTime[0].substring(5, 7);
        let day = tempRawTime[0].substring(8, 10);
        /*非同一年*/
        if (year < tempSysTime[0].substring(0, 4)) {
          timeInfo = tempRawTime[0].replace(/-/g, "/");
        } else {
          timeInfo = Number(month) + "月" + Number(day) + "日";
        }
      }
      return timeInfo;
    }


上傳文件vue的插件 vue-upload-web 再有一些簡(jiǎn)單上傳前的處理; 效果如下:(ps它喵的什么產(chǎn)品 偏要上傳也能拖拉拽功能,氣死人。花里胡哨)

image.png

dom:

      <vue-upload-web
        :url="uploadUrl"
        :upload-button="uploadBtn"
        :accept="docAccept"
        :formData="formData"
        @success="handleIEUpDocSuccess"
        @before="beforeDocUpload"
        @error="handleError"
        @complete="handleComplete"
      ></vue-upload-web>

js:

      /**@augments file 待上傳的正文文件對(duì)象
       * @description 正文上傳前執(zhí)行,檢查文件類型,若不符合則進(jìn)行提示,正文支持pdf/txt/doc/docx四種文件類型,文件大小不能超過40M
       */
      beforeDocUpload(file) {
        let {name, size} = file;
        // 驗(yàn)證size
        if (size / 1014 / 1024 > 40) {
          this.docErrMsg = '上傳的文件不要超過40M';
          this.docUpDirty = true;
          return false;
        }
        let arr = name.split(".");
        let arrLen = arr.length
        let formatStr = (arr[arrLen - 1]).toLowerCase()
        if (
          arr.length < 2 ||
          ["pdf", "txt", "doc", "docx", 'ofd'].indexOf(formatStr) === -1
        ) {
          this.docErrMsg = '正文只支持pdf、txt、doc、docx、ofd等格式,請(qǐng)重新上傳';
          this.docUpDirty = true;
          return false;
        }
        this.docUpDirty = false;
        return true;
      },


上傳文件之后名稱需求處理

場(chǎng)景:檢查附件是否可以查看,如果為zip,ofd和rar則只能下載(wps 不支持閱讀的東西)
dom就走 v-if="checkPreview(doc_name)"


image.png
    /**@augments name 文件名
     * @description 檢查附件是否可以查看,如果為zip和rar則只能下載
     */

    checkPreview(name) {
      let nameLength = name.split('.').length
      if (['zip', 'rar', 'ofd'].indexOf(name.split('.')[nameLength - 1]) !== -1) {
        return false
      }
      return true
    }


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容