提交 8a719686 作者: 方治民

feat: 更新依赖、pont 接口生成适配 json 传参方式、细节优化

上级 f6d06082
......@@ -21,7 +21,7 @@ export function configAutoImportPlugin(): Plugin {
'@/config/app': ['$app'],
'@/api/services': ['defs'],
'@/api/services/mods': ['API'],
'@/common/message': ['Message'],
'@/common': ['Message'],
},
],
})
......@@ -33,6 +33,7 @@ export function configAutoImportPlugin(): Plugin {
*/
export function configComponentsImportPlugin(): Plugin {
return Components({
dts: 'types/components.d.ts',
resolvers: [
(name: string) => {
// FIX: 修复 easycom 在 APP 下不生效问题(原因不明
......@@ -46,6 +47,6 @@ export function configComponentsImportPlugin(): Plugin {
export function configImportPlugin(): Plugin[] {
// FIX: easycom 适配问题
// return [configAutoImportPlugin(), configComponentsImportPlugin()]
return [configAutoImportPlugin()]
return [configAutoImportPlugin(), configComponentsImportPlugin()]
// return [configAutoImportPlugin()]
}
......@@ -63,19 +63,19 @@
}
},
"dependencies": {
"@dcloudio/uni-app": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-app-plus": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-components": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-h5": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-alipay": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-baidu": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-kuaishou": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-lark": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-qq": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-toutiao": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-mp-weixin": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-quickapp-webview": "^3.0.0-alpha-3060420220922008",
"@vue/runtime-core": "^3.2.40",
"@dcloudio/uni-app": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-app-plus": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-components": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-h5": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-alipay": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-baidu": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-kuaishou": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-lark": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-qq": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-toutiao": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-mp-weixin": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-quickapp-webview": "^3.0.0-alpha-3060720221017002",
"@vue/runtime-core": "^3.2.41",
"@vueuse/core": "^8.9.4",
"axios": "^0.26.1",
"dayjs": "^1.11.5",
......@@ -83,7 +83,7 @@
"mockjs": "^1.1.0",
"pinia": "^2.0.23",
"qs": "~6.9.7",
"vue": "^3.2.40",
"vue": "^3.2.41",
"vue-i18n": "^9.2.2",
"vue-types": "^4.2.1"
},
......@@ -91,19 +91,20 @@
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^16.2.4",
"@dcloudio/types": "^3.0.15",
"@dcloudio/uni-automator": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-cli-shared": "^3.0.0-alpha-3060420220922008",
"@dcloudio/uni-automator": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-cli-shared": "^3.0.0-alpha-3060720221017002",
"@dcloudio/uni-helper-json": "^1.0.13",
"@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3060420220922008",
"@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3060720221017001",
"@types/lodash-es": "^4.17.6",
"@types/mockjs": "^1.0.7",
"@types/prettier": "^2.7.1",
"@types/qs": "^6.9.7",
"@typescript-eslint/eslint-plugin": "^5.40.0",
"@typescript-eslint/parser": "^5.40.0",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"commitizen": "^4.2.5",
"conventional-changelog-cli": "^2.2.2",
"cz-conventional-changelog": "^3.3.0",
"cz-customizable": "^7.0.0",
"dotenv": "^16.0.3",
"eslint": "^8.25.0",
"eslint-config-prettier": "^8.5.0",
......@@ -115,13 +116,13 @@
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"pont-engine": "^1.4.0",
"postcss": "^8.4.17",
"postcss": "^8.4.18",
"postcss-html": "^1.5.0",
"postcss-less": "^6.0.0",
"prettier": "^2.7.1",
"rimraf": "^3.0.2",
"sort-package-json": "^1.57.0",
"stylelint": "^14.13.0",
"stylelint": "^14.14.0",
"stylelint-config-html": "^1.1.0",
"stylelint-config-prettier": "^9.0.3",
"stylelint-config-recommended": "^8.0.0",
......@@ -132,7 +133,7 @@
"typescript": "^4.8.4",
"unplugin-auto-import": "^0.11.2",
"unplugin-vue-components": "^0.22.8",
"vite": "^3.1.7",
"vite": "^3.1.8",
"vue-eslint-parser": "^9.1.0"
},
"engines": {
......
......@@ -2,8 +2,8 @@
"originType": "SwaggerV2",
"originUrl": "http://127.0.0.1:8081/api/v2/api-docs",
"templateType": "fetch",
"templatePath": "./pont.template",
"transformPath": "./pont.transform",
"templatePath": "./pont-template",
"transformPath": "./pont-transform",
"outDir": "./src/api/services",
"surrounding": "typeScript",
"mocks": {
......
......@@ -12,19 +12,44 @@ export class FileStructures extends Pont.FileStructures {
}
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) {
let requestParams = inter.getRequestParams(this.surrounding)
let bodyTypeDef = ''
const prettier = require('prettier')
if (prettier.format(paramsCode, { parser: 'typescript' }).includes('{}')) {
if (!requestParams.includes('form')) {
requestParams = requestParams.replace('params', 'params?')
}
if (requestParams.includes('body')) {
requestParams = requestParams.replace('params?: Params, ', '')
bodyTypeDef = requestParams.replace(/^.*body: (.*),.*$/gi, '$1')
}
}
return `${requestParams.replace(
'options?: any',
`config?: http.RequestConfig<Params${requestParams.includes('form') ? ' | FormData' : ''}>`,
`config?: http.RequestConfig<${
bodyTypeDef ? bodyTypeDef : `Params${requestParams.includes('form') ? ' | FormData' : ''}`
}>`,
)}, options?: http.RequestOptions`
}
......@@ -64,7 +89,12 @@ export default class BasicGenerator extends CodeGenerator {
const paramsCode = inter.getParamsCode('Params', this.surrounding)
const requestParams = this.getParams(inter, paramsCode)
const undef = inter.response.getInitialValue() === 'undefined'
const isBody = this.checkJsonParam(inter, paramsCode)
// TODO
// 扩展 hooks mode
// 采用 vue-request 或 @tanstack/vue-query
// export function useRequest()
return `
/**
* @desc ${inter.description}
......@@ -73,7 +103,7 @@ export default class BasicGenerator extends CodeGenerator {
${undef ? '' : `import * as defs from '../../baseClass';`}
import { defHttp } from '/@/utils/http/axios'
export ${paramsCode}
${isBody ? '' : `export ${paramsCode}`}
${undef ? '' : `export const init = ${inter.response.getInitialValue(true)};`}
......@@ -84,11 +114,13 @@ export default class BasicGenerator extends CodeGenerator {
${
method === 'GET'
? 'params'
: `data: ${requestParams.includes('form') ? 'form || params' : 'params'}`
: `data: ${requestParams.includes('form') ? 'form || params' : isBody ? 'body' : 'params'}`
},
${
requestParams.includes('form')
? `headers: { 'Content-Type': 'multipart/form-data;charset=UTF-8' },`
: isBody
? `headers: { 'Content-Type': 'application/json' },`
: ''
}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -26,6 +26,20 @@ export class MenuVo {
redirect = ''
}
export class PageParam {
/** 当前页数 */
pageNo = undefined
/** 分页条数 */
pageSize = undefined
/** 排序字段 */
sortField = ''
/** 排序方向(ASC|DESC) */
sortOrder = 'ASC'
}
export class PageVo {
/** 数据 */
data = []
......@@ -118,6 +132,14 @@ export class RoleVo {
uid = ''
}
export class UserExtensionVo {
/** 年龄 */
age = undefined
/** 性别 */
gender = undefined
}
export class UserInfo {
/** 头像 */
avatar = ''
......@@ -128,6 +150,9 @@ export class UserInfo {
/** 用户主页 */
homePath = ''
/** 手机号 */
mobile = ''
/** 真实姓名 */
realName = ''
......
......@@ -4,5 +4,6 @@
import * as login from './login'
import * as logout from './logout'
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'
......@@ -12,7 +12,7 @@ export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/example/test',
url: '/auth/valid',
method: 'GET',
params,
......
/**
* @desc download
* @desc 文件下载
*/
import { defHttp } from '/@/utils/http/axios'
......
/**
* @desc fail
* @desc 测试失败
*/
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'
......
......@@ -4,7 +4,8 @@
import * as hello from './hello'
import * as download from './download'
import * as fail from './fail'
import * as findUserExtensionInfo from './findUserExtensionInfo'
import * as json from './json'
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'
......
/**
* @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 文件管理
*/
import * as download from './download'
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'
import * as permission from './permission'
import * as role from './role'
import * as user from './user'
import * as userView from './userView'
export const API = {
auth,
......@@ -12,4 +13,5 @@ export const API = {
permission,
role,
user,
userView,
}
......@@ -37,7 +37,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/permission/add',
url: '/sys/permission/add',
method: 'POST',
data: params,
......
......@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/permission/deleted',
url: '/sys/permission/deleted',
method: 'POST',
data: params,
......
......@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/permission/find',
url: '/sys/permission/find',
method: 'GET',
params,
......
......@@ -39,7 +39,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/permission/modify',
url: '/sys/permission/modify',
method: 'POST',
data: params,
......
......@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/permission/page',
url: '/sys/permission/page',
method: 'GET',
params,
......
......@@ -7,7 +7,7 @@ import { defHttp } from '/@/utils/http/axios'
export class Params {
/** pid */
pid: string
pid?: string
}
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) {
return defHttp.request(
{
url: '/manage/permission/tree',
url: '/sys/permission/tree',
method: 'GET',
params,
......
......@@ -17,7 +17,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/role/add',
url: '/sys/role/add',
method: 'POST',
data: params,
......
......@@ -17,7 +17,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/role/assign',
url: '/sys/role/assign',
method: 'POST',
data: params,
......
......@@ -6,8 +6,8 @@ import * as defs from '../../baseClass'
import { defHttp } from '/@/utils/http/axios'
export class Params {
/** id */
id: string
/** ids 多个以逗号分割 */
ids: string
}
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) {
return defHttp.request(
{
url: '/manage/role/deleted',
url: '/sys/role/deleted',
method: 'POST',
data: params,
......
......@@ -15,7 +15,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/role/find',
url: '/sys/role/find',
method: 'GET',
params,
......
......@@ -19,7 +19,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/role/modify',
url: '/sys/role/modify',
method: 'POST',
data: params,
......
......@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/role/page',
url: '/sys/role/page',
method: 'GET',
params,
......
......@@ -12,7 +12,7 @@ export const init = new defs.Result()
export function request(params?: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/manage/role/selector',
url: '/sys/role/selector',
method: 'GET',
params,
......
......@@ -17,7 +17,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/user/manage/assign',
url: '/sys/user/assign',
method: 'POST',
data: params,
......
/**
* @description 用户管理
*/
import * as getMenuList from './getMenuList'
import * as getPermCode from './getPermCode'
import * as getUserInfo from './getUserInfo'
import * as assign from './assign'
import * as page from './page'
export { getMenuList, getPermCode, getUserInfo, assign, page }
export { assign, page }
......@@ -21,7 +21,7 @@ export const init = new defs.Result()
export function request(params: Params, config?: http.RequestConfig<Params>, options?: http.RequestOptions) {
return defHttp.request(
{
url: '/user/manage/page',
url: '/sys/user/page',
method: 'GET',
params,
......
/**
* @description 用户信息
*/
import * as getMenuList from './getMenuList'
import * as getPermCode from './getPermCode'
import * as getUserInfo from './getUserInfo'
export { getMenuList, getPermCode, getUserInfo }
import { Message } from './message'
// export some global utils function
export { Message }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论