setting.vue 11 KB

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