Bläddra i källkod

feat(home-new): 新增设备定检提醒功能,对接后端接口替换静态数据

1. 新增设备台账列表API接口
2. 改造首页定检组件,从静态数据改为后端获取并按需显示空状态
3. 改造定检详情页面,支持分页筛选和动态数据加载
4. 调整组件样式和判断逻辑适配真实接口数据
huoyi 1 månad sedan
förälder
incheckning
ae84a64356

+ 9 - 0
src/api/home-new/home-new.js

@@ -139,3 +139,12 @@ export function getPushMessage(query) {
139 139
     params: query
140 140
   })
141 141
 }
142
+
143
+//查询设备台账列表全量
144
+export function getDeviceList(query) {
145
+  return request({
146
+    url: '/equipment/ledger/notice',
147
+    method: 'get',
148
+    params: query
149
+  })
150
+}

+ 57 - 21
src/pages/home-new/components/selfCheck.vue

@@ -7,7 +7,7 @@
7 7
 
8 8
         <view class="self-check-content">
9 9
             <!-- 已过期定检提醒 -->
10
-            <view class="check-section">
10
+            <view class="check-section" v-if="expiredItems.length > 0">
11 11
                 <view class="section-header">
12 12
                     <text class="section-title">已过期定检提醒</text>
13 13
                     <text class="view-more" @click="goToSelfCheckPage('expired')">查看更多</text>
@@ -29,7 +29,7 @@
29 29
             </view>
30 30
 
31 31
             <!-- 两周内到期提醒 -->
32
-            <view class="check-section">
32
+            <view class="check-section" v-if="twoWeeksItems.length > 0">
33 33
                 <view class="section-header">
34 34
                     <text class="section-title">两周内到期提醒</text>
35 35
                     <text class="view-more" @click="goToSelfCheckPage('twoWeeks')">查看更多</text>
@@ -51,7 +51,7 @@
51 51
             </view>
52 52
 
53 53
             <!-- 一月内检到期提醒 -->
54
-            <view class="check-section">
54
+            <view class="check-section" v-if="oneMonthItems.length > 0">
55 55
                 <view class="section-header">
56 56
                     <text class="section-title">一月内检到期提醒</text>
57 57
                     <text class="view-more" @click="goToSelfCheckPage('oneMonth')">查看更多</text>
@@ -76,32 +76,68 @@
76 76
 </template>
77 77
 
78 78
 <script>
