handleSubmit()

in console-ui/src/components/NewNameSpace/NewNameSpace.js [100:166]


  handleSubmit() {
    const { locale = {} } = this.props;
    this.field.validate((errors, values) => {
      if (errors) return;
      this.disabled = true;
      this.setState({
        disabled: true,
      });
      let { customNamespaceId } = values;
      if (!customNamespaceId) {
        customNamespaceId = '';
      }
      request({
        type: 'get',
        url: 'v3/console/core/namespace/exist',
        contentType: 'application/x-www-form-urlencoded',
        beforeSend: () => this.openLoading(),
        data: {
          customNamespaceId,
        },
        success: res => {
          res = res.data;
          this.disabled = false;
          this.setState({
            disabled: false,
          });
          if (res === true) {
            Dialog.alert({
              title: locale.notice,
              content: locale.namespaceIdAlreadyExist,
            });
          } else {
            request({
              type: 'post',
              url: 'v3/console/core/namespace',
              contentType: 'application/x-www-form-urlencoded',
              beforeSend: () => this.openLoading(),
              data: {
                customNamespaceId,
                namespaceName: values.namespaceShowName,
                namespaceDesc: values.namespaceDesc,
              },
              success: res => {
                res = res.data;
                this.disabled = false;
                this.setState({
                  disabled: false,
                });
                if (res === true) {
                  this.closeDialog();
                  this.props.getNameSpaces();
                  this.refreshNameSpace(); // 刷新全局namespace
                } else {
                  Dialog.alert({
                    title: locale.notice,
                    content: locale.newnamespceFailedMessage,
                  });
                }
              },
              complete: () => this.closeLoading(),
            });
          }
        },
        complete: () => this.closeLoading(),
      });
    });
  }