|
@@ -0,0 +1,207 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+ <nav-bar ifPunch />
|
|
|
+ <head-info />
|
|
|
+ <van-divider :style="{ color: '#aaa', borderColor: '#aaa', margin: 0 }" />
|
|
|
+ <!-- <keep-alive> -->
|
|
|
+ <van-row class="main-button" type="flex" justify="center" align="center">
|
|
|
+ <van-button
|
|
|
+ :color="buttonInfo(buttonData.code)"
|
|
|
+ size="large"
|
|
|
+ round
|
|
|
+ style="width: 80%"
|
|
|
+ @click="punchCard"
|
|
|
+ :disabled="buttonInfo(buttonData.code) === '#aaa' ? true : false"
|
|
|
+ >
|
|
|
+ <span>{{ buttonData.type }} {{ nowDate }}</span>
|
|
|
+ </van-button>
|
|
|
+ </van-row>
|
|
|
+ <!-- </keep-alive> -->
|
|
|
+ <van-row style="padding-left: 30px">今日打卡信息</van-row>
|
|
|
+ <template v-if="punchInfo.upSignRecordState != 3">
|
|
|
+ <punch-info
|
|
|
+ :punchItem="punchInfo"
|
|
|
+ ></punch-info>
|
|
|
+ </template>
|
|
|
+ <template v-else>
|
|
|
+ <van-empty
|
|
|
+ class="custom-image"
|
|
|
+ :image="empty"
|
|
|
+ description="暂无任何打卡信息"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import navBar from "@/components/navBar";
|
|
|
+import headInfo from "@/components/headInfo";
|
|
|
+import punchInfo from "@/components/punchInfo";
|
|
|
+import empty from "@/assets/empty.png";
|
|
|
+import { Toast,Notify } from "vant";
|
|
|
+import { getButtonState,getTodaySignRecord,signRecord } from "@/api"
|
|
|
+export default {
|
|
|
+ name: "punch",
|
|
|
+ components: {
|
|
|
+ navBar,
|
|
|
+ headInfo,
|
|
|
+ punchInfo
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ // 当前时间
|
|
|
+ nowDate: "",
|
|
|
+ // 按钮数据
|
|
|
+ buttonData: {},
|
|
|
+ // 按钮变灰(不能点击)的code值
|
|
|
+ buttonPrayCode: [0,3,7],
|
|
|
+ // 图片路径
|
|
|
+ empty: empty,
|
|
|
+ // 打卡信息 status 1 正常 2 迟到 3 早退 4 缺卡
|
|
|
+ // 定时器名字
|
|
|
+ interval: "",
|
|
|
+ // 打卡信息
|
|
|
+ punchInfo: {},
|
|
|
+ // 定时器1
|
|
|
+ interOne: "",
|
|
|
+ // 定时器2
|
|
|
+ interTwo: ""
|
|
|
+ };
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ buttonInfo() {
|
|
|
+ return function(code) {
|
|
|
+ if(this.buttonPrayCode.some((item) => item == code)){
|
|
|
+ return "#aaa"
|
|
|
+ }
|
|
|
+ return "#67a2ff"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.$store.commit('showLoading')
|
|
|
+ this.getButtonStateInfo()
|
|
|
+ },
|
|
|
+ // mounted() {
|
|
|
+
|
|
|
+ // },
|
|
|
+ activated() {
|
|
|
+ this.currentTime();
|
|
|
+ },
|
|
|
+ deactivated() {
|
|
|
+ clearInterval(this.interOne)
|
|
|
+ // clearInterval(this.interTwo)
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ // 获取按钮信息
|
|
|
+ getButtonStateInfo(arg = true) {
|
|
|
+ getButtonState().then(res => {
|
|
|
+ if(res.status === 10000) {
|
|
|
+ this.buttonData = res.data
|
|
|
+ if(arg) {
|
|
|
+ this.getTodaySignRecordInfo()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$store.commit('hideLoading')
|
|
|
+ Notify({ type: 'warning', message: res.message })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取打卡信息
|
|
|
+ getTodaySignRecordInfo(arg = true) {
|
|
|
+ getTodaySignRecord().then(res => {
|
|
|
+ if(res.status === 10000){
|
|
|
+ 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 })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ currentTime() {
|
|
|
+ this.interOne = setInterval(this.formatDate, 1000);
|
|
|
+ // this.interTwo = setInterval(this.getButtonStateInfo(false), 1000);
|
|
|
+ },
|
|
|
+ formatDate() {
|
|
|
+ let date = new Date();
|
|
|
+ let hour = date.getHours(); // 时
|
|
|
+ hour = hour < 10 ? "0" + hour : hour; // 如果只有一位,则前面补零
|
|
|
+ let minute = date.getMinutes(); // 分
|
|
|
+ minute = minute < 10 ? "0" + minute : minute; // 如果只有一位,则前面补零
|
|
|
+ let second = date.getSeconds(); // 秒
|
|
|
+ second = second < 10 ? "0" + second : second; // 如果只有一位,则前面补零
|
|
|
+ this.nowDate = `${hour}:${minute}:${second}`;
|
|
|
+ },
|
|
|
+ // 打卡
|
|
|
+ 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.message })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ // 获取定位信息
|
|
|
+ getLocation() {
|
|
|
+ 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);
|
|
|
+ // data是具体的定位信息
|
|
|
+ function onComplete(data) {
|
|
|
+ // 经度 lng 纬度 lat
|
|
|
+ const {lng,lat} = data.position
|
|
|
+ that.nowSignRecord(lng,lat)
|
|
|
+ }
|
|
|
+ function onError(data) {
|
|
|
+ Toast.fail('定位失败,请重试');
|
|
|
+ // 失败 启用 ip定位
|
|
|
+ // AMap.plugin('AMap.CitySearch', function () {
|
|
|
+ // var citySearch = new AMap.CitySearch();
|
|
|
+ // citySearch.getLocalCity(function (status, result) {
|
|
|
+ // if (status === 'complete' && result.info === 'OK') {
|
|
|
+ // // 查询成功,result即为当前所在城市信息
|
|
|
+ // console.log('通过ip获取当前城市:', result)
|
|
|
+ // } else {
|
|
|
+
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // that.$store.commit('hideLoading')
|
|
|
+ // })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+<style scoped lang="scss">
|
|
|
+.main-button {
|
|
|
+ height: 20vh;
|
|
|
+}
|
|
|
+/deep/ .van-empty__image {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+/deep/ .custom-image .van-empty__image img {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+}
|
|
|
+/deep/ .van-button--disabled {
|
|
|
+ opacity: 1;
|
|
|
+}
|
|
|
+</style>
|