butterfly-decorators
v1.1.4
Published
``` npm install butterfly-decorators ``` ## 使用 ``` ts // dir: api/Http.ts @Http({ baseUrl: 'http://127.0.0.1:8080', interceptors: { req(req: RequestConfig) { // doing... return req }, res(res: Response) { //
Downloads
9
Maintainers
Readme
安装
npm install butterfly-decorators
使用
// dir: api/Http.ts
@Http({
baseUrl: 'http://127.0.0.1:8080',
interceptors: {
req(req: RequestConfig) {
// doing...
return req
},
res(res: Response) {
// doing...
return res
}
}
})
export class Http {}
// modules/user/user.controller.ts
@Controller('user')
export class UserController extends Http {
@Get()
getUserListReq(@Query() query: any): void | Res<User[]> {}
@Post()
addUserReq(@Body() body: any): void | Res<any>
@Put()
updateUserReq(@Body() body: any): void | Res<any> {}
@Delete(':id')
delUserReq(@Param('id') id: number): void | Res<any> {}
uploadImageReq(@Formdata() data: any): void | Res<any> {}
}
// modules/user/user.service.ts
@Injectable()
export class UserService {
constructor(
private readonly userController: UserController
) {}
async getUserList(query) {
let res = await this.userController.getUserListReq(query)
if(res.code == 200) {
return { list: res.data.list, total: res.data.total }
}
return { list: [], total: 0 }
}
}
@Module()
export class UserModule{
@Resource()
static userService: UserService
@Log('获取用户列表')
renderUserList() {
let { list, total } = this.userService.getUserList({ page: 1, size: 20 })
state.tableData = list
state.total = total
}
// 定时任务
@TimedTask(1000, 1)
testTask() {
console.log(1)
}
}
// modules/user/user.vue
<script setup>
UserModule.renderUserList()
</script>