import { service } from './service' import { config } from './config' import { useCache } from '@/hooks/web/useCache' const { default_headers } = config const { wsCache } = useCache() console.log('lang='+wsCache.get('lang')); const language = wsCache.get('lang') const request = (option: any) => { const { url, method, params, data, headersType, responseType, ...config } = option return service({ url: url, method, params, data, ...config, responseType: responseType, headers: { 'Content-Type': headersType || default_headers, 'language': language } }) } export default { get: async (option: any) => { const res = await request({ method: 'GET', ...option }) return res.data as unknown as T }, post: async (option: any) => { const res = await request({ method: 'POST', ...option }) return res.data as unknown as T }, postOriginal: async (option: any) => { const res = await request({ method: 'POST', ...option }) return res }, delete: async (option: any) => { const res = await request({ method: 'DELETE', ...option }) return res.data as unknown as T }, put: async (option: any) => { const res = await request({ method: 'PUT', ...option }) return res.data as unknown as T }, download: async (option: any) => { const res = await request({ method: 'GET', responseType: 'blob', ...option }) return res as unknown as Promise }, downloadPost: async (option: any) => { const res = await request({ method: 'POST', responseType: 'blob', ...option }) return res as unknown as Promise }, upload: async (option: any) => { option.headersType = 'multipart/form-data' const res = await request({ method: 'POST', ...option }) return res as unknown as Promise } }