setting.vue 8.4 KB

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