|
|
@@ -0,0 +1,265 @@
|
|
|
+<template>
|
|
|
+ <div class="p-2">
|
|
|
+ <transition :enter-active-class="proxy?.animate.searchAnimate.enter"
|
|
|
+ :leave-active-class="proxy?.animate.searchAnimate.leave">
|
|
|
+ <div v-show="showSearch" class="mb-[10px]" :style="{ marginTop: '10px', height: '60px' }">
|
|
|
+ <el-card shadow="hover">
|
|
|
+ <el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
|
|
+ <el-form-item label="设备名称" prop="name">
|
|
|
+ <el-input v-model="queryParams.name" placeholder="请输入设备名称" clearable @keyup.enter="handleQuery"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="设备SN" prop="serialNumber">
|
|
|
+ <el-input v-model="queryParams.serialNumber" placeholder="请输入设备SN" clearable @keyup.enter="handleQuery"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="MAC" prop="mac">
|
|
|
+ <el-input v-model="queryParams.mac" placeholder="请输入设备MAC" clearable @keyup.enter="handleQuery"/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
|
|
+ <el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-card>
|
|
|
+ </div>
|
|
|
+ </transition>
|
|
|
+
|
|
|
+ <el-card shadow="never">
|
|
|
+ <div class="table-content">
|
|
|
+ <el-table v-loading="loading" :data="deviceList">
|
|
|
+ <el-table-column label="" align="left" prop="" width="10"/>
|
|
|
+ <el-table-column label="设备ID" align="left" prop="id" width="175" v-if="true"/>
|
|
|
+ <el-table-column label="设备标识" align="left" width="250" prop="identifier"/>
|
|
|
+ <el-table-column label="设备名称" align="left" prop="name" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column label="设备SN" align="left" prop="serialNumber" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column label="设备MAC" align="left" prop="mac" width="220"/>
|
|
|
+ <el-table-column label="在线状态" width="150" align="center" prop="onlineStatus">
|
|
|
+ <template #default="scope">
|
|
|
+ <dict-tag :options="sys_device_online" :value="scope.row.onlineStatus"/>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="操作" width="300" align="center" class-name="small-padding fixed-width">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-tooltip content="开始抓取" placement="top">
|
|
|
+ <el-button link type="primary" icon="Refresh" @click="handleStartLog(scope.row)"
|
|
|
+ v-hasPermi="['device:log:add']">开始抓取</el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip content="结束抓取" placement="top">
|
|
|
+ <el-button link type="primary" icon="Close" @click="handleEndLog(scope.row)"
|
|
|
+ v-hasPermi="['device:log:edit']">结束抓取</el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip content="抓取结果" placement="top">
|
|
|
+ <el-button link type="primary" icon="CircleCheck" @click="handleLogResult(scope.row)"
|
|
|
+ v-hasPermi="['device:log:list']">抓取结果</el-button>
|
|
|
+ </el-tooltip>
|
|
|
+<!-- <el-tooltip content="设备心跳" placement="top">
|
|
|
+ <el-button link type="primary" icon="Clock" @click="handleHeartbeat(scope.row)"
|
|
|
+ v-hasPermi="['device:log:list']">设备心跳</el-button>
|
|
|
+ </el-tooltip>-->
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum"
|
|
|
+ v-model:limit="queryParams.pageSize" @pagination="getList"/>
|
|
|
+ </el-card>
|
|
|
+ <!-- 添加或修改设备对话框 -->
|
|
|
+ <el-dialog :title="dialog.title" v-model="dialog.visible" width="700px" append-to-body>
|
|
|
+ <el-form ref="deviceFormRef" :model="form" :rules="rules" label-width="70px">
|
|
|
+ <el-form-item label="抓取时长" prop="duration">
|
|
|
+ <el-input-number :min="60" v-model="form.duration" placeholder="请输入抓取时长" clearable/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="抓取命令" prop="logCmd">
|
|
|
+ <el-input type="textarea" v-model="form.logCmd" :rows="5" placeholder="请输入抓取命令" clearable/>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="是否重启" prop="isReboot">
|
|
|
+ <el-radio-group v-model="form.isReboot">
|
|
|
+ <el-radio label="0">否</el-radio>
|
|
|
+ <el-radio label="1">是</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
+ <div class="dialog-footer">
|
|
|
+ <el-button :loading="buttonLoading" type="primary" @click="submitForm">开始抓取</el-button>
|
|
|
+ <el-button @click="cancel">取 消</el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
+ <!-- 抓取结果对话框 -->
|
|
|
+ <el-dialog :title="listDialog.title" v-model="listDialog.visible" width="1000px" style="height: 800px" append-to-body>
|
|
|
+ <el-table v-loading="listLoading" :data="deviceLogPushList">
|
|
|
+ <el-table-column label="设备名称" align="left" prop="deviceName" width="200" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column label="抓取时长" align="center" prop="duration" width="80"/>
|
|
|
+ <el-table-column label="抓取结果" align="center" prop="logStatus" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <dict-tag :options="smsb_device_log_status" :value="scope.row.logStatus"/>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="是否重启" align="center" prop="isReboot" width="80">
|
|
|
+ <template #default="scope">
|
|
|
+ <dict-tag :options="smsb_yes_no" :value="scope.row.isReboot"/>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="抓取命令" align="left" prop="logCmd" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column label="抓取时间" align="left" prop="createTime" width="160" :show-overflow-tooltip="true"/>
|
|
|
+ <el-table-column label="操作" width="120" align="center" class-name="small-padding fixed-width">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-tooltip content="日志下载" placement="top">
|
|
|
+ <el-button link type="primary" :disabled="!scope.row.logFile" icon="Download" @click="handleDownloadLog(scope.row)"
|
|
|
+ v-hasPermi="['device:log:add']">日志下载</el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup name="Device" lang="ts">
|
|
|
+import {listDevice} from '@/api/smsb/device/device';
|
|
|
+import {DeviceQuery, DeviceVO} from '@/api/smsb/device/device_type';
|
|
|
+import {DeviceLogPushForm, DeviceLogPushQuery, DeviceLogPushVO} from "@/api/smsb/device/logPush/types";
|
|
|
+import {addDeviceLogPush, listDeviceLogPush, stopDeviceLogPush} from "@/api/smsb/device/logPush/api";
|
|
|
+
|
|
|
+const {proxy} = getCurrentInstance() as ComponentInternalInstance;
|
|
|
+const {
|
|
|
+ sys_device_online,smsb_yes_no,smsb_device_log_status
|
|
|
+} = toRefs<any>(
|
|
|
+ proxy?.useDict('sys_device_online','smsb_yes_no','smsb_device_log_status')
|
|
|
+);
|
|
|
+
|
|
|
+const deviceList = ref<DeviceVO[]>([]);
|
|
|
+const deviceLogPushList = ref<DeviceLogPushVO[]>([]);
|
|
|
+const buttonLoading = ref(false);
|
|
|
+const loading = ref(true);
|
|
|
+const listLoading = ref(true);
|
|
|
+const showSearch = ref(true);
|
|
|
+const ids = ref<Array<string | number>>([]);
|
|
|
+const single = ref(true);
|
|
|
+const multiple = ref(true);
|
|
|
+const total = ref(0);
|
|
|
+
|
|
|
+const queryFormRef = ref<ElFormInstance>();
|
|
|
+const deviceFormRef = ref<ElFormInstance>();
|
|
|
+
|
|
|
+const dialog = reactive<DialogOption>({
|
|
|
+ visible: false,
|
|
|
+ title: ''
|
|
|
+});
|
|
|
+
|
|
|
+const listDialog = reactive<DialogOption>({
|
|
|
+ visible: false,
|
|
|
+ title: ''
|
|
|
+});
|
|
|
+
|
|
|
+const initFormData: DeviceLogPushForm = {
|
|
|
+ duration: 60,
|
|
|
+ deviceId: undefined,
|
|
|
+ logCmd: 'logcat -vtime | grep -i -E "MqttClient|PushCallback|MqttService"',
|
|
|
+ isReboot: '0',
|
|
|
+}
|
|
|
+const data = reactive<PageData<DeviceLogPushForm, DeviceQuery>>({
|
|
|
+ form: {...initFormData},
|
|
|
+ queryParams: {
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ name: undefined,
|
|
|
+ serialNumber: undefined,
|
|
|
+ params: {}
|
|
|
+ },
|
|
|
+ rules: {}
|
|
|
+});
|
|
|
+
|
|
|
+const {queryParams, form, rules} = toRefs(data);
|
|
|
+
|
|
|
+/** 查询设备列表 */
|
|
|
+const getList = async () => {
|
|
|
+ loading.value = true;
|
|
|
+ const res = await listDevice(queryParams.value);
|
|
|
+ deviceList.value = res.rows;
|
|
|
+ total.value = res.total;
|
|
|
+ loading.value = false;
|
|
|
+}
|
|
|
+
|
|
|
+/** 取消按钮 */
|
|
|
+const cancel = () => {
|
|
|
+ reset();
|
|
|
+ dialog.visible = false;
|
|
|
+}
|
|
|
+
|
|
|
+const handleStartLog = (row: DeviceVO) => {
|
|
|
+ const deviceId = row.id;
|
|
|
+ form.value.deviceId = deviceId;
|
|
|
+ dialog.title = "日志抓取";
|
|
|
+ dialog.visible = true;
|
|
|
+}
|
|
|
+
|
|
|
+const handleDownloadLog = (row: DeviceLogPushVO) => {
|
|
|
+ const fileUrl = row.logFile;
|
|
|
+ if (!fileUrl) {
|
|
|
+ proxy?.$modal.msgWarning("无日志文件可下载");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 创建隐藏的下载链接并触发下载
|
|
|
+ const link = document.createElement('a');
|
|
|
+ link.href = fileUrl;
|
|
|
+ link.download = fileUrl.substring(fileUrl.lastIndexOf('/') + 1); // 从URL提取文件名
|
|
|
+ link.style.display = 'none';
|
|
|
+ document.body.appendChild(link);
|
|
|
+ link.click();
|
|
|
+ document.body.removeChild(link);
|
|
|
+}
|
|
|
+const handleLogResult = async (row: DeviceVO) => {
|
|
|
+ const deviceId = row.id;
|
|
|
+ listDialog.title = "抓取结果";
|
|
|
+ listDialog.visible = true;
|
|
|
+ listLoading.value = true;
|
|
|
+ const params = {
|
|
|
+ deviceId : deviceId
|
|
|
+ }
|
|
|
+ const res = await listDeviceLogPush(params as DeviceLogPushQuery);
|
|
|
+ deviceLogPushList.value = res.rows;
|
|
|
+ listLoading.value = false;
|
|
|
+}
|
|
|
+
|
|
|
+/** 表单重置 */
|
|
|
+const reset = () => {
|
|
|
+ form.value = {...initFormData};
|
|
|
+ deviceFormRef.value?.resetFields();
|
|
|
+}
|
|
|
+
|
|
|
+/** 搜索按钮操作 */
|
|
|
+const handleQuery = () => {
|
|
|
+ queryParams.value.pageNum = 1;
|
|
|
+ getList();
|
|
|
+}
|
|
|
+
|
|
|
+/** 重置按钮操作 */
|
|
|
+const resetQuery = () => {
|
|
|
+ queryFormRef.value?.resetFields();
|
|
|
+ handleQuery();
|
|
|
+}
|
|
|
+
|
|
|
+const handleEndLog = async (row: DeviceVO) => {
|
|
|
+ const deviceId = row.id;
|
|
|
+ await stopDeviceLogPush(deviceId);
|
|
|
+ proxy?.$modal.msgSuccess("操作成功");
|
|
|
+}
|
|
|
+/** 提交按钮 */
|
|
|
+const submitForm = () => {
|
|
|
+ deviceFormRef.value?.validate(async (valid: boolean) => {
|
|
|
+ if (valid) {
|
|
|
+ buttonLoading.value = true;
|
|
|
+ await addDeviceLogPush(form.value).finally(() => buttonLoading.value = false);
|
|
|
+ proxy?.$modal.msgSuccess("操作成功");
|
|
|
+ await getList();
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ getList();
|
|
|
+});
|
|
|
+</script>
|