From 2af5f043b60c1f7ac38ecccc8f5bf44743134325 Mon Sep 17 00:00:00 2001
From: cuiqian2004 <cuiqian2004@163.com>
Date: 星期五, 12 十二月 2025 18:08:00 +0800
Subject: [PATCH] test

---
 pages/station/index.vue |  122 ++++++++++++++++++++--------------------
 1 files changed, 62 insertions(+), 60 deletions(-)

diff --git a/pages/station/index.vue b/pages/station/index.vue
index c22a196..c967451 100644
--- a/pages/station/index.vue
+++ b/pages/station/index.vue
@@ -5,7 +5,7 @@
 				<view class="position-site">
 					<a-button type="ghost" class="button" @click="clickPositionStation">
 						<text class="ico my-location-rounded" />
-						<text class="text">鑾峰彇鎼繍杞︿綅缃拰鏈濆悜</text>
+						<text class="text">{{translate("obtain_positon_and_orientation_of_vehicle")}}</text>
 					</a-button>
 				</view>
 			</view>
@@ -21,17 +21,17 @@
 						@touchcancel="onTouchCancelStation">
 						<view class="item-title">{{item.name}}</view>
 						<view class="item-text">
-							瑙掑害锛歿{Math.round(item.angle *180/3.14)}}锛屽潗鏍囷紙{{Math.round(Number(item.x)*100)/100}},{{Math.round(Number(item.y)*100)/100}})
+							{{translate("angle")}}锛歿{Math.round(item.angle *180/3.14)}}锛寋{translate("coordinates")}}锛坽{Math.round(Number(item.x)*100)/100}},{{Math.round(Number(item.y)*100)/100}})
 						</view>
 						<template v-slot:right>
-							<view class="btn-del" @click="clickDelStation(item)">鍒犻櫎</view>
+							<view class="btn-del" @click="clickDelStation(item)">{{translate("delete")}}</view>
 						</template>
 					</uni-swipe-action-item>
 				</uni-swipe-action>
 			</view>
 			<view class="list-no-content" v-else>
 				<uni-icons color="#ccc" type="info" size="128"></uni-icons>
-				<view class="space">杩樻病鏈夌珯鐐�/view>
+				<view class="space">{{translate("no_station")}}</view>
 			</view>
 			<view class="position-add" v-if="opStationType ==''" @click="clickAddStation" @touchstart='btnAddTouchStart'
 				@touchmove='btnAddTouchMove'
@@ -45,13 +45,13 @@
 				<view class="tip">璇疯緭鍏ョ珯鐐瑰悕绉�/view>
 				<view class="name-input">
 					<input ref="refInputName" :focus="true" placeholder="杈撳叆绔欑偣鍚嶇О" :value="stationEdit.name"
-						@input="onInputName"/>
+						@input="onInputName" />
 					<uni-icons class="clear" color="#ccc" type="clear" size="20" v-if="showClearName"
 						@click="clickClearName"></uni-icons>
 				</view>
 				<view class="text-button-group">
-					<a-button type="ghost" class="button" @click="clickNameCancel">鍙栨秷</a-button>
-					<a-button type="primary" class="button" @click="clickNameOK">纭畾</a-button>
+					<a-button type="ghost" class="button" @click="clickNameCancel">{{translate('cancel')}}</a-button>
+					<a-button type="primary" class="button" @click="clickNameOK">{{translate('ok')}}</a-button>
 				</view>
 			</view>
 			<view class="bottom-content" v-else-if=" opStationType =='edit_pos'">
@@ -60,12 +60,12 @@
 					<view class="coordinate">
 						<text class="name">妯潗鏍�</text>
 						<input ref="refInputX" class="number-input" type="number" :value="stationEdit.x"
-							@input="onInputX"/>
+							@input="onInputX" />
 					</view>
 					<view class="coordinate">
 						<text class="name">绔栧潗鏍�</text>
 						<input ref="refInputX" class="number-input" type="number" :value="stationEdit.y"
-							@input="onInputY"/>
+							@input="onInputY" />
 					</view>
 				</view>
 
