cuiqian2004
4 天以前 2af5f043b60c1f7ac38ecccc8f5bf44743134325
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'
@@ -50,8 +50,8 @@
                  @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'">
@@ -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) {
            // 常用正则模式
            const patterns = {
               integer: /^-?\d+$/, // 整数,包括负数 [citation:6]
               positiveInt: /^[1-9]\d*$/, // 正整数 [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("输入数字超出数值安全范围")
            if (!this.validateNumber(num)) {
               showToast(this.translate("input_content_only_numbers_and_signs_and_decimal"))
               return
                  }
               } else {
                  if (!Number.isSafeInteger(Math.round(Number(num)))) {
                     showToast("输入数字超出数值安全范围")
                  }
               }
            }
            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>