处理微信小程序 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
+9 -3
View File
@@ -263,17 +263,23 @@ export const reqSaveWeldAppearanceCheck = (data = {}) => post('/WeldAppearanceCh
* 按班组查询任务单列表
* @param {Object} params - { projectId, teamGroupId?, unitWorkId? }
*/
export const reqWeldTaskListByTeamGroup = (params = {}) => get('WeldTask/GetTaskListByTeamGroup', params)
export const reqWeldTaskListByTeamGroup = (params) => request('WeldTask/GetTaskListByTeamGroup', {
method: 'GET',
data: params || {},
})
/**
* 查询任务单详情(含 Joints)
* @param {Object} params - { projectId, taskCode, unitWorkId? }
*/
export const reqWeldTaskDetail = (params = {}) => get('WeldTask/GetTaskDetail', params)
export const reqWeldTaskDetail = (params) => request('WeldTask/GetTaskDetail', {
method: 'GET',
data: params || {},
})
/**
* 根据任务单生成出库申请
* @param {Object} data - { ProjectId, TaskCode, PersonId }
*/
export const reqWeldTaskGenerateOutPlan = (data = {}) => post('WeldTask/GenerateOutPlan', data)
export const reqWeldTaskGenerateOutPlan = (data) => post('WeldTask/GenerateOutPlan', data || {})
+32 -30
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({
const params = {
projectId: projectId.value,
taskCode: taskCode.value,
unitWorkId: unitWorkId.value || undefined,
})
detail.value = res?.data || {}
if (!res?.data) {
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({
reqWeldTaskGenerateOutPlan({
ProjectId: projectId.value,
TaskCode: taskCode.value,
PersonId: personId,
})
// 接口成功也可能 data 为 null(首次/已存在/无材料均可能 code:1)
}).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>
+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>
+20 -19
View File
@@ -28,14 +28,13 @@ function toQueryString(params) {
* {boolean} loading - 是否显示 loading,默认 true
* {boolean} toast - 是否在失败时弹 toast,默认 true
*/
export function request(url, options = {}) {
const {
method = 'GET',
data,
header = {},
loading = true,
toast = true
} = options
export function request(url, options) {
const opts = options || {}
const method = opts.method || 'GET'
const data = opts.data
const header = opts.header || {}
const loading = opts.loading !== false
const toast = opts.toast !== false
const userStore = useUserStore()
const headers = {
@@ -47,22 +46,22 @@ export function request(url, options = {}) {
}
// GET: 手动拼 query string(不依赖 uni.request 各平台差异)
let fullUrl = `${baseUrl}${url}`
let fullUrl = baseUrl + url
if (method === 'GET' && data) {
fullUrl += toQueryString(data)
fullUrl = fullUrl + toQueryString(data)
}
if (loading) {
uni.showLoading({ title: '加载中...', mask: true })
}
return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
uni.request({
url: fullUrl,
method,
method: method,
data: method === 'POST' ? data : undefined,
header: headers,
success: (res) => {
success: function (res) {
if (loading) uni.hideLoading()
const body = res.data
if (body.code !== 1) {
@@ -81,7 +80,7 @@ export function request(url, options = {}) {
}
resolve(body)
},
fail: (err) => {
fail: function (err) {
if (loading) uni.hideLoading()
uni.showToast({ title: '网络连接失败', icon: 'none' })
reject(err)
@@ -95,18 +94,20 @@ export function request(url, options = {}) {
* 兼容两种调用方式:
* get('/path?key=val') 旧风格(URL 自带参数)
* get('/path', { key: 'val' }) 新风格(参数对象,自动编码)
* 不可对形参 url 做 += 重赋值,正式版 Babel 会把形参编译为只读,触发 "a" is read-only
*/
export const get = (url, params) => {
const fullUrl = params ? `${url}${toQueryString(params)}` : url
export function get(url, params) {
let fullUrl = url
if (params) {
fullUrl = url + toQueryString(params)
}
return request(fullUrl, { method: 'GET' })
}
/**
* POST 快捷方法
*/
export const post = (url, data) => {
return request(url, { method: 'POST', data })
export function post(url, data) {
return request(url, { method: 'POST', data: data })
}
/**