index.vue
7.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
<div class="table-box">
<ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam" :data-callback="dataCallback">
<!-- 表格 header 按钮 -->
<template #tableHeader>
<el-button type="primary" :icon="CirclePlus" @click="openDailog('新增设备')">新增设备</el-button>
<!-- <el-button type="primary" @click="openDailog('新增设备')">导入</el-button>
<el-button type="primary" @click="openDailog('新增设备')">导出</el-button> -->
</template>
<!-- 表格操作 -->
<template #operation="scope">
<el-button type="primary" link @click="openReport(scope.row)">通信</el-button>
<el-button type="primary" link @click="openLog(scope.row)">日志文件</el-button>
<el-button type="primary" link @click="openConfig('更新配置', scope.row)">更新配置</el-button>
<!-- <el-button type="primary" link @click="openDailog('查看', scope.row)">查看</el-button> -->
<el-button type="primary" link @click="openDailog('更新设备信息', scope.row)">更新设备信息</el-button>
<!-- <el-button type="primary" link @click="handleDelete(scope.row)">删除</el-button> -->
<!-- <el-button type="primary" link @click="sendCmd(scope.row)">上报信息</el-button> -->
</template>
</ProTable>
<Dialog ref="dialogRef" />
<Config ref="configRef" />
<Report ref="reportRef" :show-report="showReport" v-if="showReport" @close="showReport = false" :device-id="deviceId" />
<LogFile ref="logFileRef" :show-log="showLog" v-if="showLog" @close="showLog = false" :device-id="deviceId" />
</div>
</template>
<script setup lang="tsx" name="logProTable">
import { ref, reactive } from "vue";
import { Device } from "@/api/interface";
// import { useHandleData } from "@/hooks/useHandleData";
import ProTable from "@/components/ProTable/index.vue";
import Dialog from "./components/Dailog.vue";
import Config from "./components/Config.vue";
import LogFile from "./components/LogFile.vue";
import Report from "./components/Report.vue";
import { ProTableInstance, ColumnProps } from "@/components/ProTable/interface";
import { CirclePlus } from "@element-plus/icons-vue";
import { getDeviceList, editDevice, addDevice } from "@/api/modules/device";
// import { useCmd } from "@/hooks/useCmd";
// import useWebSocket from "@/hooks/useWebSocket";
// const socketUrl = import.meta.env.VITE_API_URL + "/ws/device";
// ProTable 实例
const proTable = ref<ProTableInstance>();
// 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
const initParam = reactive({});
const showLog = ref<boolean>(false);
let showReport = ref<boolean>(false);
const deviceId = ref<number>(0);
// dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段
// 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
const dataCallback = (data: any) => {
return {
list: data.data,
total: data.total
};
};
const formatDate = (date?: string) => {
return date ? new Date(date).toLocaleString() : "-";
};
// 如果你想在请求之前对当前请求参数做一些操作,可以自定义如下函数:params 为当前所有的请求参数(包括分页),最后返回请求列表接口
// 默认不做操作就直接在 ProTable 组件上绑定 :requestApi="getDeviceList"
const getTableList = (params: any) => {
let newParams = JSON.parse(JSON.stringify(params));
return getDeviceList(newParams);
};
// 表格配置项
const columns = reactive<ColumnProps<Device.ResDeviceList>[]>([
{
prop: "user",
label: "用户名",
search: { el: "input", props: { placeholder: "请输入用户名", maxlength: 15 } }
},
{
prop: "mobile",
label: "手机号",
search: { el: "input", props: { placeholder: "请输入手机号", maxlength: 11 } }
},
{
prop: "sn",
label: "设备编号",
search: { el: "input", props: { placeholder: "请输入设备编号", maxlength: 50 } }
},
// {
// prop: "sn",
// label: "APP版本",
// search: { el: "input", props: { placeholder: "APP版本", maxlength: 50 } },
// render: () => {
// return "V2.0.0";
// }
// },
{
prop: "log_saved_days",
label: "日志存储时间",
render: scope => {
return scope.row.log_saved_days;
},
width: 120
},
{
prop: "last_log_remove_time",
label: "删除日志时间",
render: scope => {
return formatDate(scope.row.last_log_remove_time);
}
},
{
prop: "last_log_upload_time",
label: "上传日志时间",
render: scope => {
return formatDate(scope.row.last_log_upload_time);
}
},
{
prop: "last_offline_time",
label: "上次上线时间",
render: scope => {
return formatDate(scope.row.last_offline_time);
}
// search: { el: "input" }
},
{
prop: "last_login_time",
label: "上次登录时间",
render: scope => {
return formatDate(scope.row.last_login_time);
}
// search: { el: "input" }
},
{
prop: "status",
label: "在线状态",
width: 90,
render: scope => {
return <el-tag type={scope.row.status == 1 ? "success" : "danger"}>{scope.row.status == 1 ? "在线" : "离线"}</el-tag>;
},
enum: [
{
label: "在线",
value: 1
},
{
label: "离线",
value: 2
}
],
search: { el: "select", props: { placeholder: "请选择在线状态" } },
fieldNames: { label: "label", value: "value" }
},
{ prop: "operation", label: "操作", fixed: "right", width: 320 }
]);
// 删除
// const handleDelete = async (params: Device.ResDeviceList) => {
// await useHandleData(deleteDevice, { id: [params.id] }, `是否确定删除该记录?`);
// proTable.value?.getTableList();
// };
// 打开 dialog(新增、查看、编辑)
const dialogRef = ref<InstanceType<typeof Dialog> | null>(null);
const openDailog = (title: string, row: Partial<Device.ResDeviceList> = {}) => {
const { sn, user, mobile, id: device_id } = row;
const params = {
title,
isView: title === "查看",
row: { sn, user, mobile, device_id },
api: title === "新增设备" ? addDevice : title === "更新设备信息" ? editDevice : undefined,
getTableList: proTable.value?.getTableList
};
dialogRef.value?.acceptParams(params);
};
//打开 dialog(配置)
const configRef = ref<InstanceType<typeof Config> | null>(null);
const openConfig = (title: string, row: Partial<Device.ResDeviceList> = {}) => {
const params = {
title,
row: { device_id: row.id, log_saved_days: row.log_saved_days },
api: editDevice,
getTableList: proTable.value?.getTableList
};
configRef.value?.acceptParams(params);
};
const reportRef = ref<InstanceType<typeof Report> | null>(null);
const openReport = (row: Partial<Device.ResDeviceList> = {}) => {
showReport.value = true;
deviceId.value = row.id!;
};
const openLog = (row: Partial<Device.ResDeviceList> = {}) => {
showLog.value = true;
deviceId.value = row.id!;
};
// const sendCmd = async (row: Partial<Device.ResDeviceList> = {}) => {
// await useCmd({
// device_id: row.id!,
// event: "private",
// data: { command: "getStorage", key: "recordList" }
// });
// };
// //websocket连接
// const { sendMessage } = useWebSocket(socketUrl, (message: any) => {
// console.log(message);
// });
// // sendMessage 数据推送方法
// //向成功连接的服务端推送数据
// sendMessage({ filed: "hello" });
</script>