Files
desktop_task_schedule/code/web/task_schedule/src/utils/account.ts

96 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-03-02 16:59:48 +08:00
/*
* @Author: Kane
* @Date: 2023-03-02 14:48:35
* @LastEditors: Kane
* @FilePath: /task_schedule/src/utils/account.ts
2023-03-06 11:22:43 +08:00
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
2023-03-02 16:59:48 +08:00
*/
2023-03-06 11:22:43 +08:00
import { type AxiosResponse } from "axios";
2023-03-07 17:54:52 +08:00
import { service as instance } from "./api/request.js";
import { API_URL } from "./api/config.js";
2023-03-24 15:11:47 +08:00
import { cleanStaffInfo, clearCallerInfo } from "./api/localStorage.js";
// @ts-expect-error 之后再补充类型文件
import { router } from "../router/index.js";
// declare const require: any;
// const { router, } = require( "../router/index.js" );
2023-03-02 16:59:48 +08:00
interface LoginInfo
{
2023-03-02 19:48:08 +08:00
p13account: string;
2023-03-02 16:59:48 +08:00
password: string;
}
2023-04-28 17:46:54 +08:00
interface LoginCallerInfo
{
2023-11-01 20:49:54 +08:00
telsaler: string;
2023-04-28 17:46:54 +08:00
}
interface RequestResult
{
success: boolean;
message: string;
}
interface LoginCallerResult extends RequestResult
{
tel_saler_code: string;
tel_saler_name: string;
2023-04-28 17:46:54 +08:00
team_code: string;
team_name: string;
department_code: string;
department_name: string;
}
/**
*
* @param data
* @returns Promise对象
*/
2023-03-17 18:53:13 +08:00
async function login( data: LoginInfo ): Promise<AxiosResponse<any, any>>
2023-03-02 16:59:48 +08:00
{
2023-03-06 11:22:43 +08:00
return await instance.request(
2023-03-02 16:59:48 +08:00
{
method: "post",
url: API_URL.URL_LOGIN,
2023-03-06 11:22:43 +08:00
data,
2023-04-28 17:46:54 +08:00
});
2023-03-02 16:59:48 +08:00
}
2023-04-28 17:46:54 +08:00
/**
*
* @param data
* @returns Promise对象
*/
async function loginCaller( data: LoginCallerInfo ): Promise<AxiosResponse<any, any>>
{
return await instance.request(
{
method: "post",
url: API_URL.URL_LOGIN_CALLER,
data,
});
}
/**
* 退
*/
function logout(): void
{
cleanStaffInfo();
2023-03-24 15:11:47 +08:00
clearCallerInfo();
void router.push( "/login" );
}
2023-04-28 17:46:54 +08:00
export {
type LoginInfo,
type LoginCallerInfo,
type LoginCallerResult,
login,
loginCaller,
logout
};