绿满眶商城微信小程序-uniapp
xiangpei
2025-05-09 c3e6cdbb29580e77444541c7953aca33581a4267
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
<template>
  <view class="sign-in">
    <view class="date-card">
      <div class="box">
        <div class="circle-box">
          <div class="cricle" @click="signIn()">
            <span v-if="!ifSign" :class="{ active: signFlag || ifSign }">签到</span>
            <span v-else :class="{ active: signFlag || ifSign }"
              :style="ifSign ? 'transform: rotateY(0deg);' : ''">已签</span>
          </div>
        </div>
        <text class="tips">坚持每天连续签到可以获多重奖励哦</text>
      </div>
    </view>
    <div class="date-card">
      <view class="date-con">
        <view class="date-tit">
          <div class="current-month">
            <div class="day">每日记录<span> ({{ currentMonth }})</span></div>
          </div>
        </view>
        <view class="week">
          <text v-for="item in weekArr" :key="item.id">{{ item }}</text>
        </view>
        <view class="date" v-for="obj in dataObj" :key="obj.id">
          <view class="item" v-for="item in obj" :key="item.id" :class="item == '' ? 'hide' : ''"
            :animation="item == currentDay ? animationData : ''">
            <view class="just" :class="signArr.indexOf(item) != -1 ? 'active' : ''">
              <view class="top">{{ item }} </view>
              <view class="bottom">
                <u-icon name="error" v-if="item <= currentDay" color="#999"></u-icon>
              </view>
            </view>
            <view class="back" :class="signArr.indexOf(item) != -1 ? 'active' : ''" :style="
                signArr.indexOf(item) != -1 && ifSign
                  ? 'transform: rotateY(0deg);'
                  : signArr.indexOf(item) != -1 && item != currentDay
                  ? 'transform: rotateY(0deg);'
                  : ''
              ">
              <view class="top">{{ item }}</view>
              <view class="bottom">
                <u-icon name="checkmark" :color="aiderLightColor"></u-icon>
              </view>
            </view>
          </view>
        </view>
      </view>
    </div>
    <view class="mask" :class="{ show: maskFlag, trans: transFlag }" ref="mask">
      <view class="mask-header">
        <text class="close"></text>
        <text>签到成功</text>
        <text class="close" @click="close">×</text>
      </view>
      <view class="mask-con">
        <u-icon size="120" style="margin: 50rpx 0" :color="aiderLightColor" name="checkmark"></u-icon>
        <text class="text">连续签到可获得额外奖励哦!</text>
      </view>
    </view>
  </view>
</template>
 
