index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <view class="setting" @click="toSet">设备控制</view>
  5. <view class="header-status chong-active" v-if="portDetail.port_first_status == 1">
  6. 充电枪未连接
  7. </view>
  8. <view class="header-status chong-active" v-if="portDetail.port_first_status == 0">
  9. 正在读取状态
  10. </view>
  11. <view class="header-status chong-active" v-if="portDetail.port_first_status == 5">
  12. 充电枪已连接
  13. </view>
  14. <view class="header-status chong-active" v-if="portDetail.port_first_status == 2">
  15. 充电枪已连接
  16. </view>
  17. <view class="header-img" v-if="portDetail.port_first_status == 2">
  18. <image :src="imgUrl+'/chargedetail/chonging.png'">
  19. </image>
  20. </view>
  21. <view class="header-img" v-if="portDetail.port_first_status != 2">
  22. <image :src="imgUrl+'/chargedetail/chongoff.png'">
  23. </image>
  24. </view>
  25. <view class="header-status-desc" v-if="portDetail.port_first_status == 2">
  26. 充电中
  27. </view>
  28. <view class="header-status-desc" style="color: #B2B2B2" v-if="portDetail.port_first_status != 2">
  29. 未充电
  30. </view>
  31. </view>
  32. <view class="info-body">
  33. <view class="info-content">
  34. <view class="info-content-value">{{ portDetail.voltage }}V</view>
  35. <view class="info-content-text">
  36. 充电电压
  37. </view>
  38. </view>
  39. <view class="info-content">
  40. <view class="info-content-value" v-if="portDetail.voltage == 0">0A</view>
  41. <view class="info-content-value" v-else>{{portDetail.POWER/portDetail.voltage}}A</view>
  42. <view class="info-content-text">
  43. 充电电流
  44. </view>
  45. </view>
  46. <view class="info-content">
  47. <view class="info-content-value">{{portDetail.dev_temper}}℃</view>
  48. <view class="info-content-text">
  49. 设备温度
  50. </view>
  51. </view>
  52. <view class="info-content">
  53. <view class="info-content-value">{{portDetail.wire_temper}}℃</view>
  54. <view class="info-content-text">
  55. 线路温度
  56. </view>
  57. </view>
  58. </view>
  59. <view class="info-summary">
  60. <view class="summary charge-time">
  61. <view class="charge-num">{{ portDetail.time }}分钟</view>
  62. <view class="charge-title">已冲时间</view>
  63. </view>
  64. <view class="summary charge-gonglv">
  65. <view class="charge-num">{{ portDetail.power }}W</view>
  66. <view class="charge-title">充电功率</view>
  67. </view>
  68. <view class="summary charge-dianliang">
  69. <view class="charge-num">{{ portDetail.elec }} 度</view>
  70. <view class="charge-title">已冲电量</view>
  71. </view>
  72. </view>
  73. <view class="info-bottom">
  74. <view class="info-bottom-btn" >
  75. <view class="btn-area left" @click="getInfo">
  76. <image class="btn-image" :src="imgUrl+'/chargedetail/getstatus.png'">
  77. </image>
  78. </view>
  79. <view class="btn-area right" @click="trigger()">
  80. <image class="btn-image" :src="imgUrl+'/chargedetail/stop.png'" v-if="portDetail.port_first_status == 2">
  81. </image>
  82. <image class="btn-image" :src="imgUrl+'/chargedetail/start.png'" v-if="portDetail.port_first_status != 2">
  83. </image>
  84. </view>
  85. </view>
  86. <view class="info-plan" @click="toPlan">
  87. 预约充电
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. import {getDeviceInfo,getPortDetail,startCharge,stopCharge,sendPortDetailCmd,checkStatusChange} from "@/api/device/device";
  94. import websocket from '@/utils/websocket'
  95. export default {
  96. data() {
  97. return {
  98. deviceInfo:{},
  99. visitTime:"",
  100. timer:null,
  101. portDetail:{port_first_status:0,POWER:0,voltage:0},
  102. statusTimer:"",
  103. connected:false,
  104. scriptTask:null,
  105. }
  106. },
  107. computed: {
  108. imgUrl() {
  109. return getApp().globalData.config.imgUrl;
  110. }
  111. },
  112. onLoad(opt) {
  113. this.deviceInfo.deviceId = opt.id;
  114. this.deviceInfo.ccid = opt.ccid;
  115. },
  116. onShow(){
  117. this.getInfo();
  118. },
  119. onUnload (){
  120. this.closeSocket();
  121. },
  122. methods: {
  123. initSocket(key){
  124. let self = this;
  125. let socketUrl = getApp().globalData.config.socketUrl
  126. this.scriptTask = websocket({
  127. url:"/"+key+"/",
  128. });
  129. let scriptTask = this.scriptTask;
  130. scriptTask.onOpen(function (res) {
  131. console.log('WebSocket连接已打开!');
  132. self.connected = true;
  133. });
  134. scriptTask.onError(function (res) {
  135. self.connected = false;
  136. console.log(res);
  137. });
  138. scriptTask.onMessage(function (res) {
  139. let data = JSON.parse(res.data);
  140. let type = data.type;
  141. let real_data = data.real_data;
  142. if(type == 103){
  143. self.portDetail = real_data
  144. self.$modal.closeLoading();
  145. }
  146. if(type == 116){
  147. self.$modal.closeLoading();
  148. self.getInfo();
  149. }
  150. if(type == 113){
  151. self.$modal.closeLoading();
  152. self.getInfo();
  153. }
  154. if(type == 96){
  155. self.mainBoardInfo = real_data;
  156. self.formatMainboardData();
  157. self.$modal.closeLoading();
  158. }
  159. self.$forceUpdate();
  160. console.log('收到服务器内容:' + JSON.stringify(data));
  161. });
  162. scriptTask.onClose(function (res) {
  163. console.log('WebSocket 已关闭!');
  164. });
  165. },
  166. toSet(){
  167. this.closeSocket();
  168. uni.navigateTo({
  169. url: '/pages/weitiandi/device/setting?id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  170. });
  171. },
  172. toPlan(){
  173. uni.navigateTo({
  174. url: '/pages/weitiandi/device/plan?id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  175. });
  176. },
  177. trigger(){
  178. let port_first_status = this.portDetail.port_first_status;
  179. if(port_first_status == 2){//需要停止充电
  180. this.$modal.confirm("需要停止充电么?").then(res=>{
  181. this.stopCharge();
  182. })
  183. }else{
  184. if(port_first_status == 1){
  185. this.$modal.msg("请先将充电枪插入后再点击充电");
  186. }
  187. if(port_first_status == 5){
  188. this.$modal.confirm("确认开始充电么?").then(res=>{
  189. this.startCharge();
  190. })
  191. }
  192. }
  193. },
  194. getInfo() {
  195. this.$modal.loading("正在获取状态,请稍等...");
  196. sendPortDetailCmd(this.deviceInfo).then(res => {
  197. this.$modal.loading("正在获取状态,请稍等...");
  198. this.visitTime = res.msg;
  199. if(!this.visitTime){
  200. this.$modal.msg("请重新进入页面");
  201. return;
  202. }
  203. if(!this.scriptTask){
  204. this.initSocket(this.deviceInfo.deviceId);
  205. }
  206. // this.getPortInfo()
  207. })
  208. },
  209. stopCharge(){
  210. let self = this;
  211. stopCharge(this.deviceInfo).then(()=>{
  212. self.$modal.loading("停止成功");
  213. setTimeout((()=>{
  214. self.getInfo();
  215. }),1000);
  216. })
  217. },
  218. startCharge(){
  219. let self = this;
  220. startCharge(this.deviceInfo).then(res=>{
  221. self.$modal.loading("启动成功");
  222. setTimeout((()=>{
  223. self.getInfo();
  224. }),1000);
  225. })
  226. },
  227. getPortInfo(){
  228. this.startPortDetailTimer();
  229. },
  230. startPortDetailTimer(){
  231. let self = this;
  232. this.timer = setTimeout(function (){
  233. getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
  234. let data = res.data;
  235. if(data != null){
  236. self.portDetail = data;
  237. self.checkStatusCheck();
  238. self.$modal.closeLoading();
  239. }else{
  240. self.startPortDetailTimer();
  241. }
  242. });
  243. },1000);
  244. },
  245. checkStatusCheck(){
  246. this.statusChangeTimer();
  247. },
  248. checkOnPage(){
  249. var pages = getCurrentPages() // 获取栈实例
  250. let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
  251. if("pages/weitiandi/device/index" != currentRoute){
  252. return false;
  253. }
  254. return true;
  255. },
  256. closeSocket(){
  257. this.scriptTask.close();
  258. this.scriptTask = null;
  259. },
  260. statusChangeTimer(){
  261. let self = this;
  262. this.statusTimer = setTimeout(function(){
  263. if(!this.checkOnPage()){
  264. return;
  265. }
  266. checkStatusChange(self.deviceInfo,self.visitTime).then(res=>{
  267. let data = res.data;
  268. if(data != null){
  269. self.getInfo();
  270. }else{
  271. self.statusChangeTimer();
  272. }
  273. });
  274. },3000);
  275. }
  276. }
  277. }
  278. </script>
  279. <style>
  280. .container {
  281. background: rgb(249, 252, 255);
  282. inset: 0;
  283. position: absolute;
  284. }
  285. .header {
  286. position: relative;
  287. margin-top:4vw;
  288. }
  289. .header-status-desc {
  290. position: absolute;
  291. text-align: center;
  292. width: 100%;
  293. bottom:1vh;
  294. font-size: 5vw;
  295. font-weight: bold;
  296. color: #0E9F9B;
  297. }
  298. .header-status {
  299. font-weight: bold;
  300. padding-left: 5vw;
  301. }
  302. .chong-active {
  303. color: #0E9F9B
  304. }
  305. .header-img {
  306. width: 100%;
  307. padding: 5% 10%;
  308. text-align: center;
  309. }
  310. .header-img image {
  311. width: 100%;
  312. height: 23vh;
  313. }
  314. .info-body{
  315. background: #0E9F9B;
  316. height: 20vh;
  317. margin: 0 10%;
  318. border-radius: 1vw;
  319. margin-top:2vh;
  320. color: #F8FCFF;
  321. line-height: 3vh;
  322. }
  323. .info-content{
  324. display: inline-block;
  325. width: 48%;
  326. text-align: center;
  327. margin: 1%;
  328. margin-top:2.5vh;
  329. }
  330. .info-content-value{
  331. font-weight: bold;
  332. }
  333. .info-content-text{
  334. }
  335. .info-summary{
  336. display: flex;
  337. flex-direction: row;
  338. text-align: center;
  339. margin:3vh 0;
  340. }
  341. .summary{
  342. width: 33%;
  343. line-height: 2.5vh;
  344. }
  345. .charge-num{
  346. color: #0E9F9B;
  347. font-weight: bold;
  348. font-size: 4.5vw;
  349. }
  350. .charge-title{
  351. color: #B2B2B2;
  352. font-weight: 400;
  353. }
  354. .btn-image{
  355. width: 90%;
  356. height: 100%;
  357. }
  358. .info-bottom-btn{
  359. display: flex;
  360. flex-direction: row;
  361. text-align: center;
  362. position: relative;
  363. margin-top: 10vh
  364. ;
  365. }
  366. .btn-area{
  367. width: 50%;
  368. height: 50px;
  369. }
  370. .left{
  371. position: relative;
  372. left: 10px;
  373. text-align: right;
  374. }
  375. .right{
  376. text-align: left;
  377. position: relative;
  378. right: 10px;
  379. }
  380. .info-plan{
  381. text-align: center;
  382. color: #0E9F9B;
  383. margin-top:1vh;
  384. font-weight: 400;
  385. }
  386. .setting{
  387. position: fixed;
  388. right: -1px;
  389. top: 10vh;
  390. z-index: 999;
  391. background: rgb(227,243,245);
  392. color: #0E9F9B;
  393. font-size: 10px;
  394. border-radius: 5px;
  395. padding: 3px;
  396. }
  397. </style>