| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558 |
- <template>
- <view class="container">
- <!-- 头部区域 -->
- <BluetoothHeader
- @ble-data-received="handleBleDataReceived"
- />
- <!-- 主要内容区域 -->
- <scroll-view class="content" scroll-y>
- <view class="param-section">
- <!-- 经度 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="primary" size="mini" class="param-label">经度</u-button>
- </view>
- <view class="input-class">
- <u-input
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- v-model="params.longitude"
- placeholder=""
- class="param-input"
- ></u-input>
- </view>
- </view>
- <!-- 纬度 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="primary" size="mini" class="param-label">纬度</u-button>
- </view>
- <view class="input-class">
- <u-input
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- v-model="params.latitude"
- placeholder=""
- class="param-input"
- ></u-input>
- </view>
- </view>
- <!-- 时区 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="primary" size="mini" class="param-label">时区</u-button>
- </view>
- <view class="input-class">
- <u-input
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- v-model="params.timezone"
- placeholder=""
- class="param-input"
- ></u-input>
- </view>
- <u-radio-group v-model="params.timezoneMode" class="radio-group">
- <u-radio label="读" name="read"></u-radio>
- <u-radio label="写" name="write"></u-radio>
- </u-radio-group>
- <u-button :plain="true" :hairline="true" :disabled="params.timezoneMode == 'read'" size="mini" class="action-btn" @click="addValue('READ_TEMPERATURE')">天文写入</u-button>
- </view>
- <!-- 频点 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">频点[0-83]</u-button>
- </view>
- <view class="input-class">
- <u-input
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- v-model="params.frequency"
- placeholder=""
- class="param-input"
- ></u-input>
- </view>
- </view>
- <!-- 网络ID -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">网络ID</u-button>
- </view>
- <view class="input-class">
- <u-input
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- v-model="params.networkId"
- placeholder=""
- class="param-input"
- ></u-input>
- </view>
- </view>
- <!-- 模块地址 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">模块地址</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.moduleAddress"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- <u-checkbox-group
- placement="column">
- <u-checkbox v-model="params.wWl" class="checkbox" label="W_WL" @change="handleWwlChange" >W_WL</u-checkbox>
- </u-checkbox-group>
- <u-button :plain="true" :hairline="true" :disabled="params.wWl" size="mini" class="action-btn" @click="addValue('WRITE_ADDRESS')">参数写入</u-button>
- </view>
- <!-- 东限位 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="primary" size="mini" class="param-label">东限位(°)</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.eastLimit"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- </view>
- <!-- 西限位 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="primary" size="mini" class="param-label">西限位(°)</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.westLimit"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- <u-checkbox-group
- placement="column">
- <u-checkbox v-model="params.wLim" class="checkbox" label="W_Lin" @change="limit">W_Lim</u-checkbox>
- </u-checkbox-group>
- <u-button :plain="true" :hairline="true" :disabled="params.wLim" size="mini" class="action-btn" @click="addValue('READ_LIMIT')">限位写入</u-button>
- </view>
- <!-- 宽度 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">宽度</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.width"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- </view>
- <!-- 间距 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">间距</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.spacing"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- </view>
- <!-- 上坡度 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">上坡度</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.uphillSlope"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- </view>
- <!-- 下坡度 -->
- <view class="param-row">
- <view class="btn-class">
- <u-button type="warning" size="mini" class="param-label">下坡度</u-button>
- </view>
- <view class="input-class">
- <u-input
- v-model="params.downhillSlope"
- placeholder=""
- class="param-input"
- @focus="editStatus = true"
- @blur="handleBlurWithDelay"
- ></u-input>
- </view>
- <u-radio-group v-model="params.downhillMode" class="radio-group">
- <u-radio label="读" name="read"></u-radio>
- <u-radio label="写" name="write"></u-radio>
- </u-radio-group>
- <u-button :plain="true" :hairline="true" :disabled="params.downhillMode == 'read'" size="mini" class="action-btn" @click="addValue('READ_INCLINATION')">参数写入</u-button>
- </view>
- </view>
- </scroll-view>
- <DeviceStatusInfo/>
- <u-modal :show="confirmShow" title="提示" :content='confirmContent' :showCancelButton=true @cancel="cancel" @confirm="confirm" ></u-modal>
- </view>
- </template>
- <script>
- import BluetoothHeader from '@/pages/components/header.vue';
- import DeviceStatusInfo from '@/pages/components/DeviceStatusInfo.vue';
- import {writeRegister,getAgreement} from '@/utils/modbus.js';
- export default {
- components: {
- BluetoothHeader,
- DeviceStatusInfo
- },
- data() {
- return {
- editStatus: false,
- communicationLink_1: false,
- communicationTimer_1: null, // 添加这一行用于保存定时器 ID
- selectAction: '',
- confirmShow: false,
- confirmContent: '是否确定执行该操作?',
- checkboxValue1: [],
- activeTab: 'home',
- params: {
- longitude: '',
- latitude: '',
- latMode: 'read',
- timezone: '',
- timezoneMode: 'read',
- frequency: '',
- networkId: '',
- moduleAddress: '',
- wWl: true,
- eastLimit: '',
- westLimit: '',
- wLim: true,
- width: '',
- spacing: '',
- uphillSlope: '',
- uphillMode: 'read',
- downhillSlope: '',
- downhillMode: 'read',
- agreementTypeName: '',
- }
- }
- },
- onShow() {
- this.agreementTypeName = getAgreement();
- },
- methods: {
- // 处理从子组件传递过来的蓝牙数据
- handleBleDataReceived(data) {
- console.log('在父组件中接收到蓝牙数据:', JSON.stringify( data));
- this.updateSensorData(data);
- },
- limit(value){
- console.log('限制选择:', value)
- this.params.wLim = !value;
- },
- handleWwlChange(value){
- this.params.wWl = !value;
- },
- handleBlurWithDelay() {
- setTimeout(() => {
- this.editStatus = false;
- }, 1000);
- },
- cancel(){
- this.confirmShow = false
- },
- addValue(action) {
- this.selectAction = action;
- this.confirmShow = true;
- },
- confirm() {
- const action = this.selectAction;
- switch (action) {
- case 'READ_TEMPERATURE': // 天文写入
- const longitude = parseFloat(this.params.longitude || "0");
- const latitude = parseFloat(this.params.latitude || "0");
- const timezone = parseFloat(this.params.timezone || "0");
- // 转换为带两位小数的整数(乘以100)
- const intValue1 = Math.round(longitude * 100);
- const intValue2 = Math.round(latitude * 100);
- const intValue3 = Math.round(timezone * 100);
- // 创建数组存储值
- const values = [];
- values.push(intValue1);
- values.push(intValue2);
- values.push(intValue3);
- writeRegister("READ_TEMPERATURE",values);
- break
- case 'WRITE_ADDRESS': // 网络地址写入
- // 获取输入值
- let frequency = parseInt(this.params.frequency) || 0; // 频点
- let networkId = parseInt(this.params.networkId) || 0; // 网络ID
- let moduleAddr = parseInt(this.params.moduleAddress) || 0; // 模块地址
- // 限制频点范围为0-83
- frequency = Math.max(0, Math.min(83, frequency));
- // 计算模块地址: 网络ID * 256 + 设备地址
- let calculatedModuleAddr = (networkId * 256) + moduleAddr;
- // 创建值数组
- let addressValues = [frequency, networkId, calculatedModuleAddr];
- // 调用写入寄存器函数
- writeRegister("READ_FREQUENCY", addressValues);
- break
- case 'READ_LIMIT': // 限位写入
- let eastLimit = parseInt(this.params.eastLimit) || 0;
- let westLimit = parseInt(this.params.westLimit) || 0;
- let limit = [eastLimit, westLimit];
- writeRegister("READ_LIMIT",limit);
- break
- case 'READ_INCLINATION': // 坡度写入
- let width = parseFloat( this.params.width);
- let interval = parseFloat(this.params.spacing);
- let upgrade = parseFloat(this.params.uphillSlope);
- let downgrade = parseFloat(this.params.downhillSlope);
- // 转换为16位整数并乘以100
- let number = Math.floor(width * 100);
- let number1 = Math.floor(interval * 100);
- let number2 = Math.floor(upgrade * 100);
- let number3 = Math.floor(downgrade * 100);
- let number4 = [number, number1, number2, number3];
- writeRegister("READ_INCLINATION",number4);
- break
- }
- this.confirmShow = false;
- uni.showToast({
- title: '操作执行成功!',
- icon: 'success',
- duration: 2000
- });
- },
- handleLink() {
- uni.showToast({
- title: '连接设备',
- icon: 'none'
- })
- },
- switchTab(tab) {
- this.activeTab = tab
- uni.showToast({
- title: `切换到${tab}`,
- icon: 'none'
- })
- },
- updateSensorData(data) {
- if (data.device !== '255')
- // 根据蓝牙数据更新参数值
- if (data.Longitude_50 !== undefined && this.params.timezoneMode == 'read') {
- this.params.longitude = data.Longitude_50
- }
- if (data.Latitude_51 !== undefined && this.params.timezoneMode == 'read') {
- this.params.latitude = data.Latitude_51
- }
- if (data.TimeZone_52 !== undefined && this.params.timezoneMode == 'read') {
- this.params.timezone = data.TimeZone_52
- }
- if (data.Frequence_25 !== undefined && this.params.wWl) {
- this.params.frequency = data.Frequence_25
- }
- if (data.NetworkId_26 !== undefined && this.params.wWl) {
- this.params.networkId = data.NetworkId_26
- }
- if (data.modAddre_27 !== undefined && this.params.wWl) {
- this.params.moduleAddress = data.modAddre_27
- }
- if (data.qEasternLimit_64 !== undefined && this.params.wLim) {
- this.params.eastLimit = data.qEasternLimit_64
- }
- if (data.qWesternLimit_65 !== undefined && this.params.wLim) {
- this.params.westLimit = data.qWesternLimit_65
- }
- if (data.qwidth_60 !== undefined && this.params.downhillMode == 'read') {
- this.params.width = data.qwidth_60
- }
- if (data.Interval_61 !== undefined && this.params.downhillMode == 'read') {
- this.params.spacing = data.Interval_61
- }
- if (data.UpGrade_62 !== undefined && this.params.downhillMode == 'read') {
- this.params.uphillSlope = data.UpGrade_62
- }
- if (data.DownGrade_63 !== undefined && this.params.downhillMode == 'read') {
- this.params.downhillSlope = data.DownGrade_63
- }
- // 设置6秒后将 communicationLink_1 设置为 false 的定时器
- this.communicationTimer_1 = setTimeout(() => {
- this.communicationLink_1 = false
- this.communicationTimer_1 = null
- }, 5000)
- }
- }
- }
- </script>
- <style lang="scss" >
- @import '@/static/scss/custom-theme.scss';
- .container {
- height: calc(100vh - 140px);
- display: flex;
- flex-direction: column;
- background-color: $custom-bg-tertiary;
- }
- .status-bar {
- height: $custom-status-height;
- background-color: $custom-bg-primary;
- @include flex-between;
- padding: 0 $custom-spacing-md;
- font-size: 14px;
- .status-left {
- color: $custom-text-primary;
- }
- .status-right {
- @include flex-start;
- gap: $custom-spacing-xs;
- .data-rate {
- color: $custom-text-secondary;
- font-size: 12px;
- }
- .wifi-icon, .hd-text, .network, .battery {
- font-size: 12px;
- }
- }
- }
- .content {
- flex: 1;
- padding: $custom-spacing-md;
- height: calc(100vh - 180px);
- }
- .param-section {
- @include card-style;
- overflow: auto;
- }
- .param-row {
- @include flex-start;
- margin-bottom: $custom-spacing-md;
- gap: $custom-spacing-sm;
- height: 40px;
- .param-label {
- width: 70px;
- @include button-style('primary');
- }
- .param-input {
- flex: 1;
- width: 60px;
- @include input-style;
- }
- .radio-group {
- @include flex-start;
- gap: $custom-spacing-md;
- }
- .checkbox {
- margin-left: $custom-spacing-sm;
- }
- .action-btn {
- border: 1px solid $custom-border-secondary;
- height: 20px;
- line-height: 20px;
- margin-right: 0px;
- }
- }
- // 响应式设计
- @include responsive(md) {
- .param-row {
- .param-input {
- min-width: 150px;
- }
- }
- }
- @include responsive(lg) {
- .param-row {
- .param-input {
- min-width: 200px;
- }
- }
- }
- ::v-deep .param-section .u-button--mini{
- width: 80px !important;
- height: 36px !important;
- font-size: 10px !important;
- }
- ::v-deep .param-section .u-input{
- width: 60px !important;
- }
- ::v-deep .content text{
- font-size: 12px !important;
- }
- .typeSelect{
- font-size: 16px;
- color: #fff;
- font-weight: 600;
- display: flex;
- }
- </style>
|