setting.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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" v-if="current.custom">
  12. <input v-model="current.customValue" class="input" :placeholder="i18('请输入电流')"/>
  13. <view style="color: #0E9F9B">A</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="bottom-area">
  18. <view class="btn" @click="confirm">{{i18('确认')}}</view>
  19. <view class="areas">
  20. <view class="areas-item" @click="sendMainboardCmd">
  21. <view class="areas-img">
  22. <image style="width: 50px;height: 50px" :src="imgUrl+'/seting/mainboard.png'"></image>
  23. </view>
  24. <view>
  25. <view>{{i18('获取主板配置')}}</view>
  26. </view>
  27. </view>
  28. <view class="areas-item" @click="resetMainboard">
  29. <view class="areas-img">
  30. <image style="width: 50px;height: 50px" :src="imgUrl+'/seting/reset.png'"></image>
  31. </view>
  32. <view>
  33. <view >{{i18('恢复默认配置')}}</view>
  34. </view>
  35. </view>
  36. <view class="areas-item" @click="restartMainboard">
  37. <view class="areas-img">
  38. <image style="width: 50px;height: 50px" :src="imgUrl+'/seting/restart.png'"></image>
  39. </view>
  40. <view>
  41. <view>{{i18('重启充电桩')}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {setCurrent, getMainbordConfig,sendMainboardCmd, reset, restart,parseDataObj} from "@/utils/weitiandi/device/device.js";
  50. // #ifdef APP
  51. import ecUI from '@/utils/ecUI.js'
  52. import ecBLE from '@/utils/ecBLE/ecBLE.js'
  53. // #endif
  54. // #ifdef MP
  55. const ecUI = require('@/utils/ecUI.js')
  56. const ecBLE = require('@/utils/ecBLE/ecBLE.js')
  57. // #endif
  58. import i18 from '@/utils/i18.js'
  59. let ctx
  60. let isCheckScroll = true
  61. let isCheckRevHex = false
  62. let isCheckSendHex = false
  63. let sendData = ''
  64. export default {
  65. data() {
  66. return {
  67. scriptTask:null,
  68. deviceId: "",
  69. ccid:"",
  70. visitTime: "",
  71. mainBoardInfo:{},
  72. current: {
  73. items: [
  74. {text: "8A", style: "", value: 8},
  75. {text: "10A", style: "", value: 10},
  76. {text: "16A", style: "", value: 16},
  77. {text: "32A", style: "", value: 32},
  78. {text: i18("自定义"), style: "", value: -1}
  79. ],
  80. custom: false,
  81. customValue: ''
  82. }
  83. }
  84. },
  85. onUnload (){
  86. this.closeSocket();
  87. },
  88. computed: {
  89. imgUrl: function () {
  90. return getApp().globalData.config.imgUrl;
  91. }
  92. },
  93. onLoad(opt) {
  94. this.deviceId = opt.id;
  95. this.ccid = opt.ccid;
  96. this.buletooth();
  97. },
  98. methods: {
  99. i18(text){
  100. return i18(text)
  101. },
  102. closeSocket(){
  103. ecBLE.onBLEConnectionStateChange(() => {})
  104. ecBLE.onBLECharacteristicValueChange(() => {})
  105. },
  106. recon(){
  107. let self = this;
  108. ecUI.showLoading('设备连接中')
  109. let blueid = uni.getStorageSync('blueid');
  110. ecBLE.onBLEConnectionStateChange(res => {
  111. ecUI.hideLoading()
  112. if (res.ok) {
  113. self.buletooth();
  114. } else {
  115. uni.removeStorageSync('blueid');
  116. ecUI.showModal(
  117. '提示',
  118. '连接失败,errCode=' + res.errCode + ',errMsg=' + res.errMsg
  119. )
  120. }
  121. })
  122. ecBLE.createBLEConnection(blueid);
  123. },
  124. buletooth(){
  125. let self = this;
  126. ctx = this
  127. isCheckScroll = true
  128. isCheckRevHex = false
  129. isCheckSendHex = false
  130. sendData = ''
  131. //on disconnect
  132. ecBLE.onBLEConnectionStateChange(() => {
  133. uni.showModal({
  134. title: '提示',
  135. content: '蓝牙断开连接',
  136. confirmText:"点击重连",
  137. showCancel:false,
  138. success: function (res) {
  139. if (res.confirm) {
  140. self.recon();
  141. } else if (res.cancel) {
  142. console.log('用户点击取消');
  143. }
  144. }
  145. });
  146. })
  147. //receive data
  148. ecBLE.onBLECharacteristicValueChange((str, strHex) => {
  149. isCheckRevHex = true;
  150. let data =
  151. (isCheckRevHex ? strHex.replace(/[0-9a-fA-F]{2}/g, ' $&') : str)
  152. // console.log(data)
  153. self.$modal.closeLoading();
  154. console.log("settting:"+data);
  155. //AA 67 0D 05 00 00 00 00 00 00 00 00 00 25 E2 00 80
  156. data = parseDataObj(data);
  157. self.messageCallback(data);
  158. })
  159. self.sendMainboardCmd();
  160. },
  161. messageCallback(data){
  162. let self = this;
  163. let type = data.type;
  164. let real_data = data.real_data;
  165. if(type == 103){
  166. self.portDetail = real_data;
  167. self.$modal.closeLoading();
  168. }
  169. if(type == 116){
  170. self.$modal.closeLoading();
  171. }
  172. if(type == 96){
  173. self.mainBoardInfo = real_data;
  174. self.formatMainboardData();
  175. self.$modal.closeLoading();
  176. }
  177. console.log('收到服务器内容:' + JSON.stringify(data));
  178. },
  179. formatMainboardData(){
  180. let mainBoardInfo = this.mainBoardInfo;
  181. let max_current = mainBoardInfo.max_current;
  182. max_current = max_current/100;
  183. this.setCurrent(max_current);
  184. },
  185. setCurrent(max_current){
  186. this.current.currenValue = max_current;
  187. let items = this.current.items;
  188. let len = items.length;
  189. let hasValue = false;
  190. this.current.custom = false;
  191. for (let i = 0; i < len; i++) {
  192. let dian = items[i];
  193. if(dian.value == max_current){
  194. hasValue = true;
  195. dian.style = "; background: #0E9F9B;color:white"
  196. }else{
  197. dian.style = "; background: rgb(227, 242, 245);color: #0E9F9B;"
  198. }
  199. }
  200. if(!hasValue){
  201. this.current.custom = true;
  202. items[len-1].style = "; background: #0E9F9B;color:white"
  203. }
  204. this.current.customValue = max_current;
  205. },
  206. async checkItem(obj, item) {
  207. let items = obj.items;
  208. let len = items.length;
  209. for (let i = 0; i < len; i++) {
  210. let dian = items[i];
  211. dian.style = "; background: rgb(227, 242, 245);color: #0E9F9B;"
  212. }
  213. item.style = "; background: #0E9F9B;color:white"
  214. if (item.value == -1) {
  215. obj.custom = true;
  216. obj.customValue = 0;
  217. } else {
  218. obj.custom = false;
  219. obj.customValue = item.value;
  220. }
  221. },
  222. async confirm() {
  223. let currenValue = this.current.customValue;
  224. currenValue = currenValue *100;
  225. let deviceId = this.deviceId;
  226. // 发送到后端
  227. let self = this;
  228. this.$modal.loading("保存中。。");
  229. setCurrent(currenValue).then(res => {
  230. this.$modal.showToast("保存成功");
  231. setTimeout(function(){
  232. self.sendMainboardCmd();
  233. },1000)
  234. })
  235. },
  236. sendMainboardCmd() {
  237. // 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";
  238. // let data = parseDataObj(str);
  239. // this.messageCallback(data);
  240. this.$modal.loading("正在获取配置信息");
  241. sendMainboardCmd().then(res => {
  242. })
  243. },
  244. getMainboardConfig(){
  245. this.startTimer();
  246. },
  247. startTimer(){
  248. let self = this;
  249. this.timer = setTimeout(function (){
  250. getMainbordConfig({deviceId: self.deviceId,ccid:this.ccid},self.visitTime).then(res=>{
  251. let data = res.data;
  252. if(data != null){
  253. self.mainBoardInfo = data;
  254. self.formatMainboardData();
  255. self.$modal.closeLoading();
  256. }else{
  257. self.startTimer();
  258. }
  259. });
  260. },1000);
  261. },
  262. resetMainboard() {
  263. let deviceId = this.deviceId;
  264. // 恢复默认配置
  265. let self = this;
  266. this.$modal.loading("正在重置,请稍等...");
  267. reset().then(res => {
  268. setTimeout(function(){
  269. self.sendMainboardCmd();
  270. },1000)
  271. })
  272. },
  273. async restartMainboard() {
  274. let deviceId = this.deviceId;
  275. this.$modal.loading("正在重启中,请稍等...");
  276. // 重启充电桩
  277. let self = this;
  278. restart().then(res => {
  279. setTimeout(function(){
  280. self.sendMainboardCmd();
  281. },1000)
  282. })
  283. }
  284. }
  285. }
  286. </script>
  287. <style>
  288. .container {
  289. position: absolute;
  290. inset: 0;
  291. background: rgb(249, 252, 255);
  292. }
  293. .prop-item {
  294. padding: 2vh;
  295. }
  296. .prop-value {
  297. display: flex;
  298. flex-direction: row;
  299. }
  300. .prop-title {
  301. color: #252525;
  302. font-weight: bold;
  303. margin-bottom: 2.5vh;
  304. }
  305. .value-tag {
  306. background: rgb(227, 242, 245);
  307. color: #0E9F9B;
  308. width: 14vw;
  309. height: 4vh;
  310. line-height: 4vh;
  311. border-radius: 3vw;
  312. text-align: center;
  313. margin: 0 1vw;
  314. font-weight: bold;
  315. font-size: 12px;
  316. }
  317. .prop-input {
  318. display: flex;
  319. flex-direction: row;
  320. line-height: 4vh;
  321. margin: 2vh 0;
  322. }
  323. .input {
  324. background: rgb(227, 242, 245);
  325. border-radius: 30px;
  326. font-size: 12px;
  327. height: 4vh;
  328. padding: 0 2vw;
  329. margin: 0 1vw;
  330. width: 90%;
  331. }
  332. .bottom-area {
  333. position: absolute;
  334. bottom: 0px;
  335. height: 24vh;
  336. left: 0;
  337. right: 0;
  338. }
  339. .btn {
  340. background: #0E9F9B;
  341. text-align: center;
  342. color: white;
  343. height: 6vh;
  344. line-height: 6vh;
  345. margin: 0 5vh;
  346. border-radius: 1vh;
  347. border-style: none;
  348. }
  349. .btn1 {
  350. background: #f9fcff;
  351. /* text-align: center;
  352. color: white;
  353. height:6vh;
  354. line-height: 6vh;
  355. margin:0 5vh;
  356. border-radius: 1vh; */
  357. border-color: transparent;
  358. }
  359. .areas {
  360. display: flex;
  361. flex-direction: row;
  362. text-align: center;
  363. margin-top: 3vh
  364. }
  365. .areas-item {
  366. width: 33%;
  367. }
  368. .areas-img {
  369. text-align: center;
  370. }
  371. </style>