diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index ca9045a..2269a10 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -21,7 +21,7 @@ const isError = ref(false) const taskDescribe = ref('') const origin = window.location.href -const taskId = ref('') +const taskId = ref('26') if (origin.indexOf('=') > -1) { taskId.value = origin.split('=')[1] @@ -42,7 +42,7 @@ const getTaskDetailsData = async () => { } } -getTaskDetailsData() +// getTaskDetailsData() // 填写意见按钮 const onSubmitOptions = () => { diff --git a/src/pages/opinion/index.vue b/src/pages/opinion/index.vue index 19c4838..668ae23 100644 --- a/src/pages/opinion/index.vue +++ b/src/pages/opinion/index.vue @@ -181,39 +181,79 @@ const onSubmitOptions = () => { .then(async (valid) => { if (valid) { let files = [] - fileList.value.forEach((f) => { - let d = { - file: f.url, - name: 'file', - uri: f.url, - } - files.push(d) - }) - uni.uploadFile({ - url: '/manager/option/appUploadFile', - files: files, - name: 'file', - formData: { - param: JSON.stringify(opinionModel.value), - }, - success: (res) => { - res = JSON.parse(res.data) - if (res.data === '添加成功') { - uni.$u.toast('提交成功') - opinionModel.value = { - userName: '', - userPhone: '', - unit: '', - userOpinion: '', - } - fileList.value = [] - isSuccess.value = true - } else { - uni.$u.toast('添加失败' + res.data) + if (fileList.value.length > 0) { + fileList.value.forEach((f) => { + let d = { + file: f.url, + name: 'file', + uri: f.url, } - }, - fail: (err) => {}, - }) + files.push(d) + }) + + uni.uploadFile({ + url: '/manager/option/appUploadFile', + files: files, + name: 'file', + formData: { + param: JSON.stringify(opinionModel.value), + }, + success: (res) => { + res = JSON.parse(res.data) + if (res.data === '添加成功') { + uni.$u.toast('提交成功') + opinionModel.value = { + userName: '', + userPhone: '', + unit: '', + userOpinion: '', + } + fileList.value = [] + isSuccess.value = true + } else { + uni.$u.toast('添加失败' + res.data) + } + }, + fail: (err) => {}, + }) + } else { + const boundary = '----WebKitFormBoundary' + Math.random().toString(16).substr(2) + const data = + `--${boundary}\r\n` + + `Content-Disposition: form-data; name="param"\r\n\r\n` + + `${JSON.stringify(opinionModel.value)}\r\n` + + `--${boundary}--` + + uni.request({ + url: '/manager/option/appUploadFile', + method: 'POST', + header: { + 'Content-Type': `multipart/form-data; boundary=${boundary}`, + }, + data: data, + success: (res) => { + res = JSON.parse(res.data) + if (res.data === '添加成功') { + uni.$u.toast('提交成功') + opinionModel.value = { + userName: '', + userPhone: '', + unit: '', + userOpinion: '', + } + fileList.value = [] + isSuccess.value = true + } else { + uni.$u.toast('添加失败' + res.data) + } + }, + fail: (err) => { + // 处理错误 + }, + }) + + console.log(result, 'result') + } } }) .catch(() => {