setting.vue 8.8 KB

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