处理微信小程序 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
+37 -35
View File
@@ -33,7 +33,7 @@
</view>
<view class="card__row">
<text class="card__label">焊口数量</text>
<text class="card__value">{{ detail.WeldJointCount ?? joints.length }}</text>
<text class="card__value">{{ detail.WeldJointCount != null ? detail.WeldJointCount : joints.length }}</text>
</view>
</view>
</view>
@@ -106,15 +106,14 @@
<script setup>
/**
* 焊接任务单详情:展示 Joints,支持生成出库申请单
* 使用 Promise 链而非 async/await,规避微信小程序 Babel regenerator 的 "a" is read-only
*/
import { computed, ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { storeToRefs } from 'pinia'
import { useUserStore } from '@/store'
import { reqWeldTaskDetail, reqWeldTaskGenerateOutPlan } from '@/api/hj.js'
const userStore = useUserStore()
const { userInfo, token } = storeToRefs(userStore)
const projectId = ref('')
const taskCode = ref('')
@@ -123,12 +122,15 @@ const detail = ref({})
const loading = ref(false)
const submitting = ref(false)
const joints = computed(() => {
const list = detail.value?.Joints
const joints = computed(function () {
const d = detail.value
const list = d ? d.Joints : null
return Array.isArray(list) ? list : []
})
const canGenerate = computed(() => !!(projectId.value && taskCode.value))
const canGenerate = computed(function () {
return !!(projectId.value && taskCode.value)
})
const fmtDate = (val) => {
if (!val) return '--'
@@ -137,7 +139,7 @@ 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 formatSize = (val) => {
@@ -145,28 +147,29 @@ const formatSize = (val) => {
return String(val)
}
const loadDetail = async () => {
const loadDetail = () => {
if (!projectId.value || !taskCode.value) {
uni.showToast({ title: '入口参数错误', icon: 'none' })
return
}
loading.value = true
try {
const res = await reqWeldTaskDetail({
projectId: projectId.value,
taskCode: taskCode.value,
unitWorkId: unitWorkId.value || undefined,
})
detail.value = res?.data || {}
if (!res?.data) {
const params = {
projectId: projectId.value,
taskCode: taskCode.value,
unitWorkId: unitWorkId.value || '',
}
reqWeldTaskDetail(params).then(function (res) {
const data = res ? res.data : null
detail.value = data || {}
if (!data) {
uni.showToast({ title: '未找到任务单', icon: 'none' })
}
} catch (e) {
}).catch(function (e) {
console.error('任务单详情加载失败:', e)
detail.value = {}
} finally {
}).then(function () {
loading.value = false
}
})
}
const handleGenerate = () => {
@@ -174,38 +177,37 @@ const handleGenerate = () => {
uni.showModal({
title: '确认生成',
content: '确定根据当前任务单生成出库申请单吗?已生成过的不会重复建单。',
success: async (modalRes) => {
success: function (modalRes) {
if (!modalRes.confirm) return
const personId = userInfo.value?.PersonId || token.value
const user = userStore.userInfo
const personId = (user && user.PersonId) || userStore.token
if (!personId) {
uni.showToast({ title: '缺少登录人信息', icon: 'none' })
return
}
submitting.value = true
try {
await reqWeldTaskGenerateOutPlan({
ProjectId: projectId.value,
TaskCode: taskCode.value,
PersonId: personId,
})
// 接口成功也可能 data 为 null(首次/已存在/无材料均可能 code:1)
reqWeldTaskGenerateOutPlan({
ProjectId: projectId.value,
TaskCode: taskCode.value,
PersonId: personId,
}).then(function () {
uni.showToast({
title: '生成请求已处理',
icon: 'none',
})
} catch (e) {
}).catch(function (e) {
console.error('生成出库申请失败:', e)
} finally {
}).then(function () {
submitting.value = false
}
})
},
})
}
onLoad((opt) => {
projectId.value = decodeURIComponent(opt.projectId || '')
taskCode.value = decodeURIComponent(opt.taskCode || '')
unitWorkId.value = decodeURIComponent(opt.unitWorkId || '')
onLoad(function (opt) {
projectId.value = decodeURIComponent((opt && opt.projectId) || '')
taskCode.value = decodeURIComponent((opt && opt.taskCode) || '')
unitWorkId.value = decodeURIComponent((opt && opt.unitWorkId) || '')
loadDetail()
})
</script>