<script>
import { sign, signTime } from "@/api/point.js";
export default {
  data() {
    return {
      aiderLightColor:this.$aiderLightColor,
      signFlag: false,
      animationData: {},
      maskFlag: false, //
      transFlag: false, //动画
      weekArr: ["日", "一", "二", "三", "四", "五", "六"], //周数组
      dateArr: [], //每个月的天数
      monthArr: [
        //实例化每个月
        "1月",
        "2月",
        "3月",
        "4月",
        "5月",
        "6月",
        "7月",
        "8月",
        "9月",
        "10月",
        "11月",
        "12月",
      ], //今天一个月英文
      currentMonth: "", //当月
      currentMonthIndex: "", //当月
      currentYear: "", //今年
      currentDay: "", //今天
      currentWeek: "", //获取当月一号是周几
      dataObj: [], //一个月有多少天这个获取
      signArr: [], //本月签到过的天数 该参数用于请求接口后获取当月都哪天签到了
      signAll: [], //所有签到数据
      ifSign: false, //今天是否签到
    };
  },
  async onLoad() {
    //获取签到数据
    var response = await signTime(
      new Date().getFullYear() + "" + this.makeUp(new Date().getMonth() + 1)
    );
    this.signAll = response.data.result;
    //获取展示数据
    this.getDate();
  },
  methods: {
    /**
     * 补0
     */
    makeUp(val) {
      if (val >= 10) {
        return val;
      } else {
        return "0" + val;
      }
    },
 
    /**
     * 点击签到
     */
    async signIn() {
      await sign().then((response) => {
        if (this.ifSign) return;
        if (this.signFlag) return;
        if (response.data.code != 200) {
          uni.showToast({
            title: response.data.message,
            duration: 2000,
            icon: "none",
          });
 
          return false;
        }
        var that = this;
        var animation = uni.createAnimation({
          duration: 200,
          timingFunction: "linear",
        });
        this.signArr.push(this.currentDay);
        this.animation = animation;
        animation.rotateY(0).step();
        this.animationData = animation.export();
 
        setTimeout(
          function () {
            that.signFlag = true;
            this.maskFlag = true;
            this.ifSign = !this.ifSign;
            animation.rotateY(0).step();
            this.animationData = animation.export();
          }.bind(this),
          200
        );
      });
    },
 
    /**
     * 签到成功后关闭弹窗
     */
    close() {
      var that = this;
      this.maskFlag = false;
      this.transFlag = true;
      setTimeout(() => {
        that.transFlag = false;
      }, 500);
    },
 
    /**
     * 获取今天时间
     *
     */
    getDate() {
      var date = new Date(),
        index = date.getMonth(),
        curDay = null;
      this.currentYear = date.getFullYear();
      this.currentMonth = this.monthArr[index];
      this.currentMonthIndex = index + 1;
      this.currentDay = date.getDate();
      if (this.currentDay == this.signArr[this.signArr.length - 1]) {
        this.ifSign = true;
      }
      curDay = this.getWeekByDay(this.currentYear + "-" + (index + 1) + "-1");
      this.getMonthDays(index, curDay);
      this.curentSignData();
    },
 
    /**
     * 获取当前已经签到的时间
     */
    curentSignData() {
      var date = new Date(),
        index = date.getMonth(),
        curDay = null;
      this.signArr = [];
      for (var i = 0; i < this.signAll.length; i++) {
        var item = this.signAll[i];
        item.createTime = item.createTime.split(" ")[0];
        var itemVal = item.createTime.split("-");
        if (
          Number(itemVal[0]) === Number(this.currentYear) &&
          Number(itemVal[1]) === Number(this.currentMonthIndex)
        ) {
          this.signArr.push(Number(itemVal[2]));
        }
        if (
          Number(itemVal[0]) === Number(date.getFullYear()) &&
          Number(itemVal[1]) === Number(index + 1) &&
          Number(itemVal[2]) === Number(date.getDate())
        ) {
          this.ifSign = true;
        }
      }
    },
 
    /**
     *  循环出当前月份的时间
     *  例子:
     *  "","","","","","",1,
     *  2 ,3 ,4 ,5 ,6 ,7 ,8,
     *  ...依次向下排
     */
    getMonthDays(index, day) {
      //day 当月1号是周几
      this.dateArr = [];
      this.dataObj = [];
      for (var i = 0; i < day; i++) {
        this.dateArr.push("");
      }
      if (
        index == 0 ||
        index == 2 ||
        index == 4 ||
        index == 6 ||
        index == 7 ||
        index == 9 ||
        index == 11
      ) {
        for (let i = 1; i < 32; i++) {
          this.dateArr.push(i);
        }
      }
      if (index == 3 || index == 5 || index == 8 || index == 10) {
        for (let i = 1; i < 31; i++) {
          this.dateArr.push(i);
        }
      }
      if (index == 1) {
        if (
          (this.currentYear % 4 == 0 && this.currentYear % 100 != 0) ||
          this.currentYear % 400 == 0
        ) {
          for (let i = 1; i < 30; i++) {
            this.dateArr.push(i);
          }
        } else {
          for (let i = 1; i < 29; i++) {
            this.dateArr.push(i);
          }
        }
      }
      for (var y = 0; y < 10; y++) {
        if (this.dateArr.length > 7) {
          this.dataObj.push(this.dateArr.splice(0, 7));
        } else {
          for (let i = 0; i < 7 - this.dateArr.length; i++) {
            this.dateArr.push("");
          }
        }
      }
      this.dataObj.push(this.dateArr);
    },
 
    /**
     * 获取当前月份有几周
     */
    getWeekByDay(dayValue) {
      var day = new Date(Date.parse(dayValue.replace(/-/g, "/"))).getDay(); //将日期值格式化
      return day;
    },
  },
};
</script>
<style scoped>
page {
  background: #f7f7f7;
}
</style>
<style lang="scss" scoped>
.date-card {
  padding: 0 32rpx;
  margin: 32rpx 0;
  box-shadow: 0 4rpx 24rpx 0 rgba($color: #f6f6f6, $alpha: 1);
}
.tips {
  margin-top: 54rpx;
  color: #999;
  font-size: 24rpx;
  letter-spacing: 1rpx;
}
 
.circle-box {
  width: 200rpx;
  height: 200rpx;
  border-radius: 50%;
  background: $aider-light-color;
  box-shadow: 0 4rpx 24rpx 0 rgba($color: $aider-light-color, $alpha: 1);
  display: flex;
  justify-content: center; //这个是X轴居中
  align-items: center; //这个是 Y轴居中
 
}
 
.cricle {
  width: 160rpx;
  height: 160rpx;
  border-radius: 50%;
  background: $aider-light-color;
  text-align: center;
  line-height: 160rpx;
  color: #fff;
  font-size: 40rpx;
}
.current-month {
  width: 100%;
  margin: 20rpx 0;
}
.box {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding:64rpx 32rpx;
  background: #fff;
  border-radius: 20rpx;
}
.sign-in {
  color: #333;
  .date-con {
    background: #fff;
    min-height: 730rpx;
    border-radius: 20rpx;
    padding: 0 28rpx;
  }
  .day {
    font-size: 36rpx;
 
    > span {
      font-size: 30rpx;
      color: #999;
      margin-left: 20rpx;
    }
  }
  .date-tit {
    display: flex;
    justify-content: space-between;
    margin: 0 0 30rpx 0;
  }
 
  .week {
    display: flex;
    justify-content: space-between;
    color: #a6a6a6;
    font-size: 26rpx;
 
    text {
      width: 66rpx;
      text-align: center;
    }
  }
 
  .date {
    margin: 10rpx 0 36rpx;
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
 
    .item {
      width: 66rpx;
      height: 80rpx;
      border-radius: 5px;
      overflow: hidden;
 
      position: relative;
 
      &.hide {
        opacity: 0;
      }
 
      .just,
      .back {
        display: flex;
        flex-direction: column;
        width: 100%;
        height: 100%;
        position: absolute;
 
        .top {
          position: relative;
          flex: 1;
          text-align: center;
          line-height: 40rpx;
 
          &:before {
            content: "";
            width: 40rpx;
            height: 40rpx;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            top: 15rpx;
          }
        }
      }
 
      .just {
        &.active {
          display: none;
        }
      }
      .back {
        display: none;
        &.active {
          display: flex;
        }
 
        .top {
          color: $aider-light-color;
        }
      }
 
      .bottom {
        color: #999;
        font-size: 20rpx;
        height: 20rpx;
        line-height: 20rpx;
        text-align: center;
      }
    }
  }
  .mask {
    position: fixed;
    top: 0;
    bottom: 0;
    left: -100%;
    right: 100%;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.5s;
 
    &.show {
      opacity: 1;
      left: 0;
      right: 0;
    }
 
    &.trans {
      left: 0;
      right: 0;
    }
 
    .mask-header {
      width: 540rpx;
      height: 130rpx;
      line-height: 130rpx;
      background: $aider-light-color;
      color: #fff;
      font-size: 40rpx;
      font-weight: 500;
      display: flex;
      justify-content: space-between;
 
      .close {
        width: 60rpx;
        font-size: 66rpx;
        font-weight: 400;
        line-height: 60rpx;
      }
    }
 
    .mask-con {
      width: 540rpx;
      height: 380rpx;
      background: #fff;
      display: flex;
      flex-direction: column;
      align-items: center;
      color: #999;
      font-size: 24rpx;
      border-radius: 0 0 9px 9px;
 
      .keep-sign {
        font-size: 30rpx;
        margin-top: 30rpx;
 
        text {
          font-size: 46rpx;
          font-weight: 500;
          color: #999;
          padding: 0 6rpx 0 8rpx;
        }
      }
 
      .mark {
        // flex: 1;
        display: flex;
        align-items: flex-end;
        position: relative;
        margin-bottom: 16rpx;
 
        text {
          margin-left: 4rpx;
          color: #999;
        }
      }
 
      .text {
        color: #6f6f6f;
        height: 90rpx;
      }
    }
  }
}
</style>