Ver Fonte

添加日志下载功能

soobin há 2 anos atrás
pai
commit
e121494080

BIN
src/assets/device/operIcon/viewLogs.png


+ 4 - 1
src/assets/language/en.json

@@ -313,7 +313,7 @@
     "parameterSetting": "Parameter setting",
     "operationConfirmation": "Operation confirmation",
     "pleaseConfirmAgainWhetherToOperate": "Please confirm again whether to operate",
-    "IllThinkAboutItAgain": "I'll think about it again",
+	"IllThinkAboutItAgain": "I'll think about it again",
     "restartSucceeded": "Restart succeeded",
     "deleteDeviceSucceed": "Delete device successfully",
     "sleepSuccessfully": "Sleep successfully",
@@ -403,6 +403,8 @@
     "pleaseSelectAMachine": "Please select a machine",
     "quantityPurchased": "Quantity purchased",
     "pleaseEnterThePurchaseQuantity": "Please enter the purchase quantity",
+	"download": "Download",
+	"downloading": "Downloading...",
     "month": "month",
     "weChat": "WeChat",
     "alipay": "Alipay",
@@ -441,6 +443,7 @@
       "customLogoSucceed": "Custom logo success"
     },
     "deleteDevice": "Delete Device",
+	"viewLogs": "View logs",
     "noPosition": "No positioning",
     "equipLocation": "Equipment location",
     "position": "Position",

+ 3 - 1
src/assets/language/zh.json

@@ -403,6 +403,8 @@
     "pleaseSelectAMachine": "请选择机器",
     "quantityPurchased": "购买的数量",
     "pleaseEnterThePurchaseQuantity": "请输入购买数量",
+	"download": "下载",
+	"downloading": "下载中...",
     "month": "月",
     "weChat": "微信",
     "alipay": "支付宝",
@@ -444,7 +446,6 @@
       "registerButton": "提交",
       "customLogoSucceed": "定制logo成功"
     },
-
 	"devicePasswordPage":{
 		"title": "修改机器密码",
 		"equipmentName": "设备名称",
@@ -458,6 +459,7 @@
 	},
 	"changePassword": "修改机器密码",
 	"deleteDevice": "删除设备",
+	"viewLogs": "查看日志",
     "noPosition":"暂无定位",
     "equipLocation":"设备位置",
     "position":"定位",

+ 2 - 2
src/router/index.js

