Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mes-pda-scan
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ximai
mes-pda-scan
Commits
bc3edf4c
Commit
bc3edf4c
authored
Aug 07, 2024
by
沈翠玲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
APP自动升级(未对接接口)
parent
cf3fd2a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
120 additions
and
0 deletions
+120
-0
App.vue
App.vue
+11
-0
checkappupdate.js
common/checkappupdate.js
+109
-0
No files found.
App.vue
View file @
bc3edf4c
<
script
>
<
script
>
import
checkappupdate
from
'common/checkappupdate.js'
export
default
{
export
default
{
onLaunch
:
function
()
{
onLaunch
:
function
()
{
// #ifdef APP-PLUS
// #ifdef APP-PLUS
...
@@ -7,6 +8,16 @@ export default {
...
@@ -7,6 +8,16 @@ export default {
// plus.screen.lockOrientation("landscape-primary");
// plus.screen.lockOrientation("landscape-primary");
// 锁定竖屏
// 锁定竖屏
plus
.
screen
.
lockOrientation
(
"portrait-primary"
);
plus
.
screen
.
lockOrientation
(
"portrait-primary"
);
const
fn
=
()
=>
{
checkappupdate
.
check
({
title
:
'检测到有新版本!'
,
content
:
'请升级app到最新版本!'
,
canceltext
:
'暂不升级'
,
oktext
:
'立即升级'
})
return
fn
// 函数中返回自身
}
setInterval
(
fn
(),
3600
*
1000
)
// #endif
// #endif
},
},
onShow
:
function
()
{
onShow
:
function
()
{
...
...
common/checkappupdate.js
0 → 100644
View file @
bc3edf4c
import
config
from
'./config.js'
function
check
(
param
=
{})
{
// 合并默认参数
param
=
Object
.
assign
({
title
:
"检测到有新版本!"
,
content
:
"请升级app到最新版本!"
,
canceltext
:
"暂不升级"
,
oktext
:
"立即升级"
},
param
)
plus
.
runtime
.
getProperty
(
plus
.
runtime
.
appid
,
(
widgetInfo
)
=>
{
let
platform
=
plus
.
os
.
name
.
toLocaleLowerCase
()
try
{
console
.
log
(
'widgetInfo'
,
widgetInfo
.
version
)
uni
.
request
({
url
:
config
.
baseUrl
+
'/md/appconfig/getVersion'
,
success
:
(
result
)
=>
{
result
=
result
.
data
console
.
log
(
'result'
,
result
)
let
data
=
result
.
data
?
result
.
data
[
0
]
:
null
;
if
(
widgetInfo
.
version
===
data
.
version
)
{
return
;
}
if
(
result
.
code
==
200
)
{
// android进行如下操作
uni
.
showModal
({
title
:
param
.
title
,
content
:
data
.
updateDesc
?
data
.
updateDesc
+
''
:
param
.
content
,
showCancel
:
false
,
confirmText
:
param
.
oktext
,
cancelText
:
param
.
canceltext
,
success
:
res
=>
{
if
(
!
res
.
confirm
)
{
console
.
log
(
'取消了升级'
);
plus
.
runtime
.
quit
();
}
// 清除缓存
// request.clearLogin();
// 开始下载
// 创建下载任务
var
dtask
=
plus
.
downloader
.
createDownload
(
data
.
url
,
{
filename
:
"_downloads/"
},
function
(
d
,
status
)
{
// 下载完成
if
(
status
==
200
)
{
plus
.
runtime
.
install
(
d
.
filename
,
{
force
:
true
},
function
()
{
//进行重新启动;
plus
.
runtime
.
restart
();
},
(
e
)
=>
{
uni
.
showToast
({
title
:
'安装升级包失败:'
+
JSON
.
stringify
(
e
),
icon
:
'none'
})
});
}
else
{
this
.
tui
.
toast
(
"下载升级包失败,请手动去站点下载安装,错误码: "
+
status
);
}
});
let
view
=
new
plus
.
nativeObj
.
View
(
"maskView"
,
{
backgroundColor
:
"rgba(0,0,0,.6)"
,
left
:
'0px'
,
bottom
:
"0px"
,
width
:
plus
.
screen
.
resolutionWidth
,
height
:
plus
.
screen
.
resolutionHeight
})
view
.
drawText
(
'开始下载'
,
{},
{
size
:
'12px'
,
color
:
'#FFFFFF'
});
view
.
show
()
dtask
.
addEventListener
(
"statechanged"
,
(
e
)
=>
{
if
(
e
&&
e
.
downloadedSize
>
0
)
{
let
jindu
=
((
e
.
downloadedSize
/
e
.
totalSize
)
*
100
).
toFixed
(
2
)
view
.
reset
();
view
.
drawText
(
'进度:'
+
jindu
+
'%'
,
{},
{
size
:
'12px'
,
color
:
'#FFFFFF'
});
}
},
false
);
dtask
.
start
();
}
})
}
}
})
}
catch
(
e
)
{
console
.
log
(
'eee'
,
e
)
}
});
}
export
default
{
check
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment