81 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { request, type ApiBody, type RequestOptions } from './request'
export { request, type ApiBody, type RequestOptions } from './request'
// export * from './order'
const workerPayload = {
device: 'workerstation',
project: 'warehouse',
}
/** 微信扫码登录:获取客户端码 / 二维码信息 */
export function getLoginWechatCode(
data: Record<string, unknown> = {},
options?: RequestOptions
) {
return request<ApiBody>('user.getLoginWechatCode', data, {
skipAuth: true,
...options,
})
}
/**
* 工作台登录:获取工作台绑定码 / 绑定状态(免登录、免鉴权)
* - 不传 clientCode:分配新客户端编码并立即返回绑定码
* - 传入 clientCode:进入长轮询等待 workbench.bind,绑定成功返回 token;
* 等待超时/缓存失效时服务端会重新生成绑定码后才返回
*/
export function getWorkbenchBindCode(
data: Record<string, unknown> = {},
options?: RequestOptions
) {
return request<ApiBody>('index.getWorkbenchBindCode', data, {
skipAuth: true,
...options,
})
}
/**
* 工作台信息:使用工作台 token 获取工作台信息(免登录、免鉴权)
* - 需传工作台 token(64 位);token 不存在或无对应工作台时返回失败(flag=failure、code=403)
*/
export function getWorkbenchInfo(token: string) {
return request<ApiBody>(
'workbench.getWorkbenchInfo',
{ token },
{ skipAuth: true }
)
}
/** 工牌 / 条码码登录 */
export function loginByCode(code: string) {
return request<ApiBody>('user.loginByCode', { code }, { skipAuth: true })
}
/** 账号密码登录 */
export function loginByAccount(username: string, password: string) {
return request<ApiBody>(
'user.login',
{ username, password },
{ skipAuth: true }
)
}
/** 当前登录用户信息 */
export function fetchUserInfo() {
return request<ApiBody>('user.info', { ...workerPayload })
}
/** 切换角色 / 门店身份 */
export function changeUserRole(roleId: string | number) {
return request<ApiBody>('user.changeRole', {
roleId,
...workerPayload,
})
}
/** 退出登录 */
export function logout() {
return request<ApiBody>('user.logout', {})
}