setting.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  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="margin-left: 100px;border-color: aliceblue;" v-model="value" asyncChange activeColor="#57B03D" inactiveColor="#080808" :activeValue="0" :inactiveValue="1" @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. if(!autoCharge ){
  140. autoCharge = 0;
  141. }
  142. return autoCharge;
  143. },
  144. setAutoCharge(value,tip){
  145. console.log("value>>>>"+value)
  146. this.value=value
  147. // for (let i = 0; i < this.autoCharge.length; i++) {
  148. // let obj = this.autoCharge[i];
  149. // if(obj.value == value){
  150. // // obj.style = "; background: #57B03D;color:white";
  151. // this.value=0
  152. // }else{
  153. // // obj.style = "; background: rgb(227, 242, 245);color: #000000;"
  154. // this.value=1
  155. // }
  156. // if(obj.text ==i18('自定义')){
  157. // obj.style +=";width:100px;"
  158. // }
  159. // }
  160. uni.setStorageSync("autoCharge",value);
  161. if(!tip){
  162. this.$modal.showToast("设置成功")
  163. }
  164. },
  165. closeSocket(){
  166. ecBLE.onBLEConnectionStateChange(() => {})
  167. ecBLE.onBLECharacteristicValueChange(() => {})
  168. },
  169. recon(){
  170. let self = this;
  171. ecUI.showLoading('设备连接中')
  172. let blueid = uni.getStorageSync('blueid');
  173. ecBLE.onBLEConnectionStateChange(res => {
  174. ecUI.hideLoading()
  175. if (res.ok) {
  176. self.buletooth();
  177. } else {
  178. uni.removeStorageSync('blueid');
  179. ecUI.showModal(
  180. '提示',
  181. '连接失败,errCode=' + res.errCode + ',errMsg=' + res.errMsg
  182. )
  183. }
  184. })
  185. ecBLE.createBLEConnection(blueid);
  186. },
  187. buletooth(){
  188. let self = this;
  189. ctx = this
  190. isCheckScroll = true
  191. isCheckRevHex = false
  192. isCheckSendHex = false
  193. sendData = ''
  194. //on disconnect
  195. ecBLE.onBLEConnectionStateChange(() => {
  196. uni.showModal({
  197. title: '提示',
  198. content: '蓝牙断开连接',
  199. confirmText:"点击重连",
  200. showCancel:false,
  201. success: function (res) {
  202. if (res.confirm) {
  203. // self.recon();
  204. uni.reLaunch({
  205. url: '/pages/bluetooth/index/index'
  206. });
  207. } else if (res.cancel) {
  208. console.log('用户点击取消');
  209. }
  210. }
  211. });
  212. })
  213. //receive data
  214. ecBLE.onBLECharacteristicValueChange((str, strHex) => {
  215. isCheckRevHex = true;
  216. let data =
  217. (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
  218. // console.log(data)
  219. self.$modal.closeLoading();
  220. console.log("settting:"+data);
  221. //AA 67 0D 05 00 00 00 00 00 00 00 00 00 25 E2 00 80
  222. data = parseDataObj(data);
  223. self.messageCallback(data);
  224. })
  225. self.sendMainboardCmd();
  226. },
  227. messageCallback(data){
  228. let self = this;
  229. let type = data.type;
  230. let real_data = data.real_data;
  231. if(type == 103){
  232. self.portDetail = real_data;
  233. self.$modal.closeLoading();
  234. }
  235. if(type == 116){
  236. self.$modal.closeLoading();
  237. }
  238. if(type == 96){
  239. self.mainBoardInfo = real_data;
  240. self.formatMainboardData();
  241. self.$modal.closeLoading();
  242. }
  243. console.log('收到服务器内容:' + JSON.stringify(data));
  244. },
  245. formatMainboardData(){
  246. let mainBoardInfo = this.mainBoardInfo;
  247. let max_current = mainBoardInfo.max_current;
  248. max_current = max_current/100;
  249. this.setCurrent(max_current);
  250. },
  251. setCurrent(max_current){
  252. this.current.currenValue = max_current;
  253. let items = this.current.items;
  254. let len = items.length;
  255. let hasValue = false;
  256. this.current.custom = false;
  257. for (let i = 0; i < len; i++) {
  258. let dian = items[i];
  259. if(dian.value == max_current){
  260. hasValue = true;
  261. dian.style = "; background: #57B03D;color:white"
  262. }else{
  263. dian.style = "; background: rgb(227, 242, 245);color: #000000;"
  264. }
  265. if(dian.text ==i18('自定义')){
  266. dian.style +=";width:100px;"
  267. }
  268. }
  269. if(!hasValue){
  270. this.current.custom = true;
  271. items[len-1].style = "; background: #57B03D;color:white"
  272. }
  273. this.current.customValue = max_current;
  274. },
  275. async checkItem(obj, item) {
  276. let items = obj.items;
  277. let len = items.length;
  278. for (let i = 0; i < len; i++) {
  279. let dian = items[i];
  280. dian.style = "; background: rgb(227, 242, 245);color: #000000;"
  281. }
  282. item.style = "; background: #57B03D;color:white"
  283. if (item.value == -1) {
  284. obj.custom = true;
  285. obj.customValue = 8;
  286. } else {
  287. obj.custom = false;
  288. obj.customValue = item.value;
  289. }
  290. },
  291. async confirm() {
  292. let currenValue = this.current.customValue;
  293. currenValue = currenValue *100;
  294. let deviceId = this.deviceId;
  295. // 发送到后端
  296. let self = this;
  297. this.$modal.loading("保存中。。");
  298. setCurrent(currenValue).then(res => {
  299. this.$modal.showToast("保存成功");
  300. setTimeout(function(){
  301. self.sendMainboardCmd();
  302. },1000)
  303. })
  304. },
  305. sendMainboardCmd() {
  306. // 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";
  307. // let data = parseDataObj(str);
  308. // this.messageCallback(data);
  309. this.$modal.loading("正在获取配置信息");
  310. sendMainboardCmd().then(res => {
  311. })
  312. },
  313. getMainboardConfig(){
  314. this.startTimer();
  315. },
  316. startTimer(){
  317. let self = this;
  318. this.timer = setTimeout(function (){
  319. getMainbordConfig({deviceId: self.deviceId,ccid:this.ccid},self.visitTime).then(res=>{
  320. let data = res.data;
  321. if(data != null){
  322. self.mainBoardInfo = data;
  323. self.formatMainboardData();
  324. self.$modal.closeLoading();
  325. }else{
  326. self.startTimer();
  327. }
  328. });
  329. },1000);
  330. },
  331. resetMainboard() {
  332. let deviceId = this.deviceId;
  333. // 恢复默认配置
  334. let self = this;
  335. this.$modal.loading("正在重置,请稍等...");
  336. reset().then(res => {
  337. this.$modal.loading("正在重置,请稍等...");
  338. setTimeout(function(){
  339. self.sendMainboardCmd();
  340. },5000)
  341. })
  342. setTimeout(function (){
  343. self.$modal.loading("正在重置,请稍等...");
  344. },1000);
  345. },
  346. async restartMainboard() {
  347. let deviceId = this.deviceId;
  348. this.$modal.loading("正在重置,请稍等...");
  349. // 重启充电桩
  350. let self = this;
  351. restart().then(res => {
  352. this.$modal.loading("正在重置,请稍等...");
  353. setTimeout(function(){
  354. self.sendMainboardCmd();
  355. },5000)
  356. })
  357. setTimeout(function (){
  358. self.$modal.loading("正在重置,请稍等...");
  359. },1000);
  360. }
  361. }
  362. }
  363. </script>
  364. <style>
  365. .container {
  366. position: absolute;
  367. inset: 0;
  368. left:0px;
  369. top: 0px;
  370. right: 0px;
  371. bottom:0px;
  372. background-image: url('../../../static/images/new/starts/bg2.jpg');
  373. background-size: cover;
  374. background-repeat: no-repeat;;
  375. }
  376. .prop-item {
  377. padding: 2vh;
  378. }
  379. .prop-item-auto{
  380. padding: 2vh;
  381. display: flex;
  382. }
  383. .prop-value {
  384. display: flex;
  385. flex-direction: row;
  386. }
  387. .prop-title {
  388. color: white;
  389. font-weight: bold;
  390. margin-bottom: 2.5vh;
  391. }
  392. .prop-title-auto {
  393. display: grid;
  394. justify-items: start;
  395. color: white;
  396. font-weight: bold;
  397. margin-bottom: 2.5vh;
  398. }
  399. .value-tag {
  400. background: rgb(227, 242, 245);
  401. color: #000000;
  402. width: 15vw;
  403. height: 4vh;
  404. line-height: 4vh;
  405. border-radius: 3vw;
  406. text-align: center;
  407. margin: 0 1vw;
  408. font-weight: bold;
  409. font-size: 12px;
  410. }
  411. .prop-input {
  412. display: flex;
  413. flex-direction: row;
  414. line-height: 4vh;
  415. margin: 2vh 0;
  416. }
  417. .input {
  418. background: rgb(227, 242, 245);
  419. border-radius: 30px;
  420. font-size: 12px;
  421. height: 4vh;
  422. padding: 0 2vw;
  423. margin: 0 1vw;
  424. width: 90%;
  425. }
  426. .bottom-area {
  427. position: absolute;
  428. bottom: 0px;
  429. height: 24vh;
  430. left: 0;
  431. right: 0;
  432. }
  433. .btn {
  434. width: 40vw;
  435. background: #57B03D;
  436. color: white;
  437. height: 6vh;
  438. line-height: 6vh;
  439. margin: 0 30vw;
  440. border-radius: 20vh;
  441. border-style: none;
  442. }
  443. .btn1 {
  444. background: #f9fcff;
  445. /* text-align: center;
  446. color: white;
  447. height:6vh;
  448. line-height: 6vh;
  449. margin:0 5vh;
  450. border-radius: 1vh; */
  451. border-color: transparent;
  452. }
  453. .areas {
  454. display: flex;
  455. flex-direction: row;
  456. text-align: center;
  457. margin-top: 3vh
  458. }
  459. .areas-item {
  460. width: 33%;
  461. color: aliceblue;
  462. }
  463. .areas-img {
  464. text-align: center;
  465. }
  466. </style>