setting.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  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" 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. setTimeout(function(){
  230. self.sendMainboardCmd();
  231. },1000)
  232. })
  233. },
  234. async restartMainboard() {
  235. let deviceId = this.deviceId;
  236. this.$modal.loading("正在重启中,请稍等...");
  237. // 重启充电桩
  238. let self = this;
  239. restart({deviceId:deviceId,ccid:this.ccid}).then(res => {
  240. setTimeout(function(){
  241. self.sendMainboardCmd();
  242. },1000)
  243. })
  244. }
  245. }
  246. }
  247. </script>
  248. <style>
  249. .container {
  250. position: absolute;
  251. inset: 0;
  252. background: rgb(249, 252, 255);
  253. }
  254. .prop-item {
  255. padding: 2vh;
  256. }
  257. .prop-value {
  258. display: flex;
  259. flex-direction: row;
  260. }
  261. .prop-title {
  262. color: #252525;
  263. font-weight: bold;
  264. margin-bottom: 2.5vh;
  265. }
  266. .value-tag {
  267. background: rgb(227, 242, 245);
  268. color: #1A87FF;
  269. width: 14vw;
  270. height: 4vh;
  271. line-height: 4vh;
  272. border-radius: 3vw;
  273. text-align: center;
  274. margin: 0 1vw;
  275. font-weight: bold;
  276. font-size: 12px;
  277. }
  278. .prop-input {
  279. display: flex;
  280. flex-direction: row;
  281. line-height: 4vh;
  282. margin: 2vh 0;
  283. }
  284. .input {
  285. background: rgb(227, 242, 245);
  286. border-radius: 30px;
  287. font-size: 12px;
  288. height: 4vh;
  289. padding: 0 2vw;
  290. margin: 0 1vw;
  291. width: 90%;
  292. }
  293. .bottom-area {
  294. position: absolute;
  295. bottom: 0px;
  296. height: 24vh;
  297. left: 0;
  298. right: 0;
  299. }
  300. .btn {
  301. background: #1A87FF;
  302. text-align: center;
  303. color: white;
  304. height: 6vh;
  305. line-height: 6vh;
  306. margin: 0 5vh;
  307. border-radius: 1vh;
  308. border-style: none;
  309. }
  310. .btn1 {
  311. background: #f9fcff;
  312. /* text-align: center;
  313. color: white;
  314. height:6vh;
  315. line-height: 6vh;
  316. margin:0 5vh;
  317. border-radius: 1vh; */
  318. border-color: transparent;
  319. }
  320. .areas {
  321. display: flex;
  322. flex-direction: row;
  323. text-align: center;
  324. margin-top: 3vh
  325. }
  326. .areas-item {
  327. width: 33%;
  328. }
  329. .areas-img {
  330. text-align: center;
  331. }
  332. </style>