setting.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="container">
  3. <view class="setting">
  4. <view class="prop-item">
  5. <view class="prop-title">充电电流</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="请输入电流"/>
  13. <view style="color: #0E9F9B">A</view>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="bottom-area">
  18. <view class="btn" @click="confirm">确认</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>获取主板配置</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 >恢复默认配置</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>重启充电桩</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import {setCurrent, getMainbordConfig,sendMainboardCmd, reset, restart} from "@/utils/weitiandi/device/device.js";
  50. export default {
  51. data() {
  52. return {
  53. scriptTask:null,
  54. deviceId: "",
  55. ccid:"",
  56. visitTime: "",
  57. mainBoardInfo:{},
  58. current: {
  59. items: [
  60. {text: "8A", style: "", value: 8},
  61. {text: "10A", style: "", value: 10},
  62. {text: "16A", style: "", value: 16},
  63. {text: "32A", style: "", value: 32},
  64. {text: "自定义", style: "", value: -1}
  65. ],
  66. custom: false,
  67. customValue: ''
  68. }
  69. }
  70. },
  71. onUnload (){
  72. this.closeSocket();
  73. },
  74. computed: {
  75. imgUrl: function () {
  76. return getApp().globalData.config.imgUrl;
  77. }
  78. },
  79. onLoad(opt) {
  80. this.deviceId = opt.id;
  81. this.ccid = opt.ccid;
  82. this.sendMainboardCmd();
  83. },
  84. methods: {
  85. closeSocket(){
  86. this.scriptTask.close();
  87. },
  88. initSocket(key){
  89. let self = this;
  90. let socketUrl = getApp().globalData.config.socketUrl
  91. this.scriptTask = websocket({
  92. url:"/"+key+"/",
  93. });
  94. let scriptTask = this.scriptTask;
  95. scriptTask.onOpen(function (res) {
  96. console.log('WebSocket连接已打开!');
  97. self.connected = true;
  98. });
  99. scriptTask.onError(function (res) {
  100. self.connected = false;
  101. console.log(res);
  102. });
  103. scriptTask.onMessage(function (res) {
  104. let data = JSON.parse(res.data);
  105. let type = data.type;
  106. let real_data = data.real_data;
  107. if(type == 103){
  108. self.portDetail = real_data;
  109. self.$modal.closeLoading();
  110. }
  111. if(type == 116){
  112. self.$modal.closeLoading();
  113. }
  114. if(type == 96){
  115. self.mainBoardInfo = real_data;
  116. self.formatMainboardData();
  117. self.$modal.closeLoading();
  118. }
  119. console.log('收到服务器内容:' + JSON.stringify(data));
  120. });
  121. scriptTask.onClose(function (res) {
  122. self.connected = true;
  123. console.log('WebSocket 已关闭!');
  124. });
  125. },
  126. formatMainboardData(){
  127. let mainBoardInfo = this.mainBoardInfo;
  128. let max_current = mainBoardInfo.max_current;
  129. max_current = max_current/100;
  130. this.setCurrent(max_current);
  131. },
  132. setCurrent(max_current){
  133. this.current.currenValue = max_current;
  134. let items = this.current.items;
  135. let len = items.length;
  136. let hasValue = false;
  137. this.current.custom = false;
  138. for (let i = 0; i < len; i++) {
  139. let dian = items[i];
  140. if(dian.value == max_current){
  141. hasValue = true;
  142. dian.style = "; background: #0E9F9B;color:white"
  143. }else{
  144. dian.style = "; background: rgb(227, 242, 245);color: #0E9F9B;"
  145. }
  146. }
  147. if(!hasValue){
  148. this.current.custom = true;
  149. items[len-1].style = "; background: #0E9F9B;color:white"
  150. }
  151. this.current.customValue = max_current;
  152. },
  153. async checkItem(obj, item) {
  154. let items = obj.items;
  155. let len = items.length;
  156. for (let i = 0; i < len; i++) {
  157. let dian = items[i];
  158. dian.style = "; background: rgb(227, 242, 245);color: #0E9F9B;"
  159. }
  160. item.style = "; background: #0E9F9B;color:white"
  161. if (item.value == -1) {
  162. obj.custom = true;
  163. obj.customValue = 0;
  164. } else {
  165. obj.custom = false;
  166. obj.customValue = item.value;
  167. }
  168. },
  169. async confirm() {
  170. let currenValue = this.current.customValue;
  171. currenValue = currenValue *100;
  172. let deviceId = this.deviceId;
  173. // 发送到后端
  174. let self = this;
  175. this.$modal.loading("保存中。。");
  176. setCurrent({deviceId: deviceId,ccid:this.ccid},currenValue).then(res => {
  177. this.$modal.showToast("保存成功");
  178. setTimeout(function(){
  179. self.sendMainboardCmd();
  180. },1000)
  181. })
  182. },
  183. sendMainboardCmd() {
  184. let deviceId = this.deviceId;
  185. // 获取主板配置
  186. sendMainboardCmd({deviceId: deviceId,ccid:this.ccid}).then(res => {
  187. })
  188. },
  189. getMainboardConfig(){
  190. this.startTimer();
  191. },
  192. startTimer(){
  193. let self = this;
  194. this.timer = setTimeout(function (){
  195. getMainbordConfig({deviceId: self.deviceId,ccid:this.ccid},self.visitTime).then(res=>{
  196. let data = res.data;
  197. if(data != null){
  198. self.mainBoardInfo = data;
  199. self.formatMainboardData();
  200. self.$modal.closeLoading();
  201. }else{
  202. self.startTimer();
  203. }
  204. });
  205. },1000);
  206. },
  207. resetMainboard() {
  208. let deviceId = this.deviceId;
  209. // 恢复默认配置
  210. let self = this;
  211. this.$modal.loading("正在重置,请稍等...");
  212. reset({deviceId:deviceId,ccid:this.ccid}).then(res => {
  213. setTimeout(function(){
  214. self.sendMainboardCmd();
  215. },1000)
  216. })
  217. },
  218. async restartMainboard() {
  219. let deviceId = this.deviceId;
  220. this.$modal.loading("正在重启中,请稍等...");
  221. // 重启充电桩
  222. let self = this;
  223. restart({deviceId:deviceId,ccid:this.ccid}).then(res => {
  224. setTimeout(function(){
  225. self.sendMainboardCmd();
  226. },1000)
  227. })
  228. }
  229. }
  230. }
  231. </script>
  232. <style>
  233. .container {
  234. position: absolute;
  235. inset: 0;
  236. background: rgb(249, 252, 255);
  237. }
  238. .prop-item {
  239. padding: 2vh;
  240. }
  241. .prop-value {
  242. display: flex;
  243. flex-direction: row;
  244. }
  245. .prop-title {
  246. color: #252525;
  247. font-weight: bold;
  248. margin-bottom: 2.5vh;
  249. }
  250. .value-tag {
  251. background: rgb(227, 242, 245);
  252. color: #0E9F9B;
  253. width: 14vw;
  254. height: 4vh;
  255. line-height: 4vh;
  256. border-radius: 3vw;
  257. text-align: center;
  258. margin: 0 1vw;
  259. font-weight: bold;
  260. font-size: 12px;
  261. }
  262. .prop-input {
  263. display: flex;
  264. flex-direction: row;
  265. line-height: 4vh;
  266. margin: 2vh 0;
  267. }
  268. .input {
  269. background: rgb(227, 242, 245);
  270. border-radius: 30px;
  271. font-size: 12px;
  272. height: 4vh;
  273. padding: 0 2vw;
  274. margin: 0 1vw;
  275. width: 90%;
  276. }
  277. .bottom-area {
  278. position: absolute;
  279. bottom: 0px;
  280. height: 24vh;
  281. left: 0;
  282. right: 0;
  283. }
  284. .btn {
  285. background: #0E9F9B;
  286. text-align: center;
  287. color: white;
  288. height: 6vh;
  289. line-height: 6vh;
  290. margin: 0 5vh;
  291. border-radius: 1vh;
  292. border-style: none;
  293. }
  294. .btn1 {
  295. background: #f9fcff;
  296. /* text-align: center;
  297. color: white;
  298. height:6vh;
  299. line-height: 6vh;
  300. margin:0 5vh;
  301. border-radius: 1vh; */
  302. border-color: transparent;
  303. }
  304. .areas {
  305. display: flex;
  306. flex-direction: row;
  307. text-align: center;
  308. margin-top: 3vh
  309. }
  310. .areas-item {
  311. width: 33%;
  312. }
  313. .areas-img {
  314. text-align: center;
  315. }
  316. </style>