Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx
/
gl_tape
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
3
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f17e470e
authored
Jul 02, 2024
by
yixinjj
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
添加兼容函数
1 parent
09536d03
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
35 deletions
mixin/uploader.js
utils/RecordManager.js
utils/utils.js
mixin/uploader.js
View file @
f17e470
...
@@ -53,7 +53,7 @@ export default {
...
@@ -53,7 +53,7 @@ export default {
filePathOnClient
=
filePath
+
fileName
,
filePathOnClient
=
filePath
+
fileName
,
}
=
result
.
detail
.
data
[
0
];
}
=
result
.
detail
.
data
[
0
];
if
(
code
==
0
)
{
if
(
code
==
0
)
{
this
.
uploadSuccess
(
recordId
,
data
.
filePath
,
filePathOnClient
,
fileName
);
this
.
uploadSuccess
(
recordId
,
data
.
filePath
,
filePathOnClient
,
fileName
);
}
else
{
}
else
{
this
.
polling
();
this
.
polling
();
}
}
...
@@ -106,20 +106,6 @@ export default {
...
@@ -106,20 +106,6 @@ export default {
return
_snapshot
;
return
_snapshot
;
},
},
/**
/**
* 获取文件系统根目录的完整路径
* 这个函数使用 HTML5 的 plus.io.requestFileSystem API 在私有文档目录中请求文件系统访问权限
* 当文件系统访问权限被授予后,使用 resolve 方法返回根目录的完整路径
* 这个 Promise 风格的函数可以被其他代码使用,以异步方式获取文件系统的根路径
* @returns {Promise<string>} 一个 Promise,当获取到文件系统根目录的完整路径时兑现,并返回根目录的路径作为字符串
*/
getFilePath
()
{
return
new
Promise
((
resolve
)
=>
{
plus
.
io
.
requestFileSystem
(
plus
.
io
.
PRIVATE_DOC
,
function
(
fs
)
{
resolve
(
fs
.
root
.
fullPath
);
});
});
},
/**
* 将指定记录上传到服务器
* 将指定记录上传到服务器
* 此函数使用 WebView 的 evalJS 方法,将 OSS 令牌信息和记录详情传递给 UniApp 应用,以便进行文件上传
* 此函数使用 WebView 的 evalJS 方法,将 OSS 令牌信息和记录详情传递给 UniApp 应用,以便进行文件上传
*
*
...
@@ -129,7 +115,8 @@ export default {
...
@@ -129,7 +115,8 @@ export default {
* @throws {Error} - 如果获取 OSS 令牌的过程中出现错误,将抛出错误
* @throws {Error} - 如果获取 OSS 令牌的过程中出现错误,将抛出错误
*/
*/
async
uploadRecord
(
record
)
{
async
uploadRecord
(
record
)
{
const
{
lsaccessKeySecret
,
securityToken
,
lsaccessKeyId
}
=
await
getOssToken
();
const
{
lsaccessKeySecret
,
securityToken
,
lsaccessKeyId
}
=
await
getOssToken
();
wv
.
evalJS
(
wv
.
evalJS
(
`msgFromUniapp('
${
lsaccessKeyId
}
','
${
lsaccessKeySecret
}
','
${
securityToken
}
','
${
record
.
fileName
}
','
${
record
.
filePath
}
')`
`msgFromUniapp('
${
lsaccessKeyId
}
','
${
lsaccessKeySecret
}
','
${
securityToken
}
','
${
record
.
fileName
}
','
${
record
.
filePath
}
')`
);
);
...
@@ -146,14 +133,22 @@ export default {
...
@@ -146,14 +133,22 @@ export default {
* @returns {void} - 此函数不返回任何值
* @returns {void} - 此函数不返回任何值
* @throws {error} - 如果在尝试获取记录或保存记录时发生错误,将抛出错误
* @throws {error} - 如果在尝试获取记录或保存记录时发生错误,将抛出错误
*/
*/
async
uploadSuccess
(
recordId
,
filePathOnServer
,
filePathOnClient
,
fileName
)
{
async
uploadSuccess
(
recordId
,
filePathOnServer
,
filePathOnClient
,
fileName
)
{
const
unlock
=
await
recordManager
.
lock
();
const
unlock
=
await
recordManager
.
lock
();
try
{
try
{
const
record
=
recordManager
.
getRecordById
(
recordId
);
const
record
=
recordManager
.
getRecordById
(
recordId
);
if
(
!
record
)
return
;
if
(
!
record
)
return
;
const
recordFileList
=
record
.
recordUrlList
;
const
recordFileList
=
record
.
recordUrlList
;
recordFileList
.
forEach
((
fileInfo
)
=>
{
recordFileList
.
forEach
((
fileInfo
)
=>
{
if
(
fileInfo
.
file
===
filePathOnClient
||
fileInfo
.
file
.
endsWith
(
fileName
))
{
if
(
fileInfo
.
file
===
filePathOnClient
||
fileInfo
.
file
.
endsWith
(
fileName
)
)
{
fileInfo
.
file
=
filePathOnServer
;
fileInfo
.
file
=
filePathOnServer
;
delete
fileInfo
.
status
;
delete
fileInfo
.
status
;
}
}
...
@@ -197,15 +192,10 @@ export default {
...
@@ -197,15 +192,10 @@ export default {
const
result
=
records
.
reduce
((
acc
,
cur
)
=>
{
const
result
=
records
.
reduce
((
acc
,
cur
)
=>
{
acc
=
acc
.
concat
(
acc
=
acc
.
concat
(
cur
.
recordUrlList
.
map
((
file
)
=>
{
cur
.
recordUrlList
.
map
((
file
)
=>
{
const
fileName
=
file
.
file
.
split
(
"/"
).
pop
();
const
aFullPath
=
file
.
file
.
split
(
"/"
);
if
(
!
file
.
file
.
startsWith
(
"file://"
))
{
const
fileName
=
aFullPath
.
pop
();
file
.
file
=
this
.
fileSaveFolderOnClient
+
fileName
;
const
filePath
=
aFullPath
.
join
(
"/"
);
}
return
{
...
file
,
recordId
:
cur
.
id
,
fileName
,
filePath
};
return
{
...
file
,
recordId
:
cur
.
id
,
fileName
,
filePath
:
file
.
file
.
replace
(
fileName
,
""
)
};
})
})
);
);
return
acc
;
return
acc
;
...
@@ -218,6 +208,7 @@ export default {
...
@@ -218,6 +208,7 @@ export default {
*/
*/
polling
()
{
polling
()
{
if
(
this
.
snapshot
.
size
==
0
)
{
if
(
this
.
snapshot
.
size
==
0
)
{
this
.
enQueue
();
setTimeout
(()
=>
{
setTimeout
(()
=>
{
this
.
polling
();
this
.
polling
();
},
1000
*
60
*
10
);
},
1000
*
60
*
10
);
...
...
utils/RecordManager.js
View file @
f17e470
import
{
storageApi
}
from
"./cache"
;
import
{
storageApi
}
from
"./cache"
;
import
{
getFileSaveFolderOnClient
,
uuid
}
from
"./utils"
;
/**
/**
* 记录管理器类
* 记录管理器类
* 用于管理记录列表
* 用于管理记录列表
...
@@ -9,7 +9,9 @@ class RecordManager {
...
@@ -9,7 +9,9 @@ class RecordManager {
* RecordManager 类的构造函数
* RecordManager 类的构造函数
* 用于初始化 RecordManager 实例
* 用于初始化 RecordManager 实例
*/
*/
constructor
()
{}
constructor
()
{
this
.
fileSaveFolderOnClient
=
getFileSaveFolderOnClient
();
}
// 单例模式
// 单例模式
static
instance
=
null
;
static
instance
=
null
;
// 读写锁
// 读写锁
...
@@ -87,7 +89,8 @@ class RecordManager {
...
@@ -87,7 +89,8 @@ class RecordManager {
* 根据给定的 ID 获取一条记录
* 根据给定的 ID 获取一条记录
*
*
* @param {number} id - 要获取的记录的 ID
* @param {number} id - 要获取的记录的 ID
* @returns {Object} - 具有给定 ID 的记录对象,如果没有找到符合条件的记录,则返回 undefined
* @returns {Object} - 具有给定 ID 的记录对象,如果没有找到符合条件的记录,则返回 undefined881008
*
*/
*/
getRecordById
(
id
)
{
getRecordById
(
id
)
{
const
records
=
this
.
getRecords
();
const
records
=
this
.
getRecords
();
...
@@ -113,12 +116,36 @@ class RecordManager {
...
@@ -113,12 +116,36 @@ class RecordManager {
updateRecord
(
record
)
{
updateRecord
(
record
)
{
const
records
=
this
.
getRecords
();
const
records
=
this
.
getRecords
();
const
index
=
records
.
findIndex
((
i
)
=>
i
.
id
===
record
.
id
);
const
index
=
records
.
findIndex
((
i
)
=>
i
.
id
===
record
.
id
);
if
(
index
!==
-
1
)
{
if
(
index
!==
-
1
)
{
records
[
index
]
=
record
;
records
[
index
]
=
record
;
this
.
setRecords
(
records
);
this
.
setRecords
(
records
);
}
}
}
}
async
compatible
()
{
const
unlock
=
await
this
.
lock
();
try
{
let
records
=
this
.
getRecords
();
records
.
forEach
((
i
)
=>
{
if
(
i
.
recordUrlList
&&
i
.
recordUrlList
.
length
)
{
i
.
recordUrlList
.
forEach
((
j
)
=>
{
if
(
!
j
.
file
.
startsWith
(
"file://"
))
{
const
fileName
=
j
.
file
.
split
(
"/"
).
pop
();
j
.
file
=
this
.
fileSaveFolderOnClient
+
fileName
;
}
});
}
if
(
!
i
.
id
)
{
i
.
id
=
uuid
();
}
});
}
catch
(
e
)
{
throw
e
;
}
finally
{
unlock
();
}
}
/**
/**
* 清除所有记录
* 清除所有记录
*
*
...
@@ -128,5 +155,4 @@ class RecordManager {
...
@@ -128,5 +155,4 @@ class RecordManager {
storageApi
.
removeRecords
();
storageApi
.
removeRecords
();
}
}
}
}
export
default
RecordManager
export
default
RecordManager
;
utils/utils.js
View file @
f17e470
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* @Author: 前端 qianduan01@didihu.com.cn
* @Author: 前端 qianduan01@didihu.com.cn
* @Date: 2024-04-08 17:16:46
* @Date: 2024-04-08 17:16:46
* @LastEditors: limin
* @LastEditors: limin
* @LastEditTime: 2024-0
6-28 17:51:38
* @LastEditTime: 2024-0
7-02 09:32:33
* @FilePath: \gl_tape\utils\utils.js
* @FilePath: \gl_tape\utils\utils.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
*/
...
@@ -118,6 +118,25 @@ var uuid = function(len, radix) {
...
@@ -118,6 +118,25 @@ var uuid = function(len, radix) {
return
uuid
.
join
(
''
);
return
uuid
.
join
(
''
);
}
}
/**
* 获取文件系统根目录的完整路径
* 这个函数使用 HTML5 的 plus.io.requestFileSystem API 在私有文档目录中请求文件系统访问权限
* 当文件系统访问权限被授予后,使用 resolve 方法返回根目录的完整路径
* 这个 Promise 风格的函数可以被其他代码使用,以异步方式获取文件系统的根路径
* @returns {Promise<string>} 一个 Promise,当获取到文件系统根目录的完整路径时兑现,并返回根目录的路径作为字符串
*/
function
getFilePath
()
{
return
new
Promise
((
resolve
)
=>
{
plus
.
io
.
requestFileSystem
(
plus
.
io
.
PRIVATE_DOC
,
function
(
fs
)
{
resolve
(
fs
.
root
.
fullPath
);
});
});
}
function
getFileSaveFolderOnClient
(){
const
rootPath
=
getFilePath
();
return
`file://
${
rootPath
}
uniapp_save/`
;
}
export
default
{
export
default
{
convertDateTimeFormat
,
convertDateTimeFormat
,
deepClone
,
deepClone
,
...
@@ -125,5 +144,7 @@ export default {
...
@@ -125,5 +144,7 @@ export default {
debounce
,
debounce
,
throttle
,
throttle
,
isNetWork
,
isNetWork
,
uuid
uuid
,
getFilePath
,
getFileSaveFolderOnClient
};
};
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment