setting.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  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. this.$modal.loading("正在重置,请稍等...");
  324. setTimeout(function(){
  325. self.sendMainboardCmd();
  326. },5000)
  327. })
  328. setTimeout(function (){
  329. self.$modal.loading("正在重置,请稍等...");
  330. },1000);
  331. },
  332. async restartMainboard() {
  333. let deviceId = this.deviceId;
  334. this.$modal.loading("正在重置,请稍等...");
  335. // 重启充电桩
  336. let self = this;
  337. restart().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. }
  348. }
  349. </script>
  350. <style>
  351. .container {
  352. position: absolute;
  353. inset: 0;
  354. left:0px;
  355. top: 0px;
  356. right: 0px;
  357. bottom:0px;
  358. background: rgb(249, 252, 255);
  359. }
  360. .prop-item {
  361. padding: 2vh;
  362. }
  363. .prop-value {
  364. display: flex;
  365. flex-direction: row;
  366. }
  367. .prop-title {
  368. color: #252525;
  369. font-weight: bold;
  370. margin-bottom: 2.5vh;
  371. }
  372. .value-tag {
  373. background: rgb(227, 242, 245);
  374. color: #1A87FF;
  375. width: 14vw;
  376. height: 4vh;
  377. line-height: 4vh;
  378. border-radius: 3vw;
  379. text-align: center;
  380. margin: 0 1vw;
  381. font-weight: bold;
  382. font-size: 12px;
  383. }
  384. .prop-input {
  385. display: flex;
  386. flex-direction: row;
  387. line-height: 4vh;
  388. margin: 2vh 0;
  389. }
  390. .input {
  391. background: rgb(227, 242, 245);
  392. border-radius: 30px;
  393. font-size: 12px;
  394. height: 4vh;
  395. padding: 0 2vw;
  396. margin: 0 1vw;
  397. width: 90%;
  398. }
  399. .bottom-area {
  400. position: absolute;
  401. bottom: 0px;
  402. height: 24vh;
  403. left: 0;
  404. right: 0;
  405. }
  406. .btn {
  407. background: #1A87FF;
  408. text-align: center;
  409. color: white;
  410. height: 6vh;
  411. line-height: 6vh;
  412. margin: 0 5vh;
  413. border-radius: 1vh;
  414. border-style: none;
  415. }
  416. .btn1 {
  417. background: #f9fcff;
  418. /* text-align: center;
  419. color: white;
  420. height:6vh;
  421. line-height: 6vh;
  422. margin:0 5vh;
  423. border-radius: 1vh; */
  424. border-color: transparent;
  425. }
  426. .areas {
  427. display: flex;
  428. flex-direction: row;
  429. text-align: center;
  430. margin-top: 3vh
  431. }
  432. .areas-item {
  433. width: 33%;
  434. }
  435. .areas-img {
  436. text-align: center;
  437. }
  438. </style>