|
@@ -1,3 +1,5 @@
|
|
|
+import { useI18n } from '@/hook/useI18n'
|
|
|
+import { AxiosResponse } from 'axios'
|
|
|
import axios from './instance'
|
|
|
import { SRoom } from './room'
|
|
|
|
|
@@ -65,7 +67,7 @@ export const getTop5 = async (): Promise<Top5DataType> => {
|
|
|
|
|
|
export const getRoomMsgList = async (params: RoomMsgParams): Promise<RoomMsgListData> => {
|
|
|
const res = await axios.get<RoomMsgListData>('takelook/roomMsgList', {
|
|
|
- params: params
|
|
|
+ params: params,
|
|
|
})
|
|
|
return res
|
|
|
}
|
|
@@ -76,17 +78,43 @@ export const getAllRoomStatistic = async (params: RoomMsgParams): Promise<AllRoo
|
|
|
})
|
|
|
return res
|
|
|
}
|
|
|
-export const exportAllRoomStatistic = async (params: RoomMsgParams): Promise<AllRoomMsgListData> => {
|
|
|
- const res = await axios.get<AllRoomMsgListData>('takelook/exportRoomData', {
|
|
|
- params: params
|
|
|
+export const exportAllRoomStatistic = async (params: RoomMsgParams): Promise<void> => {
|
|
|
+ const { t } = useI18n()
|
|
|
+ const res = await axios.get<AxiosResponse>('takelook/exportRoomData', {
|
|
|
+ params: params,
|
|
|
+ responseType: 'blob', // Important
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/vnd.ms-excel'
|
|
|
+ }
|
|
|
})
|
|
|
- return res
|
|
|
+ var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }); //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
|
|
|
+ var downloadElement = document.createElement('a');
|
|
|
+ var href = window.URL.createObjectURL(blob); //创建下载的链接
|
|
|
+ downloadElement.href = href;
|
|
|
+ downloadElement.download = `${t('statistic.roomData')}.xlsx`; //下载后文件名
|
|
|
+ document.body.appendChild(downloadElement);
|
|
|
+ downloadElement.click(); //点击下载
|
|
|
+ document.body.removeChild(downloadElement); //下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(href); //释放掉blob对象
|
|
|
}
|
|
|
-export const exportRoomMsgStatistic = async (params: RoomMsgParams): Promise<AllRoomMsgListData> => {
|
|
|
- const res = await axios.get<AllRoomMsgListData>('takelook/exportRoomMsg', {
|
|
|
- params: params
|
|
|
+export const exportRoomMsgStatistic = async (params: RoomMsgParams): Promise<void> => {
|
|
|
+ const { t } = useI18n()
|
|
|
+ const res = await axios.get<AxiosResponse>('takelook/exportRoomMsg', {
|
|
|
+ params: params,
|
|
|
+ responseType: 'blob', // Important
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'application/vnd.ms-excel'
|
|
|
+ }
|
|
|
})
|
|
|
- return res
|
|
|
+ var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8' }); //application/vnd.openxmlformats-officedocument.spreadsheetml.sheet这里表示xlsx类型
|
|
|
+ var downloadElement = document.createElement('a');
|
|
|
+ var href = window.URL.createObjectURL(blob); //创建下载的链接
|
|
|
+ downloadElement.href = href;
|
|
|
+ downloadElement.download = `${t('statistic.roomMssage')}.xlsx`; //下载后文件名
|
|
|
+ document.body.appendChild(downloadElement);
|
|
|
+ downloadElement.click(); //点击下载
|
|
|
+ document.body.removeChild(downloadElement); //下载完成移除元素
|
|
|
+ window.URL.revokeObjectURL(href); //释放掉blob对象
|
|
|
}
|
|
|
|
|
|
export const getOnlineTimeCount = async (): Promise<DataLabelType[]> => {
|
|
@@ -95,4 +123,4 @@ export const getOnlineTimeCount = async (): Promise<DataLabelType[]> => {
|
|
|
}
|
|
|
export const getRoomVisitData = async (param: RoomMsgParams): Promise<RoomUseType> => {
|
|
|
return await axios.get<RoomUseType>('takelook/roomVisitData', { params: param })
|
|
|
-}
|
|
|
+}
|