提交 23acbedb 作者: 方治民

feat: pont 接口生成适配 json 传参方式

上级 cb22edda
...@@ -135,7 +135,7 @@ ...@@ -135,7 +135,7 @@
"lint-staged": "12.3.7", "lint-staged": "12.3.7",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"picocolors": "^1.0.0", "picocolors": "^1.0.0",
"pont-engine": "^1.3.3", "pont-engine": "^1.4.0",
"postcss": "^8.4.16", "postcss": "^8.4.16",
"postcss-html": "^1.5.0", "postcss-html": "^1.5.0",
"postcss-less": "^6.0.0", "postcss-less": "^6.0.0",
......
...@@ -67,7 +67,7 @@ specifiers: ...@@ -67,7 +67,7 @@ specifiers:
path-to-regexp: ^6.2.1 path-to-regexp: ^6.2.1
picocolors: ^1.0.0 picocolors: ^1.0.0
pinia: ^2.0.21 pinia: ^2.0.21
pont-engine: ^1.3.3 pont-engine: ^1.4.0
postcss: ^8.4.16 postcss: ^8.4.16
postcss-html: ^1.5.0 postcss-html: ^1.5.0
postcss-less: ^6.0.0 postcss-less: ^6.0.0
...@@ -198,7 +198,7 @@ devDependencies: ...@@ -198,7 +198,7 @@ devDependencies:
lint-staged: 12.3.7 lint-staged: 12.3.7
npm-run-all: 4.1.5 npm-run-all: 4.1.5
picocolors: 1.0.0 picocolors: 1.0.0
pont-engine: 1.3.3 pont-engine: 1.4.0
postcss: 8.4.16 postcss: 8.4.16
postcss-html: 1.5.0 postcss-html: 1.5.0
postcss-less: 6.0.0_postcss@8.4.16 postcss-less: 6.0.0_postcss@8.4.16
...@@ -5436,7 +5436,7 @@ packages: ...@@ -5436,7 +5436,7 @@ packages:
source-map: 0.6.1 source-map: 0.6.1
wordwrap: 1.0.0 wordwrap: 1.0.0
optionalDependencies: optionalDependencies:
uglify-js: 3.17.0 uglify-js: 3.17.3
dev: true dev: true
/hard-rejection/2.1.0: /hard-rejection/2.1.0:
...@@ -7142,8 +7142,8 @@ packages: ...@@ -7142,8 +7142,8 @@ packages:
engines: {node: '>=10.13.0'} engines: {node: '>=10.13.0'}
dev: false dev: false
/pont-engine/1.3.3: /pont-engine/1.4.0:
resolution: {integrity: sha512-JvN32pu25vrc/cw8/hkgNXNIJS+sxTZ9+7ZXZnvpsLdujmlTD7V67ka1Ak37BeylKTNb1sWdRrg4bSQXDqaB3Q==} resolution: {integrity: sha512-PwitNXZpTXcsGn04wEYIy6pLArVVOkMNBVztSVTgX1ixlE0p76IA7CvGKlKxGRU3Fl6CBFvkI7RCGSvbfSb89g==}
hasBin: true hasBin: true
dependencies: dependencies:
chalk: 2.4.2 chalk: 2.4.2
...@@ -8661,8 +8661,8 @@ packages: ...@@ -8661,8 +8661,8 @@ packages:
resolution: {integrity: sha512-e4+UtA5IRO+ha6hYklwj6r7BjiGMxS0O+UaSg9HbaTefg4kMkzj4tXzEBajRR+wkxf+golgAWKzLbytCUDMJAA==} resolution: {integrity: sha512-e4+UtA5IRO+ha6hYklwj6r7BjiGMxS0O+UaSg9HbaTefg4kMkzj4tXzEBajRR+wkxf+golgAWKzLbytCUDMJAA==}
dev: true dev: true
/uglify-js/3.17.0: /uglify-js/3.17.3:
resolution: {integrity: sha512-aTeNPVmgIMPpm1cxXr2Q/nEbvkmV8yq66F3om7X3P/cvOXQ0TMQ64Wk63iyT1gPlmdmGzjGpyLh1f3y8MZWXGg==} resolution: {integrity: sha512-JmMFDME3iufZnBpyKL+uS78LRiC+mK55zWfM5f/pWBJfpOttXAqYfdDGRukYhJuyRinvPVAtUhvy7rlDybNtFg==}
engines: {node: '>=0.8.0'} engines: {node: '>=0.8.0'}
hasBin: true hasBin: true
requiresBuild: true requiresBuild: true
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
"originType": "SwaggerV2", "originType": "SwaggerV2",
"originUrl": "http://127.0.0.1:8081/api/v2/api-docs", "originUrl": "http://127.0.0.1:8081/api/v2/api-docs",
"templateType": "fetch", "templateType": "fetch",
"templatePath": "./pont.template", "templatePath": "./pont-template",
"transformPath": "./pont.transform", "transformPath": "./pont-transform",
"outDir": "./src/api/services", "outDir": "./src/api/services",
"surrounding": "typeScript", "surrounding": "typeScript",
"mocks": { "mocks": {
......
...@@ -12,19 +12,44 @@ export class FileStructures extends Pont.FileStructures { ...@@ -12,19 +12,44 @@ export class FileStructures extends Pont.FileStructures {
} }
export default class BasicGenerator extends CodeGenerator { export default class BasicGenerator extends CodeGenerator {
checkJsonParam(inter: Interface, paramsCode: string): boolean {
const prettier = require('prettier')
const requestParams = inter.getRequestParams(this.surrounding)
const code = prettier.format(paramsCode, { parser: 'typescript' })
return code.includes('{}') && requestParams.includes('body')
}
// 认为没有返回值的接口表示下载(通常是)
isDownload(inter: Interface): boolean {
return inter.responseType === 'any'
}
// 认为包含 form 参数的接口表示带有上传功能
isUpload(inter: Interface): boolean {
return inter.getRequestParams(this.surrounding).includes('form')
}
getParams(inter: Interface, paramsCode: string) { getParams(inter: Interface, paramsCode: string) {
let requestParams = inter.getRequestParams(this.surrounding) let requestParams = inter.getRequestParams(this.surrounding)
let bodyTypeDef = ''
const prettier = require('prettier') const prettier = require('prettier')
if (prettier.format(paramsCode, { parser: 'typescript' }).includes('{}')) { if (prettier.format(paramsCode, { parser: 'typescript' }).includes('{}')) {
if (!requestParams.includes('form')) { if (!requestParams.includes('form')) {
requestParams = requestParams.replace('params', 'params?') requestParams = requestParams.replace('params', 'params?')
} }
if (requestParams.includes('body')) {
requestParams = requestParams.replace('params?: Params, ', '')
bodyTypeDef = requestParams.replace(/^.*body: (.*),.*$/gi, '$1')
}
} }
return `${requestParams.replace( return `${requestParams.replace(
'options?: any', 'options?: any',
`config?: http.RequestConfig<Params${requestParams.includes('form') ? ' | FormData' : ''}>`, `config?: http.RequestConfig<${
bodyTypeDef ? bodyTypeDef : `Params${requestParams.includes('form') ? ' | FormData' : ''}`
}>`,
)}, options?: http.RequestOptions` )}, options?: http.RequestOptions`
} }
...@@ -64,7 +89,12 @@ export default class BasicGenerator extends CodeGenerator { ...@@ -64,7 +89,12 @@ export default class BasicGenerator extends CodeGenerator {
const paramsCode = inter.getParamsCode('Params', this.surrounding) const paramsCode = inter.getParamsCode('Params', this.surrounding)
const requestParams = this.getParams(inter, paramsCode) const requestParams = this.getParams(inter, paramsCode)
const undef = inter.response.getInitialValue() === 'undefined' const undef = inter.response.getInitialValue() === 'undefined'
const isBody = this.checkJsonParam(inter, paramsCode)
// TODO
// 扩展 hooks mode
// 采用 vue-request 或 @tanstack/vue-query
// export function useRequest()
return ` return `
/** /**
* @desc ${inter.description} * @desc ${inter.description}
...@@ -73,7 +103,7 @@ export default class BasicGenerator extends CodeGenerator { ...@@ -73,7 +103,7 @@ export default class BasicGenerator extends CodeGenerator {
${undef ? '' : `import * as defs from '../../baseClass';`} ${undef ? '' : `import * as defs from '../../baseClass';`}
import { defHttp } from '/@/utils/http/axios' import { defHttp } from '/@/utils/http/axios'
export ${paramsCode} ${isBody ? '' : `export ${paramsCode}`}
${undef ? '' : `export const init = ${inter.response.getInitialValue(true)};`} ${undef ? '' : `export const init = ${inter.response.getInitialValue(true)};`}
...@@ -84,11 +114,13 @@ export default class BasicGenerator extends CodeGenerator { ...@@ -84,11 +114,13 @@ export default class BasicGenerator extends CodeGenerator {
${ ${
method === 'GET' method === 'GET'
? 'params' ? 'params'
: `data: ${requestParams.includes('form') ? 'form || params' : 'params'}` : `data: ${requestParams.includes('form') ? 'form || params' : isBody ? 'body' : 'params'}`
}, },
${ ${
requestParams.includes('form') requestParams.includes('form')
? `headers: { 'Content-Type': 'multipart/form-data;charset=UTF-8' },` ? `headers: { 'Content-Type': 'multipart/form-data;charset=UTF-8' },`
: isBody
? `headers: { 'Content-Type': 'application/json' },`
: '' : ''
} }
......
...@@ -26,6 +26,20 @@ export class MenuVo { ...@@ -26,6 +26,20 @@ export class MenuVo {
redirect = '' redirect = ''
} }
export class PageParam {
/** 当前页数 */
pageNo = undefined
/** 分页条数 */
pageSize = undefined
/** 排序字段 */
sortField = ''
/** 排序方向(ASC|DESC) */
sortOrder = 'ASC'
}
export class PageVo { export class PageVo {
/** 数据 */ /** 数据 */
data = [] data = []
...@@ -118,6 +132,14 @@ export class RoleVo { ...@@ -118,6 +132,14 @@ export class RoleVo {
uid = '' uid = ''
} }
export class UserExtensionVo {
/** 年龄 */
age = undefined
/** 性别 */
gender = undefined
}
export class UserInfo { export class UserInfo {
/** 头像 */ /** 头像 */
avatar = '' avatar = ''
...@@ -128,6 +150,9 @@ export class UserInfo { ...@@ -128,6 +150,9 @@ export class UserInfo {
/** 用户主页 */ /** 用户主页 */
homePath = '' homePath = ''
/** 手机号 */
mobile = ''
/** 真实姓名 */ /** 真实姓名 */
realName = '' realName = ''
......
...@@ -4,5 +4,6 @@ ...@@ -4,5 +4,6 @@
import * as login from './login' import * as login from './login'
import * as logout from './logout' import * as logout from './logout'
import * as register from './register' import * as register from './register'
import * as valid from './valid'
export { login, logout, register } export { login, logout, register, valid }
/** /**
* @desc 测试 MyBatis Plus 查询 * @desc 检查登录状态
*/ */
import * as defs from '../../baseClass' import * as defs from '../../baseClass'
...@@ -12,7 +12,7 @@ export const init = new defs.Result() ...@@ -12,7 +12,7 @@ export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/example/test', url: '/auth/valid',
method: 'GET', method: 'GET',
params, params,
......
/** /**
* @desc download * @desc 文件下载
*/ */
import { defHttp } from '/@/utils/http/axios' import { defHttp } from '/@/utils/http/axios'
......
/** /**
* @desc fail * @desc 测试失败
*/ */
import * as defs from '../../baseClass' import * as defs from '../../baseClass'
......
/**
* @desc 查询用户属性
*/
import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios'
export class Params {}
export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/example/findUserExtensionInfo',
method: 'GET',
params,
...config,
},
options,
)
}
/** /**
* @desc hello * @desc Hello World
*/ */
import * as defs from '../../baseClass' import * as defs from '../../baseClass'
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
import * as hello from './hello' import * as hello from './hello'
import * as download from './download' import * as download from './download'
import * as fail from './fail' import * as fail from './fail'
import * as findUserExtensionInfo from './findUserExtensionInfo'
import * as json from './json'
import * as page from './page' import * as page from './page'
import * as test from './test'
export { hello, download, fail, page, test } export { hello, download, fail, findUserExtensionInfo, json, page }
/**
* @desc JSON 传参
*/
import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios'
export const init = new defs.Result()
export function request(
body: defs.PageParam,
config?: http.RequestConfig<defs.PageParam>,
options?: http.RequestOptions,
) {
return defHttp.request(
{
url: '/example/json',
method: 'POST',
data: body,
headers: { 'Content-Type': 'application/json' },
...config,
},
options,
)
}
/** /**
* @desc page * @desc 分页条件查询
*/ */
import * as defs from '../../baseClass' import * as defs from '../../baseClass'
......
/**
* @desc 文件下载
*/
import { defHttp } from '/@/utils/http/axios'
export class Params {
/** bucket */
bucket: string
/** object */
object: string
}
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/common/file/download',
method: 'GET',
params,
...config,
},
options,
)
}
/** /**
* @description 文件管理 * @description 文件管理
*/ */
import * as download from './download'
import * as upload from './upload' import * as upload from './upload'
import * as uploadBase64Image from './uploadBase64Image'
export { upload } export { download, upload, uploadBase64Image }
/**
* @desc Base64 图片上传
*/
import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios'
export class Params {
/** Base64 图片信息 */
base64Image: string
}
export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/common/file/uploadBase64Image',
method: 'POST',
data: params,
...config,
},
options,
)
}
...@@ -4,6 +4,7 @@ import * as file from './file' ...@@ -4,6 +4,7 @@ import * as file from './file'
import * as permission from './permission' import * as permission from './permission'
import * as role from './role' import * as role from './role'
import * as user from './user' import * as user from './user'
import * as userView from './userView'
export const API = { export const API = {
auth, auth,
...@@ -12,4 +13,5 @@ export const API = { ...@@ -12,4 +13,5 @@ export const API = {
permission, permission,
role, role,
user, user,
userView,
} }
...@@ -37,7 +37,7 @@ export const init = new defs.Result() ...@@ -37,7 +37,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/permission/add', url: '/sys/permission/add',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -15,7 +15,7 @@ export const init = new defs.Result() ...@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/permission/deleted', url: '/sys/permission/deleted',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -15,7 +15,7 @@ export const init = new defs.Result() ...@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/permission/find', url: '/sys/permission/find',
method: 'GET', method: 'GET',
params, params,
......
...@@ -39,7 +39,7 @@ export const init = new defs.Result() ...@@ -39,7 +39,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/permission/modify', url: '/sys/permission/modify',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -21,7 +21,7 @@ export const init = new defs.Result() ...@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/permission/page', url: '/sys/permission/page',
method: 'GET', method: 'GET',
params, params,
......
...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios' ...@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** pid */ /** pid */
pid: string pid?: string
} }
export const init = new defs.Result() export const init = new defs.Result()
...@@ -15,7 +15,7 @@ export const init = new defs.Result() ...@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/permission/tree', url: '/sys/permission/tree',
method: 'GET', method: 'GET',
params, params,
......
...@@ -17,7 +17,7 @@ export const init = new defs.Result() ...@@ -17,7 +17,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/add', url: '/sys/role/add',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -17,7 +17,7 @@ export const init = new defs.Result() ...@@ -17,7 +17,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/assign', url: '/sys/role/assign',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -6,8 +6,8 @@ import * as defs from '../../baseClass' ...@@ -6,8 +6,8 @@ import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios' import { defHttp } from '/@/utils/http/axios'
export class Params { export class Params {
/** id */ /** ids 多个以逗号分割 */
id: string ids: string
} }
export const init = new defs.Result() export const init = new defs.Result()
...@@ -15,7 +15,7 @@ export const init = new defs.Result() ...@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/deleted', url: '/sys/role/deleted',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -15,7 +15,7 @@ export const init = new defs.Result() ...@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/find', url: '/sys/role/find',
method: 'GET', method: 'GET',
params, params,
......
...@@ -19,7 +19,7 @@ export const init = new defs.Result() ...@@ -19,7 +19,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/modify', url: '/sys/role/modify',
method: 'POST', method: 'POST',
data: params, data: params,
......
...@@ -21,7 +21,7 @@ export const init = new defs.Result() ...@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/page', url: '/sys/role/page',
method: 'GET', method: 'GET',
params, params,
......
...@@ -12,7 +12,7 @@ export const init = new defs.Result() ...@@ -12,7 +12,7 @@ export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/manage/role/selector', url: '/sys/role/selector',
method: 'GET', method: 'GET',
params, params,
......
...@@ -17,7 +17,7 @@ export const init = new defs.Result() ...@@ -17,7 +17,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/user/manage/assign', url: '/sys/user/assign',
method: 'POST', method: 'POST',
data: params, data: params,
......
/** /**
* @description 用户管理 * @description 用户管理
*/ */
import * as getMenuList from './getMenuList'
import * as getPermCode from './getPermCode'
import * as getUserInfo from './getUserInfo'
import * as assign from './assign' import * as assign from './assign'
import * as page from './page' import * as page from './page'
export { getMenuList, getPermCode, getUserInfo, assign, page } export { assign, page }
...@@ -21,7 +21,7 @@ export const init = new defs.Result() ...@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) { export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request( return defHttp.request(
{ {
url: '/user/manage/page', url: '/sys/user/page',
method: 'GET', method: 'GET',
params, params,
......
/**
* @description 用户信息
*/
import * as getMenuList from './getMenuList'
import * as getPermCode from './getPermCode'
import * as getUserInfo from './getUserInfo'
export { getMenuList, getPermCode, getUserInfo }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论