coderzzp 3 年之前
父节点
当前提交
c6c160ed75
共有 3 个文件被更改,包括 94 次插入74 次删除
  1. 1 1
      src/utils/native.js
  2. 2 2
      src/utils/request.js
  3. 91 71
      src/views/base/punch.vue

+ 1 - 1
src/utils/native.js

@@ -11,4 +11,4 @@ export function returnApp () {
       }
     )
   })
-}
+}

+ 2 - 2
src/utils/request.js

@@ -11,7 +11,7 @@ import { returnApp } from '@/utils/native'
  export const request = axios.create({
   baseURL: 'http://www.gzjlzhwy.com/',
   // baseURL: 'https://www.gzjlzhwy.com:4433/',
-  // baseURL: 'http://172.18.0.15:30000/',
+  // baseURL: 'http://172.18.0.188:30000/',
   // baseURL: process.env.BASE_API,
   timeout: process.env.TIME_OUT,
   type: "JSON"
@@ -143,4 +143,4 @@ request.interceptors.response.use(
     // 弹出层
     return Promise.reject(error)
   }
-)
+)

+ 91 - 71
src/views/base/punch.vue

@@ -19,10 +19,10 @@
     </van-row>
     <!-- </keep-alive> -->
     <van-row style="padding-left: 30px">今日打卡信息</van-row>
-    <template v-if="punchInfo.upSignRecordState != 3 && Object.keys(punchInfo).length">
-      <punch-info
-        :punchItem="punchInfo"
-      ></punch-info>
+    <template
+      v-if="punchInfo.upSignRecordState != 3 && Object.keys(punchInfo).length"
+    >
+      <punch-info :punchItem="punchInfo"></punch-info>
     </template>
     <template v-else>
       <van-empty
@@ -33,7 +33,9 @@
     </template>
     <van-tabbar v-model="active">
       <van-tabbar-item icon="location-o">打卡</van-tabbar-item>
-      <van-tabbar-item to="/statistics" replace icon="records">统计</van-tabbar-item>
+      <van-tabbar-item to="/statistics" replace icon="records"
+        >统计</van-tabbar-item
+      >
     </van-tabbar>
   </div>
 </template>
@@ -45,18 +47,24 @@ import punchInfo from "@/components/punchInfo";
 import Loading from "@/components/loading";
 import { mapState } from "vuex";
 import empty from "@/assets/empty.png";
-import { Toast,Notify } from "vant";
-import { returnApp } from '@/utils/native'
-import { setStore } from '@/utils/store'
+import { Toast, Notify } from "vant";
+import { returnApp } from "@/utils/native";
+import { setStore } from "@/utils/store";
+import debounce from "@/utils/debounce";
 import { getToken } from "@/utils/auth";
