index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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. console.log('收到服务器内容:' + JSON.stringify(data));
  160. });
  161. scriptTask.onClose(function (res) {
  162. console.log('WebSocket 已关闭!');
  163. });
  164. },
  165. toSet(){
  166. this.closeSocket();
  167. uni.navigateTo({
  168. url: '/pages/weitiandi/device/setting?id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  169. });
  170. },
  171. toPlan(){
  172. uni.navigateTo({
  173. url: '/pages/weitiandi/device/plan?id='+this.deviceInfo.deviceId+"&ccid="+this.deviceInfo.ccid
  174. });
  175. },
  176. trigger(){
  177. let port_first_status = this.portDetail.port_first_status;
  178. if(port_first_status == 2){//需要停止充电
  179. this.$modal.confirm("需要停止充电么?").then(res=>{
  180. this.stopCharge();
  181. })
  182. }else{
  183. if(port_first_status == 1){
  184. this.$modal.msg("请先将充电枪插入后再点击充电");
  185. }
  186. if(port_first_status == 1){
  187. this.$modal.confirm("确认开始充电么?").then(res=>{
  188. this.startCharge();
  189. })
  190. }
  191. }
  192. },
  193. getInfo() {
  194. this.$modal.loading("正在获取状态,请稍等...");
  195. sendPortDetailCmd(this.deviceInfo).then(res => {
  196. this.visitTime = res.msg;
  197. if(!this.visitTime){
  198. this.$modal.msg("请重新进入页面");
  199. return;
  200. }
  201. if(!this.scriptTask){
  202. this.initSocket(this.deviceInfo.deviceId);
  203. }
  204. // this.getPortInfo()
  205. })
  206. },
  207. stopCharge(){
  208. let self = this;
  209. stopCharge(this.deviceInfo).then(()=>{
  210. self.$modal.loading("停止成功");
  211. setTimeout((()=>{
  212. self.getInfo();
  213. }),1000);
  214. })
  215. },
  216. startCharge(){
  217. let self = this;
  218. startCharge(this.deviceInfo).then(res=>{
  219. self.$modal.loading("启动成功");
  220. setTimeout((()=>{
  221. self.getInfo();
  222. }),1000);
  223. })
  224. },
  225. getPortInfo(){
  226. this.startPortDetailTimer();
  227. },
  228. startPortDetailTimer(){
  229. let self = this;
  230. this.timer = setTimeout(function (){
  231. getPortDetail(self.deviceInfo,self.visitTime).then(res=>{
  232. let data = res.data;
  233. if(data != null){
  234. self.portDetail = data;
  235. self.checkStatusCheck();
  236. self.$modal.closeLoading();
  237. }else{
  238. self.startPortDetailTimer();
  239. }
  240. });
  241. },1000);
  242. },
  243. checkStatusCheck(){
  244. this.statusChangeTimer();
  245. },
  246. checkOnPage(){
  247. var pages = getCurrentPages() // 获取栈实例
  248. let currentRoute = pages[pages.length - 1].route; // 获取当前页面路由
  249. if("pages/weitiandi/device/index" != currentRoute){
  250. return false;
  251. }
  252. return true;
  253. },
  254. closeSocket(){
  255. this.scriptTask.close();
  256. this.scriptTask = null;
  257. },
  258. statusChangeTimer(){
  259. let self = this;
  260. this.statusTimer = setTimeout(function(){
  261. if(!this.checkOnPage()){
  262. return;
  263. }
  264. checkStatusChange(self.deviceInfo,self.visitTime).then(res=>{
  265. let data = res.data;
  266. if(data != null){
  267. self.getInfo();
  268. }else{
  269. self.statusChangeTimer();
  270. }
  271. });
  272. },3000);
  273. }
  274. }
  275. }
  276. </script>
  277. <style>
  278. .container {
  279. background: rgb(249, 252, 255);
  280. inset: 0;
  281. position: absolute;
  282. }
  283. .header {
  284. position: relative;
  285. }
  286. .header-status-desc {
  287. position: absolute;
  288. text-align: center;
  289. width: 100%;
  290. bottom:1vh;
  291. font-size: 5vw;
  292. font-weight: bold;
  293. color: #0E9F9B;
  294. }
  295. .header-status {
  296. font-weight: bold;
  297. padding-left: 5vw;
  298. }
  299. .chong-active {
  300. color: #0E9F9B
  301. }
  302. .header-img {
  303. width: 100%;
  304. padding: 5% 10%;
  305. text-align: center;
  306. }
  307. .header-img image {
  308. width: 100%;
  309. height: 23vh;
  310. }
  311. .info-body{
  312. background: #0E9F9B;
  313. height: 20vh;
  314. margin: 0 10%;
  315. border-radius: 1vw;
  316. margin-top:2vh;
  317. color: #F8FCFF;
  318. line-height: 3vh;
  319. }
  320. .info-content{
  321. display: inline-block;
  322. width: 48%;
  323. text-align: center;
  324. margin: 1%;
  325. margin-top:2.5vh;
  326. }
  327. .info-content-value{
  328. font-weight: bold;
  329. }
  330. .info-content-text{
  331. }
  332. .info-summary{
  333. display: flex;
  334. flex-direction: row;
  335. text-align: center;
  336. margin:3vh 0;
  337. }
  338. .summary{
  339. width: 33%;
  340. line-height: 2.5vh;
  341. }
  342. .charge-num{
  343. color: #0E9F9B;
  344. font-weight: bold;
  345. font-size: 4.5vw;
  346. }
  347. .charge-title{
  348. color: #B2B2B2;
  349. font-weight: 400;
  350. }
  351. .btn-image{
  352. width: 90%;
  353. height: 100%;
  354. }
  355. .info-bottom-btn{
  356. display: flex;
  357. flex-direction: row;
  358. text-align: center;
  359. position: relative;
  360. margin-top: 10vh
  361. ;
  362. }
  363. .btn-area{
  364. width: 50%;
  365. height: 50px;
  366. }
  367. .left{
  368. position: relative;
  369. left: 10px;
  370. text-align: right;
  371. }
  372. .right{
  373. text-align: left;
  374. position: relative;
  375. right: 10px;
  376. }
  377. .info-plan{
  378. text-align: center;
  379. color: #0E9F9B;
  380. margin-top:1vh;
  381. font-weight: 400;
  382. }
  383. .setting{
  384. position: fixed;
  385. right: -1px;
  386. top: 10vh;
  387. z-index: 999;
  388. background: rgb(227,243,245);
  389. color: #0E9F9B;
  390. font-size: 10px;
  391. border-radius: 5px;
  392. padding: 3px;
  393. }
  394. </style>