signIn.vue 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <div class="Clockln-box">
  3. <div class="box1">
  4. <div class="box-item box1-avatar">
  5. <avatar />
  6. </div>
  7. <div class="box-item box1-title">{{signInfo.name}}</div>
  8. <div class="box1-time">签到结束时间</div>
  9. <div class="box1-time">{{endTimeStr}}</div>
  10. </div>
  11. <div :class="{ 'myDIV': true }" @click="goSign">
  12. <div>{{signText}}</div>
  13. <span>{{currentTimeStr}}</span>
  14. </div>
  15. <img src="~@/assets/basemap.png" alt width="100%" />
  16. </div>
  17. </template>
  18. <script>
  19. import { getSignInInfo, postSignIn } from '@/util/api'
  20. import { parseTime } from '@/util/formattingData'
  21. import { mapState } from 'vuex'
  22. export default {
  23. components: {
  24. avatar: () => import('@/components/Avatar/index.vue')
  25. },
  26. data() {
  27. return {
  28. signInfo: {},
  29. canSign: false,
  30. noSignErr: '',
  31. shortErr: '',
  32. ticker: null,
  33. now: new Date()
  34. }
  35. },
  36. computed: {
  37. ...mapState({
  38. person: (s) => s.user
  39. }),
  40. endTimeStr() {
  41. if (!this.signInfo.endTime) return '未知'
  42. return parseTime(this.signInfo.endTime, '{y}年{m}月{d}日 {h}:{i}')
  43. },
  44. currentTimeStr() {
  45. return parseTime(this.now, '{h}:{i}:{s}')
  46. },
  47. signText() {
  48. return this.canSign ? '签 到' : this.shortErr
  49. }
  50. },
  51. watch: {
  52. '$route.query.signId': {
  53. handler(v) {
  54. if (v) {
  55. this.onLoadSinInfo(v)
  56. }
  57. },
  58. immediate: true
  59. }
  60. },
  61. created() {
  62. this.ticker = setInterval(() => {
  63. this.now = new Date()
  64. }, 1000)
  65. },
  66. mounted() {
  67. const { phone } = this.person || {}
  68. if (!phone) {
  69. this.$dialog
  70. .alert({
  71. message: '请先维护您的个人信息'
  72. })
  73. .then(() => {
  74. this.$router.push({ name: 'SetUser' })
  75. })
  76. }
  77. },
  78. beforeDestroy() {
  79. if (this.ticker) {
  80. clearInterval(this.ticker)
  81. }
  82. },
  83. methods: {
  84. parseTime,
  85. //首先判断他有没有资格
  86. // this.$toast.success('修改成功!')
  87. onLoadSinInfo(id) {
  88. getSignInInfo(id)
  89. .then((e) => {
  90. this.signInfo = e
  91. // 必须属于签到池人员
  92. if (!this.signInfo.canSign) {
  93. this.canSign = false
  94. this.noSignErr = '当前活动您未参与'
  95. this.shortErr = '未参与'
  96. return
  97. }
  98. if (this.signInfo.isSigned) {
  99. this.canSign = false
  100. this.noSignErr = '您已签到'
  101. this.shortErr = '已签到'
  102. return
  103. }
  104. // 必须是签到时间
  105. const isGtStart = this.now - new Date(this.signInfo.startTime) > 0
  106. const isLtEnd = this.now - new Date(this.signInfo.endTime) < 0
  107. if (!isGtStart) {
  108. this.canSign = false
  109. this.noSignErr = '签到未开始'
  110. this.shortErr = '未开始'
  111. return
  112. }
  113. if (!isLtEnd) {
  114. this.canSign = false
  115. this.noSignErr = '签到已结束'
  116. this.shortErr = '已结束'
  117. return
  118. }
  119. this.canSign = true
  120. this.noSignErr = ''
  121. this.shortErr = ''
  122. })
  123. .catch((e) => {
  124. this.$toast(e.message)
  125. })
  126. },
  127. goSign() {
  128. if (!this.canSign) {
  129. this.$toast(this.noSignErr)
  130. return
  131. }
  132. postSignIn(this.$route.query.signId).then((e) => {
  133. console.log(e)
  134. this.canSign = false
  135. this.signInfo.isSigned = true
  136. this.noSignErr = '您已签到'
  137. this.shortErr = '已签到'
  138. this.$toast('签到成功')
  139. })
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="less" scoped>
  145. .Clockln-box {
  146. background-color: #fff;
  147. height: 100%;
  148. width: 100vw;
  149. padding-top: 60px;
  150. .box-item {
  151. & + .box-item {
  152. margin-top: 3em;
  153. }
  154. }
  155. .box1 {
  156. width: 100%;
  157. &-avatar {
  158. display: flex;
  159. justify-content: center;
  160. }
  161. &-title {
  162. width: 90%;
  163. margin: 0 auto;
  164. text-align: center;
  165. color: #000;
  166. font-size: 18px;
  167. font-weight: 700;
  168. margin-bottom: 30px;
  169. }
  170. &-time {
  171. width: 90%;
  172. margin: 0 auto;
  173. text-align: center;
  174. color: rgb(133, 133, 133);
  175. font-size: 13px;
  176. line-height: 26px;
  177. letter-spacing: 2px;
  178. }
  179. }
  180. .myDIV {
  181. margin: 6vh auto auto auto;
  182. width: 140px;
  183. height: 140px;
  184. // margin: 0 auto;
  185. border-radius: 100%;
  186. background-color: #42a9aa;
  187. display: flex;
  188. animation: qiandao 3s infinite;
  189. flex-direction: column;
  190. justify-content: center;
  191. text-align: center;
  192. > div {
  193. width: 100%;
  194. margin: 0 auto;
  195. color: white;
  196. font-size: 19px;
  197. margin-bottom: 10px;
  198. font-weight: 600;
  199. letter-spacing: 2px;
  200. }
  201. > span {
  202. color: white;
  203. display: block;
  204. font-size: 15px;
  205. }
  206. }
  207. .disabled {
  208. pointer-events: none;
  209. background-color: #d1d1d1ec;
  210. }
  211. > img {
  212. position: fixed;
  213. bottom: 7vh;
  214. }
  215. }
  216. @keyframes qiandao {
  217. 0% {
  218. box-shadow: 0 0 10px #0d888a;
  219. }
  220. 50% {
  221. box-shadow: 0 0 20px #7bdadb;
  222. }
  223. 100% {
  224. box-shadow: 0 0 10px #0d888a;
  225. }
  226. }
  227. </style>