|
@@ -69,6 +69,57 @@ export const showProgress = (index : number, title : string) => {
|
|
|
}, 50);
|
|
}, 50);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+export const moveFile = (oldPath : string) : Promise<string> => {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ // 生成唯一的文件名
|
|
|
|
|
+ const timestamp = Date.now();
|
|
|
|
|
+ const randomNum = Math.floor(Math.random() * 1000);
|
|
|
|
|
+ const fileExtension = oldPath.substring(oldPath.lastIndexOf('.'));
|
|
|
|
|
+ const newImgName = `download_${timestamp}_${randomNum}${fileExtension}`;
|
|
|
|
|
+
|
|
|
|
|
+ // 定义新的保存路径 - 不放在相册里,放在应用数据目录下的downloadImgs文件夹
|
|
|
|
|
+ const destPath = `${uni.env.USER_DATA_PATH}/downloadImgs/${newImgName}`;
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 确保目标目录存在
|
|
|
|
|
+ const fs = uni.getFileSystemManager();
|
|
|
|
|
+ try {
|
|
|
|
|
+ fs.accessSync(`${uni.env.USER_DATA_PATH}/downloadImgs`);
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ // 目录不存在,创建目录
|
|
|
|
|
+ fs.mkdirSync(`${uni.env.USER_DATA_PATH}/downloadImgs`, true);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 先拷贝文件到新路径
|
|
|
|
|
+ fs.copyFile({
|
|
|
|
|
+ srcPath: oldPath,
|
|
|
|
|
+ destPath: destPath,
|
|
|
|
|
+ success: function () {
|
|
|
|
|
+ // 删除原文件,释放空间
|
|
|
|
|
+ fs.unlink({
|
|
|
|
|
+ filePath: oldPath,
|
|
|
|
|
+ success: function () {
|
|
|
|
|
+ console.log('原文件已删除');
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: function (unlinkErr) {
|
|
|
|
|
+ console.error('删除原文件失败', unlinkErr);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ console.log('文件移动成功,新路径:', destPath);
|
|
|
|
|
+ resolve(destPath);
|
|
|
|
|
+ },
|
|
|
|
|
+ fail: function (copyErr) {
|
|
|
|
|
+ console.error('拷贝文件失败', copyErr);
|
|
|
|
|
+ reject(copyErr);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ console.error('文件移动过程发生错误', error);
|
|
|
|
|
+ reject(error);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
//声像任务下载
|
|
//声像任务下载
|
|
|
export const downloadDataFromAPI = async (productCode : string, callback ?: () => void) : Promise<boolean> => {
|
|
export const downloadDataFromAPI = async (productCode : string, callback ?: () => void) : Promise<boolean> => {
|
|
|
try {
|
|
try {
|
|
@@ -231,28 +282,27 @@ export const downloadDataFromAPI = async (productCode : string, callback ?: () =
|
|
|
if (res.statusCode === 200) {
|
|
if (res.statusCode === 200) {
|
|
|
// 等待一小段时间确保文件完全下载
|
|
// 等待一小段时间确保文件完全下载
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
- // 图片下载成功,使用uni.saveImageToPhotosAlbum保存到相册
|
|
|
|
|
- uni.saveImageToPhotosAlbum({
|
|
|
|
|
- filePath: res.tempFilePath,
|
|
|
|
|
- success: () => {
|
|
|
|
|
- console.log('图片保存成功:', res.tempFilePath);
|
|
|
|
|
- // 将保存路径添加到数组中
|
|
|
|
|
- imagePathsArr.push(res.tempFilePath);
|
|
|
|
|
-
|
|
|
|
|
- // 保存成功后等待1秒再处理下一张
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- resolve();
|
|
|
|
|
- }, 1000);
|
|
|
|
|
- },
|
|
|
|
|
- fail: (err) => {
|
|
|
|
|
- console.error('保存图片失败:', err);
|
|
|
|
|
- // 保存失败也继续处理下一张,但记录错误
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- reject(err);
|
|
|
|
|
- }, 500);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 直接移动文件到应用数据目录,不保存到相册
|
|
|
|
|
+ moveFile(res.tempFilePath).then((newFilePath) => {
|
|
|
|
|
+ // 将新的文件路径添加到数组中
|
|
|
|
|
+ imagePathsArr.push(newFilePath);
|
|
|
|
|
+ console.log('图片已移动并添加到数组:', newFilePath);
|
|
|
|
|
+
|
|
|
|
|
+ // 处理完成后等待1秒再处理下一张
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }, 500);
|
|
|
|
|
+ }).catch((error) => {
|
|
|
|
|
+ console.error('文件移动失败,使用原始路径:', error);
|
|
|
|
|
+ // 如果移动失败,使用原始路径作为备选
|
|
|
|
|
+ imagePathsArr.push(res.tempFilePath);
|
|
|
|
|
+
|
|
|
|
|
+ // 处理完成后等待1秒再处理下一张
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ resolve();
|
|
|
|
|
+ }, 1000);
|
|
|
});
|
|
});
|
|
|
- }, 500); // 等待500ms确保文件完全下载
|
|
|
|
|
|
|
+ }, 500); // 等待500ms确保文件完全下载
|
|
|
} else {
|
|
} else {
|
|
|
console.error('下载图片失败,状态码:', res.statusCode);
|
|
console.error('下载图片失败,状态码:', res.statusCode);
|
|
|
reject(new Error(`下载图片失败,状态码: ${res.statusCode}`));
|
|
reject(new Error(`下载图片失败,状态码: ${res.statusCode}`));
|
|
@@ -593,14 +643,14 @@ export const uploadDataToAPI = async (productCode : string, callback ?: () => vo
|
|
|
if (callback != null) {
|
|
if (callback != null) {
|
|
|
callback();
|
|
callback();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
if (finalFailedCount === 0) {
|
|
if (finalFailedCount === 0) {
|
|
|
let updatedData = " uploadflag = 1 "
|
|
let updatedData = " uploadflag = 1 "
|
|
|
updateData('app_media_info', updatedData, 'productno', productCode).then((res : UTSJSONObject) => {
|
|
updateData('app_media_info', updatedData, 'productno', productCode).then((res : UTSJSONObject) => {
|
|
|
console.log(`更新完上传标识 ${productCode}`)
|
|
console.log(`更新完上传标识 ${productCode}`)
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
return finalFailedCount === 0;
|
|
return finalFailedCount === 0;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error(error);
|
|
console.error(error);
|