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'
@@ -45,13 +45,13 @@
            <view class="tip">请输入站点名称</view>
            <view class="name-input">
               <input ref="refInputName" :focus="true" placeholder="输入站点名称" :value="stationEdit.name"
                  @input="onInputName"></input>
                  @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,19 +60,19 @@
               <view class="coordinate">
                  <text class="name">横坐标:</text>
                  <input ref="refInputX" class="number-input" type="number" :value="stationEdit.x"
                     @input="onInputX"></input>
                     @input="onInputX" />
               </view>
               <view class="coordinate">
                  <text class="name">竖坐标:</text>
                  <input ref="refInputX" class="number-input" type="number" :value="stationEdit.y"
                     @input="onInputY"></input>
                     @input="onInputY" />
               </view>
            </view>
            <view class="tip">调节朝向</view>
            <view class="angle-group">
               <image class="img-angle" :src="angleSvg" alt="SVG 图片" />
               <image class="img-angle-pos" src="/images/Frame 153.svg" alt="SVG 图片"
               <image class="img-angle-pos" src="/images/Frame_153.svg" alt="SVG 图片"
                  @touchstart="handleAngleTouchStart" @touchmove="handleAngleTouchMove" />
            </view>
            <a-button type="primary" class="button" @click="clickPosOK">完成</a-button>
@@ -110,8 +110,10 @@
      showToast,
      showModal,
      session,
      showError,
      showInfo
   } from "@/comm/utils.js"
   // import OIFabric from "@/components/oi-fabric/index.vue"
   import {
      Button
   } from 'antd-mobile-vue-next'
@@ -173,7 +175,7 @@
         this.onlyAdd = option.isAdd ? true : false
         uni.setNavigationBarTitle({
            title: "站点列表"
            title: this.translate("station_list")
         })
         uni.getSystemInfo({
            success(e) {
@@ -184,7 +186,7 @@
         if (this.onlyAdd) {
            this.opStationType = "edit_name"
            uni.setNavigationBarTitle({
               title: "添加站点"
               title: this.translate("add_station")
            })
         }
@@ -203,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")
@@ -258,7 +260,7 @@
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         async loadAgvState() {
@@ -266,7 +268,7 @@
               const info = await getAgvState(this.ip)
               return info
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
               return {}
            }
         },
@@ -275,7 +277,7 @@
               const info = await stations(this.ip)
               return info.station_list || []
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
               return []
            }
         },
@@ -291,7 +293,7 @@
            }
            this.opStationType = "edit_name"
            uni.setNavigationBarTitle({
               title: "添加站点"
               title:  this.translate("add_station")
            })
         },
@@ -359,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)
               }
@@ -386,13 +393,18 @@
               }
            } catch (ex) {
               this.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()
@@ -406,7 +418,7 @@
            this.opStationType = "edit_pos"
            uni.setNavigationBarTitle({
               title: "调整站点位置和朝向"
               title: this.translate("adjust_position_orientation")
            })
            this.$refs.refPopupOperateStation.close()
         },
@@ -414,7 +426,7 @@
            this.isEdit = true
            this.opStationType = "edit_name"
            uni.setNavigationBarTitle({
               title: "站点重命名"
               title: this.translate("rename")
            })
            this.$refs.refPopupOperateStation.close()
         },
@@ -433,7 +445,7 @@
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         async stationUpdate(item) {
@@ -449,7 +461,7 @@
               }
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
            }
         },
@@ -463,7 +475,7 @@
            if (this.isEdit) {
               this.opStationType = ""
               uni.setNavigationBarTitle({
                  title: "站点列表"
                  title: this.translate("station_list")
               })
               this.$refs.refPopupOperateStation.open("bottom")
            } else {
@@ -474,7 +486,7 @@
            try {
               const name = this.stationEdit.name.trim()
               if (!name) {
                  showToast("站点名称还未输入")
                  showToast(this.translate("input_station_name"))
                  return
               }
               if (this.isEdit) {
@@ -482,7 +494,7 @@
                  await this.stationUpdate(this.stationEdit)
                  this.opStationType = ""
                  uni.setNavigationBarTitle({
                     title: "站点列表"
                     title: this.translate("station_list")
                  })
                  this.$refs.refPopupOperateStation.open("bottom")
               } else {
@@ -497,7 +509,7 @@
               }
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
            }
         },
@@ -517,7 +529,7 @@
                  await this.stationUpdate(this.stationEdit)
                  this.opStationType = ""
                  uni.setNavigationBarTitle({
                     title: "站点列表"
                     title: this.translate("station_list")
                  })
                  this.$refs.refPopupOperateStation.open("bottom")
               } else {
@@ -527,7 +539,7 @@
               }
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         clickClearName() {
@@ -541,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("输入数字超出数值安全范围")
                  }
               } 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) {
@@ -664,18 +665,14 @@
               this.angleSvg = `/static/images/angle${angle}.svg`
               this.stationEdit.angle = angle * 3.14 / 180
            } catch (ex) {
               this.showError(ex)
               showError(ex, this.translate('error'))
            }
         },
         showError(ex) {
            let exStr = JSON.stringify(ex)
            if (exStr == "{}")
               exStr = ex
            let tip = typeof ex.msg == "string" ? ex.msg : exStr
            showModal(tip, "错误", false,"确定")
         translate(t) {
            if (typeof this.$t == "function") return this.$t(`page.${t}`)
            else return t;
         },
      }
   }
</script>