vue规范

1.命名规范

  • mod 修改
  • del 刪除
  • sel 获取多个
  • get 获取单个
以 item结尾
searchItem  搜素按钮
addItem 添加按钮 
addItem() {
    this.editFormVisible = true;
    //清空之前表单中的数据
   this.$refs.editForm.resetFields
  }
modItem 修改按钮
modItem(row) {
    //   显示弹出框
    this.editFormVisible = true;
    // 根据row中的主键构造入参
    let para = {
      majorId: row.majorId
    };
    // 使用后台提供的get接口获取 单条数据 并填充到editForm中
    majorGet(para).then(res => {
      let data = res.data.result;
      //赋值
      // this.utilCommen.getFormValue(this.editForm, data);
      this.editForm = data
    });
  },
selItem 获取多个数据(刷新页面获取)
//获取分页数据
  selItem() {
    let param = this.searchInfo;
    param.pageIndex = this.currentPage;
    param.pageSize = this.pageSize;
    majorPage(param).then(res => {
      this.total = res.data.result.total;
      this.majorList = res.data.result.records;
    });
  },

getItem 获取单个数据(页面刷新获取)

2.命名规则

a.搜索 searchInfo 对象里面的数据为搜索的字段

searchInfo: {
        majorNo: "",
        majorName: "",
        majorGovName: "",
        majorYear: ""
      }

b.修改或者添加的字段对象里面属于需要填写的数据

editForm: {
        campusUseFlag: "",
        chargeLevel: "",
        enrollFlag: "",
        graduateFlag: "",
        majorGovName: "",
        majorLevel: "",
        majorName: "",
        majorNo: "",
        majorType: "",
        majorYear: "",
        note: ""
      }

3.addInfo和 modInfo

 //提交 判断主键 是否存在 如果存在则是修改操作 否则是添加操作 
    submitInfo() {
      this.editFormLoading = true;
      //如果有editForm.userId 为假 则 是addInfo 否则 modInfo
      if (!this.editForm.majorId) {
        //添加
        this.addInfo();
      } else {
        //修改
        this.modInfo();
      }
    },
//点击修改数据
    modInfo() {
    //必填项都有 valid则返回true 进行后台校验 参数为editForm 
      this.$refs.editForm.validate(valid => {
        if (valid) {
          let param = this.editForm;
          majorMod(param)
            .then(res => {
              let data = res.data;
              if (data.returnFlag == "0") {
                this.$notify.success("修改成功");
                this.utilCommen.resetForm(this.searchInfo);
                this.selItem();
                this.editFormVisible = false;
              } else {
                this.$notify.error(data.returnMsg);
              }
              this.editFormLoading = false;
            })
            .catch(error => {
              this.$message.error(error);
              this.editFormLoading = false;
            });
        } else {
          this.editFormLoading = false;
        }
      });
    },
 //点击添加 
    addInfo() {
      //输入框校验
      this.$refs.editForm.validate(valid => {
        if (valid) {
          let param = this.editForm;
          majorAdd(param)
            .then(res => {
              let data = res.data;
              if (data.returnFlag == "0") {
                this.$notify.success("添加成功");
                this.utilCommen.resetForm(this.searchInfo);
                this.selItem();
                this.editFormVisible = false;
              } else {
                this.$notify.error(data.returnMsg);
              }
              this.editFormLoading = false;
            })
            .catch(error => {
              this.$message.error(error);
              this.editFormLoading = false;
            });
        } else {
          this.editFormLoading = false;
        }
      });
    },
    //删除
   delItem(row) {
     this.$confirm("确认删除吗?", "提示", { type: "warning" }).then(() => {
       let params = { majorId: row.majorId };
       majorDel(params)
         .then(res => {
           console.log(res);
           
           let data = res.data;
           if (data.returnFlag == 0) {
             this.$notify.success("删除成功");
             this.selItem();
           } else {
             this.$notify.error(data.returnMsg);
           }
         })
         .catch(error => {
           this.$message.error(error);
         });
     });
   },

3.excel导出

    //导出员工的excel
    exportItem() {
      // 防止反复点击Excel
      this.excelLoading = true;
      setTimeout(() => {
        this.excelLoading = false;
      }, 3000);

      let param = this.searchInfo;
      window.location.href =
        majorExcelDownload +
        "?params=" +
        encodeURI(encodeURI(JSON.stringify(param)));
  

在这里插入图片描述api文档中设置地址

### 写给自己看的  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呵呵的牛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值