79
+import { getDeviceList } from "@/api/home-new/home-new";
80
+
79 81
 export default {
80 82
     name: 'SelfCheck',
81 83
     data() {
82 84
         return {
83 85
             // 已过期定检数据
84
-            expiredItems: [
85
-                { name: '设备名称', serialNumber: '设备序列号', location: '设备位置', role: '组长、组员、组员', date: '2026-06-10' },
86
-                { name: '设备名称', serialNumber: '设备序列号', location: '设备位置', role: '组长、组员、组员', date: '2026-06-10' }
87
-            ],
86
+            expiredItems: [],
88 87
             // 两周内到期数据
89
-            twoWeeksItems: [
90
-                { name: '设备名称', serialNumber: '设备序列号', location: '设备位置', role: '组长、组员、组员', date: '2026-06-10' },
91
-                { name: '设备型号', serialNumber: '设备序列号', location: '设备位置', role: '组长、组员、组员', date: '2026-06-10' }
92
-            ],
88
+            twoWeeksItems: [],
93 89
             // 一月内到期数据
94
-            oneMonthItems: [
95
-                { name: '设备型号', serialNumber: '设备序列号', location: '设备位置', role: '组长、组员、组员', date: '2026-06-10' },
96
-                { name: '设备型号', serialNumber: '设备序列号', location: '设备位置', role: '组长、组员、组员', date: '2026-06-10' }
97
-            ]
90
+            oneMonthItems: []
98 91
         }
99 92
     },
93
+    mounted() {
94
+        this.fetchDeviceList();
95
+    },
100 96
     methods: {
101 97
         goToSelfCheckPage(tab) {
102 98
             uni.navigateTo({
103 99
                 url: `/pages/selfCheck/index?tab=${tab}`
104 100
             });
101
+        },
102
+        fetchDeviceList() {
103
+            // 分别请求三种颜色的数据
104
+            Promise.all([
105
+                getDeviceList({ colorType: 'RED' }),      // 已过期 - 红色
106
+                getDeviceList({ colorType: 'ORANGE' }),   // 两周内到期 - 橙色
107
+                getDeviceList({ colorType: 'YELLOW' })     // 一月内到期 - 黄色
108
+            ]).then(results => {
109
+                // 处理红色数据(已过期)
110
+                if (results[0].code === 200) {
111
+                    this.expiredItems = (results[0].data || []).slice(0, 2).map(item => this.formatDeviceItem(item));
112
+                }
113
+                // 处理橙色数据(两周内到期)
114
+                if (results[1].code === 200) {
115
+                    this.twoWeeksItems = (results[1].data || []).slice(0, 2).map(item => this.formatDeviceItem(item));
116
+                }
117
+                // 处理黄色数据(一月内到期)
118
+                if (results[2].code === 200) {
119
+                    this.oneMonthItems = (results[2].data || []).slice(0, 2).map(item => this.formatDeviceItem(item));
120
+                }
121
+            }).catch(err => {
122
+                console.error('获取设备列表失败', err);
123
+            });
124
+        },
125
+        formatDeviceItem(item) {
126
+            return {
127
+                name: item.equipmentName || '空',
128
+                serialNumber: item.equipmentCode || '空',
129
+                location: item.installationLocation || '空',
130
+                role:`${item.inspectionTeamLeaderName || ''}、${item.inspectionTeamMember1Name || ''}、${item.inspectionTeamMember2Name || ''}`|| '空',
131
+                date: this.formatDate(item.nextInspectionDueDate)|| '空'
132
+            };
133
+        },
134
+        formatDate(dateStr) {
135
+            if (!dateStr) return '';
136
+            const date = new Date(dateStr);
137
+            const year = date.getFullYear();
138
+            const month = String(date.getMonth() + 1).padStart(2, '0');
139
+            const day = String(date.getDate()).padStart(2, '0');
140
+            return `${year}-${month}-${day}`;
105 141
         }
106 142
     }
107 143
 }
@@ -183,18 +219,18 @@ export default {
183 219
 }
184 220
 
185 221
 .item-indicator.expired {
186
-    background-color: #8c3c34;
187
-    height: 60px;
222
+    background-color: #FF0000;
223
+    height: 48px;
188 224
 }
189 225
 
190 226
 .item-indicator.urgent {
191
-    background-color: #ff291f;
192
-    height: 60px;
227
+    background-color: #FFA500;
228
+    height: 48px;
193 229
 }
194 230
 
195 231
 .item-indicator.normal {
196
-    background-color: #b97c45;
197
-    height: 60px;
232
+    background-color: #FFD700;
233
+    height: 48px;
198 234
 }
199 235
 
