第一次打包失败
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
<!-- 目录名称输入 -->
|
||||
<view class="new-folder-name">目录名称</view>
|
||||
<view class="create-folder-name" :class="{'has-value': isNFNFocused || newFolderName}">
|
||||
<input v-model="newFolderName" @focus="isNFNFocused=true"
|
||||
@blur="isNFNFocused=false" type="text" placeholder="输入目录名称,如:项目资料/设计图" />
|
||||
<input v-model="newFolderName" @focus="isNFNFocused=true" @blur="isNFNFocused=false" type="text"
|
||||
placeholder="输入目录名称,如:项目资料/设计图" />
|
||||
</view>
|
||||
|
||||
<!-- 当前路径 -->
|
||||
@@ -50,7 +50,9 @@
|
||||
@click="handleMenu"></view>
|
||||
</view>
|
||||
<view v-if="isMenuOpen" class="menu-card">
|
||||
<view class="menu-card-item" @click="handleSelectFolder();handleMenu()">选择</view>
|
||||
<!-- <view class="menu-card-item" @click="handleSelectFolder();handleMenu()">选择</view>
|
||||
<view class="solid-line"></view> -->
|
||||
<view class="menu-card-item" @click="handleUploadFile();handleMenu()">上传文件</view>
|
||||
<view class="solid-line"></view>
|
||||
<view class="menu-card-item" @click="newWorkspaceFolder();handleMenu()">新建文件夹</view>
|
||||
</view>
|
||||
@@ -88,11 +90,11 @@
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="isSelectFolder" class="workspace-footer" :class="{'folder-actions':selectFileList.length>0}">
|
||||
<view class="iconfont icon-shangchuan"></view>
|
||||
<view class="iconfont icon-fuzhi"></view>
|
||||
<view class="iconfont icon-wenjian"></view>
|
||||
<view class="iconfont icon-shangchuan" @click="handleUploadFile"></view>
|
||||
<!-- <view class="iconfont icon-fuzhi"></view> -->
|
||||
<!-- <view class="iconfont icon-wenjian"></view> -->
|
||||
<view class="iconfont icon-del"></view>
|
||||
<view class="iconfont icon-gengduo"></view>
|
||||
<!-- <view class="iconfont icon-gengduo"></view> -->
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -107,11 +109,17 @@
|
||||
getWorkspaceId,
|
||||
getToken
|
||||
} from '@/utils/user-info.js'
|
||||
import {
|
||||
chooseFile
|
||||
} from '@/uni_modules/lime-choose-file';
|
||||
import {
|
||||
getWorkspaceList,
|
||||
createWorkspaceFolder,
|
||||
daleteWorkspace,
|
||||
getWorkspaceFileURL
|
||||
getWorkspaceFileURL,
|
||||
uploadFileToShortStorage,
|
||||
workspaceUploadFileByURL,
|
||||
updateWorkspaceFileName
|
||||
} from '@/utils/cloud-api.js'
|
||||
|
||||
const UserToken = ref('')
|
||||
@@ -148,6 +156,84 @@
|
||||
showNewFolder.value = true
|
||||
}
|
||||
|
||||
// ========== 上传文件 ==========
|
||||
const handleUploadFile = () => {
|
||||
chooseFile({
|
||||
count: 10,
|
||||
type: 'all',
|
||||
success: async (res) => {
|
||||
const files = res.tempFiles || [];
|
||||
if (files.length === 0) {
|
||||
uni.showToast({
|
||||
title: '未选择文件',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
await doUploadWorkspaceFiles(files);
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('选择文件失败:', err);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const doUploadWorkspaceFiles = async (files) => {
|
||||
uni.showLoading({
|
||||
title: '上传中...'
|
||||
});
|
||||
try {
|
||||
const dirPath = folderStack.value.length > 0 ?
|
||||
'./' + folderStack.value.map(f => f.name).join('/') + '/' :
|
||||
'/';
|
||||
|
||||
// 1. 一次性上传所有文件到短存云端,获取 URL 数组
|
||||
const results = await uploadFileToShortStorage(
|
||||
workspaceId.value,
|
||||
files,
|
||||
dirPath
|
||||
);
|
||||
// results: [{ url, success }, ...]
|
||||
|
||||
// 2. 收集成功的 URL,批量上传到工作区
|
||||
const successUrls = results
|
||||
.filter(r => r.success)
|
||||
.map(r => r.url);
|
||||
|
||||
if (successUrls.length === 0) {
|
||||
const errors = results.filter(r => !r.success).map(r => r.error).join('; ');
|
||||
throw new Error(errors || '所有文件上传失败');
|
||||
}
|
||||
|
||||
await workspaceUploadFileByURL(
|
||||
UserToken.value,
|
||||
workspaceId.value,
|
||||
successUrls,
|
||||
dirPath
|
||||
);
|
||||
|
||||
uni.hideLoading();
|
||||
const total = files.length;
|
||||
const failed = total - successUrls.length;
|
||||
const msg = failed > 0 ?
|
||||
`上传完成:成功 ${successUrls.length},失败 ${failed}` :
|
||||
`成功上传 ${total} 个文件`;
|
||||
uni.showToast({
|
||||
title: msg,
|
||||
icon: successUrls.length > 0 ? 'success' : 'error'
|
||||
});
|
||||
// 刷新文件列表
|
||||
initCurrentFolderList();
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error('上传文件失败:', error);
|
||||
uni.showToast({
|
||||
title: typeof error === 'string' ? error : '上传失败,请重试',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 当前文件夹路径
|
||||
const currentFolderPath = computed(() => {
|
||||
if (folderStack.value.length === 0) return '根目录'
|
||||
@@ -168,7 +254,10 @@
|
||||
const confirmCreateFolder = async () => {
|
||||
const name = newFolderName.value.trim()
|
||||
if (!name) {
|
||||
uni.showToast({ title: '请输入目录名称', icon: 'none' })
|
||||
uni.showToast({
|
||||
title: '请输入目录名称',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
try {
|
||||
@@ -176,12 +265,18 @@
|
||||
const folderPath = folderStack.value.map(f => f.name).join('/')
|
||||
const dirPath = folderPath ? `./${folderPath}/${name}` : `./${name}`
|
||||
await createWorkspaceFolder(UserToken.value, workspaceId.value, dirPath)
|
||||
uni.showToast({ title: '创建成功', icon: 'success' })
|
||||
uni.showToast({
|
||||
title: '创建成功',
|
||||
icon: 'success'
|
||||
})
|
||||
closeNewFolderModal()
|
||||
initCurrentFolderList()
|
||||
} catch (error) {
|
||||
console.error('创建文件夹失败:', error)
|
||||
uni.showToast({ title: '创建失败,请重试', icon: 'error' })
|
||||
uni.showToast({
|
||||
title: '创建失败,请重试',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,132 +284,107 @@
|
||||
const handleLongPress = (folder) => {
|
||||
if (isSelectFolder.value) return;
|
||||
uni.showActionSheet({
|
||||
itemList: ['重命名', '删除', '下载', '压缩'],
|
||||
itemList: ['下载', '删除'], // ['删除', '下载', '压缩', '重命名']
|
||||
success: (res) => {
|
||||
switch (res.tapIndex) {
|
||||
case 0:
|
||||
handleRename(folder);
|
||||
handleDownload(folder);
|
||||
break;
|
||||
case 1:
|
||||
handleDelete(folder);
|
||||
break;
|
||||
case 2:
|
||||
handleDownload(folder);
|
||||
break;
|
||||
case 3:
|
||||
handleDownload(folder);
|
||||
break;
|
||||
// case 2:
|
||||
// handleDownload(folder);
|
||||
// break;
|
||||
// case 3:
|
||||
// handleRename(folder);
|
||||
// break;
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 重命名
|
||||
const handleRename = (folder) => {
|
||||
const handleRename = async (folder) => {
|
||||
uni.showModal({
|
||||
title: '重命名',
|
||||
content: '请输入新名称',
|
||||
editable: true,
|
||||
placeholderText: folder.name,
|
||||
success: (res) => {
|
||||
success: async (res) => {
|
||||
if (res.confirm && res.content) {
|
||||
// 更新文件夹名称
|
||||
updateFolderName(folder.id, res.content);
|
||||
try {
|
||||
uni.showLoading({
|
||||
title: '重命名中...'
|
||||
});
|
||||
// 构建文件路径:当前目录 + 文件名
|
||||
const dirPath = folderStack.value.length > 0 ?
|
||||
'./' + folderStack.value.map(f => f.name).join('/') + '/' :
|
||||
'/';
|
||||
const filePath = dirPath + folder.name;
|
||||
await updateWorkspaceFileName(
|
||||
workspaceId.value,
|
||||
filePath,
|
||||
res.content
|
||||
);
|
||||
uni.hideLoading();
|
||||
uni.showToast({
|
||||
title: '重命名成功',
|
||||
icon: 'success'
|
||||
});
|
||||
// 刷新文件列表
|
||||
initCurrentFolderList();
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error('重命名失败:', error);
|
||||
uni.showToast({
|
||||
title: typeof error === 'string' ? error : '重命名失败,请重试',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// // 下载文件
|
||||
// const handleDownload = async (folder) => {
|
||||
// // 目录不能下载
|
||||
// if (folder.type === 'directory') {
|
||||
// uni.showToast({ title: '暂不支持下载目录', icon: 'none' });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// try {
|
||||
// uni.showLoading({ title: '获取下载链接...' });
|
||||
|
||||
// // 构建文件路径,去掉开头的 ./
|
||||
// const filePath = folder.path.startsWith('./') ? folder.path.slice(2) : folder.path;
|
||||
// const result = await getWorkspaceFileURL(UserToken.value, workspaceId.value, filePath);
|
||||
|
||||
// uni.hideLoading();
|
||||
|
||||
// // 接口返回数组,取第一个文件的 url
|
||||
// const fileInfo = Array.isArray(result) ? result[0] : result;
|
||||
// if (!fileInfo || !fileInfo.url) {
|
||||
// uni.showToast({ title: '获取下载链接失败', icon: 'error' });
|
||||
// return;
|
||||
// }
|
||||
|
||||
// const downloadUrl = fileInfo.url;
|
||||
// const fileName = folder.name;
|
||||
|
||||
// uni.showLoading({ title: '下载中...' });
|
||||
|
||||
// uni.downloadFile({
|
||||
// url: downloadUrl,
|
||||
// success: (downloadRes) => {
|
||||
// uni.hideLoading();
|
||||
// if (downloadRes.statusCode === 200) {
|
||||
// // 保存到手机相册/文件
|
||||
// uni.saveFile({
|
||||
// tempFilePath: downloadRes.tempFilePath,
|
||||
// success: (saveRes) => {
|
||||
// uni.showToast({ title: '下载成功', icon: 'success' });
|
||||
// console.log('文件已保存到:', saveRes.savedFilePath);
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// console.error('保存文件失败:', err);
|
||||
// uni.showToast({ title: '保存文件失败', icon: 'error' });
|
||||
// }
|
||||
// });
|
||||
// } else {
|
||||
// uni.showToast({ title: '下载失败', icon: 'error' });
|
||||
// }
|
||||
// },
|
||||
// fail: (err) => {
|
||||
// uni.hideLoading();
|
||||
// console.error('下载文件失败:', err);
|
||||
// uni.showToast({ title: '下载失败,请重试', icon: 'error' });
|
||||
// }
|
||||
// });
|
||||
// } catch (error) {
|
||||
// uni.hideLoading();
|
||||
// console.error('获取下载链接失败:', error);
|
||||
// uni.showToast({ title: '获取下载链接失败,请重试', icon: 'error' });
|
||||
// }
|
||||
// };
|
||||
const handleDownload = async (folder) => {
|
||||
// 目录不能下载
|
||||
if (folder.type === 'directory') {
|
||||
uni.showToast({ title: '暂不支持下载目录', icon: 'none' });
|
||||
uni.showToast({
|
||||
title: '暂不支持下载目录',
|
||||
icon: 'none'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
uni.showLoading({ title: '获取下载链接...' });
|
||||
|
||||
uni.showLoading({
|
||||
title: '获取下载链接...'
|
||||
});
|
||||
|
||||
// 构建文件路径,去掉开头的 ./
|
||||
const filePath = folder.path.startsWith('./') ? folder.path.slice(2) : folder.path;
|
||||
const result = await getWorkspaceFileURL(UserToken.value, workspaceId.value, filePath);
|
||||
|
||||
|
||||
uni.hideLoading();
|
||||
|
||||
|
||||
// 接口返回数组,取第一个文件的 url
|
||||
const fileInfo = Array.isArray(result) ? result[0] : result;
|
||||
if (!fileInfo || !fileInfo.url) {
|
||||
uni.showToast({ title: '获取下载链接失败', icon: 'error' });
|
||||
uni.showToast({
|
||||
title: '获取下载链接失败',
|
||||
icon: 'error'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const downloadUrl = fileInfo.url;
|
||||
const fileName = folder.name;
|
||||
|
||||
uni.showLoading({ title: '下载中...' });
|
||||
|
||||
|
||||
uni.showLoading({
|
||||
title: '下载中...'
|
||||
});
|
||||
|
||||
uni.downloadFile({
|
||||
url: downloadUrl,
|
||||
name: fileName,
|
||||
@@ -325,19 +395,28 @@
|
||||
// 下载成功,保存到 yxd 目录
|
||||
saveFileToYxd(fileName, tempPath);
|
||||
} else {
|
||||
uni.showToast({ title: '下载失败', icon: 'error' });
|
||||
uni.showToast({
|
||||
title: '下载失败',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
console.error('下载文件失败:', err);
|
||||
uni.showToast({ title: '下载失败,请重试', icon: 'error' });
|
||||
uni.showToast({
|
||||
title: '下载失败,请重试',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
uni.hideLoading();
|
||||
console.error('获取下载链接失败:', error);
|
||||
uni.showToast({ title: '获取下载链接失败,请重试', icon: 'error' });
|
||||
uni.showToast({
|
||||
title: '获取下载链接失败,请重试',
|
||||
icon: 'error'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -352,16 +431,24 @@
|
||||
callback(dirEntry);
|
||||
}, () => {
|
||||
plus.io.resolveLocalFileSystemURL('/storage/emulated/0/', (rootEntry) => {
|
||||
rootEntry.getDirectory('yxd', { create: true }, (dirEntry) => {
|
||||
rootEntry.getDirectory('yxd', {
|
||||
create: true
|
||||
}, (dirEntry) => {
|
||||
callback(dirEntry);
|
||||
}, (err) => {
|
||||
console.error('创建 yxd 目录失败:', JSON.stringify(err));
|
||||
uni.showToast({ title: '创建目录失败', icon: 'error' });
|
||||
uni.showToast({
|
||||
title: '创建目录失败',
|
||||
icon: 'error'
|
||||
});
|
||||
openFileConfirm(fileName, tempPath);
|
||||
});
|
||||
}, (err) => {
|
||||
console.error('访问外部存储根目录失败:', JSON.stringify(err));
|
||||
uni.showToast({ title: '无法访问存储目录', icon: 'error' });
|
||||
uni.showToast({
|
||||
title: '无法访问存储目录',
|
||||
icon: 'error'
|
||||
});
|
||||
openFileConfirm(fileName, tempPath);
|
||||
});
|
||||
});
|
||||
@@ -478,13 +565,19 @@
|
||||
try {
|
||||
// 路径加 ./ 前缀
|
||||
const filePath = `./${folder.path}`
|
||||
console.log("删除的是:",filePath);
|
||||
console.log("删除的是:", filePath);
|
||||
await daleteWorkspace(UserToken.value, workspaceId.value, filePath)
|
||||
uni.showToast({ title: '删除成功', icon: 'success' })
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
icon: 'success'
|
||||
})
|
||||
initCurrentFolderList()
|
||||
} catch (error) {
|
||||
console.error('删除失败:', error)
|
||||
uni.showToast({ title: '删除失败,请重试', icon: 'error' })
|
||||
uni.showToast({
|
||||
title: '删除失败,请重试',
|
||||
icon: 'error'
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user