From fd047fa7234dc11643dab8ecbf38e8d7a8ba0854 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 22 十一月 2025 23:48:12 +0800
Subject: [PATCH] feat:修改任务
---
app/components/AttachmentUpload.vue | 99 +++++--------------------------------------------
1 files changed, 10 insertions(+), 89 deletions(-)
diff --git a/app/components/AttachmentUpload.vue b/app/components/AttachmentUpload.vue
index ab0bcf5..2f319d3 100644
--- a/app/components/AttachmentUpload.vue
+++ b/app/components/AttachmentUpload.vue
@@ -67,8 +67,10 @@
</template>
<script>
- import { getAttachmentList, uploadAttachmentFromWechat, deleteAttachment, getWechatAccessToken } from '@/api/task'
+ import { getAttachmentList, deleteAttachment } from '@/api/task'
import { formatDateTime } from '@/utils/common'
+ import { getToken } from '@/utils/auth'
+ import config from '@/config'
export default {
name: 'AttachmentUpload',
@@ -106,16 +108,10 @@
{ label: '绯诲畨鍏ㄥ甫', value: '6' }
],
selectedCategoryIndex: 0,
- tempImagePath: null,
- isWechatMiniProgram: false
+ tempImagePath: null
}
},
mounted() {
- // 妫�娴嬫槸鍚︽槸寰俊灏忕▼搴忕幆澧�
- // #ifdef MP-WEIXIN
- this.isWechatMiniProgram = true
- // #endif
-
// 鑷姩鍔犺浇闄勪欢鍒楄〃
if (this.autoLoad && this.taskId) {
this.loadAttachmentList()
@@ -189,95 +185,20 @@
const that = this
const category = this.categoryList[this.selectedCategoryIndex].value
- // 寰俊灏忕▼搴忕幆澧冿細鍏堣幏鍙朅ccessToken锛屽啀涓婁紶鍒板井淇℃湇鍔″櫒锛屾渶鍚庢彁浜ediaId鍒板悗绔�
- // #ifdef MP-WEIXIN
- if (this.isWechatMiniProgram) {
- uni.showLoading({
- title: '涓婁紶涓�...'
- })
-
- // 绗竴姝ワ細浠庡悗绔幏鍙朅ccessToken
- getWechatAccessToken().then(tokenResponse => {
- // 鎺ュ彛杩斿洖鏍煎紡锛歿"msg":"token鍊�","code":200}
- console.log('鑾峰彇AccessToken鎴愬姛:', tokenResponse)
- const accessToken = tokenResponse.msg || tokenResponse.data || tokenResponse
- if (!accessToken) {
- uni.hideLoading()
- that.$modal.showToast('鑾峰彇AccessToken澶辫触')
- console.error('鑾峰彇AccessToken澶辫触锛屽搷搴旀暟鎹�:', tokenResponse)
- return
- }
-
- console.log('鑾峰彇鍒癆ccessToken:', accessToken)
-
- // 绗簩姝ワ細涓婁紶鍒板井淇℃湇鍔″櫒
- const uploadUrl = `https://api.weixin.qq.com/cgi-bin/media/upload?access_token=${accessToken}&type=image`
-
- uni.uploadFile({
- url: uploadUrl,
- filePath: that.tempImagePath,
- name: 'media',
- success: function(res) {
- console.log('寰俊涓婁紶鍝嶅簲:', res)
- try {
- const data = JSON.parse(res.data)
- if (data.media_id) {
- // 绗笁姝ワ細鎻愪氦mediaId鍒板悗绔�
- uploadAttachmentFromWechat(that.taskId, data.media_id, category).then(response => {
- uni.hideLoading()
- that.$modal.showToast('涓婁紶鎴愬姛')
- that.closeUploadDialog()
- that.loadAttachmentList()
- that.$emit('uploaded', response)
- }).catch(error => {
- uni.hideLoading()
- console.error('鎻愪氦mediaId澶辫触:', error)
- that.$modal.showToast('涓婁紶澶辫触锛�' + (error.msg || '璇烽噸璇�'))
- that.$emit('error', error)
- })
- } else {
- uni.hideLoading()
- const errMsg = data.errmsg || '鏈煡閿欒'
- console.error('寰俊杩斿洖閿欒:', data)
- that.$modal.showToast('寰俊涓婁紶澶辫触锛�' + errMsg)
- }
- } catch (e) {
- uni.hideLoading()
- console.error('瑙f瀽寰俊鍝嶅簲澶辫触:', e, res.data)
- that.$modal.showToast('涓婁紶澶辫触锛氬搷搴旇В鏋愰敊璇�')
- }
- },
- fail: function(err) {
- uni.hideLoading()
- console.error('涓婁紶鍒板井淇″け璐�:', err)
- that.$modal.showToast('涓婁紶澶辫触锛�' + (err.errMsg || '璇锋鏌ョ綉缁�'))
- that.$emit('error', err)
- }
- })
- }).catch(error => {
- uni.hideLoading()
- console.error('鑾峰彇AccessToken澶辫触:', error)
- that.$modal.showToast('鑾峰彇AccessToken澶辫触')
- that.$emit('error', error)
- })
- return
- }
- // #endif
-
- // 闈炲井淇″皬绋嬪簭鐜锛氱洿鎺ヤ笂浼犲埌鍚庣鏈嶅姟鍣�
+ // 缁熶竴鐩存帴涓婁紶鍒板悗绔湇鍔″櫒
uni.showLoading({
title: '涓婁紶涓�...'
})
uni.uploadFile({
- url: that.$baseUrl + '/task/attachment/upload/' + that.taskId,
+ url: config.baseUrl + '/task/attachment/upload/' + that.taskId,
filePath: that.tempImagePath,
name: 'file',
formData: {
'category': category
},
header: {
- 'Authorization': 'Bearer ' + uni.getStorageSync('token')
+ 'Authorization': 'Bearer ' + getToken()
},
success: function(uploadRes) {
uni.hideLoading()
@@ -301,7 +222,7 @@
fail: function(err) {
uni.hideLoading()
console.error('涓婁紶澶辫触:', err)
- that.$modal.showToast('涓婁紶澶辫触')
+ that.$modal.showToast('涓婁紶澶辫触锛�' + (err.errMsg || '璇锋鏌ョ綉缁�'))
that.$emit('error', err)
}
})
@@ -318,7 +239,7 @@
let imageUrl = item.fileUrl
// 濡傛灉娌℃湁fileUrl锛屽垯浣跨敤涓嬭浇鎺ュ彛
if (!imageUrl) {
- imageUrl = this.$baseUrl + '/task/attachment/download/' + item.attachmentId
+ imageUrl = config.baseUrl + '/task/attachment/download/' + item.attachmentId
}
// 寰俊灏忕▼搴忎腑棰勮鍥剧墖
@@ -405,7 +326,7 @@
}
// 浣跨敤涓嬭浇鎺ュ彛
if (item.attachmentId) {
- return this.$baseUrl + '/task/attachment/download/' + item.attachmentId
+ return config.baseUrl + '/task/attachment/download/' + item.attachmentId
}
// 榛樿鍗犱綅鍥�
return '/static/images/default-image.png'
--
Gitblit v1.9.1