@@ -123,8 +123,8 @@ const router = createRouter({
     { path: '/hpp', name: 'Hpp', component: () => import('@/views/Hpp.vue'), meta: { index: 1, noLogin: true } },
     // 定制logo
     { path: '/customLogo', name: 'customLogo', component: () => import('@/views/device/customLogo.vue'), meta: { index: 1} },
-    // TODO:日志管理
-    // { path: '/logMan', name: 'logMan', component: () => import('@/views/logMan/index'), meta: { index: 1 } },
+    // 查看日志
+    { path: '/viewLogs', name: 'viewLogs', component: () => import('@/views/device/viewLogs/index'), meta: { index: 1 } },
 	// 账户操作
 	{ path: '/accountOperation', name: 'accountOperation', component: () => import('@/views/accountOperation/index'), meta: { index: 1 } },
     // apk管理,广告管理,订单导出 不是所有的帐号能看到

+ 4 - 4
src/service/device/index.js

@@ -1,5 +1,5 @@
 import axios from '../../utils/axios';
-import {stringToUrl} from '@/common/js/utils';
+import { stringToUrl } from '@/common/js/utils';
 
 
 // 获取设备列表
@@ -170,7 +170,7 @@ export function customLogo(params) {
     return axios.post(`/SZWL-SERVER/tLogo/customLogo`, params)
 }
 
-// 上传日志
-export function uploadLog(params) {
-    return axios.post('/SZWL-SERVER/Log/uploadLog', params);
+// 日志下载
+export function downloadLog(params) {
+  return axios.get(`/SZWL-SERVER/tEquipment/downloadLog?${stringToUrl(params)}`,{responseType:'blob', timeout: 15000});
 }

+ 18 - 4
src/views/device/deviceOper.vue

@@ -170,7 +170,16 @@
 	    </div>
 	    <div class="operText">{{ $t("device.deleteDevice") }}</div>
 	  </div>
-
+	  <!-- 日志功能 -->
+	  <div v-if="user.type < 2" class="operItem" @click="viewLogs()">
+	    <div class="operIcon">
+	      <img
+	        class="operImg"
+	        src="../../assets/device/operIcon/viewLogs.png"
+	      />
+	    </div>
+	    <div class="operText">{{ $t("device.viewLogs") }}</div>
+	  </div>
     <!-- 定制logo -->
     <div v-if="user.type < 2" class="operItem" @click="customLogo()">
 	    <div class="operIcon">
@@ -242,7 +251,7 @@ export default {
     const router = useRouter();
     const show = ref(false);
     const operCheckShow = ref(false);
-    const device = ref({});
+	const device = ref({});
     const operType = ref("");
     // 休眠按钮
     const sleepTitle = ref(t("device.enableSleep"));
@@ -286,7 +295,11 @@ export default {
 	const openDoorFun = () => {
       router.push({ path: "openDoor", query: { deviceId: device.value.id } });
 	};
-  // 定制logo
+	// 日志功能
+	const viewLogs = () => {
+		router.push({ path: "viewLogs", query: {deviceId: device.value.id }});
+	};
+	// 定制logo
     const customLogo = () => {
       router.push({ path: "customLogo", query: {deviceId: device.value.id }});
     }
@@ -456,8 +469,9 @@ export default {
       tuojiEquipmentFun,
       isRole,
       modifyPriceClk,
-	    showGoodsClk,
+	  showGoodsClk,
       sleepTitle,
+	  viewLogs,
       deleteDevice,
 	  changePasswordClk,
     };

+ 205 - 0
src/views/device/viewLogs/index.vue

@@ -0,0 +1,205 @@
+<template>
+	<!--  修改logo  -->
+	<div class="page flex-col">
+		<s-header :name="$t('device.viewLogs')" :noback="false"></s-header>
+		<div class="block2 flex-row justify-between">
+			<div class="block3 flex-col"></div>
+			<span class="info2">{{ $t('device.equipmentName') }}:{{ deviceDetail ? deviceDetail.name : '' }}</span>
+		</div>
+		<div class="wrap1 flex-col o-pt-15">
+			<van-field v-model="logsTime" is-link readonly label="日期" placeholder="点击选择时间" @click="chooseTime()" />
+			<van-popup v-model:show="showPicker" round position="bottom">
+				<van-datetime-picker v-model="logsTime" type="date" :min-date="minDate" :max-date="maxDate"
+					@confirm="selectTime" @cancel="showPicker = false" />
+			</van-popup>
+			<van-button v-if="!downloading" round :disabled="logsTime === ''" type="primary" class="volumeChangeButton"
+				@click="downloadBtn">{{ $t('device.download') }}</van-button>
+			<van-button v-else disabled loading round class="volumeChangeButton" type="primary"
+				:loading-text="$t('device.downloading')" />
+		</div>
+	</div>
+</template>
+
+<script>
+	import {
+		onMounted,
+		computed,
+		ref
+	} from 'vue';
+	import sHeader from "@/components/SimpleHeader.vue";
+	import {
+		downloadLog,
+		getDeviceDetal
+	} from "@/service/device";
+	import { $M_ExportFile } from "@/common/js/utils";
+	import {
+		Toast
+	} from "vant";
+	import {
+		useRoute
+	} from "vue-router";
+	import dateUtil from "@/utils/dateUtil";
+	// import {useI18n} from "vue-i18n";
+
+	export default ({
+		components: {
+			sHeader
+		},
+		setup() {
+			// const { t } = useI18n();
+			const route = useRoute();
+			const deviceId = route.query.deviceId;
+			const deviceDetail = ref(null);
+			const showPicker = ref(false);
+			const downloading = ref(false);
+			const logsTime = ref(null);
+			const curDate = new Date(); // 获取当前时间日期
+
+			// 计算最小日期为当前日期7天前
+			const minDate = computed(() => {
+				const minTimestamp = curDate.getTime() - 6 * 24 * 3600 * 1000;
+				const minDate = dateUtil.formateDate(new Date(minTimestamp), "yyyy-MM-dd");
+				return new Date(minDate);
+			});
+
+			// 计算最大日期为当前日期
+			const maxDate = computed(() => {
+				return curDate;
+			});
+
+
+			// 初始化页面获取列表
+			onMounted(async () => {
+				await getDeviceDetailFun();
+				// console.log(deviceDetail.value.name);
+			});
+
+			// 选择时间
+			const chooseTime = () => {
+				// console.log('chooseTime function is called');
+				showPicker.value = true;
+				console.log(showPicker.value);
+			};
+
+
+			const selectTime = (time) => {
+				// console.log('selectTime function is called', time);
+				logsTime.value = dateUtil.formateDate(time, "yyyy-MM-dd");
+				showPicker.value = false;
+			};
+
+			const getDeviceDetailFun = async () => {
+				const {
+					data
+				} = await getDeviceDetal({
+					id: deviceId
+				});
+				if (data.code === '00000') {
+					deviceDetail.value = data.data;
+				} else {
+					Toast.fail(data.message);
+				}
+			}
+
+			const downloadBtn = async () => {
+				const pattern = /^\d{4}-\d{2}-\d{2}$/;
+				if(!pattern.test(logsTime.value)) {
+					Toast.fail('日期格式有误');
+					return;
+				}
+				const formattedDate = logsTime.value.replace(/-/g, '');
+				downloading.value = true;
+				try {
+					const {
+						headers, data
+					} = await downloadLog({
+						equipmentId: deviceId,
+						day: formattedDate,
+					});
+					console.log('请求成功', headers, data);
+					$M_ExportFile(data, headers);
+				} catch (error) {
+					if (error.code === 'ECONNABORTED') {
+					    // 处理请求超时的错误
+					    console.error('请求超时:', error);
+						Toast.fail("请求超时");
+					} else {
+					    // 处理其他请求错误
+					    console.error('请求失败:', error);
+						Toast.fail("请求失败");
+					}
+				} finally {
+					downloading.value = false;
+				}
+			}
+
+			return {
+				deviceDetail,
+				downloadBtn,
+				chooseTime,
+				selectTime,
+				showPicker,
+				logsTime,
+				minDate,
+				maxDate,
+				downloading,
+			}
+		},
+
+	});
+</script>
+
+<style lang="less" scoped>
+	@import "../../../common/style/common";
+
+	.page {
+		background-color: rgba(255, 255, 255, 1);
+		position: relative;
+		width: 100%;
+		height: calc(100vh - 44px);
+		overflow: hidden;
+
+		.volumeChangeButton {
+			background-color: #4d6add;
+			width: 220px;
+			height: 34px;
+			margin: 49px auto;
+
+			.van-button__text {
+				font-size: 15px;
+			}
+		}
+
+		.wrap1 {
+			width: 100%;
+			height: 274px;
+		}
+
+		.block2 {
+			width: 162px;
+			height: 20px;
+			margin: 18px 0 0 15px;
+
+			.block3 {
+				background-color: rgba(128, 150, 236, 1);
+				border-radius: 2px;
+				width: 4px;
+				height: 12px;
+				margin-top: 4px;
+			}
+
+			.info2 {
+				width: 150px;
+				height: 20px;
+				overflow-wrap: break-word;
+				color: rgba(64, 77, 116, 1);
+				font-size: 14px;
+				font-family: PingFangSC-Medium;
+				text-align: left;
+				white-space: nowrap;
+				line-height: 20px;
+				display: block;
+			}
+		}
+	}
+</style>

+ 0 - 21
src/views/logMan/index.vue

@@ -1,21 +0,0 @@
-<template>
-    <div>
-        <tr>
-            <th>
-                <span class="requiredField"></span>获取日志:
-            </th>
-            <td>
-                <input type="text" class="text" maxlength="20" id="day" placeholder="20200101" value=""/>
-                <button type="button" id="rizhi">上传</button>
-            </td>
-        </tr>
-    </div>
-</template>
-
-<script>
-    
-</script>
-
-<style>
-
-</style>