checkIn.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <template>
  2. <view class="attendance-page">
  3. <view class="header">
  4. <text class="title">我的考勤记录</text>
  5. <picker mode="selector" :range="timeRanges" @change="onTimeRangeChange">
  6. <view class="picker">
  7. {{ selectedTimeRange }}/切换
  8. </view>
  9. </picker>
  10. </view>
  11. <!-- 数据统计区域 -->
  12. <view class="statistics" :class="{'show': chartShow}">
  13. <view class="statistic-card">
  14. <view class="statistic-title">考勤统计</view>
  15. <view class="statistic-item">
  16. <view>
  17. <text class="ygoa-icon icon-attendance"></text>
  18. <text class="label">出勤:</text>
  19. </view>
  20. <text class="value">{{ attendanceCount }}</text>
  21. </view>
  22. <view class="statistic-item">
  23. <view>
  24. <text class="ygoa-icon icon-leave"></text>
  25. <text class="label">请假:</text>
  26. </view>
  27. <text class="value">{{ leaveCount }}</text>
  28. </view>
  29. <view class="statistic-item">
  30. <view>
  31. <text class="ygoa-icon icon-businessTrip"></text>
  32. <text class="label">出差:</text>
  33. </view>
  34. <text class="value">{{ businessTripCount }}</text>
  35. </view>
  36. <view class="statistic-item">
  37. <view>
  38. <text class="ygoa-icon icon-clockIn1"></text>
  39. <text class="label">打卡:</text>
  40. </view>
  41. <text class="value">{{ clockInCount }}</text>
  42. </view>
  43. <view class="statistic-item">
  44. <view>
  45. <text class="ygoa-icon icon-makeUp"></text>
  46. <text class="label">补卡:</text>
  47. </view>
  48. <text class="value">{{ makeUpCount }}</text>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 今日签到信息区域 -->
  53. <view class="todayCheckIn" :class="{'show': shouldShow}">
  54. <view class="check-in-container">
  55. <text class="title2">今日签到信息</text>
  56. <view class="info-row">
  57. <view>
  58. <text class="ygoa-icon icon-date"></text>
  59. <text class="value">日期:</text>
  60. </view>
  61. <text class="label">{{todayData.day}}</text>
  62. </view>
  63. <view class="info-row">
  64. <view>
  65. <text class="ygoa-icon icon-day"></text>
  66. <text class="value">晨签时间:</text>
  67. </view>
  68. <text class="label">{{todayData.startTime || '未打卡'}} </text>
  69. </view>
  70. <view class="info-row">
  71. <view>
  72. <text class="ygoa-icon icon-night"></text>
  73. <text class="value">晚签时间:</text>
  74. </view>
  75. <text class="label">{{todayData.endTime || '未打卡'}} </text>
  76. </view>
  77. <view class="info-row">
  78. <view>
  79. <text class="ygoa-icon icon-checkInStatus"></text>
  80. <text class="value">状态:</text>
  81. </view>
  82. <text class="label">{{todayData.status}}</text>
  83. </view>
  84. </view>
  85. </view>
  86. <!-- 图表区域 -->
  87. <view class="chart-container" :class="{'show': chartShow}">
  88. <view class="">
  89. <text class="chart-title">考勤趋势图</text>
  90. <view class="charts-box">
  91. <qiun-data-charts :type="chartsType" :opts="opts" :chartData="chartData" />
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </template>
  97. <script setup>
  98. import {
  99. ref,
  100. onMounted,
  101. reactive
  102. } from 'vue';
  103. // 创建一个响应式对象记录今天的考勤数据
  104. const todayData = reactive({
  105. day: '2024-11-11', // 当前日期
  106. startTime: '08:59:59', // 晨签到时间
  107. endTime: '', // 晚签到时间
  108. status: '待补卡' // 签到状态
  109. })
  110. // 控制今日签到信息和图表显示的状态
  111. const shouldShow = ref(true) // 今日签到信息是否显示
  112. const chartShow = ref(false) // 图表是否显示
  113. // 图表类型的响应式引用
  114. const chartsType = ref('')
  115. // 图表要填充的数据
  116. const chartData = ref({})
  117. // 图表配置选项
  118. const opts = ref({
  119. color: ["#1890FF", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", "#FC8452", "#9A60B4", "#ea7ccc"], // 设定图表颜色
  120. padding: [15, 15, 0, 5],
  121. enableScroll: false, // 禁用滚动
  122. legend: {}, // 图例设置
  123. xAxis: {
  124. disableGrid: true // 禁用网格线
  125. },
  126. yAxis: {
  127. data: [{
  128. min: 0 // y轴最小值
  129. }]
  130. },
  131. extra: {
  132. column: {
  133. type: "group",
  134. width: 30,
  135. activeBgColor: "#000000",
  136. activeBgOpacity: 0.08
  137. }
  138. }
  139. });
  140. // 时间范围选择数组
  141. const timeRanges = ref(['日', '周', '月']);
  142. const selectedTimeRange = ref('日'); // 初始化选择的时间范围为“日”
  143. // 考勤相关统计数据
  144. const attendanceCount = ref(0); // 出勤次数
  145. const leaveCount = ref(0); // 请假次数
  146. const businessTripCount = ref(0); // 出差次数
  147. const clockInCount = ref(0); // 打卡次数
  148. const makeUpCount = ref(0); // 补卡次数
  149. const currentData = ref({
  150. attendance: 0, // 出勤
  151. leave: 0, // 请假
  152. businessTrip: 0, // 出差
  153. clockIn: 0, // 打卡
  154. makeUp: 0, // 补卡
  155. res: {}, // 记录详细数据
  156. });
  157. onMounted(() => {
  158. fetchAttendanceData();
  159. });
  160. // 时间范围切换事件
  161. function onTimeRangeChange(event) {
  162. const selectedIndex = event.detail.value;
  163. selectedTimeRange.value = timeRanges.value[selectedIndex]; // 设置选择的时间范围(日周月)
  164. fetchAttendanceData(); // 获取考勤数据
  165. // 根据选择的时间范围更新展示内容
  166. switch (selectedTimeRange.value) {
  167. case '日':
  168. showDay(); // 显示今日考勤
  169. break;
  170. case '周':
  171. chartsType.value = 'pie'; // 设置图表类型为饼图
  172. showWeekAndMonth(); // 显示周考勤
  173. break;
  174. case '月':
  175. chartsType.value = 'column'; // 设置图表类型为柱状图
  176. showWeekAndMonth(); // 显示月考勤
  177. break;
  178. }
  179. };
  180. // 显示今日考勤数据
  181. function showDay() {
  182. shouldShow.value = true; // 显示今日签到信息
  183. chartShow.value = false; // 隐藏图表
  184. }
  185. // 显示周或者月考勤
  186. function showWeekAndMonth() {
  187. shouldShow.value = false; // 隐藏今日签到信息
  188. chartShow.value = true; // 显示图表
  189. getData(); // 获取图表数据
  190. }
  191. // 获取考勤数据的函数
  192. function fetchAttendanceData() {
  193. // 模拟考勤数据
  194. const mockData = {
  195. 日: {
  196. attendance: 5,
  197. leave: 0,
  198. businessTrip: 1,
  199. clockIn: 5,
  200. makeUp: 0,
  201. res: {}
  202. },
  203. 周: {
  204. attendance: 30,
  205. leave: 2,
  206. businessTrip: 1,
  207. clockIn: 32,
  208. makeUp: 1,
  209. res: {
  210. series: [{
  211. data: [{
  212. "name": "出勤",
  213. "value": 50,
  214. "labelText": "出勤:50次"
  215. }, {
  216. "name": "请假",
  217. "value": 30
  218. }, {
  219. "name": "出差",
  220. "value": 20
  221. }, {
  222. "name": "打卡",
  223. "value": 18,
  224. "labelText": "打卡:18次"
  225. }, {
  226. "name": "补卡",
  227. "value": 8
  228. }]
  229. }],
  230. }
  231. },
  232. 月: {
  233. attendance: 100,
  234. leave: 5,
  235. businessTrip: 2,
  236. clockIn: 105,
  237. makeUp: 3,
  238. res: {
  239. categories: ["第1周", "第2周", "第3周", "第4周"],
  240. series: [{
  241. name: "出勤",
  242. data: [35, 8, 25, 37]
  243. },
  244. {
  245. name: "出差",
  246. data: [70, 40, 65, 100]
  247. },
  248. {
  249. name: "请假",
  250. data: [100, 80, 95, 10]
  251. }]
  252. },
  253. }
  254. };
  255. // 获取当前选择时间范围的考勤数据
  256. const currentData1 = mockData[selectedTimeRange.value];
  257. currentData.value = currentData1; // 更新当前数据
  258. // 更新统计数据
  259. if (currentData1) {
  260. if('周'==selectedTimeRange.value){
  261. const weekData=currentData1.res.series[0].data;
  262. attendanceCount.value = weekData[0].value;
  263. leaveCount.value = weekData[1].value;
  264. businessTripCount.value = weekData[2].value;
  265. clockInCount.value = weekData[3].value;
  266. makeUpCount.value = weekData[4].value;
  267. }else{
  268. attendanceCount.value = currentData1.attendance;
  269. leaveCount.value = currentData1.leave;
  270. businessTripCount.value = currentData1.businessTrip;
  271. clockInCount.value = currentData1.clockIn;
  272. makeUpCount.value = currentData1.makeUp;
  273. }
  274. } else {
  275. console.error('没有找到相关的考勤数据:', selectedTimeRange.value); // 错误处理
  276. }
  277. }
  278. // 获取图表数据
  279. function getData() {
  280. let res = currentData.value.res; // 获取当前数据的额外信息
  281. chartData.value = JSON.parse(JSON.stringify(res)); // 更新图表数据
  282. }
  283. // 计算数组和的辅助函数 (未使用)
  284. function countArr(arr){
  285. const sum=0;
  286. for (var i = 0; i < arr.length; i++) {
  287. sum+=arr[i];
  288. }
  289. return sum;
  290. }
  291. </script>
  292. <style scoped>
  293. @import "@/static/font/ygoa/iconfont.css";
  294. .ygoa-icon{
  295. margin-right: 20rpx;
  296. font-size: 50rpx;
  297. vertical-align: middle; /* 确保图标与文本竖直居中 */
  298. }
  299. .attendance-page {
  300. padding: 20px;
  301. background-color: #f9f9f9;
  302. }
  303. .header {
  304. display: flex;
  305. justify-content: space-between;
  306. align-items: center;
  307. margin-bottom: 20px;
  308. }
  309. .title {
  310. font-size: 24px;
  311. font-weight: bold;
  312. color: #333;
  313. }
  314. .picker {
  315. border: 1px solid #3498db;
  316. border-radius: 5px;
  317. padding: 10px;
  318. background-color: #ecf6fc;
  319. color: #3498db;
  320. }
  321. .statistics {
  322. display: flex;
  323. justify-content: center;
  324. }
  325. .statistic-card {
  326. background: white;
  327. border-radius: 10px;
  328. padding: 20px;
  329. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  330. /* width: 100%; */
  331. max-width: 600px;
  332. }
  333. .statistic-title {
  334. text-align: center;
  335. font-size: 20px;
  336. font-weight: bold;
  337. color: #333;
  338. }
  339. .statistic-item {
  340. display: flex;
  341. justify-content: space-between;
  342. margin-bottom: 10px;
  343. border-bottom: 1px solid #eee;
  344. padding-bottom: 10px;
  345. }
  346. .label {
  347. color: #666;
  348. }
  349. .value {
  350. font-size: 18px;
  351. font-weight: bold;
  352. color: #333;
  353. }
  354. .value, .label {
  355. line-height: 50rpx; /* 与图标高度一致,确保垂直对齐 */
  356. }
  357. .chart-container {
  358. margin-top: 20px;
  359. }
  360. .chart-title {
  361. font-size: 20px;
  362. font-weight: bold;
  363. text-align: center;
  364. margin-bottom: 10px;
  365. color: #333;
  366. }
  367. .charts-box {
  368. width: 100%;
  369. height: 300px;
  370. }
  371. .todayCheckIn {
  372. background-color: #ffffff;
  373. padding: 20px;
  374. box-sizing: border-box;
  375. }
  376. .check-in-container {
  377. width: 100%;
  378. height: 100%;
  379. display: flex;
  380. flex-direction: column;
  381. align-items: center;
  382. justify-content: center;
  383. }
  384. .title2 {
  385. font-size: 22px;
  386. font-weight: bold;
  387. margin-bottom: 20px;
  388. }
  389. .info-row {
  390. width: 100%;
  391. display: flex;
  392. align-items: center;
  393. justify-content: space-between;
  394. margin-bottom: 10px;
  395. }
  396. .todayCheckIn,
  397. .chart-container,
  398. .statistics {
  399. /* 默认隐藏 */
  400. display: none;
  401. }
  402. /* 当需要显示时,可以添加一个额外的类 */
  403. .todayCheckIn.show,
  404. .chart-container.show,
  405. .statistics.show {
  406. display: block;
  407. }
  408. .icon {
  409. width: 50rpx;
  410. height: 50rpx;
  411. margin-right: 20rpx;
  412. vertical-align: middle; /* 确保图标与文本竖直居中 */
  413. }
  414. </style>