@@ -175,7 +175,7 @@
 			this.onlyAdd = option.isAdd ? true : false
 
 			uni.setNavigationBarTitle({
-				title: "绔欑偣鍒楄〃"
+				title: this.translate("station_list")
 			})
 			uni.getSystemInfo({
 				success(e) {
@@ -186,7 +186,7 @@
 			if (this.onlyAdd) {
 				this.opStationType = "edit_name"
 				uni.setNavigationBarTitle({
-					title: "娣诲姞绔欑偣"
+					title: this.translate("add_station")
 				})
 			}
 
@@ -205,7 +205,7 @@
 				if (this.opStationType == "edit_name" || this.opStationType == "edit_pos") {
 					this.opStationType = ""
 					uni.setNavigationBarTitle({
-						title: "绔欑偣鍒楄〃"
+						title: this.translate("station_list")
 					})
 					this.$refs.refPopupOperateStation.open("bottom")
 
@@ -260,7 +260,7 @@
 
 				} catch (ex) {
 
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 			},
 			async loadAgvState() {
@@ -268,7 +268,7 @@
 					const info = await getAgvState(this.ip)
 					return info
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 					return {}
 				}
 			},
@@ -277,7 +277,7 @@
 					const info = await stations(this.ip)
 					return info.station_list || []
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 					return []
 				}
 			},
@@ -293,7 +293,7 @@
 				}
 				this.opStationType = "edit_name"
 				uni.setNavigationBarTitle({
-					title: "娣诲姞绔欑偣"
+					title:  this.translate("add_station")
 				})
 
 			},
