更新
This commit is contained in:
104
src/views/Inform/androidlog/hook.tsx
Normal file
104
src/views/Inform/androidlog/hook.tsx
Normal file
@@ -0,0 +1,104 @@
|
||||
import { ref } from "vue";
|
||||
import { message } from "@/utils/message";
|
||||
import {
|
||||
queryAndroidList,
|
||||
DeteleAndroidLog
|
||||
} from "@/api/modules/Inform";
|
||||
export function useData() {
|
||||
const loading = ref(true);
|
||||
const tableList = ref([]);
|
||||
const isShow = ref(false);
|
||||
const pagination = ref({
|
||||
total: 0,
|
||||
pageSize: 10,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
currentPage: 1,
|
||||
background: true
|
||||
});
|
||||
const tableLabel = ref([
|
||||
{
|
||||
label: "id",
|
||||
prop: "id"
|
||||
},
|
||||
{
|
||||
label: "用户名",
|
||||
prop: "nickname"
|
||||
},
|
||||
{
|
||||
label: "文件名",
|
||||
prop: "log_name"
|
||||
},
|
||||
{
|
||||
label: "上传时间",
|
||||
prop: "createtime"
|
||||
},
|
||||
{
|
||||
label: "操作",
|
||||
fixed: "right",
|
||||
slot: "operation"
|
||||
}
|
||||
]);
|
||||
const onSearch = async () => {
|
||||
loading.value = true;
|
||||
const { data, code } = await queryAndroidList({
|
||||
page: pagination.value.currentPage,
|
||||
page_limit: pagination.value.pageSize,
|
||||
|
||||
});
|
||||
if (code) {
|
||||
tableList.value = data.lists.map(ele => {
|
||||
return {
|
||||
...ele, ...data.total
|
||||
}
|
||||
});
|
||||
pagination.value.total = data.count;
|
||||
pagination.value.currentPage = data.page;
|
||||
}
|
||||
loading.value = false;
|
||||
};
|
||||
const handleSizeChange = (val: number) => {
|
||||
pagination.value.pageSize = val;
|
||||
onSearch();
|
||||
};
|
||||
const handleCurrentChange = (val: number) => {
|
||||
pagination.value.currentPage = val;
|
||||
onSearch();
|
||||
};
|
||||
const handleDelete = async rowData => {
|
||||
const { code } = await DeteleAndroidLog({ id: rowData.id });
|
||||
if (code) {
|
||||
message(`删除成功`, {
|
||||
type: "success"
|
||||
});
|
||||
onSearch();
|
||||
}
|
||||
}
|
||||
const downloadData = (rowData) => {
|
||||
console.log(rowData)
|
||||
// 创建Blob对象的临时URL
|
||||
const blobUrl = window.URL.createObjectURL(new Blob([rowData.log_url]));
|
||||
|
||||
// 创建a标签并触发下载
|
||||
const link = document.createElement('a');
|
||||
link.href = blobUrl;
|
||||
link.setAttribute('download', rowData.log_name); // 设置下载的文件名
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
|
||||
// 清理和释放URL对象
|
||||
link.remove();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
}
|
||||
return {
|
||||
onSearch,
|
||||
isShow,
|
||||
tableList,
|
||||
tableLabel,
|
||||
pagination,
|
||||
handleSizeChange,
|
||||
handleCurrentChange,
|
||||
handleDelete,
|
||||
downloadData,
|
||||
loading
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user