@besovideo/apifox-service-gen
v1.0.58
Published
```typescript
Keywords
Readme
当前包包含多个从apifox文档生成的typescript接口模块 和 必要的工具
// 接口文档 https://bvcsp.apifox.cn/
import bvcsp from "@besovideo/apifox-service-gen/bvcsp";
// 接口文档 https://bvnru.apifox.cn/
import bvnru from "@besovideo/apifox-service-gen/bvnru";
// 接口文档 https://bvalg.apifox.cn/
import bvalg from "@besovideo/apifox-service-gen/bvalg";
// 接口文档 https://bvworkorder.apifox.cn/
import bvworkorder from "@besovideo/apifox-service-gen/bvworkorder";
// 配置/工具库
import { ServiceGlobalConfig, ServiceGlobalUtils } from "@besovideo/apifox-service-gen";接口模块支持默认导入,也支持命名导入。
导入方式
默认导入
默认导入适合通过模块对象调用接口:
import bvcsp_auth from "@besovideo/apifox-service-gen/bvcsp_auth";
const response = await bvcsp_auth.getBvcspV1AuthUserinfo({
headers: {
Authorization: token,
},
});命名导入
只使用少量接口时,可以直接导入需要的方法:
import {
getBvcspV1AuthUserinfo,
postBvcspV1AuthLogin,
} from "@besovideo/apifox-service-gen/bvcsp_auth";
const response = await getBvcspV1AuthUserinfo({
headers: {
Authorization: token,
},
});导入接口类型
TypeScript 类型需要使用命名类型导入,可以和默认导入一起使用:
import bvcsp_auth, {
type GetBvcspV1AuthUserinfoData,
type PostBvcspV1AuthLoginData,
} from "@besovideo/apifox-service-gen/bvcsp_auth";
const options: GetBvcspV1AuthUserinfoData = {};
const response = await bvcsp_auth.getBvcspV1AuthUserinfo(options);也可以把模块的所有导出作为类型命名空间使用:
import bvcsp_auth, * as bvcsp_auth_types from "@besovideo/apifox-service-gen/bvcsp_auth";
type UserinfoOptions = bvcsp_auth_types.GetBvcspV1AuthUserinfoData;
const options: UserinfoOptions = {};
const response = await bvcsp_auth.getBvcspV1AuthUserinfo(options);默认导入是运行时对象,type 和 interface 在编译后不存在,因此不能通过默认对象访问类型:
import bvcsp_auth from "@besovideo/apifox-service-gen/bvcsp_auth";
// 不支持:命名空间“bvcsp_auth”不能用作类型命名空间
type UserinfoOptions = bvcsp_auth.GetBvcspV1AuthUserinfoData;示例
import { ServiceGlobalConfig, ServiceGlobalUtils } from "@besovideo/apifox-service-gen";
import { linkaction, auth } from "@besovideo/apifox-service-gen/bvcsp";
async function test() {
// 工具库 登录加密
const loginParams =
ServiceGlobalUtils.PlatformLoginEncryPasswordWithTimestamp(
"admin",
"123456"
);
// 登录
const loginResult = await auth.postBvcspV1AuthLogin({ body: loginParams });
if (!loginResult.error && loginResult.data?.code == 0) {
const tokenInfo = loginResult.data.data;
if (tokenInfo && tokenInfo.token) {
//设置token
ServiceGlobalConfig.SetConfig(tokenInfo.token);
}
}
// 修改报警联动
const a = await linkaction.putBvcspV1LinkactionById({
path: {
id: 1,
},
body: {}
});
}
test();