处理微信小程序 Babel regenerator 的 "a" is read-only 问题

This commit is contained in:
huhao
2026-08-21 09:03:18 +08:00
parent b32cda3e85
commit 20c3255185
4 changed files with 102 additions and 89 deletions
+36 -32
View File
@@ -16,7 +16,7 @@
>
<view class="card-header">
<text class="card-code">{{ item.TaskCode || '--' }}</text>
<text class="card-tag status-1">焊口 {{ item.WeldJointCount ?? 0 }}</text>
<text class="card-tag status-1">焊口 {{ formatJointCount(item) }}</text>
</view>
<view class="card-body">
<view class="card-row">
@@ -55,38 +55,35 @@
<script setup>
/**
* 焊接任务单列表:自动带入登录人 teamGroupId / unitWorkId + 当前项目查询
* 使用 Promise 链而非 async/await,规避微信小程序 Babel regenerator 的 "a" is read-only
*/
import { ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/store'
import { reqWeldTaskListByTeamGroup } from '@/api/hj.js'
const userStore = useUserStore()
const { currentProject, userInfo } = storeToRefs(userStore)
const listData = ref([])
const loading = ref(false)
const refreshing = ref(false)
/**
* 登录人班组 ID
* @param {object|null} user
*/
const resolveTeamGroupId = (user) => {
if (!user) return ''
return user.teamGroupId || user.TeamGroupId || ''
}
/**
* 登录人单位工程 ID
* @param {object|null} user
*/
const resolveUnitWorkId = (user) => {
if (!user) return ''
return user.unitWorkId || user.UnitWorkId || ''
}
const formatJointCount = (item) => {
if (!item) return 0
if (item.WeldJointCount == null) return 0
return item.WeldJointCount
}
const fmtDate = (val) => {
if (!val) return '--'
const d = new Date(val)
@@ -94,34 +91,40 @@ const fmtDate = (val) => {
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${y}-${m}-${day}`
return y + '-' + m + '-' + day
}
const fetchList = async () => {
const projectId = currentProject.value?.ProjectId
const fetchList = () => {
const project = userStore.currentProject
const projectId = project ? project.ProjectId : ''
if (!projectId) {
uni.showToast({ title: '请先选择项目', icon: 'none' })
listData.value = []
refreshing.value = false
return
}
if (loading.value) return
loading.value = true
try {
const res = await reqWeldTaskListByTeamGroup({
projectId,
teamGroupId: resolveTeamGroupId(userInfo.value) || undefined,
unitWorkId: resolveUnitWorkId(userInfo.value) || undefined,
})
const data = res?.data
listData.value = Array.isArray(data) ? data : []
} catch (e) {
const user = userStore.userInfo
const teamGroupId = resolveTeamGroupId(user)
const unitWorkId = resolveUnitWorkId(user)
const query = {
projectId: projectId,
teamGroupId: teamGroupId || '',
unitWorkId: unitWorkId || '',
}
reqWeldTaskListByTeamGroup(query).then(function (res) {
const data = res ? res.data : null
listData.value = Array.isArray(data) ? data.slice() : []
}).catch(function (e) {
console.error('任务单列表加载失败:', e)
listData.value = []
} finally {
}).then(function () {
loading.value = false
refreshing.value = false
}
})
}
const handleRefresh = () => {
@@ -130,21 +133,22 @@ const handleRefresh = () => {
}
const handleItemClick = (item) => {
const projectId = item.ProjectId || currentProject.value?.ProjectId || ''
const taskCode = item.TaskCode || ''
const unitWorkId = item.UnitWorkId || item.unitWorkId || resolveUnitWorkId(userInfo.value) || ''
const project = userStore.currentProject
const projectId = (item && item.ProjectId) || (project && project.ProjectId) || ''
const taskCode = (item && item.TaskCode) || ''
const unitWorkId = (item && (item.UnitWorkId || item.unitWorkId)) || resolveUnitWorkId(userStore.userInfo) || ''
if (!projectId || !taskCode) {
uni.showToast({ title: '任务单信息不完整', icon: 'none' })
return
}
let url = `/scanpages/hj/weld_task_detail?projectId=${encodeURIComponent(projectId)}&taskCode=${encodeURIComponent(taskCode)}`
let url = '/scanpages/hj/weld_task_detail?projectId=' + encodeURIComponent(projectId) + '&taskCode=' + encodeURIComponent(taskCode)
if (unitWorkId) {
url += `&unitWorkId=${encodeURIComponent(unitWorkId)}`
url = url + '&unitWorkId=' + encodeURIComponent(unitWorkId)
}
uni.navigateTo({ url })
uni.navigateTo({ url: url })
}
onShow(() => {
onShow(function () {
fetchList()
})
</script>