69 lines
2.5 KiB
TypeScript
69 lines
2.5 KiB
TypeScript
import { BoxStatus, CreateBoxBodyType, IBox, IBoxDetail, UpdateBoxBodyType } from '@/data/box/box.model';
|
|
import { CommonResponseType, PageAble } from '@/helpers/types';
|
|
import { request } from '@/services/request';
|
|
import axios from 'axios';
|
|
|
|
export const box_requests = {
|
|
async getAll(params?: {
|
|
page?: number;
|
|
sort?: string;
|
|
pageable?: string | number;
|
|
direction?: string;
|
|
cargoId?: string;
|
|
partyId?: string | number;
|
|
status?: BoxStatus;
|
|
}) {
|
|
return request.get<CommonResponseType<PageAble<IBox>>>('/packets/list', { params });
|
|
},
|
|
async changeStatus(params: { packetId: string | number; status: BoxStatus }) {
|
|
return request.put('/packets/change', undefined, { params });
|
|
},
|
|
async create({ partyId, ...body }: CreateBoxBodyType) {
|
|
return request.post<CommonResponseType>('/packets/create', body, {
|
|
params: { partyId },
|
|
});
|
|
},
|
|
async update({ packetId, ...body }: UpdateBoxBodyType) {
|
|
return request.put<CommonResponseType>('/packets/update', body, {
|
|
params: { packetId },
|
|
});
|
|
},
|
|
async find(params: { packetId?: number | string }) {
|
|
return request.get<CommonResponseType<IBoxDetail>>('/packets/find', { params });
|
|
},
|
|
async delete(params: { packetId: number | string }) {
|
|
return request.delete<CommonResponseType>('/packets/delete', { params });
|
|
},
|
|
async downloadExcel(params: { packetId: number | string }) {
|
|
return request.get<Blob>('/packets/download', { params, responseType: 'blob' });
|
|
},
|
|
async translateWithGoogleApi(params: { text: string }): Promise<string> {
|
|
const response = await axios.post('https://translation.googleapis.com/language/translate/v2', undefined, {
|
|
params: {
|
|
q: params.text,
|
|
target: 'ru',
|
|
source: 'zh',
|
|
key: 'AIzaSyA5uAPZyjF_yo1hYOWWJ2uP7XgcmohZc8o',
|
|
},
|
|
});
|
|
|
|
return response.data.data.translations?.[0]?.translatedText ?? '';
|
|
},
|
|
async translateWithMemoryApi(params: { text: string }): Promise<string> {
|
|
const response = await axios.get<{
|
|
responseData: {
|
|
translatedText: string;
|
|
match: number;
|
|
};
|
|
}>('https://api.mymemory.translated.net/get', {
|
|
params: {
|
|
q: params.text,
|
|
langpair: 'zh|ru',
|
|
// key: '7a4ac2e07cde1ff1e9de',
|
|
},
|
|
});
|
|
|
|
return response.data.responseData.translatedText;
|
|
},
|
|
};
|