js vue node工作笔记

js 和 es6 简单优雅的异步

    /* 要删除的人员列表 */
     let retList = [ {
            "user_id": "xuvbrjpk9c77c7h21wf4o9",
            "party_id": "282870841081858"
        },
        {
            "user_id": "hf07qz0rydi5m6px3mwfr6",
            "party_id": "281878703636481"
        },
        {
            "user_id": "ziz4io2vy41ic4wg6ttnm5",
            "party_id": "284326834995200"
        }] 

      let callArray = [];
      retList.forEach(item => {
        callArray.push((async () => {
          await Admin.del(item.party_id, item.user_id);
        })());
      });
      await Promise.all(callArray);


反向筛选数组 适合处理后端同学传来的数组

       let retList = [{"name": "Li", "age": "12"},{"name": "Zhang", "age": "18"},{"name": "Wang", "age": "26"}]
      let existAdmins = [{"name": "Li", "age": "12"}]
      //过滤掉已存在的项   retList数组,existAdmins数组2
      let ArryList = retList.filter((item) => {
        let exist = existAdmins.find((existItem) => {
          return existItem.name == item.name && existItem.age == item.age;
        });
        return !exist;
      });
     console.log(ArryList); 
     // [ {name: "Zhang", age: "18"},{name: "Wang", age: "26"}]


查出返回的不合法的单位数组,循环删掉

       async willCheckAuthSendParties(params){
        let { errcode, data } = await ajax.post(config.CHECK_PARTIES, {'dept_ids':params})
        //  auth_flag = 1 有不合法的单位
        if (errcode === 0 && data.auth_flag === 1) {
          this.$alert(
            "您选择的收文单位或收文员存在无效数据,请重新选择。","提示",
            {
              dangerouslyUseHTMLString: true,
              showClose: false,
              showCancelButton: false,
              confirmButtonText: "我知道了",
              confirmButtonClass: "SafetyTips_bnt"
            }
          ).then(()=>{
            // 查出返回的不合法的单位数组,循环删掉
            data.dept_ids.forEach(item =>{
              let delIndex = this.selectedContactList.findIndex(res => {return item == res.partyId})
              this.removeReceiver(delIndex)
            })
          })
        }else{
          return
        }
    }


给dom 添加简单的样式避开v-if 和 v-for 懒人方法

   //vue  dom
     {{ recvMarkMap[scope.row.status_flag] }}


    //vue methods
         statusColor(mark) {
            let color = mark === 0 ? '#389FA1' : mark === 1 ? '#348CE6' : mark === 2 ? '#38AE37' : mark === 3 ? '#F05A5A' : mark === 4 ? '#78859C' : mark === 5 ? '#9099AE' : '#389FA1'
            let background = mark === 0 ? '#ECF7F7' : mark === 1 ? '#E6F1FC' : mark === 2 ? '#EAF7EA' : mark === 3 ? '#FDEBEB' : mark === 4 ? '#E8EAEE' : mark === 5 ? '#F1F2F5' : '#ECF6F6'
            return {
                color,
                background
            }
        }

你可能感兴趣的:(js vue node工作笔记)