quasar-data-process/src/api/login.ts

56 lines
1.4 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 {api} from 'boot/axios';
import {DcodeImage, UserLoginReq} from 'stores/userStore';
export const loginRequest = async (passwordLogin: UserLoginReq): Promise<string> => {
let cancel = null;
const controller = new AbortController();
try {
if (cancel) {
controller.abort()
}
cancel = 1;
return await api.post('login', passwordLogin, {signal: controller.signal})
.then(response => {
cancel = null;
return response.data
}); // 如果响应中有 token 属性则返回它更具体的属性名称取决于API实现。
} catch (error) {
console.error(error); // 处理错误信息
throw error;
}
};
export const hello = async (): Promise<string> => {
try {
const { data } = await api.get('hello' );
return data;
} catch (error) {
console.error(error); // 处理错误信息
throw error;
}
};
export const getInfo = async (): Promise<string> => {
try {
const { data } = await api.get('getInfo' );
return data;
} catch (error) {
console.error(error); // 处理错误信息
throw error;
}
};
export const getDcode = async (): Promise<DcodeImage> => {
try {
return await api.get('login/getDcode' ).then(
response => {
console.log(response.data)
return response.data
});
} catch (error) {
console.error(error); // 处理错误信息
throw error;
}
}