setting.vue 13 KB

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