index.vue
12.5 KB
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
<template>
<view class="page-container">
<!-- 用户信息栏 -->
<view class="user-info-bar">
<view class="user-info">
<view class="user-text">
<view class="username">你好{{ userName }},欢迎登录</view>
<view class="login-desc">全域智能运营管理平台</view>
</view>
</view>
<view class="msg-icon" @click="handleMsgClick" hover-class="msg-icon--hover">
<up-icon name="chat" color="#fff" size="24"/>
<view class="msg-badge" >
<up-badge type="error" showZero="true" max="999" :value="msgCount"></up-badge>
</view>
</view>
</view>
<view class="content-wrap">
<!-- 任务完成情况标题 -->
<view class="module-title">任务完成情况</view>
<!-- 任务完成情况卡片 -->
<view class="task-chart-card">
<view class="card-header">
<view class="unit-tip">单位: 个</view>
<view class="date-picker-wrap">
<neo-datetime-pro
v-model="dateRange"
type="daterange"
:clearable="false"
placeholder="请选择日期范围"
@confirm="handleDateConfirm"
:max-date="maxDate"
/>
</view>
</view>
<!-- 双折线K线图 -->
<view class="chart-container">
<uni-charts
type="line"
:data="klineChartData"
:categories="klineCategories"
:option="klineOption"
:width="chartWidth"
:height="chartHeight"
/>
</view>
</view>
<!-- 使用up-tabs组件实现Tab切换 -->
<up-tabs
:list="tabList"
active-color="#0A86F4"
inactive-color="#666"
font-size="14px"
lineWidth="60"
@change="handleTabChange"
class="task-tab-container"
:scrollable="false"
></up-tabs>
<!-- z-paging分页列表 -->
<z-paging
ref="paging"
v-model="currentTaskList"
@query="queryList"
:auto-show-system-loading="true"
:page-size="10"
use-page-scroll
>
<template #empty>
<up-empty />
</template>
<view class="task-list-container">
<view
class="task-item"
v-for="(item,index) in currentTaskList"
:key="`${item.taskName}_${index}`"
hover-class="task-item--hover"
@click="handleTaskClick(item)"
>
<view class="task-item__content">
<view class="task-item__name u-line-1">
{{ item.taskName || '无' }}
</view>
<view class="task-item__footer u-flex common-item-center common-justify-between"
style="font-size: 13px; margin-top: 5px;">
<view class="urgency-tag" >
紧急程度: {{ item.pressingType }}
</view>
<view style="font-size: 13px;color: #333">{{
timeFormat(item.busiDateTime, 'yyyy-mm-dd hh:MM:ss')
}}
</view>
</view>
</view>
</view>
</view>
</z-paging>
</view>
</view>
</template>
<script setup lang="ts">
import {ref, watch, computed, reactive} from 'vue';
import {onShow} from '@dcloudio/uni-app'
import {useUserStore} from '@/pinia/user';
import {timeFormat} from '@/uni_modules/uview-plus';
import uniCharts from '@/components/uni-charts/uni-charts.vue';
import {getUnreadCount} from "@/api/user";
import {getTaskCompletionSummary, getTaskDetails} from "@/api/index/index";
// ========== 2. 响应式数据 ==========
const msgCount = ref(0);
const currentTab = ref('todo'); // todo:待办 done:已办
const dateRange = ref([]);
const maxDate = ref(timeFormat(new Date(), 'yyyy-mm-dd'));
// Tab列表配置
const tabList = ref([]);
const todoTotal = ref(0); // 待办事项总数
const doneTotal = ref(0); // 已办事项总数
// 分页相关
const paging = ref(null);
const currentTaskList = ref([]); // 当前显示的任务列表(分页数据)
// 折线图数据配置
const chartWidth = ref(0);
const chartHeight = ref(300);
const klineCategories = ref([]); // X轴日期
const klineChartData = ref([
{
name: '已完成任务数',
data: [],
color: '#25AF69'
},
{
name: '待完成总任务数',
data: [],
color: '#B34C17'
}
]);
// 图表配置
const klineOption = ref({
grid: {
top: '25%',
left: '12%',
right: '8%',
bottom: '16%'
},
xAxis: {
axisLabel: {fontSize: 12, color: '#666'}
},
yAxis: {
min: 0,
splitLine: {lineStyle: {color: '#f5f5f7'}},
axisLabel: {fontSize: 12, color: '#666'}
},
tooltip: {
trigger: 'axis',
formatter: (params) => {
return `${params[0].name}<br/>
${params[0].seriesName}: ${params[0].data}<br/>
${params[1].seriesName}: ${params[1].data}`;
}
},
legend: {
show: true,
top: '5%',
textStyle: {fontSize: 12}
}
});
// ========== 3. 计算属性 ==========
const userStore = useUserStore();
const userName = computed(() => userStore.userInfo?.user?.nickname || '用户');
// ========== 4. 工具函数 ==========
const rpx2px = (rpx) => {
const systemInfo = uni.getSystemInfoSync();
return Math.floor(rpx * (systemInfo.screenWidth / 750));
};
const initRecent7Days = async () => {
const now = new Date();
const sevenDaysAgo = new Date();
sevenDaysAgo.setDate(now.getDate() - 6);
// 格式化日期为 YYYY-MM-DD 格式
dateRange.value = [
timeFormat(sevenDaysAgo, 'yyyy-mm-dd'),
timeFormat(now, 'yyyy-mm-dd')
];
initChartData(timeFormat(sevenDaysAgo, 'yyyy-mm-dd'), timeFormat(now, 'yyyy-mm-dd'));
};
const getUnread = async () => {
try {
const res = await getUnreadCount();
msgCount.value = res || 0;
} catch (error) {
console.error('获取未读消息数失败:', error);
msgCount.value = 0;
}
};
/**
* 初始化图表数据
* @param {string} beginTime 开始时间
* @param {string} endTime 结束时间
*/
const initChartData = async (beginTime, endTime) => {
try {
let postData = {
beginTime: beginTime,
endTime: endTime
};
const res = await getTaskCompletionSummary(postData);
console.log('图表数据:', res);
klineCategories.value = res.map(item => item.currentDate);
klineChartData.value[0].data = res.map(item => item.completedNum);
klineChartData.value[1].data = res.map(item => item.countpendingNum);
} catch (error) {
console.error('获取图表数据失败:', error);
}
};
/**
* 获取所有Tab的总数(初始化时调用)
*/
const getAllTabTotal = async () => {
try {
// 同时请求待办和已办的总数(只请求第1页,每页1条,仅获取total)
const [todoRes, doneRes] = await Promise.all([
getTaskDetails({queryType: 1, pageNo: 1, pageSize: 1}),
getTaskDetails({queryType: 2, pageNo: 1, pageSize: 1})
]);
// 更新总数
todoTotal.value = todoRes?.total || 0;
doneTotal.value = doneRes?.total || 0;
console.log('已办:')
console.log(doneRes)
tabList.value = [
{name: `待办事项(${todoTotal.value})`},
{name: `已办事项(${doneTotal.value})`},
]
console.log('初始化总数:', {todoTotal: todoTotal.value, doneTotal: doneTotal.value});
} catch (error) {
console.error('获取Tab总数失败:', error);
// 保底:如果已办请求失败,至少保证待办数据正常
}
};
// ========== 5. 业务逻辑 ==========
/**
* up-tabs切换事件处理
* @param {object} item 选中的Tab项
*/
const handleTabChange = (item) => {
// 解析Tab类型(todo/done)
console.log(item)
const newTab = item.name.includes('待办') ? 'todo' : 'done';
if (currentTab.value === newTab) return;
currentTab.value = newTab;
// 切换标签后刷新分页数据
paging.value?.reload();
};
/**
* 分页查询列表数据
* @param {number} pageNo 页码
* @param {number} pageSize 每页条数
*/
const queryList = async (pageNo, pageSize) => {
try {
// 1:待完成 2:已完成
const queryType = currentTab.value === 'todo' ? 1 : 2;
const postData = {
queryType,
pageNo,
pageSize,
};
const res = await getTaskDetails(postData);
console.log(`${currentTab.value}列表数据:`, res);
// 更新当前Tab的总数
if (currentTab.value === 'todo') {
todoTotal.value = res?.total || 0;
} else {
doneTotal.value = res?.total || 0;
}
// 适配z-paging分页(注意接口返回结构是res.data.list)
paging.value.complete(res?.list || [], res?.total || 0);
} catch (error) {
console.error(`加载${currentTab.value}列表失败:`, error);
paging.value?.complete(false);
uni.showToast({title: '加载失败,请重试', icon: 'none'});
}
};
// 日期选择确认事件
const handleDateConfirm = (e) => {
console.log('日期选择确认:', e);
// 更新选中的日期范围
dateRange.value = e;
// 加载选择日期后的图表数据
initChartData(e[0], e[1]);
};
const handleMsgClick = () => {
uni.navigateTo({url: '/pages-sub/msg/index'});
};
const handleTaskClick = (item) => {
// uni.navigateTo({url: `/pages-sub/task/detail?id=${item.id || ''}`});
};
// ========== 6. 生命周期 ==========
onShow(async () => {
// 初始化图表尺寸
chartWidth.value = rpx2px(750 - 60);
chartHeight.value = rpx2px(300);
// 初始化默认日期范围(最近7天)
initRecent7Days();
// 获取未读消息数
getUnread();
await getAllTabTotal();
// 初始化分页数据(待办列表)
if (paging.value) {
paging.value.reload();
}
});
</script>
<style scoped lang="scss">
/* 样式变量 */
$primary-color: #1677ff;
$danger-color: #E53935;
$text-color: #333;
$text-color-light: #666;
$text-color-placeholder: #999;
$bg-color: #f5f5f7;
$card-bg: #fff;
$border-radius: 16px;
$card-radius: 5px;
$spacing-sm: 5px;
$spacing-md: 10px;
$spacing-lg: 15px;
$border-color: #e5e5e5; // 新增边框颜色变量
.page-container {
min-height: 100vh;
background-color: $bg-color;
}
.user-info-bar {
background: url("https://img.jichengshanshui.com.cn:28207/appimg/bg.jpg") no-repeat;
background-size: 100% 100%;
padding: 90px $spacing-lg 135px;
display: flex;
justify-content: space-between;
align-items: center;
color: #fff;
position: relative;
z-index: 1;
.username {
font-size: 16px;
font-weight: 500;
margin-bottom: 4px;
}
.login-desc {
font-size: 16px;
}
.msg-icon {
position: relative;
padding: 5px;
top:10px;
border-radius: 50%;
&--hover {
background-color: rgba(255, 255, 255, 0.2);
}
.msg-badge {
position: absolute;
top: -5px;
right: -5px;
}
}
}
.content-wrap {
margin-top: -122px;
border-radius: $border-radius $border-radius 0 0;
background-color: $bg-color;
position: relative;
z-index: 999;
overflow: hidden;
padding-bottom: $spacing-lg;
}
.module-title {
padding: $spacing-lg;
font-size: 15px;
font-weight: 600;
color: $text-color-light;
}
.task-chart-card {
background-color: $card-bg;
border-radius: $card-radius;
margin: 0 $spacing-lg $spacing-md;
padding: $spacing-md;
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
font-size: 12px;
color: $text-color-placeholder;
margin-bottom: $spacing-md;
.date-picker-wrap {
padding: 2px 4px;
border-radius: 3px;
transition: background-color 0.2s;
&:active {
background-color: $bg-color;
}
}
}
.chart-container {
width: 100%;
height: 150px;
display: flex;
align-items: center;
justify-content: center;
}
}
.task-tab-container {
position: relative;
z-index: 4;
margin: 0 $spacing-lg $spacing-sm;
}
.task-list-container {
margin: 0 $spacing-lg;
background-color: $card-bg;
border-radius: $card-radius;
overflow: hidden; // 防止边框溢出圆角
}
.task-item {
padding: $spacing-md;
transition: background-color 0.2s;
border-bottom: 1px solid $border-color;
&:last-child {
border-bottom: none;
}
&--hover {
background-color: $bg-color;
}
&__content {
width: 100%;
}
&__name {
font-size: 13px;
color: $text-color;
margin-bottom: $spacing-sm;
}
&__footer {
display: flex;
align-items: center;
justify-content: space-between;
}
}
// 紧急程度标签样式
.urgency-tag {
color: #7D7D7D;
}
</style>