ソースを参照

考勤功能-优化首页排班考勤接口调用次数

zhonghuizhen 1 年間 前
コミット
0c64f02ee8
1 ファイル変更32 行追加7 行削除
  1. 32 7
      src/views/system/dashboard/components/util.js

+ 32 - 7
src/views/system/dashboard/components/util.js

@@ -168,8 +168,9 @@ export function buildComponent (name, column, preview, vm) {
                 this.defaultForm = JSON.parse(JSON.stringify(this.quickNavform))
                 this.defaultForm = JSON.parse(JSON.stringify(this.quickNavform))
                 this.$nextTick(async () => {
                 this.$nextTick(async () => {
                     this.fetchData()
                     this.fetchData()
-                    this.attendanceData = await this.getAttendanceData()
-                    this.scheduleData = await this.getScheduleData()
+                    // this.attendanceData = await this.getAttendanceData()
+                    // this.scheduleData = await this.getScheduleData()
+                    this.todaySchedule = await this.getTodaySchedule()
                 })
                 })
             },
             },
             methods: {
             methods: {
@@ -592,6 +593,29 @@ export function buildComponent (name, column, preview, vm) {
                     }
                     }
                     return Math.ceil((new Date(end) - new Date(start)) / (1000 * 60 * 60 * 24))
                     return Math.ceil((new Date(end) - new Date(start)) / (1000 * 60 * 60 * 24))
                 },
                 },
+                getTodaySchedule () { // 获取今日班次
+                    const { first, second } = this.$store.getters.level || {}
+                    const today = this.$common.getDateNow()
+                    const sql = `select a.*, b.start_date_, b.end_date_ from t_schedule_detail a, t_schedule b where a.parent_id_ = b.id_ and b.di_dian_ = '${second || first}' and a.user_id_ = '${this.userId}' and b.status_ = '已发布'`
+                    return new Promise((resolve, reject) => {
+                        this.$common.request('sql', sql).then((res) => {
+                            const { data = [] } = res.variables || {}
+                            let todaySchedule = []
+                            data.forEach(item => {
+                                const days = this.getDays(item.start_date_, today)
+                                const shift = item[`d${days}_`]
+                                if (shift) {
+                                    const shiftList = shift.split(',')
+                                    todaySchedule = shiftList // 返回今日班次
+                                }
+                            })
+                            console.log(todaySchedule)
+                            resolve(todaySchedule)
+                        }).catch(error => {
+                            reject(error)
+                        })
+                    })
+                },
                 getAttendanceData () {
                 getAttendanceData () {
                     const { first, second } = this.$store.getters.level || {}
                     const { first, second } = this.$store.getters.level || {}
                     const today = this.$common.getDateNow()
                     const today = this.$common.getDateNow()
@@ -669,9 +693,9 @@ export function buildComponent (name, column, preview, vm) {
                                     }
                                     }
                                 }
                                 }
                             })
                             })
-                            const today = this.$common.getDateNow()
-                            this.todaySchedule = eventList.filter(i => i.start === today).map(i => i.title)
-                            console.log(this.todaySchedule)
+                            // const today = this.$common.getDateNow()
+                            // this.todaySchedule = eventList.filter(i => i.start === today).map(i => i.title)
+                            // console.log(this.todaySchedule)
                             resolve(eventList)
                             resolve(eventList)
                         }).catch(error => {
                         }).catch(error => {
                             reject(error)
                             reject(error)
@@ -825,7 +849,9 @@ export function buildComponent (name, column, preview, vm) {
                         })
                         })
                     }
                     }
                 },
                 },
-                showMySchedule () {
+                async showMySchedule () {
+                    this.attendanceData = await this.getAttendanceData()
+                    this.scheduleData = await this.getScheduleData()
                     const scheduleConfig = {
                     const scheduleConfig = {
                         height: '100%',
                         height: '100%',
                         locale: 'zh-cn', // 语言
                         locale: 'zh-cn', // 语言
@@ -895,7 +921,6 @@ export function buildComponent (name, column, preview, vm) {
                                         }
                                         }
                                     </div>
                                     </div>
                               </div>
                               </div>
-                             
                             `
                             `
                             // 打卡按钮显示
                             // 打卡按钮显示
                             if (this.showDaKaBtn(event.extendedProps.jieShuShiJian)) {
                             if (this.showDaKaBtn(event.extendedProps.jieShuShiJian)) {