@@ -361,7 +361,12 @@
 				this.pressStationTimer = null;
 			},
 			clickDelStation(item) {
-				showModal("纭鍒犻櫎绔欑偣", "璀﹀憡",true,"纭畾","鍙栨秷").then((res) => {
+				showModal({
+					title: this.translate("ask_confirm_remove"),
+					content: `${this.translate('delete_selected_station')}`,
+					confirmText: this.translate('remove'),
+					cancelText: this.translate('cancel'),
+				}).then((res) => {
 					if (res) {
 						this.deleteStation(item)
 					}
@@ -388,13 +393,18 @@
 					}
 
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 
 			},
 			clickStationDelete() {
 				const _this = this
-				showModal("纭鍒犻櫎绔欑偣", "璀﹀憡",true,"纭畾","鍙栨秷").then((res) => {
+				showModal({
+					title: this.translate("ask_confirm_remove"),
+					content: `${this.translate('delete_selected_station')}`,
+					confirmText: this.translate('remove'),
+					cancelText: this.translate('cancel'),
+				}).then((res) => {
 					if (res) {
 						_this.deleteStation(this.stationEdit)
 						_this.$refs.refPopupOperateStation.close()
@@ -408,7 +418,7 @@
 
 				this.opStationType = "edit_pos"
 				uni.setNavigationBarTitle({
-					title: "璋冩暣绔欑偣浣嶇疆鍜屾湞鍚�
+					title: this.translate("adjust_position_orientation")
 				})
 				this.$refs.refPopupOperateStation.close()
 			},
@@ -416,7 +426,7 @@
 				this.isEdit = true
 				this.opStationType = "edit_name"
 				uni.setNavigationBarTitle({
-					title: "绔欑偣閲嶅懡鍚�
+					title: this.translate("rename")
 				})
 				this.$refs.refPopupOperateStation.close()
 			},
@@ -435,7 +445,7 @@
 
 
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 			},
 			async stationUpdate(item) {
@@ -451,7 +461,7 @@
 					}
 
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 			},
 
@@ -465,7 +475,7 @@
 				if (this.isEdit) {
 					this.opStationType = ""
 					uni.setNavigationBarTitle({
-						title: "绔欑偣鍒楄〃"
+						title: this.translate("station_list")
 					})
 					this.$refs.refPopupOperateStation.open("bottom")
 				} else {
@@ -476,7 +486,7 @@
 				try {
 					const name = this.stationEdit.name.trim()
 					if (!name) {
-						showToast("绔欑偣鍚嶇О杩樻湭杈撳叆")
+						showToast(this.translate("input_station_name"))
 						return
 					}
 					if (this.isEdit) {
@@ -484,7 +494,7 @@
 						await this.stationUpdate(this.stationEdit)
 						this.opStationType = ""
 						uni.setNavigationBarTitle({
-							title: "绔欑偣鍒楄〃"
+							title: this.translate("station_list")
 						})
 						this.$refs.refPopupOperateStation.open("bottom")
 					} else {
@@ -499,7 +509,7 @@
 					}
 
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 
 			},
@@ -519,7 +529,7 @@
 						await this.stationUpdate(this.stationEdit)
 						this.opStationType = ""
 						uni.setNavigationBarTitle({
-							title: "绔欑偣鍒楄〃"
+							title: this.translate("station_list")
 						})
 						this.$refs.refPopupOperateStation.open("bottom")
 					} else {
@@ -529,7 +539,7 @@
 					}
 				} catch (ex) {
 
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 			},
 			clickClearName() {
@@ -543,44 +553,33 @@
 				else
 					this.showClearName = false
 			},
+			validateNumber(input) {
+				// 甯哥敤姝e垯妯″紡
+				const patterns = {
+					integer: /^-?\d+$/, // 鏁存暟锛屽寘鎷礋鏁�[citation:6]
+					positiveInt: /^[1-9]\d*$/, // 姝f暣鏁�[citation:7]
+					decimal: /^-?\d*\.?\d+$/, // 灏忔暟 (鏀寔鍍�".1" 杩欐牱鐨勬牸寮�
+					decimalFixed: /^-?\d*\.?\d{0,3}$/, // 鏈�涓や綅灏忔暟 [citation:5][citation:8]
+				};
+				// 閫夋嫨闇�鐨勬ā寮忚繘琛屾祴璇曪紝渚嬪浣跨敤 decimal
+				return patterns.decimalFixed.test(input);
+			},
 			onInputX(event) {
-				const strictRegex = /^[-+]?(\d+\.?\d*|\.\d+)$/;
 				let num = event.detail.value
-				if (!strictRegex.test(num)) {
-					showToast("杈撳叆鍐呭鍙兘鍖呭惈鏁板瓧銆佹璐熷彿鍜屽皬鏁扮偣")
+				if (!this.validateNumber(num)) {
+					showToast(this.translate("input_content_only_numbers_and_signs_and_decimal"))
 					return
-				} else {
-					if (Math.round(Number(num)) === Number(num)) {
-						if (!Number.isSafeInteger(Number(num))) {
-							showToast("杈撳叆鏁板瓧瓒呭嚭鏁板�瀹夊叏鑼冨洿")
-						}
-					} else {
-						if (!Number.isSafeInteger(Math.round(Number(num)))) {
-							showToast("杈撳叆鏁板瓧瓒呭嚭鏁板�瀹夊叏鑼冨洿")
-						}
-					}
 				}
-				this.stationEdit.x = event.detail.value
+				this.stationEdit.x = Number(event.detail.value)
 
 			},
 			onInputY(event) {
-				const strictRegex = /^[-+]?(\d+\.?\d*|\.\d+)$/;
 				let num = event.detail.value
-				if (!strictRegex.test(num)) {
-					showToast("杈撳叆鍐呭鍙兘鍖呭惈鏁板瓧銆佹璐熷彿鍜屽皬鏁扮偣")
-				} else {
-					if (Math.round(Number(num)) === Number(num)) {
-						if (!Number.isSafeInteger(Number(num))) {
-							showToast("杈撳叆鏁板瓧瓒呭嚭鏁板�瀹夊叏鑼冨洿")
-						}
-					} else {
-						if (!Number.isSafeInteger(Math.round(Number(num)))) {
-							showToast("杈撳叆鏁板瓧瓒呭嚭鏁板�瀹夊叏鑼冨洿")
-						}
-					}
-
+				if (!this.validateNumber(num)) {
+					showToast(this.translate("input_content_only_numbers_and_signs_and_decimal"))
+					return
 				}
-				this.stationEdit.y = event.detail.value
+				this.stationEdit.y = Number(event.detail.value)
 
 			},
 			getStantardAngle(angle) {
@@ -666,11 +665,14 @@
 					this.angleSvg = `/static/images/angle${angle}.svg`
 					this.stationEdit.angle = angle * 3.14 / 180
 				} catch (ex) {
-					showError(ex)
+					showError(ex, this.translate('error'))
 				}
 			},
-		
 
+			translate(t) {
+				if (typeof this.$t == "function") return this.$t(`page.${t}`)
+				else return t;
+			},
 		}
 	}
 </script>

--
Gitblit v1.9.1