200 236
 .item-content {

+ 1 - 1
src/pages/home-new/index.vue

@@ -36,7 +36,7 @@
36 36
             <MessagePush ref="messagePush" />
37 37
 
38 38
             <!-- 当 currentDepartment === '设备维修中心' 时显示 SelfCheck 组件 -->
39
-            <SelfCheck v-if="currentDepartment === '设备维修中心'" />
39
+            <SelfCheck v-if="this.userInfo.includes('设备维修中心')" />
40 40
 
41 41
             <!-- 当 currentDepartment !== '设备维修中心' 时显示原内容 -->
42 42
             <template v-else>

+ 110 - 49
src/pages/selfCheck/index.vue

@@ -1,5 +1,5 @@
1 1
 <template>
2
-    <home-container>
2
+    <home-container :customStyle="{ background: 'none',padding: '0' }" >
3 3
         <view class="self-check-page">
4 4
             <!-- 标签页区域 -->
5 5
             <view class="tabs-section">
@@ -19,13 +19,13 @@
19 19
                             <text class="card-label">{{ item.serialNumber }}</text>
20 20
                             <text class="card-date">{{ item.date }}</text>
21 21
                         </view>
22
-                        <view class="card-row">
22
+                        <view class="card-row" style="justify-content: flex-start;">
23 23
                             <text class="card-label">{{ item.location }}</text>
24
-                            <text class="card-role">{{ item.role }}</text>
24
+                            <text class="card-role" style="margin-left: 10px;">{{ item.role }}</text>
25 25
                         </view>
26 26
                     </view>
27
-                    <view :class="['status-tag', getStatusClass(item.status)]">
28
-                        {{ item.statusText }}
27
+                    <view :class="['status-tag', getStatusClass(item.colorType)]">
28
+                        {{ getStatusText(item.colorType) }}
29 29
                     </view>
30 30
                 </view>
31 31
             </view>
@@ -35,6 +35,7 @@
35 35
 
36 36
 <script>
37 37
 import HomeContainer from "@/components/HomeContainer.vue";
38
+import { getDeviceList } from "@/api/home-new/home-new";
38 39
 
39 40
 export default {
40 41
     name: 'SelfCheckPage',
@@ -43,42 +44,17 @@ export default {
43 44
     },
44 45
     data() {
45 46
         return {
46
-            currentTab: 'oneMonth',
47
+            currentTab: 'all',
47 48
             tabs: [
48 49
                 { label: '全部', value: 'all' },
49 50
                 { label: '两周临期', value: 'twoWeeks' },
50 51
                 { label: '一月临期', value: 'oneMonth' },
51 52
                 { label: '已过期', value: 'expired' }
52 53
             ],
53
-            allItems: [
54
-                { 
55
-                    name: '设备名称', 
56
-                    serialNumber: '设备序列号', 
57
-                    location: '设备位置', 
58
-                    role: '组长、组员、组员', 
59
-                    date: '2026-06-10', 
60
-                    status: 'expired',
61
-                    statusText: '已过期'
62
-                },
63
-                { 
64
-                    name: '设备型号', 
65
-                    serialNumber: '设备序列号', 
66
-                    location: '设备位置', 
67
-                    role: '组长、组员、组员', 
68
-                    date: '2026-06-10', 
69
-                    status: 'twoWeeks',
70
-                    statusText: '两周临期'
71
-                },
72
-                { 
73
-                    name: '设备型号', 
74
-                    serialNumber: '设备序列号', 
75
-                    location: '设备位置', 
76
-                    role: '组长、组员、组员', 
77
-                    date: '2026-06-10', 
78
-                    status: 'oneMonth',
79
-                    statusText: '一月临期'
80
-                }
81
-            ]
54
+            allItems: [],
55
+            redItems: [],
56
+            orangeItems: [],
57
+            yellowItems: []
82 58
         }
83 59
     },
84 60
     onLoad(options) {
@@ -86,30 +62,110 @@ export default {
86 62
         if (options && options.tab) {
87 63
             this.currentTab = options.tab;
88 64
         }
65
+        this.fetchDeviceList();
89 66
     },
90 67
     computed: {
91 68
         filteredItems() {
92
-            if (this.currentTab === 'all') {
93
-                return this.allItems;
69
+            switch(this.currentTab) {
70
+                case 'all':
71
+                    return this.allItems;
72
+                case 'expired':
73
+                    return this.redItems;
74
+                case 'twoWeeks':
75
+                    return this.orangeItems;
76
+                case 'oneMonth':
77
+                    return this.yellowItems;
78
+                default:
79
+                    return [];
94 80
             }
95
-            return this.allItems.filter(item => item.status === this.currentTab);
96 81
         }
97 82
     },
98 83
     methods: {
99 84
         switchTab(tabValue) {
100 85
             this.currentTab = tabValue;
86
+            this.fetchDeviceList();
101 87
         },
102
-        getStatusClass(status) {
103
-            switch(status) {
104
-                case 'expired':
88
+        getStatusClass(colorType) {
89
+            switch(colorType) {
90
+                case 'RED':
105 91
                     return 'expired';
106
-                case 'twoWeeks':
92
+                case 'ORANGE':
107 93
                     return 'urgent';
108
-                case 'oneMonth':
94
+                case 'YELLOW':
109 95
                     return 'normal';
110 96
                 default:
111 97
                     return '';
112 98
             }
99
+        },
100
+        getStatusText(colorType) {
101
+            switch(colorType) {
102
+                case 'RED':
103
+                    return '已过期';
104
+                case 'ORANGE':
105
+                    return '两周临期';
106
+                case 'YELLOW':
107
+                    return '一月临期';
108
+                default:
109
+                    return '';
110
+            }
111
+        },
112
+        fetchDeviceList() {
113
+            // 根据当前 tab 请求不同的接口
114
+            let colorType = '';
115
+            switch(this.currentTab) {
116
+                case 'all':
117
+                    colorType = 'MIXED';
118
+                    break;
119
+                case 'expired':
120
+                    colorType = 'RED';
121
+                    break;
122
+                case 'twoWeeks':
123
+                    colorType = 'ORANGE';
124
+                    break;
125
+                case 'oneMonth':
126
+                    colorType = 'YELLOW';
127
+                    break;
128
+            }
129
+            
130
+            getDeviceList({ colorType }).then(res => {
131
+                if (res.code === 200) {
132
+                    const data = res.data || [];
133
+                    switch(this.currentTab) {
134
+                        case 'all':
135
+                            this.allItems = data.map(item => this.formatDeviceItem(item));
136
+                            break;
137
+                        case 'expired':
138
+                            this.redItems = data.map(item => this.formatDeviceItem(item));
139
+                            break;
140
+                        case 'twoWeeks':
141
+                            this.orangeItems = data.map(item => this.formatDeviceItem(item));
142
+                            break;
143
+                        case 'oneMonth':
144
+                            this.yellowItems = data.map(item => this.formatDeviceItem(item));
145
+                            break;
146
+                    }
147
+                }
148
+            }).catch(err => {
149
+                console.error('获取设备列表失败', err);
150
+            });
151
+        },
152
+        formatDeviceItem(item) {
153
+            return {
154
+                name: item.equipmentName || '空',
155
+                serialNumber: item.equipmentCode || '空',
156
+                location: item.installationLocation || '空',
157
+                role: `${item.inspectionTeamLeaderName || ''}、${item.inspectionTeamMember1Name || ''}、${item.inspectionTeamMember2Name || ''}` || '空',
158
+                date: this.formatDate(item.nextInspectionDueDate) || '空',
159
+                colorType: item.colorType || 'YELLOW'
160
+            };
161
+        },
162
+        formatDate(dateStr) {
163
+            if (!dateStr) return '';
164
+            const date = new Date(dateStr);
165
+            const year = date.getFullYear();
166
+            const month = String(date.getMonth() + 1).padStart(2, '0');
167
+            const day = String(date.getDate()).padStart(2, '0');
168
+            return `${year}-${month}-${day}`;
113 169
         }
114 170
     }
115 171
 }
@@ -211,17 +267,22 @@ export default {
211 267
 }
212 268
 
213 269
 .status-tag.expired {
214
-    background-color: #e8c8c7;
215
-    color: #8c3c34;
270
+    background-color: #FF0000;
271
+    color: #fff;
216 272
 }
217 273
 
218 274
 .status-tag.urgent {
219
-    background-color: #ffd1d0;
220
-    color: #ff291f;
275
+    background-color: #FFA500;
276
+    color: #fff;
221 277
 }
222 278
 
223 279
 .status-tag.normal {
224
-    background-color: #e8d4bc;
225
-    color: #b97c45;
280
+    background-color: #FFD700;
281
+    color: #333;
226 282
 }
227 283
 </style>
284
+
285
+
286
+
287
+
288
+