{"version":3,"file":"api-component.mjs","sources":["../../../../../../../packages/components/api-component/src/config/api-component.ts"],"sourcesContent":["import { buildProps, definePropType } from '@ll-plus/utils'\r\n\r\nimport type { ExtractPropTypes } from 'vue'\r\n\r\nimport type ApiComponent from '../api-component.vue'\r\n\r\nimport type { FormProps } from 'ant-design-vue'\r\n\r\nimport type { IJsonXmlItem } from './'\r\n\r\nexport type IMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'\r\n\r\nexport type IValueType =\r\n  | 'string'\r\n  | 'integer'\r\n  | 'boolean'\r\n  | 'number'\r\n  | 'array'\r\n  | null\r\n  | any\r\n\r\nexport interface IParam {\r\n  required?: boolean\r\n  name?: string\r\n  value?: string\r\n  type?: IValueType\r\n  static?: boolean\r\n  contentType?: string\r\n  description?: string\r\n  chineseName?: string\r\n  children?: IParam[]\r\n  [key: string]: any\r\n}\r\n\r\nexport const DEFAULT_METHOD = 'GET'\r\n\r\nexport const requestList = [\r\n  {\r\n    key: 'params',\r\n    name: '请求参数'\r\n  },\r\n  {\r\n    key: 'body',\r\n    name: '请求报文体'\r\n  },\r\n  {\r\n    key: 'headers',\r\n    name: '请求头'\r\n  }\r\n]\r\n\r\nexport const bodyList = [\r\n  {\r\n    key: 'none',\r\n    name: 'none'\r\n  },\r\n  {\r\n    key: 'form-data',\r\n    name: 'form-data'\r\n  },\r\n  {\r\n    key: 'x-www-form-urlencoded',\r\n    name: 'x-www-form-urlencoded'\r\n  },\r\n  {\r\n    key: 'json',\r\n    name: 'json'\r\n  },\r\n  {\r\n    key: 'xml',\r\n    name: 'xml'\r\n  },\r\n  {\r\n    key: 'raw',\r\n    name: 'raw'\r\n  }\r\n]\r\n\r\nexport interface IApiParams {\r\n  url?: string\r\n  method?: IMethod\r\n  requestParams?: IParam[]\r\n  headerParams?: IParam[]\r\n  bodyParams?: Record<string, any>\r\n}\r\n\r\n// export const httpModel = buildProps({\r\n//   url: {\r\n//     type: String,\r\n//     default: ''\r\n//   },\r\n//   method: {\r\n//     type: definePropType<IMethod>(String),\r\n//     default: DEFAULT_METHOD\r\n//   },\r\n//   requestParams: {\r\n//     type: definePropType<IParam[]>(Array),\r\n//     default: () => [] as IParam[]\r\n//   },\r\n//   headerParams: {\r\n//     type: definePropType<IParam[]>(Array),\r\n//     default: () => [] as IParam[]\r\n//   },\r\n//   bodyParams: {\r\n//     type: Object,\r\n//     default: () => ({\r\n//       none: null,\r\n//       'form-data': [],\r\n//       json: [],\r\n//       xml: [],\r\n//       raw: '',\r\n//       'x-www-form-urlencoded': []\r\n//     })\r\n//   }\r\n// } as const)\r\n\r\n// export type HttpModel = ExtractPropTypes<typeof httpModel>\r\nexport type BodyParams = {\r\n  // none: null\r\n  // 'form-data': IParam[]\r\n  // json: IJsonXmlItem[]\r\n  // xml: IJsonXmlItem[]\r\n  // raw: string\r\n  // 'x-www-form-urlencoded': IParam[]\r\n  type: 'none' | 'form-data' | 'json' | 'xml' | 'raw' | 'x-www-form-urlencoded'\r\n  parameters: IParam[]\r\n  jsonSchema: IJsonXmlItem[]\r\n  description: string\r\n}\r\n\r\nexport type HttpModel = {\r\n  url: string\r\n  method: IMethod\r\n  requestParams: IParam[]\r\n  headerParams: IParam[]\r\n  bodyParams: BodyParams\r\n}\r\n\r\nexport const apiComponentProps = buildProps({\r\n  value: {\r\n    type: definePropType<HttpModel>(Object),\r\n    default: () => ({\r\n      url: '',\r\n      method: DEFAULT_METHOD,\r\n      requestParams: [],\r\n      headerParams: [],\r\n      bodyParams: {\r\n        type: 'none',\r\n        parameters: [],\r\n        jsonSchema: [],\r\n        description: ''\r\n      }\r\n    })\r\n  },\r\n  disabled: {\r\n    type: Boolean,\r\n    default: false\r\n  },\r\n  isValid: {\r\n    type: Boolean,\r\n    default: false\r\n  },\r\n  rules: {\r\n    type: definePropType<FormProps['rules']>(Object),\r\n    default: () => ({\r\n      url: [\r\n        {\r\n          required: true,\r\n          trigger: 'blur',\r\n          message: '请输入url'\r\n        },\r\n        {\r\n          trigger: 'change',\r\n          pattern:\r\n            /^(http|https?:\\/\\/)?([\\da-z.-]+)\\.([a-z.]{2,6})([\\/\\w .-]*)*\\/?$/,\r\n          message: '输入url格式错误'\r\n        }\r\n      ]\r\n    })\r\n  }\r\n} as const)\r\n\r\nexport const apiComponentEmits = {\r\n  change: (value: HttpModel) => !!value,\r\n  'update:value': (value: HttpModel) => !!value\r\n}\r\n// props\r\nexport type ApiComponentProps = ExtractPropTypes<typeof apiComponentProps>\r\n\r\n// emits\r\nexport type ApiComponentEmits = typeof apiComponentEmits\r\n\r\n// instance\r\nexport type ApiComponentInstance = InstanceType<typeof ApiComponent>\r\n"],"names":[],"mappings":";;;;AAkCO,MAAM,cAAA,GAAiB;AAEvB,MAAM,WAAA,GAAc;AAAA,EACzB;AAAA,IACE,GAAA,EAAK,QAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,MAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,SAAA;AAAA,IACL,IAAA,EAAM;AAAA;AAEV;AAEO,MAAM,QAAA,GAAW;AAAA,EACtB;AAAA,IACE,GAAA,EAAK,MAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,WAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,uBAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,MAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,KAAA;AAAA,IACL,IAAA,EAAM;AAAA,GACR;AAAA,EACA;AAAA,IACE,GAAA,EAAK,KAAA;AAAA,IACL,IAAA,EAAM;AAAA;AAEV;AA8DO,MAAM,oBAAoB,UAAA,CAAW;AAAA,EAC1C,KAAA,EAAO;AAAA,IACL,IAAA,EAAM,eAA0B,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