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

96 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-03-02 08:59:48 +00:00
/*
* @Author: Kane
* @Date: 2023-03-02 14:48:35
* @LastEditors: Kane
* @FilePath: /task_schedule/src/utils/account.ts
2023-03-06 03:22:43 +00:00
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
2023-03-02 08:59:48 +00:00
*/
2023-03-06 03:22:43 +00:00
import { type AxiosResponse } from "axios";
2023-03-07 09:54:52 +00:00
import { service as instance } from "./api/request.js";
import { API_URL } from "./api/config.js";
2023-03-24 07:11:47 +00: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 08:59:48 +00:00
interface LoginInfo
{
2023-03-02 11:48:08 +00:00
p13account: string;
2023-03-02 08:59:48 +00:00
password: string;
}
2023-04-28 09:46:54 +00:00
interface LoginCallerInfo
{
2023-11-01 12:49:54 +00:00
telsaler: string;
2023-04-28 09:46:54 +00:00
}
interface RequestResult
{
success: boolean;
message: string;
}
interface LoginCallerResult extends RequestResult
{
tel_saler_code: string;
tel_saler_name: string;
2023-04-28 09:46:54 +00:00
team_code: string;
team_name: string;
department_code: string;
department_name: string;
}
/**
*
* @param data
* @returns Promise对象
*/
2023-03-17 10:53:13 +00:00
async function login( data: LoginInfo ): Promise<AxiosResponse<any, any>>
2023-03-02 08:59:48 +00:00
{
2023-03-06 03:22:43 +00:00
return await instance.request(
2023-03-02 08:59:48 +00:00
{
method: "post",
url: API_URL.URL_LOGIN,
2023-03-06 03:22:43 +00:00
data,
2023-04-28 09:46:54 +00:00
});
2023-03-02 08:59:48 +00:00
}
2023-04-28 09:46:54 +00: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 07:11:47 +00:00
clearCallerInfo();
void router.push( "/login" );
}
2023-04-28 09:46:54 +00:00
export {
type LoginInfo,
type LoginCallerInfo,
type LoginCallerResult,
login,
loginCaller,
logout
};