setting.vue 9.2 KB

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