Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
gameExamine
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
毛细亚
gameExamine
Commits
a75b9f15
提交
a75b9f15
authored
12月 14, 2021
作者:
毛细亚
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化文件缓存
上级
090a6c33
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
81 行增加
和
21 行删除
+81
-21
config.js
config/config.js
+2
-1
game.js
game.js
+79
-20
没有找到文件。
config/config.js
浏览文件 @
a75b9f15
module
.
exports
=
{
module
.
exports
=
{
app_id
:
"wx5bf92e3883dc5a82"
,
app_id
:
"wx5bf92e3883dc5a82"
,
game_id
:
"122"
,
game_id
:
"122"
,
binVersion
:
'1'
,
// 控制bin文件缓存
/**以下参数,请勿随意修改! */
/**以下参数,请勿随意修改! */
gameVersion
:
"1.18364"
gameVersion
:
"1.18364"
}
}
\ No newline at end of file
game.js
浏览文件 @
a75b9f15
...
@@ -2,23 +2,32 @@
...
@@ -2,23 +2,32 @@
const
ROOT_PATH
=
wx
.
env
.
USER_DATA_PATH
const
ROOT_PATH
=
wx
.
env
.
USER_DATA_PATH
const
CACHE_PATH
=
ROOT_PATH
const
CACHE_PATH
=
ROOT_PATH
const
fs
=
wx
.
getFileSystemManager
()
const
fs
=
wx
.
getFileSystemManager
()
const
config
=
require
(
'./config/config'
)
let
fileList
=
[{
fileName
:
'mxy_release_qyppl.bin?v=5'
,
variable
:
'a'
}]
let
promiseList
=
[];
function
downConfig
(
fileInfo
)
{
function
downConfig
(
fileInfo
)
{
return
new
Promise
((
resolve
,
rej
)
=>
{
return
new
Promise
((
resolve
,
rej
)
=>
{
const
{
fileName
,
variable
}
=
fileInfo
const
{
fileName
,
variable
}
=
fileInfo
wx
[
'$'
+
variable
]
=
{}
wx
[
'$'
+
variable
]
=
{}
console
.
log
(
'wx.downloadFile'
)
wx
.
downloadFile
({
wx
.
downloadFile
({
url
:
'https://wanxiaomeng-1255977238.cos.ap-shanghai.myqcloud.com/'
+
fileName
,
url
:
'https://wanxiaomeng-1255977238.cos.ap-shanghai.myqcloud.com/'
+
fileName
,
filePath
:
CACHE_PATH
+
'/'
+
fileName
,
filePath
:
CACHE_PATH
+
'/'
+
fileName
,
success
:
function
(
res
)
{
success
:
function
(
res
)
{
console
.
log
(
CACHE_PATH
+
'/'
+
fileName
,
'--------'
)
console
.
log
(
'下载res:'
,
res
);
console
.
log
(
'下载res:'
,
res
);
const
json
=
fs
.
readFileSync
(
res
.
filePath
,
'utf-8'
)
const
json
=
fs
.
readFileSync
(
res
.
filePath
,
'utf-8'
)
wx
[
'$'
+
variable
]
=
JSON
.
parse
(
json
)
wx
[
'$'
+
variable
]
=
JSON
.
parse
(
json
)
wx
.
setStorage
({
key
:
variable
+
'.bin'
,
data
:
JSON
.
stringify
({
binVersion
:
config
.
binVersion
,
binUrl
:
res
.
filePath
}),
success
(
data
){
console
.
log
(
'版本号缓存成功'
,
data
)
},
fail
(
err
){
console
.
log
(
err
,
'版本号缓存失败'
)
}
})
resolve
()
resolve
()
console
.
log
(
wx
[
'$'
+
variable
])
}
}
});
});
})
})
...
@@ -26,24 +35,74 @@ function downConfig(fileInfo) {
...
@@ -26,24 +35,74 @@ function downConfig(fileInfo) {
function
checkFile
(
filePath
){
function
checkFile
(
filePath
){
fs
.
access
({
return
new
Promise
((
resolve
,
reject
)
=>
{
path
:
filePath
,
fs
.
access
({
success
(
res
)
{
path
:
filePath
,
// 文件存在
success
(
res
)
{
return
true
console
.
log
(
'检测到文件存在'
,
filePath
)
// 文件存在
resolve
()
},
fail
(
res
)
{
// 文件不存在或其他错误
reject
()
}
})
})
}
// 先检查版本号是否相同 然后再看本地是否有已经存在的文件
function
checkStorage
(
fileInfo
){
const
{
variable
}
=
fileInfo
wx
.
getStorage
({
key
:
variable
+
'.bin'
,
success
(
res
){
let
data
=
JSON
.
parse
(
res
.
data
)
// 缓存和配置文件版本号相同
if
(
res
.
data
&&
data
.
binVersion
==
config
.
binVersion
){
console
.
log
(
'版本号相同'
,
variable
)
checkFile
(
data
.
binUrl
).
then
(
res
=>
{
console
.
log
(
'文件存在'
,
variable
)
const
json
=
fs
.
readFileSync
(
data
.
binUrl
,
'utf-8'
)
wx
[
'$'
+
variable
]
=
JSON
.
parse
(
json
)
// console.log(wx['$'+variable])
require
(
'./game1.js'
)
},
err
=>
{
console
.
log
(
'文件不存在'
,
variable
)
// 本地没有缓存文件 重新请求
requestFile
()
})
}
else
{
console
.
log
(
'版本号不同'
,
variable
)
// 版本号不同 重新请求数据
requestFile
()
}
},
},
fail
(
res
)
{
fail
(
err
)
{
// 文件不存在或其他错误
console
.
log
(
'获取缓存失败'
,
err
,
variable
)
re
turn
false
re
questFile
()
}
}
})
})
}
function
requestFile
(){
fileList
.
map
((
item
,
index
)
=>
{
promiseList
.
push
(
downConfig
(
item
))
})
Promise
.
all
(
promiseList
).
then
(()
=>
{
console
.
log
(
wx
.
$a
)
console
.
log
(
'完成'
)
require
(
'./game1.js'
)
})
}
}
var
file1
=
downConfig
({
fileName
:
'mxy_release_qyppl.bin?v=5'
,
variable
:
'a'
})
fileList
.
map
((
item
,
index
)
=>
{
setTimeout
(()
=>
{
checkStorage
(
item
)
},
300
);
})
Promise
.
all
([
file1
]).
then
(()
=>
{
console
.
log
(
wx
.
$a
)
console
.
log
(
'完成'
)
require
(
'./game1.js'
)
})
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论