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

96 lines
2.0 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.

/*
* @Author: Kane
* @Date: 2023-03-02 14:48:35
* @LastEditors: Kane
* @FilePath: /task_schedule/src/utils/account.ts
* @Description:
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
import { type AxiosResponse } from "axios";
import { service as instance } from "./api/request.js";
import { API_URL } from "./api/config.js";
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" );
interface LoginInfo
{
p13account: string;
password: string;
}
interface LoginCallerInfo
{
telsaler: string;
}
interface RequestResult
{
success: boolean;
message: string;
}
interface LoginCallerResult extends RequestResult
{
tel_saler_code: string;
tel_saler_name: string;
team_code: string;
team_name: string;
department_code: string;
department_name: string;
}
/**
* 内勤员工登录
* @param data 内勤员工登录信息
* @returns 返回一个Promise对象用于给调用者添加链式处理。
*/
async function login( data: LoginInfo ): Promise<AxiosResponse<any, any>>
{
return await instance.request(
{
method: "post",
url: API_URL.URL_LOGIN,
data,
});
}
/**
* 坐席登录函数
* @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();
clearCallerInfo();
void router.push( "/login" );
}
export {
type LoginInfo,
type LoginCallerInfo,
type LoginCallerResult,
login,
loginCaller,
logout
};