You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.2 KiB
69 lines
2.2 KiB
import { service } from './service'
|
|
|
|
import { config } from './config'
|
|
import { useCache } from '@/hooks/web/useCache'
|
|
import router from '@/router'
|
|
|
|
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,
|
|
'Referer1': router.currentRoute.value.fullPath.split('?')[0]
|
|
}
|
|
})
|
|
}
|
|
export default {
|
|
get: async <T = any>(option: any) => {
|
|
const res = await request({ method: 'GET', ...option })
|
|
return res.data as unknown as T
|
|
},
|
|
post: async <T = any>(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 <T = any>(option: any) => {
|
|
const res = await request({ method: 'DELETE', ...option })
|
|
return res.data as unknown as T
|
|
},
|
|
enable: async <T = any>(option: any) => {
|
|
const res = await request({ method: 'POST', ...option })
|
|
return res.data as unknown as T
|
|
},
|
|
disable: async <T = any>(option: any) => {
|
|
const res = await request({ method: 'POST', ...option })
|
|
return res.data as unknown as T
|
|
},
|
|
put: async <T = any>(option: any) => {
|
|
const res = await request({ method: 'PUT', ...option })
|
|
return res.data as unknown as T
|
|
},
|
|
download: async <T = any>(option: any) => {
|
|
const res = await request({ method: 'GET', responseType: 'blob', ...option })
|
|
return res as unknown as Promise<T>
|
|
},
|
|
downloadPost: async <T = any>(option: any) => {
|
|
const res = await request({ method: 'POST', responseType: 'blob', ...option })
|
|
return res as unknown as Promise<T>
|
|
},
|
|
upload: async <T = any>(option: any) => {
|
|
option.headersType = 'multipart/form-data'
|
|
const res = await request({ method: 'POST', ...option })
|
|
return res as unknown as Promise<T>
|
|
}
|
|
}
|
|
|