-import { getButtonState,getTodaySignRecord,signRecord,userInfoHead } from "@/api"
+import {
+  getButtonState,
+  getTodaySignRecord,
+  signRecord,
+  userInfoHead,
+} from "@/api";
 export default {
   name: "punch",
   components: {
     navBar,
     headInfo,
     punchInfo,
-    Loading
+    Loading,
   },
   data() {
     return {
@@ -66,7 +74,7 @@ export default {
       // 按钮数据
       buttonData: {},
       // 按钮变灰(不能点击)的code值
-      buttonPrayCode: [0,3,7],
+      buttonPrayCode: [0, 3, 7],
       // 图片路径
       empty: empty,
       // 打卡信息 status 1 正常 2 迟到 3 早退 4 缺卡
@@ -75,77 +83,90 @@ export default {
       // 打卡信息
       punchInfo: {},
       // 定时器1
-      interOne: ""
+      interOne: "",
     };
   },
   computed: {
     ...mapState(["LOADING"]),
     buttonInfo() {
-      return function(code) {
-        if(this.buttonPrayCode.some((item) => item == code)){
-          return "#aaa"
+      return function (code) {
+        if (this.buttonPrayCode.some((item) => item == code)) {
+          return "#aaa";
         }
-        return "#67a2ff"
-      }
+        return "#67a2ff";
+      };
     },
   },
   created() {
     let token = this.$route.query.token || getToken();
-    if(token) {
-      setStore({'name':'token', 'content': token, 'type':''})
-      this.$store.commit('showLoading')
+    if (token) {
+      setStore({ name: "token", content: token, type: "" });
+      this.$store.commit("showLoading");
       this.currentTime();
-      this.getUserInfoHead()
-      this.getButtonStateInfo()
+      this.getUserInfoHead();
+      this.getButtonStateInfo();
     } else {
-      Notify({ type: 'warning', message: '凭证过期,请重新登录',duration: 1000 })
-      setTimeout(() => returnApp(),1000)
+      Notify({
+        type: "warning",
+        message: "凭证过期,请重新登录",
+        duration: 1000,
+      });
+      setTimeout(() => returnApp(), 1000);
     }
   },
   beforeDestroy() {
-    clearInterval(this.interOne)
+    clearInterval(this.interOne);
   },
   methods: {
     // 获取用户信息
     getUserInfoHead() {
-      userInfoHead().then(res => {
-        if(res.status === 10000) {
-          this.$store.commit('setUserInfo',res.data)
+      userInfoHead().then((res) => {
+        if (res.status === 10000) {
+          this.$store.commit("setUserInfo", res.data);
         } else {
-          this.$store.commit('hideLoading')
+          this.$store.commit("hideLoading");
         }
-      })
+      });
     },
     // 获取按钮信息
-    getButtonStateInfo(arg = true) {
-      getButtonState().then(res => {
-        if(res.status === 10000) {
-          this.buttonData = res.data
-          if(arg) {
-            this.getTodaySignRecordInfo()
+    async getButtonStateInfo(arg = true) {
+      await getButtonState().then((res) => {
+        if (res.status === 10000) {
+          if (Object.keys(res.data).length) {
+            this.buttonData = res.data;
+          } else {
+            this.buttonData.type = "今日休息";
+            this.buttonData.code = 0;
+          }
+          if (arg) {
+            this.getTodaySignRecordInfo();
           }
         } else {
-          Notify({ type: 'warning', message: res.message, duration: 1000 })
-          this.$store.commit('hideLoading')
-          setTimeout(() => returnApp(),1000)
+          Notify({ type: "warning", message: res.message, duration: 1000 });
+          this.$store.commit("hideLoading");
+          setTimeout(() => returnApp(), 1000);
         }
-      })
+      });
     },
     // 获取打卡信息
-    getTodaySignRecordInfo(arg = true) {
-      getTodaySignRecord().then(res => {
-        if(res.status === 10000){
-          this.punchInfo = res.data
-          this.$store.commit('hideLoading')
-          if(!arg){
-             Notify({ type: 'warning', message: '打卡成功' })
+    async getTodaySignRecordInfo(arg = true) {
+      await getTodaySignRecord().then((res) => {
+        if (res.status === 10000) {
+          if (this.buttonData.type === "今日休息") {
+            this.punchInfo = {};
+          } else {
+            this.punchInfo = res.data;
+          }
+          this.$store.commit("hideLoading");
+          if (!arg) {
+            Notify({ type: "warning", message: "打卡成功" });
           }
         } else {
-          this.$store.commit('hideLoading')
-          Notify({ type: 'warning', message: res.message, duration: 1000 })
-          setTimeout(() => returnApp(),1000)
+          this.$store.commit("hideLoading");
+          Notify({ type: "warning", message: res.message, duration: 1000 });
+          setTimeout(() => returnApp(), 1000);
         }
-      })
+      });
     },
     currentTime() {
       this.interOne = setInterval(this.formatDate, 1000);
@@ -159,42 +180,41 @@ export default {
       let second = date.getSeconds(); // 秒
       second = second < 10 ? "0" + second : second; // 如果只有一位,则前面补零
       this.nowDate = `${hour}:${minute}:${second}`;
-      this.getButtonStateInfo(false)
+      this.getButtonStateInfo(false);
     },
     // 打卡
     punchCard() {
-      this.$store.commit('showLoading')
-      signRecord().then(res => {
-        if(res.status === 10000) {
-          this.getTodaySignRecordInfo(false)
-        }
-        else {
-          this.$store.commit('hideLoading')
-          Notify({ type: 'warning', message: res.data })
+      this.$store.commit("showLoading");
+      signRecord().then((res) => {
+        if (res.status === 10000) {
+          this.getTodaySignRecordInfo(false);
+        } else {
+          this.$store.commit("hideLoading");
+          Notify({ type: "warning", message: res.data });
         }
-      })
+      });
     },
     // 获取定位信息
     getLocation() {
-      let that = this
-      AMap.plugin('AMap.Geolocation', function () {
+      let that = this;
+      AMap.plugin("AMap.Geolocation", function () {
         var geolocation = new AMap.Geolocation({
           // 是否使用高精度定位,默认:true
           enableHighAccuracy: true,
           // 设置定位超时时间,默认:无穷大
           timeout: 5000,
-        })
-        geolocation.getCurrentPosition()
-        AMap.event.addListener(geolocation, 'complete', onComplete);
-        AMap.event.addListener(geolocation, 'error', onError);
+        });
+        geolocation.getCurrentPosition();
+        AMap.event.addListener(geolocation, "complete", onComplete);
+        AMap.event.addListener(geolocation, "error", onError);
         // data是具体的定位信息
         function onComplete(data) {
           // 经度 lng 纬度 lat
-          const {lng,lat} = data.position
-          that.nowSignRecord(lng,lat)
+          const { lng, lat } = data.position;
+          that.nowSignRecord(lng, lat);
         }
         function onError(data) {
-          Toast.fail('定位失败,请重试');
+          Toast.fail("定位失败,请重试");
           // 失败 启用 ip定位
           // AMap.plugin('AMap.CitySearch', function () {
           //   var citySearch = new AMap.CitySearch();
@@ -209,7 +229,7 @@ export default {
           //   that.$store.commit('hideLoading')
           // })
         }
-      })
+      });
     },
   },
 };