PC业务校验(已有该名称,已有该编码)

      rules: {
        name: [
          { required: true, message: "部门名称不能为空", trigger: "blur" },
          {
            min: 2,
            max: 10,
            message: "部门名称的长度为2-10个字符",
            trigger: "blur",
          },
          {
            trigger: "blur",
            validator: async (rule, value, callback) => {
            //调数据的接口
              let res = await getDepartmentUser();
              if (res.some((item) => (item.name = value))) {
                callback(new Error("部门中已经有该名称了"));
              } else {
                callback();
              }
            },
          },
        ], // 部门名称
        code: [
          { required: true, message: "请输入部门编码", trigger: "blur" },
          {
            trigger: "blur",
            validator: async (rule, value, callback) => {
              const res = await getDepartmentUser();
              if (res.some((item) => (item.code = value))) {
                callback(new Error("部门中已经有该编码了"));
              } else {
                callback();
              }
            },
          },
        ],
      },

PC业务校验(已有该名称,已有该编码)_第1张图片

你可能感兴趣的:(前端,javascript)