xiaohaizhao il y a 9 mois
Parent
commit
129be17d13

+ 46 - 24
Bluetooth/index/index.vue

@@ -119,7 +119,7 @@ export default {
     startBluetooth(services = []) {
       let that = this;
       uni.onBluetoothDeviceFound(function ({ devices }) {
-        that.devices = devices;
+        that.devices = that.devices.concat(devices);
         that.empty = devices.length == 0;
       });
       uni.startBluetoothDevicesDiscovery({
@@ -168,24 +168,44 @@ export default {
                   });
                   that.closeBLEConnection();
                 } else {
-                  device.service = res.services[0];
+                  let services = res.services.find(
+                    (v) => v.uuid.split("-")[0] == "0000FFE0"
+                  );
+                  
+                  try {
+                    uni.setBLEMTU({
+                      deviceId: item.deviceId,
+                      mtu: 512,
+                      success: (success) => {
+                        console.log("设置mtu512", success);
+                      },
+                      fail: (fail) => {
+                        console.log("设置mtu512fail", fail);
+                      },
+                    });
+                  } catch (error) {}
 
-                  uni.getBLEDeviceCharacteristics({
-                    deviceId: item.deviceId,
-                    serviceId: device.service.uuid,
-                    success(res) {
-                      console.log("获取特征", res);
-                      if (res.characteristics.length == 0) {
-                        uni.showModal({
-                          content: "未获取到蓝牙服务的特征信息",
-                          showCancel: false,
-                          confirmText: "确认",
+                  if (services) {
+                    device.services = services;
+                    uni.getBLEDeviceCharacteristics({
+                      deviceId: item.deviceId,
+                      serviceId: services.uuid,
+                      success(res) {
+                        let write = false,
+                          notify = false;
+
+                        res.characteristics.forEach((v) => {
+                          if (v.properties.notify) {
+                            device.Ncharacteristic = v;
+                            notify = true;
+                            console.log("获取到notify" + v.uuid.split("-")[0]);
+                          } else if (res.characteristics[0].properties.write) {
+                            device.Wcharacteristic = v;
+                            write = true;
+                            console.log("获取到write" + v.uuid.split("-")[0]);
+                          }
                         });
-                        that.closeBLEConnection();
-                      } else {
-                        device.characteristic = res.characteristics[0];
-                        const { write, notify } =
-                          device.characteristic.properties;
+
                         if (write && notify) {
                           uni.showModal({
                             content: `${
@@ -210,13 +230,15 @@ export default {
                           });
                           that.closeBLEConnection();
                         }
-                      }
-                    },
-                    fail(err) {
-                      console.log("获取特征失败", err);
-                      that.handleFail(fail);
-                    },
-                  });
+                      },
+                    });
+                  } else {
+                    uni.showModal({
+                      content: "未获取到蓝牙设备指定‘0000FFE0’服务",
+                      showCancel: false,
+                      confirmText: "确认",
+                    });
+                  }
                 }
               },
               fail(err) {

+ 21 - 12
control/components/prodnum-FW01B/prodnum-FW01B.vue

@@ -70,13 +70,16 @@ export default {
         }
         this.list = this.__proto__.getControlItem(names, newVal, {
           安装位置: "radio",
+          第二域名: "string",
         });
+        console.log(this.list);
         try {
           const E013 = this.list.find((v) => v.paramName == "E013");
           if (E013) {
-            this.onSendMsg(E013.w_functionid, {
-              E013: E013.params.options[0].value,
-            });
+            this.$refs.refCD.send(
+              { password: E013.params.options[0].value },
+              E013
+            );
           }
         } catch (error) {}
 
@@ -117,14 +120,22 @@ export default {
       this.$set(this.list[index], "loading", true);
     },
     onFeedback(res) {
-      const index = this.list.findIndex((v) => v.msgid == res.msgid);
+      console.log("onFeedback", res);
+
+      const index = res.node
+        ? this.list.findIndex((v) => res.node == v.paramName)
+        : this.list.findIndex((v) => v.msgid == res.msgid);
+
       if (index != -1) {
         let item = this.list[index];
         let MyInput = this.$refs.MyInput;
         MyInput.loading = false;
-
         if (res.status == 1) {
-          item.params.lastvalue = item.msg.d[item.params.param];
+          if (res.node) {
+             item.params.lastvalue = res.v;
+          } else if (res.msgid) {
+            item.params.lastvalue = item.msg.d[item.params.param];
+          }
           MyInput.show = false;
           MyInput.stepIsCalculate = null;
         } else if (res.status == 0) {
@@ -134,11 +145,10 @@ export default {
               content: `身份验证失败,将断开连接`,
               showCancel: false,
             });
-
             uni.closeBLEConnection({
-              deviceId: that.connected,
-              success(res) {},
+              deviceId: that.connected
             });
+            uni.closeBluetoothAdapter();
           } else {
             uni.showModal({
               title: "失败",
@@ -147,11 +157,10 @@ export default {
             });
           }
         }
-
         MyInput.$refs.uModal.loading = false;
         delete item.loading;
-        delete item.msgid;
-        delete item.msg;
+        // delete item.msgid;
+        // delete item.msg;
 
         this.$set(this.list, index, item);
         console.log(item);

+ 27 - 0
control/modules/My_input.vue

@@ -32,6 +32,25 @@
             </text>
           </view>
         </block>
+        <!-- string类型 -->
+        <block v-else-if="item.inputType == 'string'">
+          <view class="title u-line-1">
+            {{ item.funcname }}{{ item.params.unit || "" }}
+          </view>
+          <u--input
+            :focus="intFocus"
+            v-model="value"
+            :placeholder="item.showValue || item.params.lastvalue"
+            border="surround"
+          />
+          <view class="tips" v-if="item.paramValue">
+            <u-icon name="info-circle-fill" color="#E2201A" />
+            <text style="margin-left: 4px">
+              有一条待更新记录,待更新值为:{{ item.paramValue
+              }}{{ item.params.unit || "" }}
+            </text>
+          </view>
+        </block>
         <!-- 布尔开关 -->
         <block v-else-if="item.inputType == 'switch'">
           <view class="title u-line-1">
@@ -296,6 +315,12 @@ export default {
               params.options.find((v) => v.value == item.paramValue).label
             }”`;
           }
+        } else if (item.inputType == "string") {
+          this.value = "";
+          this.intFocus = false;
+          setTimeout(() => {
+            this.intFocus = true;
+          }, 300);
         }
         if (item.inputType == "radioNum") {
           if (item.paramValue)
@@ -422,6 +447,8 @@ export default {
         value = { ...this.replenish };
         params.options.forEach((v) => (value[`${v.key}`] = v.value));
         return this.submit(item.w_functionid, value);
+      } else if (item.inputType == "string") {
+        value = this.value;
       }
       this.submit(item.w_functionid, {
         [item.paramName]: value,

+ 19 - 7
control/modules/connectingDevice.vue

@@ -76,6 +76,7 @@ export default {
           that.circulation = null;
         },
       });
+      uni.closeBluetoothAdapter();
     },
     /* 发送 */
     send(content = {}, item) {
@@ -83,9 +84,18 @@ export default {
       content.msgid = hexMD5(
         JSON.stringify({ w_functionid: item.w_functionid, ...msg })
       );
+
       item.msgid = content.msgid;
       item.msg = content;
-      let msg = JSON.stringify(content);
+      console.log("发送通信内容", item.msg);
+
+      let msg = JSON.stringify({
+        d: content.d,
+        password: content.password,
+        msgid: content.msgid,
+        ts: content.ts,
+      });
+
       let that = this;
       const buffer = new ArrayBuffer(msg.length);
       const dataView = new DataView(buffer);
@@ -94,11 +104,14 @@ export default {
       }
       uni.writeBLECharacteristicValue({
         deviceId: that.Bluetooth.device.deviceId,
-        serviceId: that.Bluetooth.service.uuid,
-        characteristicId: that.Bluetooth.characteristic.uuid,
+        serviceId: that.Bluetooth.services.uuid,
+        characteristicId: that.Bluetooth.Wcharacteristic.uuid,
         value: buffer,
         success(res) {
           console.log("发送信息", res);
+          uni.showModal({
+            title: "测试",
+          });
         },
         fail(err) {
           console.error("发送信息失败", err);
@@ -119,8 +132,8 @@ export default {
       let that = this;
       uni.notifyBLECharacteristicValueChange({
         deviceId: that.Bluetooth.device.deviceId,
-        serviceId: that.Bluetooth.service.uuid,
-        characteristicId: that.Bluetooth.characteristic.uuid,
+        serviceId: that.Bluetooth.services.uuid,
+        characteristicId: that.Bluetooth.Ncharacteristic.uuid,
         state: true,
         success(res) {
           console.log("监听信息", res);
@@ -128,7 +141,7 @@ export default {
             let resHex = that.ab2hex(res.value);
             let result = that.hexCharCodeToStr(resHex);
             console.log("Notice", result);
-            that.$emit("onFeedback", result);
+            that.$emit("onFeedback", JSON.parse(result));
           });
         },
         fail(err) {
@@ -194,7 +207,6 @@ export default {
       }
       return resultStr.join("");
     },
-
     getRSSIText: function (rssi) {
       let text = "";
       if (rssi >= -70) {

+ 3 - 1
main.js

@@ -28,9 +28,11 @@ Vue.component('My_Files', My_Files);
 import connectingDevice from './control/modules/connectingDevice';
 Vue.component('connectingDevice', connectingDevice);
 
+console.log("process.env.NODE_ENV",process.env.NODE_ENV)
 //挂载接口
-let isDev = process.env.NODE_ENV === 'development';
+let isDev = ['development','production'].includes(process.env.NODE_ENV);
 console.log('运行环境', isDev ? '开发' : '生产');
+
 const http = {};
 // #ifdef H5
 http.baseUrl = isDev ? "/apis1" : "/apis";

+ 5 - 0
pages/facility/detail.vue

@@ -224,6 +224,7 @@ export default {
                     uni.closeBLEConnection({
                       deviceId: that.$Http.Bluetooth.device.deviceId,
                     });
+                  uni.closeBluetoothAdapter();
                   delete that.$Http.Bluetooth;
                 } catch (error) {}
               }
@@ -231,6 +232,9 @@ export default {
           });
           break;
         case 1:
+          /*    uni.openBluetoothAdapter({
+            mode: "peripheral",
+          }); */
           uni.openBluetoothAdapter({
             success: (result) => {
               if (result.errno == 0) {
@@ -253,6 +257,7 @@ export default {
                   this.$Http.setDetailMode = function (mode1) {
                     this.mode = mode1;
                     delete this.$Http.setDetailMode;
+                    uni.closeBluetoothAdapter();
                   }.bind(this);
                   this.$Http.Bluetooth = Bluetooth;
                   delete this.$Http.setBluetooth;

+ 108 - 60
pages/index/index.vue

@@ -1,33 +1,80 @@
 <template>
-	<view class="container">
-		<tab-control ref="tabControl" :active='opentabControl' />
-		<home ref="Home" v-show="PageCur == 'Home'" />
-		<facility ref="Map" :tabHeight="tabHeight" v-show="PageCur == 'Map'" />
-		<message ref="Message" v-show="PageCur == 'Message'" />
-		<mine ref="Mine" v-show="PageCur == 'Mine'" />
-		<view class="cu-bar tabbar bg-white foot" style="z-index: 100000;">
-			<!-- bg-black -->
-			<view @click="changePage('Home')" :class="PageCur == 'Home' ? 'action pitch-on-color' : 'action text-gray'">
-				<view class="iconfont" :class="PageCur == 'Home' ? 'icon-shouye-xuanzhong' : 'icon-shouye-weixuanzhong'" />
-				首页
-			</view>
-			<view @click="changePage('Map')" :class="PageCur == 'Map' ? 'action pitch-on-color' : 'action text-gray'">
-				<view class="iconfont" :class="PageCur == 'Map' ? 'icon-ditu-xuanzhong' : 'icon-ditu-weixuanzhong'" /> 地图
-			</view>
-			<view class="text-gray" @click.stop="opentabControl(true)">
-				<button class="cu-btn cuIcon-add shadow more" style="background-color:#0B3F7E;color: #fff;"></button>
-			</view>
-			<view @click="changePage('Message')"
-				:class="PageCur == 'Message' ? 'action pitch-on-color' : 'action text-gray'">
-				<view class="iconfont" :class="PageCur == 'Message' ? 'icon-xiaoxi-xuanzhong' : 'icon-xiaoxi-weixuanzhong'">
-					<!-- <view class="cu-tag badge">99</view> -->
-				</view> 消息
-			</view>
-			<view @click="changePage('Mine')" :class="PageCur == 'Mine' ? 'action pitch-on-color' : 'action text-gray'">
-				<view class="iconfont" :class="PageCur == 'Mine' ? 'icon-wode-xuanzhong' : 'icon-wode-weixuanzhong'" /> 我的
-			</view>
-		</view>
-	</view>
+  <view class="container">
+    <tab-control ref="tabControl" :active="opentabControl" />
+    <home ref="Home" v-show="PageCur == 'Home'" />
+    <facility ref="Map" :tabHeight="tabHeight" v-show="PageCur == 'Map'" />
+    <message ref="Message" v-show="PageCur == 'Message'" />
+    <mine ref="Mine" v-show="PageCur == 'Mine'" />
+    <view class="cu-bar tabbar bg-white foot" style="z-index: 100000">
+      <!-- bg-black -->
+      <view
+        @click="changePage('Home')"
+        :class="
+          PageCur == 'Home' ? 'action pitch-on-color' : 'action text-gray'
+        "
+      >
+        <view
+          class="iconfont"
+          :class="
+            PageCur == 'Home'
+              ? 'icon-shouye-xuanzhong'
+              : 'icon-shouye-weixuanzhong'
+          "
+        />
+        首页
+      </view>
+      <view
+        @click="changePage('Map')"
+        :class="PageCur == 'Map' ? 'action pitch-on-color' : 'action text-gray'"
+      >
+        <view
+          class="iconfont"
+          :class="
+            PageCur == 'Map' ? 'icon-ditu-xuanzhong' : 'icon-ditu-weixuanzhong'
+          "
+        />
+        地图
+      </view>
+      <view class="text-gray" @click.stop="opentabControl(true)">
+        <button
+          class="cu-btn cuIcon-add shadow more"
+          style="background-color: #0b3f7e; color: #fff"
+        ></button>
+      </view>
+      <view
+        @click="changePage('Message')"
+        :class="
+          PageCur == 'Message' ? 'action pitch-on-color' : 'action text-gray'
+        "
+      >
+        <view
+          class="iconfont"
+          :class="
+            PageCur == 'Message'
+              ? 'icon-xiaoxi-xuanzhong'
+              : 'icon-xiaoxi-weixuanzhong'
+          "
+        >
+          <!-- <view class="cu-tag badge">99</view> -->
+        </view>
+        消息
+      </view>
+      <view
+        @click="changePage('Mine')"
+        :class="
+          PageCur == 'Mine' ? 'action pitch-on-color' : 'action text-gray'
+        "
+      >
+        <view
+          class="iconfont"
+          :class="
+            PageCur == 'Mine' ? 'icon-wode-xuanzhong' : 'icon-wode-weixuanzhong'
+          "
+        />
+        我的
+      </view>
+    </view>
+  </view>
 </template>
 
 <script>
@@ -37,37 +84,38 @@ import message from "./modules/message.vue";
 import mine from "./modules/mine.vue";
 import tabControl from "./modules/bottomTabControl.vue";
 export default {
-	components: { home, facility, message, mine, tabControl },
-	data() {
-		return {
-			PageCur: "Home",
-			tabHeight: 98
-		}
-	},
-	mounted() {
-		this.getHeight('.cu-bar', this, false).then(res => {
-			this.tabHeight = res.height
-		})
-		this.loadElement()
-	},
-	onShow() {
-		this.$refs.Home.renderData();
-	},
-	methods: {
-		opentabControl(active) {
-			if (this.$refs.tabControl.active !== active) this.$nextTick(() => this.$refs.tabControl.active = active);
-		},
-		changePage(page) {
-			this.PageCur = page;
-			this.opentabControl(false)
-			this.loadElement()
-		},
-		loadElement(forcedUpdating) {
-			let page = this.$refs[this.PageCur];
-			if (page.uninitialized || forcedUpdating) page.init();
-		}
-	}
-}
+  components: { home, facility, message, mine, tabControl },
+  data() {
+    return {
+      PageCur: "Home",
+      tabHeight: 98,
+    };
+  },
+  mounted() {
+    this.getHeight(".cu-bar", this, false).then((res) => {
+      this.tabHeight = res.height;
+    });
+    this.loadElement();
+  },
+  onShow() {
+    this.$refs.Home.renderData();
+  },
+  methods: {
+    opentabControl(active) {
+      if (this.$refs.tabControl.active !== active)
+        this.$nextTick(() => (this.$refs.tabControl.active = active));
+    },
+    changePage(page) {
+      this.PageCur = page;
+      this.opentabControl(false);
+      this.loadElement();
+    },
+    loadElement(forcedUpdating) {
+      let page = this.$refs[this.PageCur];
+      if (page.uninitialized || forcedUpdating) page.init();
+    },
+  },
+};
 </script>
 
 <style lang="scss" scoped></style>