setting.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. this.$modal.showToast("保存成功");
  179. setTimeout(function(){
  180. self.sendMainboardCmd();
  181. },1000)
  182. })
  183. },
  184. sendMainboardCmd() {
  185. this.$modal.loading("正在获取状态,请稍等...");
  186. let deviceId = this.deviceId;
  187. // 获取主板配置
  188. sendMainboardCmd({deviceId: deviceId,ccid:this.ccid}).then(res => {
  189. this.visitTime = res.msg;
  190. if(!this.visitTime){
  191. this.$modal.msg("请重新进入页面");
  192. return;
  193. }
  194. if(!this.scriptTask){
  195. this.initSocket(this.deviceId)
  196. }
  197. })
  198. },
  199. getMainboardConfig(){
  200. this.startTimer();
  201. },
  202. startTimer(){
  203. let self = this;
  204. this.timer = setTimeout(function (){
  205. getMainbordConfig({deviceId: self.deviceId,ccid:this.ccid},self.visitTime).then(res=>{
  206. let data = res.data;
  207. if(data != null){
  208. self.mainBoardInfo = data;
  209. self.formatMainboardData();
  210. self.$modal.closeLoading();
  211. }else{
  212. self.startTimer();
  213. }
  214. });
  215. },1000);
  216. },
  217. resetMainboard() {
  218. let deviceId = this.deviceId;
  219. // 恢复默认配置
  220. let self = this;
  221. this.$modal.loading("正在重置,请稍等...");
  222. reset({deviceId:deviceId,ccid:this.ccid}).then(res => {
  223. setTimeout(function(){
  224. self.sendMainboardCmd();
  225. },1000)
  226. })
  227. },
  228. async restartMainboard() {
  229. let deviceId = this.deviceId;
  230. this.$modal.loading("正在重启中,请稍等...");
  231. // 重启充电桩
  232. let self = this;
  233. restart({deviceId:deviceId,ccid:this.ccid}).then(res => {
  234. setTimeout(function(){
  235. self.sendMainboardCmd();
  236. },1000)
  237. })
  238. }
  239. }
  240. }
  241. </script>
  242. <style>
  243. .container {
  244. position: absolute;
  245. inset: 0;
  246. background: rgb(249, 252, 255);
  247. }
  248. .prop-item {
  249. padding: 2vh;
  250. }
  251. .prop-value {
  252. display: flex;
  253. flex-direction: row;
  254. }
  255. .prop-title {
  256. color: #252525;
  257. font-weight: bold;
  258. margin-bottom: 2.5vh;
  259. }
  260. .value-tag {
  261. background: rgb(227, 242, 245);
  262. color: #0E9F9B;
  263. width: 14vw;
  264. height: 4vh;
  265. line-height: 4vh;
  266. border-radius: 3vw;
  267. text-align: center;
  268. margin: 0 1vw;
  269. font-weight: bold;
  270. font-size: 12px;
  271. }
  272. .prop-input {
  273. display: flex;
  274. flex-direction: row;
  275. line-height: 4vh;
  276. margin: 2vh 0;
  277. }
  278. .input {
  279. background: rgb(227, 242, 245);
  280. border-radius: 30px;
  281. font-size: 12px;
  282. height: 4vh;
  283. padding: 0 2vw;
  284. margin: 0 1vw;
  285. width: 90%;
  286. }
  287. .bottom-area {
  288. position: absolute;
  289. bottom: 0px;
  290. height: 24vh;
  291. left: 0;
  292. right: 0;
  293. }
  294. .btn {
  295. background: #0E9F9B;
  296. text-align: center;
  297. color: white;
  298. height: 6vh;
  299. line-height: 6vh;
  300. margin: 0 5vh;
  301. border-radius: 1vh;
  302. border-style: none;
  303. }
  304. .btn1 {
  305. background: #f9fcff;
  306. /* text-align: center;
  307. color: white;
  308. height:6vh;
  309. line-height: 6vh;
  310. margin:0 5vh;
  311. border-radius: 1vh; */
  312. border-color: transparent;
  313. }
  314. .areas {
  315. display: flex;
  316. flex-direction: row;
  317. text-align: center;
  318. margin-top: 3vh
  319. }
  320. .areas-item {
  321. width: 33%;
  322. }
  323. .areas-img {
  324. text-align: center;
  325. }
  326. </style>