app1首页展示个人待处理工单功能 #68

Merged
hnu202326010125 merged 2 commits from luoyuehang_branch into develop 1 month ago

@ -19,7 +19,7 @@ export const authServices = {
const requestData = {
username: registerData.username,
password: registerData.password,
userType: 'repairer', // 固定为repairer类型
userType: 'repairman', // 固定为repairma 类型
repairmanId: registerData.repairmanId
}

@ -0,0 +1,14 @@
// src/services/workOrderService.js
import api from './api'
export const workOrderService = {
// 获取我的工单
async getMyOrders(repairmanId) {
try {
const response = await api.get(`/api/app/repairman/my-orders?repairmanId=${repairmanId}`)
return response.data
} catch (error) {
throw error.response?.data || error.message
}
}
}

@ -35,10 +35,11 @@ export const useAuthStore = defineStore('auth', () => {
return user.value?.userType || localStorage.getItem('userType')
})
// 获取维修人员ID
const getRepairmanId = computed(() => {
return user.value?.repairmanId || localStorage.getItem('repairmanId')
})
// 获取维修人员ID
const getRepairmanId = computed(() => {
return user.value?.userId || localStorage.getItem('userId') // 使用userId而不是repairmanId
})
// 登出
const logout = () => {

@ -16,7 +16,7 @@
<!-- 统计卡片 -->
<div class="stats-cards">
<div class="stat-card">
<div class="stat-number">5</div>
<div class="stat-number">{{ processingOrders.length }}</div>
<div class="stat-label">待处理工单</div>
</div>
<div class="stat-card">
@ -41,20 +41,30 @@
<h3>待处理工单</h3>
</div>
<div class="work-order-list">
<div class="work-order-item urgent">
<div class="order-badge urgent">紧急</div>
<div class="order-content">
<div class="order-title">制水机#A201 - TDS超标</div>
<div class="order-location">教学楼A区 - 10分钟前</div>
<div
v-for="order in processingOrders"
:key="order.orderId"
:class="['work-order-item', getOrderPriorityClass(order.priority)]"
>
<div :class="['order-badge', getOrderPriorityClass(order.priority)]">
{{ getOrderPriorityText(order.priority) }}
</div>
</div>
<div class="work-order-item normal">
<div class="order-badge normal">一般</div>
<div class="order-content">
<div class="order-title">供水机#B105 - 水位异常</div>
<div class="order-location">图书馆 - 25分钟前</div>
<div class="order-title">{{ order.description || `工单#${order.orderId}` }}</div>
<!-- 修改这一行去掉设备位置信息只保留时间 -->
<div class="order-location">{{ getTimeAgo(order.createdTime) }}</div>
</div>
</div>
<!-- 当没有工单时显示 -->
<div v-if="processingOrders.length === 0 && !loading" class="no-orders">
暂无待处理工单
</div>
<!-- 加载状态 -->
<div v-if="loading" class="loading-orders">
加载中...
</div>
</div>
</div>
</div>
@ -77,14 +87,93 @@
</div>
</template>
<script setup>
<script setup>import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { workOrderService } from '@/services/workOrderService'
const authStore = useAuthStore()
const userInfo = authStore.getUserInfo()
const router = useRouter()
//
const processingOrders = ref([])
const loading = ref(false)
// processing
const fetchProcessingOrders = async () => {
loading.value = true
try {
// ID
const userInfo = authStore.getUserInfo()
const repairmanId = userInfo?.userId // 使userIdusername
if (repairmanId) {
const response = await workOrderService.getMyOrders(repairmanId)
if (response && response.code === 200) {
processingOrders.value = response.data.filter(order => order.status === 'processing')
}
} else {
console.warn('未找到维修人员ID')
}
} catch (error) {
console.error('获取工单失败:', error)
processingOrders.value = []
} finally {
loading.value = false
}
}
// CSS
const getOrderPriorityClass = (priority) => {
switch (priority) {
case 'urgent':
return 'urgent'
case 'high':
return 'urgent'
case 'medium':
return 'normal'
case 'low':
return 'normal'
default:
return 'normal'
}
}
//
const getOrderPriorityText = (priority) => {
switch (priority) {
case 'urgent':
return '紧急'
case 'high':
return '高'
case 'medium':
return '中'
case 'low':
return '低'
default:
return '一般'
}
}
//
const getDeviceLocation = (deviceId) => {
const locations = {
'A201': '教学楼A区',
'B105': '图书馆',
//
}
return locations[deviceId] || '未知位置'
}
//
const getTimeAgo = (createdTime) => {
if (!createdTime) return '未知时间'
//
return '刚刚'
}
const goToInspection = () => {
console.log('跳转到巡检页面')
router.push('/inspection')
@ -105,6 +194,11 @@ const goToProfile = () => {
console.log('跳转到我的页面')
router.push('/profile')
}
//
onMounted(() => {
fetchProcessingOrders()
})
</script>
<style scoped>
@ -329,4 +423,16 @@ const goToProfile = () => {
color: #666;
font-size: 11px;
}
.no-orders {
text-align: center;
padding: 20px;
color: #999;
}
.loading-orders {
text-align: center;
padding: 20px;
color: #666;
}
</style>

@ -6,7 +6,7 @@ import { useAuthStore } from '@/stores/auth'
const authStore = useAuthStore()
const router = useRouter()
const usertype = ref('repairer')
const usertype = ref('repairman')
const username = ref('')
const password = ref('')
const loading = ref(false)
@ -42,7 +42,7 @@ const handleLogin = async () => {
username: result.data.username,
userType: result.data.userType,
userId: result.data.userId,
repairmanId: username.value
repairmanId: result.data.userId
}, result.data.token);
//
@ -50,7 +50,7 @@ const handleLogin = async () => {
localStorage.setItem('userId', result.data.userId);
localStorage.setItem('username', result.data.username);
localStorage.setItem('userType', result.data.userType);
localStorage.setItem('repairmanId', username.value);
localStorage.setItem('repairmanId', result.data.userId);
alert('登录成功!');
router.push('/home');

Loading…
Cancel
Save