setting.vue 12 KB

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