two.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  1. <template>
  2. <view class="container">
  3. <!-- 头部区域 -->
  4. <BluetoothHeader
  5. @ble-data-received="handleBleDataReceived"
  6. />
  7. <!-- 主要内容区域 -->
  8. <scroll-view class="content" >
  9. <view class="param-section">
  10. <!-- 电机方向 -->
  11. <view class="param-row">
  12. <view class="btn-class">
  13. <u-button type="primary" size="mini" class="param-label">电机方向</u-button>
  14. </view>
  15. <view class="input-class" >
  16. <u-input
  17. @focus="editStatus = true"
  18. @blur="handleBlurWithDelay"
  19. v-model="params.motorDirection"
  20. disabledColor="#ffffff"
  21. placeholder="请选择方向"
  22. readonly
  23. ></u-input>
  24. </view>
  25. <view class="checkbox-class">
  26. <u-checkbox-group
  27. placement="column">
  28. <u-checkbox v-model="params.wDir" @change="handleDirectionChange" class="checkbox" label="W_Dir">W_Dir</u-checkbox>
  29. </u-checkbox-group>
  30. </view>
  31. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" @click="writeDirection" :disabled="params.wDir">方向设置</u-button>
  32. </view>
  33. <!-- 通讯时间 -->
  34. <view class="param-row">
  35. <view class="btn-class">
  36. <u-button type="primary" size="mini" class="param-label">通讯时间</u-button>
  37. </view>
  38. <view class="input-class">
  39. <u-input
  40. @focus="editStatus = true"
  41. @blur="handleBlurWithDelay"
  42. v-model="params.communicationTime"
  43. disabledColor="#ffffff"
  44. placeholder=""
  45. ></u-input>
  46. </view>
  47. <view class="checkbox-class">
  48. <u-checkbox-group v-model="checkboxValue_timedSend"
  49. placement="column">
  50. <u-checkbox name="timedSend" v-model="params.timedSend" class="checkbox" label="定时发送" @change="handleCommunicationTimeChange">定时发送</u-checkbox>
  51. </u-checkbox-group>
  52. </view>
  53. </view>
  54. <!-- 夜返角度 -->
  55. <view class="param-row">
  56. <view class="btn-class">
  57. <u-button type="primary" size="mini" class="param-label">夜返角度°</u-button>
  58. </view>
  59. <view class="input-class">
  60. <u-input
  61. @focus="editStatus = true"
  62. @blur="handleBlurWithDelay"
  63. v-model="params.nightReturnAngle"
  64. placeholder="请输入角度"
  65. type="text"
  66. class="param-input"
  67. ></u-input>
  68. </view>
  69. <view class="checkbox-class">
  70. <u-checkbox-group
  71. placement="column">
  72. <u-checkbox v-model="params.wBackA" class="checkbox" label="W_BackA" @change="handleNightReturnAngleChange">W_BackA</u-checkbox>
  73. </u-checkbox-group>
  74. </view>
  75. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wBackA"
  76. @click="writeNightReturnAngle">夜返角写入
  77. </u-button>
  78. </view>
  79. <!-- 放平角度 -->
  80. <view class="param-row">
  81. <view class="btn-class">
  82. <u-button type="primary" size="mini" class="param-label">放平角度°</u-button>
  83. </view>
  84. <view class="input-class">
  85. <u-input
  86. @focus="editStatus = true"
  87. @blur="handleBlurWithDelay"
  88. v-model="params.flatAngle"
  89. placeholder="请输入角度"
  90. type="text"
  91. class="param-input"
  92. ></u-input>
  93. </view>
  94. <view class="checkbox-class">
  95. <u-checkbox-group
  96. placement="column">
  97. <u-checkbox v-model="params.wFlat" class="checkbox" label="W_Flat" @change="handleFlatAngleChange">W_Flat</u-checkbox>
  98. </u-checkbox-group>
  99. </view>
  100. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wFlat" @click="writeFlatAngle">
  101. 放平角度写入
  102. </u-button>
  103. </view>
  104. <!-- 指定角度 -->
  105. <view class="param-row">
  106. <view class="btn-class">
  107. <u-button type="primary" size="mini" class="param-label">指定角度°</u-button>
  108. </view>
  109. <view class="input-class">
  110. <u-input
  111. @focus="editStatus = true"
  112. @blur="handleBlurWithDelay"
  113. v-model="params.specifiedAngle"
  114. placeholder="请输入角度"
  115. type="text"
  116. class="param-input"
  117. ></u-input>
  118. </view>
  119. <view class="checkbox-class">
  120. <u-checkbox-group
  121. placement="column">
  122. <u-checkbox v-model="params.wSetA" class="checkbox" label="W_SetA" @change="handleSpecifiedAngleChange">W_SetA</u-checkbox>
  123. </u-checkbox-group>
  124. </view>
  125. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wSetA" @click="writeSpecifiedAngle">
  126. 指定角度写入
  127. </u-button>
  128. </view>
  129. <!-- 雪天角度 -->
  130. <view class="param-row">
  131. <view class="btn-class">
  132. <u-button type="primary" size="mini" class="param-label">雪天角度°</u-button>
  133. </view>
  134. <view class="input-class">
  135. <u-input
  136. @focus="editStatus = true"
  137. @blur="handleBlurWithDelay"
  138. v-model="params.snowAngle"
  139. placeholder="请输入角度"
  140. type="text"
  141. class="param-input"
  142. ></u-input>
  143. </view>
  144. <view class="checkbox-class">
  145. <u-checkbox-group
  146. placement="column">
  147. <u-checkbox v-model="params.wSno" class="checkbox" label="W_Sno" @change="handleSnowAngleChange">W_Sno</u-checkbox>
  148. </u-checkbox-group>
  149. </view>
  150. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wSno" @click="writeSnowAngle">
  151. 雪天角度写入
  152. </u-button>
  153. </view>
  154. <!-- 大风角度 -->
  155. <view class="param-row">
  156. <view class="btn-class">
  157. <u-button type="primary" size="mini" class="param-label">大风角度°</u-button>
  158. </view>
  159. <view class="input-class">
  160. <u-input
  161. @focus="editStatus = true"
  162. @blur="handleBlurWithDelay"
  163. v-model="params.windAngle"
  164. placeholder="请输入角度"
  165. type="text"
  166. class="param-input"
  167. ></u-input>
  168. </view>
  169. <view class="checkbox-class">
  170. <u-checkbox-group
  171. placement="column">
  172. <u-checkbox v-model="params.wWin" class="checkbox" label="W_Win" @change="handleWindAngleChange">W_Win</u-checkbox>
  173. </u-checkbox-group>
  174. </view>
  175. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wWin" @click="writeWindAngle">
  176. 大风角度写入
  177. </u-button>
  178. </view>
  179. <!-- 过流值 -->
  180. <view class="param-row">
  181. <view class="btn-class">
  182. <u-button type="primary" size="mini" class="param-label">过流值(A)</u-button>
  183. </view>
  184. <view class="input-class">
  185. <u-input
  186. @focus="editStatus = true"
  187. @blur="handleBlurWithDelay"
  188. v-model="params.overcurrentValue"
  189. placeholder="请输入过流值"
  190. type="text"
  191. class="param-input"
  192. ></u-input>
  193. </view>
  194. <view class="checkbox-class">
  195. <u-checkbox-group
  196. placement="column">
  197. <u-checkbox v-model="params.wCurr" class="checkbox" label="W_Curr" @change="handleOvercurrentValueChange">W_Curr</u-checkbox>
  198. </u-checkbox-group>
  199. </view>
  200. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wCurr"
  201. @click="writeOvercurrentProtection">过流保护写入
  202. </u-button>
  203. </view>
  204. <!-- 跟踪精度 -->
  205. <view class="param-row">
  206. <view class="btn-class">
  207. <u-button type="primary" size="mini" class="param-label">跟踪精度</u-button>
  208. </view>
  209. <view class="input-class">
  210. <u-input
  211. @focus="editStatus = true"
  212. @blur="handleBlurWithDelay"
  213. v-model="params.trackingAccuracy"
  214. placeholder="请输入精度"
  215. type="text"
  216. class="param-input"
  217. ></u-input>
  218. </view>
  219. <view class="checkbox-class">
  220. <u-checkbox-group
  221. placement="column">
  222. <u-checkbox v-model="params.wAccu" class="checkbox" label="W_Accu" @change="handleAccuracyChange">W_Accu</u-checkbox>
  223. </u-checkbox-group>
  224. </view>
  225. <u-button :plain="true" :hairline="true" size="mini" class="action-btn" :disabled="params.wAccu" @click="writeAccuracy">
  226. 精度写入
  227. </u-button>
  228. </view>
  229. </view>
  230. </scroll-view>
  231. <DeviceStatusInfo/>
  232. <u-action-sheet
  233. :show="showMotorDirection"
  234. :actions="directionOptions"
  235. title="请选择电机方向"
  236. @close="showMotorDirection = false"
  237. @select="motorDirectionSelect"
  238. >
  239. </u-action-sheet>
  240. </view>
  241. </template>
  242. <script>
  243. import BluetoothHeader from '@/pages/components/header.vue';
  244. import DeviceStatusInfo from '@/pages/components/DeviceStatusInfo.vue';
  245. import {writeRegister,setTime,stopHeartbeat,setTimeStatus,getAgreement} from '@/utils/modbus.js';
  246. export default {
  247. components: {
  248. BluetoothHeader,
  249. DeviceStatusInfo
  250. },
  251. data() {
  252. return {
  253. agreementTypeName :'',
  254. checkboxValue_timedSend: ['timedSend'],
  255. editStatus: false,
  256. showMotorDirection: false,
  257. checkboxValue1: [],
  258. activeTab: 'settings2',
  259. params: {
  260. motorDirection: '正转',
  261. communicationTime: '0.5',
  262. nightReturnAngle: '-30',
  263. flatAngle: '-1',
  264. specifiedAngle: '20',
  265. snowAngle: '30',
  266. windAngle: '10',
  267. overcurrentValue: '5',
  268. trackingAccuracy: '1',
  269. wDir:true,
  270. timedSend: true,
  271. wBackA: true,
  272. wFlat: true,
  273. wSetA: true,
  274. wSno: true,
  275. wWin: true,
  276. wCurr: true,
  277. wAccu: true
  278. },
  279. directionOptions: [
  280. {name: '正转', value: '正转'},
  281. {name: '反转', value: '反转'}
  282. ],
  283. communicationLink_2: false,
  284. communicationTimer_2: null, // 添加这一行用于保存定时器 ID
  285. }
  286. },
  287. onShow() {
  288. this.agreementTypeName = getAgreement();
  289. },
  290. methods: {
  291. // 处理从子组件传递过来的蓝牙数据
  292. handleBleDataReceived(data) {
  293. console.log('在父组件中接收到蓝牙数据:', data);
  294. this.updateSensorData(data);
  295. },
  296. handleBlurWithDelay() {
  297. setTimeout(() => {
  298. this.editStatus = false;
  299. }, 1000);
  300. },
  301. handleNightReturnAngleChange(value){
  302. this.params.wBackA = !value;
  303. },
  304. handleFlatAngleChange(value){
  305. this.params.wFlat = !value;
  306. },
  307. handleSpecifiedAngleChange(value){
  308. this.params.wSetA = !value;
  309. },
  310. handleSnowAngleChange(value){
  311. this.params.wSno = !value;
  312. },
  313. handleWindAngleChange(value){
  314. this.params.wWin = !value;
  315. },
  316. handleOvercurrentValueChange(value){
  317. this.params.wCurr = !value;
  318. },
  319. handleAccuracyChange(value){
  320. this.params.wAccu = !value;
  321. },
  322. handleCommunicationTimeChange(value){
  323. this.params.wTim = !value;
  324. if (value){
  325. let number = parseFloat(this.params.communicationTime || "0");
  326. const intValue1 = Math.round(number * 1000);
  327. setTime(intValue1);
  328. }else{
  329. stopHeartbeat();
  330. }
  331. setTimeStatus(value);
  332. },
  333. handleDirectionChange(value){
  334. this.params.wDir = !value;
  335. },
  336. motorDirectionSelect(e){
  337. this.params.motorDirection = e.name
  338. uni.showModal({
  339. title: '确认写入',
  340. content: `确定执行电机方向设置?`,
  341. success: (res) => {
  342. if (res.confirm) {
  343. if (e.name === '正转'){
  344. writeRegister('READ_DIRECTION', null)
  345. }else {
  346. writeRegister('READ_REVERSE', null)
  347. }
  348. uni.showToast({
  349. title: '操作执行成功!',
  350. icon: 'success',
  351. duration: 2000
  352. });
  353. }
  354. }
  355. });
  356. },
  357. writeDirection() {
  358. this.showMotorDirection = true;
  359. },
  360. writeNightReturnAngle() {
  361. if (this.params.wBackA) return
  362. uni.showModal({
  363. title: '确认写入',
  364. content: `是否确定执行此操作?`,
  365. success: (res) => {
  366. if (res.confirm) {
  367. writeRegister('READ_RETURN', this.params.nightReturnAngle);
  368. uni.showToast({
  369. title: '操作执行成功!',
  370. icon: 'success',
  371. duration: 2000
  372. });
  373. }
  374. }
  375. });
  376. },
  377. writeFlatAngle() {
  378. if (this.params.wFlat) return
  379. uni.showModal({
  380. title: '确认写入',
  381. content: `是否确定执行此操作?`,
  382. success: (res) => {
  383. if (res.confirm) {
  384. writeRegister('READ_FLAT', this.params.flatAngle);
  385. uni.showToast({
  386. title: '操作执行成功!',
  387. icon: 'success',
  388. duration: 2000
  389. });
  390. }
  391. }
  392. });
  393. },
  394. writeSpecifiedAngle() {
  395. if (this.params.wSetA) return
  396. uni.showModal({
  397. title: '确认写入',
  398. content: `是否确定执行此操作?`,
  399. success: (res) => {
  400. if (res.confirm) {
  401. writeRegister('READ_SPECIFY', this.params.specifiedAngle);
  402. uni.showToast({
  403. title: '操作执行成功!',
  404. icon: 'success',
  405. duration: 2000
  406. });
  407. }
  408. }
  409. });
  410. },
  411. writeSnowAngle() {
  412. if (this.params.wSno) return
  413. uni.showModal({
  414. title: '确认写入',
  415. content: `是否确定执行此操作?`,
  416. success: (res) => {
  417. if (res.confirm) {
  418. writeRegister('READ_SNOW', this.params.snowAngle);
  419. uni.showToast({
  420. title: '操作执行成功!',
  421. icon: 'success',
  422. duration: 2000
  423. });
  424. }
  425. }
  426. });
  427. },
  428. writeWindAngle() {
  429. if (this.params.wWin) return
  430. uni.showModal({
  431. title: '确认写入',
  432. content: `是否确定执行此操作?`,
  433. success: (res) => {
  434. if (res.confirm) {
  435. writeRegister('READ_WIND', this.params.windAngle);
  436. uni.showToast({
  437. title: '操作执行成功!',
  438. icon: 'success',
  439. duration: 2000
  440. });
  441. }
  442. }
  443. });
  444. },
  445. writeOvercurrentProtection() {
  446. if (this.params.wCurr) return
  447. uni.showModal({
  448. title: '确认写入',
  449. content: `是否确定执行此操作?`,
  450. success: (res) => {
  451. if (res.confirm) {
  452. writeRegister('READ_OVERCURRENT', this.params.overcurrentValue);
  453. uni.showToast({
  454. title: '操作执行成功!',
  455. icon: 'success',
  456. duration: 2000
  457. });
  458. }
  459. }
  460. });
  461. },
  462. writeAccuracy() {
  463. if (this.params.wAccu) return
  464. uni.showModal({
  465. title: '确认写入',
  466. content: `是否确定执行此操作?`,
  467. success: (res) => {
  468. if (res.confirm) {
  469. writeRegister('READ_ACCURACY', this.params.trackingAccuracy);
  470. uni.showToast({
  471. title: '操作执行成功!',
  472. icon: 'success',
  473. duration: 2000
  474. });
  475. }
  476. }
  477. });
  478. },
  479. updateSensorData(data) {
  480. // 根据蓝牙数据更新参数值
  481. if (data.MotDrection_37 !== undefined && this.params.wDir) {
  482. // 电机方向: 0表示正转,1表示反转
  483. this.params.motorDirection = data.MotDrection_37 === '1' ? '反转' : '正转'
  484. }
  485. if (data.qNightAngle_66 !== undefined && this.params.wBackA) {
  486. this.params.nightReturnAngle = data.qNightAngle_66
  487. }
  488. if (data.qFlatAngle_67 !== undefined && this.params.wFlat) {
  489. this.params.flatAngle = data.qFlatAngle_67
  490. }
  491. if (data.qSpecifiedAngle_69 !== undefined && this.params.wSetA) {
  492. this.params.specifiedAngle = data.qSpecifiedAngle_69
  493. }
  494. if (data.qSnowAngle_68 !== undefined && this.params.wSno) {
  495. this.params.snowAngle = data.qSnowAngle_68
  496. }
  497. if (data.qWindAngle_70 !== undefined && this.params.wWin ) {
  498. this.params.windAngle = data.qWindAngle_70
  499. }
  500. if (data.OverProtection_38 !== undefined && this.params.wCurr) {
  501. this.params.overcurrentValue = data.OverProtection_38
  502. }
  503. if (data.TrackingAccuracy_39 !== undefined && this.params.wAccu) {
  504. this.params.trackingAccuracy = data.TrackingAccuracy_39
  505. }
  506. // 设置6秒后将 communicationLink_2 设置为 false 的定时器
  507. this.communicationTimer_2 = setTimeout(() => {
  508. this.communicationLink_2 = false
  509. this.communicationTimer_2 = null
  510. }, 5000)
  511. }
  512. }
  513. }
  514. </script>
  515. <style lang="scss" >
  516. @import '@/static/scss/custom-theme.scss';
  517. .container {
  518. height: calc(100vh - 100px);
  519. display: flex;
  520. flex-direction: column;
  521. background-color: $custom-bg-tertiary;
  522. }
  523. .status-bar {
  524. height: $custom-status-height;
  525. background-color: $custom-bg-primary;
  526. @include flex-between;
  527. padding: 0 $custom-spacing-md;
  528. font-size: 14px;
  529. .status-left {
  530. color: $custom-text-primary;
  531. }
  532. .status-right {
  533. @include flex-start;
  534. gap: $custom-spacing-xs;
  535. .data-rate {
  536. color: $custom-text-secondary;
  537. font-size: 12px;
  538. }
  539. .wifi-icon, .hd-text, .network, .battery {
  540. font-size: 12px;
  541. }
  542. }
  543. }
  544. .content {
  545. flex: 1;
  546. padding: $custom-spacing-md;
  547. height: calc(100% - 90px) ;
  548. }
  549. .param-section {
  550. height: 100%;
  551. overflow: auto;
  552. @include card-style;
  553. }
  554. .param-row {
  555. @include flex-start;
  556. margin-bottom: $custom-spacing-md;
  557. gap: 2px;
  558. .param-label {
  559. width: 70px;
  560. @include button-style('primary');
  561. }
  562. .param-input {
  563. flex: 1;
  564. width: 60px;
  565. @include input-style;
  566. }
  567. .radio-group {
  568. @include flex-start;
  569. gap: $custom-spacing-md;
  570. }
  571. .checkbox {
  572. margin-left: $custom-spacing-sm;
  573. }
  574. .action-btn {
  575. width: 90px;
  576. background-color: $custom-bg-secondary;
  577. color: $custom-text-secondary;
  578. border: 1px solid $custom-border-secondary;
  579. height: 30px;
  580. line-height: 30px;
  581. margin-right: 0px;
  582. font-size: 12px;
  583. }
  584. }
  585. .bottom-nav {
  586. height: $custom-nav-height;
  587. background-color: $custom-nav-bg;
  588. display: flex;
  589. border-top: 1px solid $custom-border-primary;
  590. .nav-item {
  591. flex: 1;
  592. @include flex-center;
  593. font-size: 14px;
  594. color: $custom-text-secondary;
  595. background-color: $custom-bg-secondary;
  596. border-right: 1px solid $custom-border-primary;
  597. transition: $custom-transition;
  598. &:last-child {
  599. border-right: none;
  600. }
  601. &.active {
  602. background-color: $custom-nav-active-bg;
  603. color: $custom-text-primary;
  604. font-weight: bold;
  605. }
  606. &:hover {
  607. background-color: darken($custom-bg-secondary, 5%);
  608. }
  609. }
  610. }
  611. .footer-status {
  612. height: $custom-footer-height;
  613. @include gradient-bg;
  614. @include flex-between;
  615. padding: 0 $custom-spacing-md;
  616. .bt-status {
  617. color: #007aff;
  618. font-size: 14px;
  619. font-weight: bold;
  620. }
  621. .rx-tx-status {
  622. color: $custom-text-primary;
  623. font-size: 12px;
  624. }
  625. }
  626. // 响应式设计
  627. @include responsive(md) {
  628. .param-row {
  629. .param-input {
  630. min-width: 150px;
  631. }
  632. }
  633. }
  634. @include responsive(lg) {
  635. .param-row {
  636. .param-input {
  637. min-width: 200px;
  638. }
  639. }
  640. }
  641. ::v-deep .param-section .u-button--mini{
  642. width: 80px !important;
  643. height: 36px !important;
  644. font-size: 10px !important;
  645. }
  646. ::v-deep .param-section .u-input{
  647. width: 60px !important;
  648. }
  649. ::v-deep .content text{
  650. font-size: 12px !important;
  651. }
  652. .typeSelect{
  653. font-size: 16px;
  654. color: #fff;
  655. font-weight: 600;
  656. display: flex;
  657. }
  658. </style>