소스 검색

增加电表开关

zhengqiang 5 년 전
부모
커밋
ffbeed862a
6개의 변경된 파일43개의 추가작업 그리고 14개의 파일을 삭제
  1. 1 1
      config/dev.env.js
  2. 6 6
      config/index.js
  3. 8 0
      src/api/remoteApi.js
  4. 19 4
      src/components/Home.vue
  5. 5 1
      src/components/Pay.vue
  6. 4 2
      src/main.js

+ 1 - 1
config/dev.env.js

@@ -4,5 +4,5 @@ const prodEnv = require('./prod.env')
 
 module.exports = merge(prodEnv, {
   NODE_ENV: '"development"',
-  BACKEND_URL:'"/epay-server"'
+  BACKEND_URL:'"http://localhost:8080/smart-community-server"'
 })

+ 6 - 6
config/index.js

@@ -9,12 +9,12 @@ module.exports = {
     // Paths
     assetsSubDirectory: 'static',
     assetsPublicPath: '/',
-    proxyTable: {
-      '/epay-server': {
-        target: 'http://localhost:8080',
-	    	changeOrigin:true
-	  	}
-    },
+    // proxyTable: {
+    //   '/epay-server': {
+    //     target: 'http://localhost:9192',
+	  //   	changeOrigin:true
+	  // 	}
+    // },
 
     // Various Dev Server settings
     host: 'localhost', // can be overwritten by process.env.HOST

+ 8 - 0
src/api/remoteApi.js

@@ -68,6 +68,14 @@ var remoteApi = {
             }
         });
     },
+    powerSwitch: function(roomId,cmd) {
+        var formData = new FormData()
+
+        formData.append("roomId",roomId);
+        formData.append("cmd",cmd);
+
+        return request.post(basePath + `/mobileApi/powerSwitch`,formData);
+    }
 }
 
 export default remoteApi

+ 19 - 4
src/components/Home.vue

@@ -30,13 +30,14 @@
           <van-dropdown-item v-model="selectedRoomId" :options="roomList" @change="roomChange"/>
         </van-dropdown-menu>
       </van-cell-group>
+      <van-cell-group>
+        <van-switch-cell title="电表开关" v-model="powerOn" :active-color="'#13ce66'" @change="powerSwitch"/>
+      </van-cell-group>
       <div class="fyy-button">
         <van-button type="primary" @click="queryPower(selectedRoomId)">查询</van-button>
         <p>
           剩余电量:<span v-html="remainingPower" class="power"></span>
           <span v-if="remainingPower!=null">度</span>
-          &nbsp;
-          当前状态:<span v-html="stateText"></span>
         </p>
       </div>
     </div>
@@ -60,7 +61,8 @@ export default {
       selectedRoomId: null,
       areaList: [],
       buildingList: [],
-      roomList: []
+      roomList: [],
+      powerOn: false
     };
   },
   computed: {
@@ -100,6 +102,7 @@ export default {
         return self.buildingChange(self.selectedBuildingId);
     }).then((resp)=>{
         self.selectedRoomId = Cookies.get("selectedRoomId");
+        self.queryPower(self.selectedRoomId)
     });
   },
   methods: {
@@ -139,10 +142,12 @@ export default {
         self.$toast.clear();
 
         if(resp.result){
-          self.$toast.success('查询成功!')
+          //self.$toast.success('查询成功!')
 
           self.remainingPower = resp.data.remain
           self.state = resp.data.state
+
+          self.powerOn = self.state==0
         }
         else {
           self.$toast.fail(resp.message)
@@ -180,6 +185,16 @@ export default {
           }
         });
       }
+    },
+    powerSwitch (){
+      remoteApi.powerSwitch(this.selectedRoomId,this.powerOn ? 1 : 0).then((resp)=>{
+        if(resp.result) {
+          this.$notify({ type: 'success', message: "操作成功!" });
+        }
+        else{
+          this.$notify({ type: 'warning', message: resp.message });
+        }
+      });
     }
   }
 };

+ 5 - 1
src/components/Pay.vue

@@ -17,6 +17,9 @@
         </div>
         <p class="fyy-h6">价格标准:<span v-html="price"></span>元/度</p>
       </van-cell-group>
+      <van-cell-group>
+        <van-switch-cell title="电表开关演示" v-model="powerOn"/>
+      </van-cell-group>
       <van-cell-group>
         <van-cell>
           <span class="iconfont color-red fyy-icon">&#xe648;</span>
@@ -76,7 +79,8 @@ export default {
       payType: 'weipay',
       showAlipay: false,
       qrCodeUrl: '',
-      timeoutId : 0
+      timeoutId : 0,
+      powerOn: false
     }
   },
   methods: {

+ 4 - 2
src/main.js

@@ -11,11 +11,11 @@ import { Button } from 'vant'
 import { Collapse, CollapseItem } from 'vant'
 import { Field } from 'vant'
 import { Cell, CellGroup } from 'vant'
-import { Toast } from 'vant'
+import { Toast,Notify } from 'vant'
 import AxiosPlugin from './plugins/AxiosPlugin'
 import { RadioGroup, Radio } from 'vant'
 import { Image,Dialog,Overlay } from 'vant'
-import { PullRefresh ,List } from 'vant';
+import { PullRefresh ,List,SwitchCell  } from 'vant';
 
 Vue.use(PullRefresh)
 Vue.use(List)
@@ -31,7 +31,9 @@ Vue.use(Button)
 Vue.use(NavBar)
 Vue.use(DropdownMenu).use(DropdownItem)
 Vue.use(Toast)
+Vue.use(Notify)
 Vue.use(AxiosPlugin)
+Vue.use(SwitchCell)
 
 Vue.config.productionTip = false