setting.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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. } else if (res.cancel) {
  194. console.log('用户点击取消');
  195. }
  196. }
  197. });
  198. })
  199. //receive data
  200. ecBLE.onBLECharacteristicValueChange((str, strHex) => {
  201. isCheckRevHex = true;
  202. let data =
  203. (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
  204. // console.log(data)
  205. self.$modal.closeLoading();
  206. console.log("settting:"+data);
  207. //AA 67 0D 05 00 00 00 00 00 00 00 00 00 25 E2 00 80
  208. data = parseDataObj(data);
  209. self.messageCallback(data);
  210. })
  211. self.sendMainboardCmd();
  212. },
  213. messageCallback(data){
  214. let self = this;
  215. let type = data.type;
  216. let real_data = data.real_data;
  217. if(type == 103){
  218. self.portDetail = real_data;
  219. self.$modal.closeLoading();
  220. }
  221. if(type == 116){
  222. self.$modal.closeLoading();
  223. }
  224. if(type == 96){
  225. self.mainBoardInfo = real_data;
  226. self.formatMainboardData();
  227. self.$modal.closeLoading();
  228. }
  229. console.log('收到服务器内容:' + JSON.stringify(data));
  230. },
  231. formatMainboardData(){
  232. let mainBoardInfo = this.mainBoardInfo;
  233. let max_current = mainBoardInfo.max_current;
  234. max_current = max_current/100;
  235. this.setCurrent(max_current);
  236. },
  237. setCurrent(max_current){
  238. this.current.currenValue = max_current;
  239. let items = this.current.items;
  240. let len = items.length;
  241. let hasValue = false;
  242. this.current.custom = false;
  243. for (let i = 0; i < len; i++) {
  244. let dian = items[i];
  245. if(dian.value == max_current){
  246. hasValue = true;
  247. dian.style = "; background: #1A87FF;color:white"
  248. }else{
  249. dian.style = "; background: rgb(227, 242, 245);color: #1A87FF;"
  250. }
  251. }
  252. if(!hasValue){
  253. this.current.custom = true;
  254. items[len-1].style = "; background: #1A87FF;color:white"
  255. }
  256. this.current.customValue = max_current;
  257. },
  258. async checkItem(obj, item) {
  259. let items = obj.items;
  260. let len = items.length;
  261. for (let i = 0; i < len; i++) {
  262. let dian = items[i];
  263. dian.style = "; background: rgb(227, 242, 245);color: #1A87FF;"
  264. }
  265. item.style = "; background: #1A87FF;color:white"
  266. if (item.value == -1) {
  267. obj.custom = true;
  268. obj.customValue = 8;
  269. } else {
  270. obj.custom = false;
  271. obj.customValue = item.value;
  272. }
  273. },
  274. async confirm() {
  275. let currenValue = this.current.customValue;
  276. currenValue = currenValue *100;
  277. let deviceId = this.deviceId;
  278. // 发送到后端
  279. let self = this;
  280. this.$modal.loading("保存中。。");
  281. setCurrent(currenValue).then(res => {
  282. this.$modal.showToast("保存成功");
  283. setTimeout(function(){
  284. self.sendMainboardCmd();
  285. },1000)
  286. })
  287. },
  288. sendMainboardCmd() {
  289. // 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";
  290. // let data = parseDataObj(str);
  291. // this.messageCallback(data);
  292. this.$modal.loading("正在获取配置信息");
  293. sendMainboardCmd().then(res => {
  294. })
  295. },
  296. getMainboardConfig(){
  297. this.startTimer();
  298. },
  299. startTimer(){
  300. let self = this;
  301. this.timer = setTimeout(function (){
  302. getMainbordConfig({deviceId: self.deviceId,ccid:this.ccid},self.visitTime).then(res=>{
  303. let data = res.data;
  304. if(data != null){
  305. self.mainBoardInfo = data;
  306. self.formatMainboardData();
  307. self.$modal.closeLoading();
  308. }else{
  309. self.startTimer();
  310. }
  311. });
  312. },1000);
  313. },
  314. resetMainboard() {
  315. let deviceId = this.deviceId;
  316. // 恢复默认配置
  317. let self = this;
  318. this.$modal.loading("正在重置,请稍等...");
  319. reset().then(res => {
  320. setTimeout(function(){
  321. self.sendMainboardCmd();
  322. },1000)
  323. })
  324. },
  325. async restartMainboard() {
  326. let deviceId = this.deviceId;
  327. this.$modal.loading("正在重启中,请稍等...");
  328. // 重启充电桩
  329. let self = this;
  330. restart().then(res => {
  331. setTimeout(function(){
  332. self.sendMainboardCmd();
  333. },1000)
  334. })
  335. }
  336. }
  337. }
  338. </script>
  339. <style>
  340. .container {
  341. position: absolute;
  342. inset: 0;
  343. background: rgb(249, 252, 255);
  344. }
  345. .prop-item {
  346. padding: 2vh;
  347. }
  348. .prop-value {
  349. display: flex;
  350. flex-direction: row;
  351. }
  352. .prop-title {
  353. color: #252525;
  354. font-weight: bold;
  355. margin-bottom: 2.5vh;
  356. }
  357. .value-tag {
  358. background: rgb(227, 242, 245);
  359. color: #1A87FF;
  360. width: 14vw;
  361. height: 4vh;
  362. line-height: 4vh;
  363. border-radius: 3vw;
  364. text-align: center;
  365. margin: 0 1vw;
  366. font-weight: bold;
  367. font-size: 12px;
  368. }
  369. .prop-input {
  370. display: flex;
  371. flex-direction: row;
  372. line-height: 4vh;
  373. margin: 2vh 0;
  374. }
  375. .input {
  376. background: rgb(227, 242, 245);
  377. border-radius: 30px;
  378. font-size: 12px;
  379. height: 4vh;
  380. padding: 0 2vw;
  381. margin: 0 1vw;
  382. width: 90%;
  383. }
  384. .bottom-area {
  385. position: absolute;
  386. bottom: 0px;
  387. height: 24vh;
  388. left: 0;
  389. right: 0;
  390. }
  391. .btn {
  392. background: #1A87FF;
  393. text-align: center;
  394. color: white;
  395. height: 6vh;
  396. line-height: 6vh;
  397. margin: 0 5vh;
  398. border-radius: 1vh;
  399. border-style: none;
  400. }
  401. .btn1 {
  402. background: #f9fcff;
  403. /* text-align: center;
  404. color: white;
  405. height:6vh;
  406. line-height: 6vh;
  407. margin:0 5vh;
  408. border-radius: 1vh; */
  409. border-color: transparent;
  410. }
  411. .areas {
  412. display: flex;
  413. flex-direction: row;
  414. text-align: center;
  415. margin-top: 3vh
  416. }
  417. .areas-item {
  418. width: 33%;
  419. }
  420. .areas-img {
  421. text-align: center;
  422. }
  423. </style>