Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
inspection-pad-web
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
专网
inspection-pad-web
Commits
e8751ec2
提交
e8751ec2
authored
4月 11, 2025
作者:
JaxBBLL
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix
上级
6d643a3c
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
117 行增加
和
0 行删除
+117
-0
index.js
utils/index.js
+29
-0
plus.js
utils/plus.js
+88
-0
没有找到文件。
utils/index.js
0 → 100644
浏览文件 @
e8751ec2
/**
* 传入inspectionData, 找出所有的照片url
* @param {*} obj
* @returns
*/
export
function
findPhotosUrls
(
obj
)
{
let
urls
=
[];
function
recurse
(
current
)
{
if
(
Array
.
isArray
(
current
))
{
current
.
forEach
(
recurse
);
}
else
if
(
current
&&
typeof
current
===
"object"
)
{
Object
.
keys
(
current
).
forEach
((
key
)
=>
{
if
(
key
===
"photos"
&&
Array
.
isArray
(
current
[
key
]))
{
current
[
key
].
forEach
((
url
)
=>
{
if
(
typeof
url
===
"string"
)
{
urls
.
push
(
url
.
trim
());
}
});
}
else
{
recurse
(
current
[
key
]);
}
});
}
}
recurse
(
obj
);
return
urls
;
}
utils/plus.js
浏览文件 @
e8751ec2
...
...
@@ -40,6 +40,58 @@ export async function createFolder(relativePath) {
}
}
/**
* 删除指定目录及其内容
* @param {string} folderPath 要删除的目录路径(相对于 PUBLIC_DOCUMENTS 根目录)
* @returns {Promise<void>} 返回一个 Promise,在删除成功或不存在时 resolve,失败时 reject
*/
export
function
deleteFolder
(
folderPath
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
// 获取文件系统对象
plus
.
io
.
requestFileSystem
(
plus
.
io
.
PUBLIC_DOCUMENTS
,
(
fs
)
=>
{
// 构造完整路径
const
fullPath
=
fs
.
root
.
fullPath
+
"/"
+
folderPath
;
// 检查目录是否存在
plus
.
io
.
resolveLocalFileSystemURL
(
fullPath
,
(
dirEntry
)
=>
{
console
.
log
(
`目录存在,开始删除:
${
fullPath
}
`
);
deleteDirectoryRecursive
(
dirEntry
)
.
then
(()
=>
{
console
.
log
(
`目录已删除:
${
fullPath
}
`
);
resolve
();
})
.
catch
((
err
)
=>
{
console
.
error
(
`删除目录失败:
${
fullPath
}
, 错误信息:
${
err
.
message
}
`
);
reject
(
err
);
});
},
(
err
)
=>
{
if
(
err
.
code
===
1
)
{
console
.
log
(
`目录不存在:
${
fullPath
}
`
);
resolve
();
// 目录不存在时直接 resolve
}
else
{
console
.
error
(
`检查目录失败:
${
fullPath
}
, 错误信息:
${
err
.
message
}
`
);
reject
(
err
);
}
}
);
},
(
err
)
=>
{
console
.
error
(
`请求文件系统失败:
${
err
.
message
}
`
);
reject
(
err
);
}
);
});
}
/**
* 复制相册图片
* @param {*} sourcePath
...
...
@@ -105,3 +157,39 @@ export async function copyImage(sourcePath, targetPath) {
throw
new
Error
(
`操作失败:
${
error
.
message
}
`
);
}
}
/**
* 传入照片数组,复制到临时目录
* @param {*} photos ["1.jpg", "2.jpg"]
* @returns
*/
export
async
function
copyPhotosToTemp
(
photos
)
{
await
deleteFolder
(
"data/temp"
);
// 删除临时目录
await
createFolder
(
"data/temp"
);
// 创建临时目录
console
.
log
(
"1111"
);
return
new
Promise
((
resolve
,
reject
)
=>
{
const
copiedPhotos
=
[];
let
completed
=
0
;
photos
.
forEach
((
photo
)
=>
{
const
targetPath
=
`_documents/data/temp`
;
console
.
log
(
"before copy"
,
photo
,
targetPath
);
copyImage
(
photo
,
targetPath
)
.
then
((
copiedUrl
)
=>
{
console
.
log
(
"copiedUrl"
,
copiedUrl
);
copiedPhotos
.
push
(
photo
);
completed
+=
1
;
if
(
completed
===
photos
.
length
)
{
resolve
(
copiedPhotos
);
}
})
.
catch
((
error
)
=>
{
console
.
error
(
`复制照片失败:
${
error
.
message
}
`
);
reject
(
error
);
});
});
});
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论