setting.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <view class="container">
  3. <view class="setting">
  4. <view class="prop-item">
  5. <view class="prop-title">充电电流</view>
  6. <view class="prop-value">
  7. <view :style="item.style" class="value-tag" @click="checkItem(current,item)" v-for="item in current.items">
  8. {{ item.text }}
  9. </view>
  10. </view>
  11. <view class="prop-input" v-if="current.custom">
  12. <input v-model="current.customValue" class="input" placeholder="请输入电流"/>
  13. <view style="color: #0E9F9B">A</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="bottom-area">
  18. <view class="btn" @click="confirm">确认</view>
  19. <view class="areas">
  20. <view class="areas-item" @click="sendMainboardCmd">
  21. <view class="areas-img">
  22. <image style="width: 50px;height: 50px" :src="imgUrl+'/seting/mainboard.png'"></image>
  23. </view>
  24. <view>
  25. <view>获取主板配置</view>
  26. </view>
  27. </view>
  28. <view class="areas-item" @click="resetMainboard">
  29. <view class="areas-img">
  30. <image style="width: 50px;height: 50px" :src="imgUrl+'/seting/reset.png'"></image>
  31. </view>
  32. <view>
  33. <view >恢复默认配置</view>
  34. </view>
  35. </view>
  36. <view class="areas-item" @click="restartMainboard">
  37. <view class="areas-img">
  38. <image style="width: 50px;height: 50px" :src="imgUrl+'/seting/restart.png'"></image>
  39. </view>
  40. <view>
  41. <view>重启充电桩</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {setCurrent, getMainbordConfig,sendMainboardCmd, reset, restart,parseDataObj} from "@/utils/weitiandi/device/device.js";
  50. // #ifdef APP
  51. import ecUI from '@/utils/ecUI.js'
  52. import ecBLE from '@/utils/ecBLE/ecBLE.js'
  53. // #endif
  54. // #ifdef MP
  55. const ecUI = require('@/utils/ecUI.js')
  56. const ecBLE = require('@/utils/ecBLE/ecBLE.js')
  57. // #endif
  58. let ctx
  59. let isCheckScroll = true
  60. let isCheckRevHex = false
  61. let isCheckSendHex = false
  62. let sendData = ''
  63. export default {
  64. data() {
  65. return {
  66. scriptTask:null,
  67. deviceId: "",
  68. ccid:"",
  69. visitTime: "",
  70. mainBoardInfo:{},
  71. current: {
  72. items: [
  73. {text: "8A", style: "", value: 8},
  74. {text: "10A", style: "", value: 10},
  75. {text: "16A", style: "", value: 16},
  76. {text: "32A", style: "", value: 32},
  77. {text: "自定义", style: "", value: -1}
  78. ],
  79. custom: false,
  80. customValue: ''
  81. }
  82. }
  83. },
  84. onUnload (){
  85. this.closeSocket();
  86. },
  87. computed: {
  88. imgUrl: function () {
  89. return getApp().globalData.config.imgUrl;
  90. }
  91. },
  92. onLoad(opt) {
  93. this.deviceId = opt.id;
  94. this.ccid = opt.ccid;
  95. this.buletooth();
  96. },
  97. methods: {
  98. closeSocket(){
  99. ecBLE.onBLEConnectionStateChange(() => {})
  100. ecBLE.onBLECharacteristicValueChange(() => {})
  101. },
  102. recon(){
  103. let self = this;
  104. ecUI.showLoading('设备连接中')
  105. let blueid = uni.getStorageSync('blueid');
  106. ecBLE.onBLEConnectionStateChange(res => {
  107. ecUI.hideLoading()
  108. if (res.ok) {
  109. self.buletooth();
  110. } else {
  111. uni.removeStorageSync('blueid');
  112. ecUI.showModal(
  113. '提示',
  114. '连接失败,errCode=' + res.errCode + ',errMsg=' + res.errMsg
  115. )
  116. }
  117. })
  118. ecBLE.createBLEConnection(blueid);
  119. },
  120. buletooth(){
  121. let self = this;
  122. ctx = this
  123. isCheckScroll = true
  124. isCheckRevHex = false
  125. isCheckSendHex = false
  126. sendData = ''
  127. //on disconnect
  128. ecBLE.onBLEConnectionStateChange(() => {
  129. uni.showModal({
  130. title: '提示',
  131. content: '蓝牙断开连接',
  132. confirmText:"点击重连",
  133. showCancel:false,
  134. success: function (res) {
  135. if (res.confirm) {
  136. self.recon();
  137. } else if (res.cancel) {
  138. console.log('用户点击取消');
  139. }
  140. }
  141. });
  142. })
  143. //receive data
  144. ecBLE.onBLECharacteristicValueChange((str, strHex) => {
  145. isCheckRevHex = true;
  146. let data =
  147. (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
  148. // console.log(data)
  149. self.$modal.closeLoading();
  150. console.log("settting:"+data);
  151. //AA 67 0D 05 00 00 00 00 00 00 00 00 00 25 E2 00 80
  152. data = parseDataObj(data);
  153. self.messageCallback(data);
  154. })
  155. self.sendMainboardCmd();
  156. },
  157. messageCallback(data){
  158. let self = this;
  159. let type = data.type;
  160. let real_data = data.real_data;
  161. if(type == 103){
  162. self.portDetail = real_data;
  163. self.$modal.closeLoading();
  164. }
  165. if(type == 116){
  166. self.$modal.closeLoading();
  167. }
  168. if(type == 96){
  169. self.mainBoardInfo = real_data;
  170. self.formatMainboardData();
  171. self.$modal.closeLoading();
  172. }
  173. console.log('收到服务器内容:' + JSON.stringify(data));
  174. },
  175. formatMainboardData(){
  176. let mainBoardInfo = this.mainBoardInfo;
  177. let max_current = mainBoardInfo.max_current;
  178. max_current = max_current/100;
  179. this.setCurrent(max_current);
  180. },
  181. setCurrent(max_current){
  182. this.current.currenValue = max_current;
  183. let items = this.current.items;
  184. let len = items.length;
  185. let hasValue = false;
  186. this.current.custom = false;
  187. for (let i = 0; i < len; i++) {
  188. let dian = items[i];
  189. if(dian.value == max_current){
  190. hasValue = true;
  191. dian.style = "; background: #0E9F9B;color:white"
  192. }else{
  193. dian.style = "; background: rgb(227, 242, 245);color: #0E9F9B;"
  194. }
  195. }
  196. if(!hasValue){
  197. this.current.custom = true;
  198. items[len-1].style = "; background: #0E9F9B;color:white"
  199. }
  200. this.current.customValue = max_current;
  201. },
  202. async checkItem(obj, item) {
  203. let items = obj.items;
  204. let len = items.length;
  205. for (let i = 0; i < len; i++) {
  206. let dian = items[i];
  207. dian.style = "; background: rgb(227, 242, 245);color: #0E9F9B;"
  208. }
  209. item.style = "; background: #0E9F9B;color:white"
  210. if (item.value == -1) {
  211. obj.custom = true;
  212. obj.customValue = 0;
  213. } else {
  214. obj.custom = false;
  215. obj.customValue = item.value;
  216. }
  217. },
  218. async confirm() {
  219. let currenValue = this.current.customValue;
  220. currenValue = currenValue *100;
  221. let deviceId = this.deviceId;
  222. // 发送到后端
  223. let self = this;
  224. this.$modal.loading("保存中。。");
  225. setCurrent(currenValue).then(res => {
  226. this.$modal.showToast("保存成功");
  227. setTimeout(function(){
  228. self.sendMainboardCmd();
  229. },1000)
  230. })
  231. },
  232. sendMainboardCmd() {
  233. // let str = "AA 60 21 01 08 F4 01 E7 03 00 D0 20 07 09 05 16 08 00 00 00 05 80 0C 00 00 FC 0D 0C 0F 12 08 07 08 07 08 07 80";
  234. // let data = parseDataObj(str);
  235. // this.messageCallback(data);
  236. this.$modal.loading("正在获取配置信息");
  237. sendMainboardCmd().then(res => {
  238. })
  239. },
  240. getMainboardConfig(){
  241. this.startTimer();
  242. },
  243. startTimer(){
  244. let self = this;
  245. this.timer = setTimeout(function (){
  246. getMainbordConfig({deviceId: self.deviceId,ccid:this.ccid},self.visitTime).then(res=>{
  247. let data = res.data;
  248. if(data != null){
  249. self.mainBoardInfo = data;
  250. self.formatMainboardData();
  251. self.$modal.closeLoading();
  252. }else{
  253. self.startTimer();
  254. }
  255. });
  256. },1000);
  257. },
  258. resetMainboard() {
  259. let deviceId = this.deviceId;
  260. // 恢复默认配置
  261. let self = this;
  262. this.$modal.loading("正在重置,请稍等...");
  263. reset().then(res => {
  264. setTimeout(function(){
  265. self.sendMainboardCmd();
  266. },1000)
  267. })
  268. },
  269. async restartMainboard() {
  270. let deviceId = this.deviceId;
  271. this.$modal.loading("正在重启中,请稍等...");
  272. // 重启充电桩
  273. let self = this;
  274. restart().then(res => {
  275. setTimeout(function(){
  276. self.sendMainboardCmd();
  277. },1000)
  278. })
  279. }
  280. }
  281. }
  282. </script>
  283. <style>
  284. .container {
  285. position: absolute;
  286. inset: 0;
  287. background: rgb(249, 252, 255);
  288. }
  289. .prop-item {
  290. padding: 2vh;
  291. }
  292. .prop-value {
  293. display: flex;
  294. flex-direction: row;
  295. }
  296. .prop-title {
  297. color: #252525;
  298. font-weight: bold;
  299. margin-bottom: 2.5vh;
  300. }
  301. .value-tag {
  302. background: rgb(227, 242, 245);
  303. color: #0E9F9B;
  304. width: 14vw;
  305. height: 4vh;
  306. line-height: 4vh;
  307. border-radius: 3vw;
  308. text-align: center;
  309. margin: 0 1vw;
  310. font-weight: bold;
  311. font-size: 12px;
  312. }
  313. .prop-input {
  314. display: flex;
  315. flex-direction: row;
  316. line-height: 4vh;
  317. margin: 2vh 0;
  318. }
  319. .input {
  320. background: rgb(227, 242, 245);
  321. border-radius: 30px;
  322. font-size: 12px;
  323. height: 4vh;
  324. padding: 0 2vw;
  325. margin: 0 1vw;
  326. width: 90%;
  327. }
  328. .bottom-area {
  329. position: absolute;
  330. bottom: 0px;
  331. height: 24vh;
  332. left: 0;
  333. right: 0;
  334. }
  335. .btn {
  336. background: #0E9F9B;
  337. text-align: center;
  338. color: white;
  339. height: 6vh;
  340. line-height: 6vh;
  341. margin: 0 5vh;
  342. border-radius: 1vh;
  343. border-style: none;
  344. }
  345. .btn1 {
  346. background: #f9fcff;
  347. /* text-align: center;
  348. color: white;
  349. height:6vh;
  350. line-height: 6vh;
  351. margin:0 5vh;
  352. border-radius: 1vh; */
  353. border-color: transparent;
  354. }
  355. .areas {
  356. display: flex;
  357. flex-direction: row;
  358. text-align: center;
  359. margin-top: 3vh
  360. }
  361. .areas-item {
  362. width: 33%;
  363. }
  364. .areas-img {
  365. text-align: center;
  366. }
  367. </style>