任务中心迁移完成
This commit is contained in:
@@ -228,6 +228,7 @@
|
||||
<text class="upload-icon">+</text>
|
||||
<text class="upload-text">选择文件</text>
|
||||
</view>
|
||||
|
||||
<view class="file-list" v-if="fileList.length > 0">
|
||||
<view
|
||||
class="file-item"
|
||||
@@ -262,7 +263,7 @@
|
||||
import { addTask } from '@/api/oa/task'
|
||||
import { listProject } from '@/api/oa/project'
|
||||
import { selectUser, deptTreeSelect } from '@/api/oa/user'
|
||||
import { uploadImage } from '@/api/common/upload'
|
||||
import { uploadFiles } from '@/api/common/upload'
|
||||
|
||||
export default {
|
||||
name: 'CreateTask',
|
||||
@@ -335,9 +336,9 @@ export default {
|
||||
// 获取用户列表
|
||||
async getUserList() {
|
||||
try {
|
||||
// const res = await selectUser({ pageNum: 1, pageSize: 999, deptId: 100 })
|
||||
const resr = await deptTreeSelect()
|
||||
// this.userList = res.rows || []
|
||||
const res = await selectUser({ pageNum: 1, pageSize: 999, deptId: 100 })
|
||||
// const resr = await deptTreeSelect()
|
||||
this.userList = res.rows || []
|
||||
} catch (error) {
|
||||
console.error('获取用户列表失败:', error)
|
||||
uni.showToast({
|
||||
@@ -408,15 +409,85 @@ export default {
|
||||
this.closeUserPopup()
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 选择文件
|
||||
chooseFile() {
|
||||
// 安卓平台使用 plus.io.pickFiles
|
||||
// #ifdef APP-PLUS
|
||||
if (typeof plus !== 'undefined' && plus.io) {
|
||||
console.log('使用安卓平台文件选择API')
|
||||
this.doPickFiles()
|
||||
return
|
||||
}
|
||||
// #endif
|
||||
|
||||
// 微信小程序环境
|
||||
if (typeof wx !== 'undefined' && wx.chooseMessageFile) {
|
||||
wx.chooseMessageFile({
|
||||
count: 5,
|
||||
type: 'all',
|
||||
success: (res) => {
|
||||
const processedFiles = res.tempFiles.map(file => ({
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
path: file.path || file.tempFilePath,
|
||||
type: file.type
|
||||
}))
|
||||
|
||||
// 验证文件
|
||||
const validFiles = this.validateFiles(processedFiles)
|
||||
if (validFiles.length > 0) {
|
||||
this.fileList = [...this.fileList, ...validFiles]
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('选择文件失败:', err)
|
||||
uni.showToast({
|
||||
title: '选择文件失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// H5平台使用 uni.chooseFile
|
||||
// #ifdef H5
|
||||
uni.chooseFile({
|
||||
count: 5,
|
||||
type: 'all',
|
||||
success: (res) => {
|
||||
this.fileList = [...this.fileList, ...res.tempFiles]
|
||||
const processedFiles = res.tempFiles.map(file => ({
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
path: file.path || file.tempFilePath || file.url,
|
||||
type: file.type
|
||||
}))
|
||||
|
||||
// 验证文件
|
||||
const validFiles = this.validateFiles(processedFiles)
|
||||
if (validFiles.length > 0) {
|
||||
this.fileList = [...this.fileList, ...validFiles]
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('选择文件失败:', err)
|
||||
uni.showToast({
|
||||
title: '选择文件失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
|
||||
// 其他平台提示不支持
|
||||
// #ifndef APP-PLUS || H5 || MP-WEIXIN
|
||||
uni.showToast({
|
||||
title: '当前平台不支持文件选择',
|
||||
icon: 'none'
|
||||
})
|
||||
// #endif
|
||||
},
|
||||
|
||||
// 移除文件
|
||||
@@ -424,6 +495,139 @@ export default {
|
||||
this.fileList.splice(index, 1)
|
||||
},
|
||||
|
||||
// 根据文件名获取文件类型
|
||||
getFileType(fileName) {
|
||||
const ext = fileName.split('.').pop().toLowerCase()
|
||||
const typeMap = {
|
||||
'jpg': 'image/jpeg',
|
||||
'jpeg': 'image/jpeg',
|
||||
'png': 'image/png',
|
||||
'gif': 'image/gif',
|
||||
'bmp': 'image/bmp',
|
||||
'webp': 'image/webp',
|
||||
'pdf': 'application/pdf',
|
||||
'doc': 'application/msword',
|
||||
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'xls': 'application/vnd.ms-excel',
|
||||
'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
'ppt': 'application/vnd.ms-powerpoint',
|
||||
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
'txt': 'text/plain',
|
||||
'zip': 'application/zip',
|
||||
'rar': 'application/x-rar-compressed',
|
||||
'7z': 'application/x-7z-compressed'
|
||||
}
|
||||
return typeMap[ext] || 'application/octet-stream'
|
||||
},
|
||||
|
||||
// 执行文件选择
|
||||
doPickFiles() {
|
||||
try {
|
||||
plus.io.pickFiles({
|
||||
multiple: true,
|
||||
maximum: 5,
|
||||
filter: 'none',
|
||||
onSuccess: (files) => {
|
||||
console.log('安卓平台选择文件成功:', files)
|
||||
const processedFiles = files.map(file => ({
|
||||
name: file.name,
|
||||
size: file.size,
|
||||
path: file.path,
|
||||
type: file.type || this.getFileType(file.name)
|
||||
}))
|
||||
|
||||
// 验证文件
|
||||
const validFiles = this.validateFiles(processedFiles)
|
||||
if (validFiles.length > 0) {
|
||||
this.fileList = [...this.fileList, ...validFiles]
|
||||
console.log('处理后的文件列表:', this.fileList)
|
||||
}
|
||||
},
|
||||
onFail: (error) => {
|
||||
console.error('安卓平台选择文件失败:', error)
|
||||
// 尝试使用备用方法
|
||||
this.fallbackPickFiles()
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
console.error('plus.io.pickFiles 不可用:', error)
|
||||
// 尝试使用备用方法
|
||||
this.fallbackPickFiles()
|
||||
}
|
||||
},
|
||||
|
||||
// 备用文件选择方法
|
||||
fallbackPickFiles() {
|
||||
// 使用 uni.chooseImage 作为备用方案
|
||||
uni.chooseImage({
|
||||
count: 5,
|
||||
sizeType: ['original'],
|
||||
sourceType: ['album'],
|
||||
success: (res) => {
|
||||
console.log('备用方法选择文件成功:', res)
|
||||
const processedFiles = res.tempFilePaths.map((path, index) => ({
|
||||
name: `image_${Date.now()}_${index}.jpg`,
|
||||
size: 0,
|
||||
path: path,
|
||||
type: 'image/jpeg'
|
||||
}))
|
||||
|
||||
// 验证文件
|
||||
const validFiles = this.validateFiles(processedFiles)
|
||||
if (validFiles.length > 0) {
|
||||
this.fileList = [...this.fileList, ...validFiles]
|
||||
console.log('处理后的文件列表:', this.fileList)
|
||||
}
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('备用方法选择文件失败:', error)
|
||||
uni.showToast({
|
||||
title: '选择文件失败',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
// 验证文件
|
||||
validateFiles(files) {
|
||||
const allowedTypes = ['doc', 'xls', 'ppt', 'txt', 'pdf', 'docx', 'xlsx', 'png', 'jpg', 'jpeg', 'zip', 'rar', '7z', 'dwg']
|
||||
const maxSize = 200 * 1024 * 1024 // 200MB
|
||||
|
||||
const validFiles = []
|
||||
const invalidFiles = []
|
||||
|
||||
files.forEach(file => {
|
||||
// 文件类型验证
|
||||
const ext = file.name.split('.').pop().toLowerCase()
|
||||
if (!allowedTypes.includes(ext)) {
|
||||
invalidFiles.push(`${file.name} (格式不支持)`)
|
||||
return
|
||||
}
|
||||
|
||||
// 文件大小验证
|
||||
if (file.size > maxSize) {
|
||||
invalidFiles.push(`${file.name} (超过200MB)`)
|
||||
return
|
||||
}
|
||||
|
||||
validFiles.push(file)
|
||||
})
|
||||
|
||||
// 显示无效文件提示
|
||||
if (invalidFiles.length > 0) {
|
||||
uni.showToast({
|
||||
title: `以下文件不符合要求:${invalidFiles.join(', ')}`,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
}
|
||||
|
||||
return validFiles
|
||||
},
|
||||
|
||||
|
||||
|
||||
// 格式化文件大小
|
||||
formatFileSize(size) {
|
||||
if (size < 1024) {
|
||||
@@ -437,21 +641,24 @@ export default {
|
||||
|
||||
// 上传文件
|
||||
async uploadFiles() {
|
||||
const uploadPromises = this.fileList.map(async (file) => {
|
||||
try {
|
||||
const result = await uploadImage(file.path)
|
||||
return {
|
||||
originalName: file.name,
|
||||
url: result.url,
|
||||
ossId: result.ossId
|
||||
if (this.fileList.length === 0) {
|
||||
return []
|
||||
}
|
||||
|
||||
try {
|
||||
const results = await uploadFiles(this.fileList, {
|
||||
allowedTypes: ['doc', 'xls', 'ppt', 'txt', 'pdf', 'docx', 'xlsx', 'png', 'jpg', 'jpeg', 'zip', 'rar', '7z', 'dwg'],
|
||||
maxSize: 200,
|
||||
extraData: 1,
|
||||
onProgress: (progress) => {
|
||||
console.log(`上传进度: ${progress.progress.toFixed(1)}% - ${progress.file.name}`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('文件上传失败:', error)
|
||||
throw error
|
||||
}
|
||||
})
|
||||
|
||||
return Promise.all(uploadPromises)
|
||||
})
|
||||
|
||||
return results
|
||||
} catch (error) {
|
||||
throw error
|
||||
}
|
||||
},
|
||||
|
||||
// 表单验证
|
||||
@@ -510,12 +717,37 @@ export default {
|
||||
try {
|
||||
// 上传文件
|
||||
if (this.fileList.length > 0) {
|
||||
// 显示上传进度提示
|
||||
uni.showLoading({
|
||||
title: '正在上传文件...',
|
||||
mask: true
|
||||
})
|
||||
|
||||
const uploadedFiles = await this.uploadFiles()
|
||||
this.form.accessory = uploadedFiles.map(file => file.ossId).join(',')
|
||||
|
||||
// 隐藏上传进度提示
|
||||
uni.hideLoading()
|
||||
|
||||
// 提取ossId并拼接成字符串
|
||||
const ossIds = uploadedFiles.map(file => file.ossId).filter(Boolean)
|
||||
this.form.accessory = ossIds.join(',')
|
||||
|
||||
console.log('上传完成,ossId字符串:', this.form.accessory)
|
||||
} else {
|
||||
this.form.accessory = ''
|
||||
}
|
||||
|
||||
// 显示提交提示
|
||||
uni.showLoading({
|
||||
title: '正在创建任务...',
|
||||
mask: true
|
||||
})
|
||||
|
||||
// 提交任务
|
||||
await addTask(this.form)
|
||||
|
||||
// 隐藏提交提示
|
||||
uni.hideLoading()
|
||||
|
||||
uni.showToast({
|
||||
title: '任务创建成功',
|
||||
@@ -529,9 +761,16 @@ export default {
|
||||
|
||||
} catch (error) {
|
||||
console.error('创建任务失败:', error)
|
||||
|
||||
// 隐藏所有loading
|
||||
uni.hideLoading()
|
||||
|
||||
// 显示错误信息
|
||||
const errorMessage = error.message || '创建任务失败'
|
||||
uni.showToast({
|
||||
title: '创建任务失败',
|
||||
icon: 'none'
|
||||
title: errorMessage,
|
||||
icon: 'none',
|
||||
duration: 3000
|
||||
})
|
||||
} finally {
|
||||
this.loading = false
|
||||
|
||||
Reference in New Issue
Block a user