| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <script>
- import { getUserInfo } from '@/utils/auth'
- import { checkAttendance } from '@/api/mine.js'
- import config from '@/config.js'
- import $tab from '@/plugins/tab.js'
- export default {
- onLaunch: function () {
- // console.warn('当前组件仅支持 uni_modules 目录结构 ,请升级 HBuilderX 到 3.1.0 版本以上!')
- this.initApp()
- // console.log('App Launch')
- },
- onShow: function () {
- // console.log('App Show')
- },
- onHide: function () {
- // console.log('App Hide')
- },
- methods: {
- // 初始化应用
- initApp() {
- // 初始化应用配置
- // this.initConfig()
- // 检查用户登录状态
- this.checkLogin()
- },
- checkLogin() {
- const user = getUserInfo()
- if (!getUserInfo()) {
- $tab.reLaunch('/pages/login')
- } else {
- // 是否在上班打卡时间段
- if (this.isInTimeRange(...config.signInTimeRange)) {
- const now = new Date()
- const params = {
- universalid: user.useId,
- rizi: (now.getFullYear()) + '-' + (now.getMonth() + 1) + '-' + (now.getDate())
- }
- // 获取当天考勤信息
- checkAttendance(params).then(({ returnParams }) => {
- if (returnParams.list.length) {
- // 已签到 跳转消息页
- $tab.reLaunch('/pages/message/index')
- } else {
- // 未签到 跳转考勤页面
- $tab.reLaunch('/pages/message/index?to=clockIn')
- }
- })
- } else {
- $tab.reLaunch('/pages/message/index')
- }
- }
- },
- //判断时间是否在区间内
- isInTimeRange(start, end) {
- // 获取当前时间戳
- const now = Date.now();
- // 获取当前日期
- const currentDate = new Date(now);
- const year = currentDate.getFullYear();
- const month = currentDate.getMonth();
- const day = currentDate.getDate();
- // 构建当天的起始时间和结束时间的时间戳
- const startTime = new Date(year, month, day, ...start.split(':').map(Number)).getTime();
- const endTime = new Date(year, month, day, ...end.split(':').map(Number)).getTime();
- // 判断当前时间是否在范围内
- return now >= startTime && now <= endTime;
- }
- }
- }
- </script>
- <style lang="scss">
- /*每个页面公共css */
- @import '@/uni_modules/uni-scss/index.scss';
- /* uni.css - 通用组件、模板样式库,可以当作一套ui库应用 */
- @import '@/common/uni.css';
- /* #ifndef APP-NVUE */
- @import '@/static/font/customicons.css';
- /* uParse富文本框渲染 样式 */
- @import url("/components/gaoyia-parse/parse.css");
- // 设置整个项目的背景色
- page {
- background-color: #f5f5f5;
- }
- /* #endif */
- .example-info {
- font-size: 14px;
- color: #333;
- padding: 10px;
- }
- </style>
|