From 50e27370dd7963fcaebd2210e29cdb57e9148109 Mon Sep 17 00:00:00 2001 From: zhuyu Date: Mon, 24 Mar 2025 18:09:16 +0800 Subject: [PATCH] feature: task --- application/admin/controller/oa/Schedule.php | 115 ++++++++---------- .../admin/view/oa/schedule/custom_index.html | 25 +--- public/assets/js/backend/oa/schedule.js | 42 +++++++ 3 files changed, 93 insertions(+), 89 deletions(-) diff --git a/application/admin/controller/oa/Schedule.php b/application/admin/controller/oa/Schedule.php index 4b8b174..88aa57a 100644 --- a/application/admin/controller/oa/Schedule.php +++ b/application/admin/controller/oa/Schedule.php @@ -76,80 +76,63 @@ class Schedule extends Backend //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { - //如果发送的来源是Selectpage,则转发到Selectpage - if ($this->request->request('keyField')) { - return $this->selectpage(); - } - list($where, $sort, $order, $offset, $limit) = $this->buildparams(); - - $list = $this->model - ->with(['admin']) - ->where($where) - ->order($sort, $order) - ->paginate($limit); - - foreach ($list as $row) { + $startDate = '2025-02-22'; + $endDate = '2025-03-22'; + + $res = []; + $admins = Db::name('admin')->field('id,nickname')->select(); + $admins = array_column($admins, NULL, 'id'); + $adminIds = array_keys($admins); + + $adminNames = array_column($admins, 'nickname', 'id'); + + $tmpDate = $startDate; + $dates = []; + while(true) { + + if ($tmpDate > $endDate) { + break; + } + + foreach ($adminIds as $adminId) { + $res[$adminId][$tmpDate] = '无'; + $res[$adminId]['name'] = $adminNames[$adminId]; + } + + $dates[] = $tmpDate; + $tmpDate = date('Y-m-d', strtotime($tmpDate) + 86400); } - $result = array("total" => $list->total(), "rows" => $list->items()); + $queryData = $this->model + ->with([ + 'admin' + ]) + ->where('date', '>=', $startDate) + ->where('date', '<=', $endDate) + ->select(); + foreach ($queryData as $queryDatum) { + $queryDatum = $queryDatum->toArray(); + + $adminId = $queryDatum['admin']['id']; + $date = $queryDatum['date']; + $type = $queryDatum['type']; + + if (isset($res[$adminId][$date])) { + $res[$adminId][$date] = $this->model->getTypeList()[$type]; + } + } + + + $res = array_values($res); + + + $result = array("total" => count($res), "rows" => $res); return json($result); } - - $startDate = '2025-02-22'; - $endDate = '2025-03-22'; - - $res = []; - $admins = Db::name('admin')->field('id,nickname')->select(); - $admins = array_column($admins, NULL, 'id'); - $adminIds = array_keys($admins); - - $adminNames = array_column($admins, 'nickname', 'id'); - - $tmpDate = $startDate; - $dates = []; - while(true) { - - if ($tmpDate > $endDate) { - break; - } - - foreach ($adminIds as $adminId) { - $res[$adminId][$tmpDate] = '无'; - } - - $dates[] = $tmpDate; - $tmpDate = date('Y-m-d', strtotime($tmpDate) + 86400); - } - - $queryData = $this->model - ->with([ - 'admin' - ]) - ->where('date', '>=', $startDate) - ->where('date', '<=', $endDate) - ->select(); - foreach ($queryData as $queryDatum) { - $queryDatum = $queryDatum->toArray(); - - $adminId = $queryDatum['admin']['id']; - $date = $queryDatum['date']; - $type = $queryDatum['type']; - - if (isset($res[$adminId][$date])) { - $res[$adminId][$date] = $this->model->getTypeList()[$type]; - } - } - - - $this->assign('adminNames', $adminNames); - $this->assign('res', $res); - $this->assign('dates', $dates); - $this->assign('types', $this->model->getTypeList()); - return $this->view->fetch(); } diff --git a/application/admin/view/oa/schedule/custom_index.html b/application/admin/view/oa/schedule/custom_index.html index 112fe93..c2f2428 100644 --- a/application/admin/view/oa/schedule/custom_index.html +++ b/application/admin/view/oa/schedule/custom_index.html @@ -6,31 +6,10 @@
- - - - {foreach $dates as $date} - - {/foreach} - - {foreach $res as $adminId => $item} - - - {foreach $item as $typeId} - - {/foreach} - - {/foreach} +
用户\日期{$date}
{$adminNames[$adminId]}{$typeId}
diff --git a/public/assets/js/backend/oa/schedule.js b/public/assets/js/backend/oa/schedule.js index 989db7b..ac38a5b 100644 --- a/public/assets/js/backend/oa/schedule.js +++ b/public/assets/js/backend/oa/schedule.js @@ -55,6 +55,48 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin // 为表格绑定事件 Table.api.bindevent(table); }, + custom_index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'oa/schedule/custom_index' + location.search, + // add_url: 'oa/schedule/add', + // edit_url: 'oa/schedule/edit', + // del_url: 'oa/schedule/del', + // multi_url: 'oa/schedule/multi', + // import_url: 'oa/schedule/import', + table: 'schedule', + } + }); + + var table = $("#table"); + + var columnArr = []; + columnArr.push({ + "title":"username", + "field":"name", + }); + + const startDate = new Date("2025-02-22"); + const endDate = new Date("2025-03-22"); + + for (let d = new Date(startDate); d <= endDate; d.setDate(d.getDate() + 1)) { + let tmpDate = d.toISOString().split('T')[0]; // 使用 d,而不是 date + columnArr.push({ + "title": tmpDate, + "field": tmpDate, + }); + } + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + columns: columnArr + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, add: function () { Controller.api.bindevent(); },