Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cxerpapp
Project
Project
Details
Activity
Releases
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
李苏
cxerpapp
Commits
057a258a
Commit
057a258a
authored
Jan 30, 2023
by
王向前
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no message
parent
0434c41e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
422 additions
and
91 deletions
+422
-91
service.js
common/service/service.js
+2
-1
appUpdate.js
common/util/appUpdate.js
+292
-65
cusmerLogin.vue
pages/login/cusmerLogin.vue
+11
-9
login.vue
pages/login/login.vue
+12
-16
update.vue
pages/login/update.vue
+105
-0
No files found.
common/service/service.js
View file @
057a258a
...
...
@@ -41,7 +41,8 @@ http.validateStatus = (statusCode) => {
http
.
interceptor
.
request
((
config
,
cancel
)
=>
{
/* 请求之前拦截器 */
config
.
header
=
{
...
config
.
header
,
'X-Access-Token'
:
getTokenStorage
()
'X-Access-Token'
:
getTokenStorage
(),
'GToken'
:
getTokenStorage
()
||
"notoken"
}
/*
if (!token) { // 如果token不存在,调用cancel 会取消本次请求,但是该函数的catch() 仍会执行
...
...
common/util/appUpdate.js
View file @
057a258a
//APP更新
import
api
from
'api/api.js'
import
{
http
}
from
'@/common/service/service.js'
export
default
function
appUpdate
()
{
http
.
post
(
'/getAppVersion'
,{
/* version: plus.runtime.version,
imei: plus.device.imei, */
apptype
:
"0"
,
appid
:
plus
.
runtime
.
appid
,
}).
then
((
res
)
=>
{
if
(
res
){
plus
.
runtime
.
getProperty
(
plus
.
runtime
.
appid
,
function
(
wgtinfo
)
{
let
client_version
=
wgtinfo
.
version
;
var
flag_update_v
=
Number
(
client_version
.
split
(
"."
)[
0
]);
var
flag_update_v2
=
Number
(
res
.
data
.
version
);
var
flag_hot
=
false
;
if
(
flag_update_v
<
flag_update_v2
)
{
// 提醒用户更新
uni
.
showModal
({
title
:
'更新提示'
,
content
:
"请进行版本更新"
,
success
:
(
showResult
)
=>
{
if
(
showResult
.
confirm
)
{
plus
.
nativeUI
.
toast
(
"正在准备环境,请稍后! "
);
var
dtask
=
plus
.
downloader
.
createDownload
(
res
.
data
.
url
,
{
method
:
'GET'
,
filename
:
'_doc/update/'
},
function
(
d
,
status
)
{
if
(
status
==
200
)
{
var
path
=
d
.
filename
;
//下载apk
plus
.
runtime
.
install
(
path
);
// 自动安装apk文件
}
else
{
plus
.
nativeUI
.
alert
(
'版本更新失败:'
+
status
);
}
});
dtask
.
start
();
}
}
})
}
else
if
(
flag_hot
)
{
uni
.
downloadFile
({
url
:
res
.
data
.
url
,
success
:
(
downloadResult
)
=>
{
console
.
log
(
downloadResult
.
tempFilePath
)
if
(
downloadResult
.
statusCode
===
200
)
{
plus
.
nativeUI
.
toast
(
`正在热更新!
${
res
.
data
.
versionCode
}
`
);
plus
.
runtime
.
install
(
downloadResult
.
tempFilePath
,
{
force
:
false
},
function
()
{
plus
.
nativeUI
.
toast
(
"热更新成功"
);
plus
.
runtime
.
restart
();
},
function
(
e
)
{
console
.
log
(
e
)
plus
.
nativeUI
.
toast
(
`热更新失败:
${
e
.
message
}
`
);
});
}
}
});
}
});
}
}).
catch
((
err
)
=>
{
}).
finally
(()
=>
{
import
api
from
'api/api.js'
;
function
versionStringCompare
(
preVersion
,
lastVersion
)
{
console
.
log
(
preVersion
,
lastVersion
)
var
sources
=
preVersion
.
split
(
'.'
);
var
dests
=
lastVersion
.
split
(
'.'
);
if
(
dests
.
length
==
2
)
{
if
(
dests
[
1
].
length
>=
2
)
{
dests
[
2
]
=
dests
[
1
][
dests
[
1
].
length
-
1
]
dests
[
1
]
=
dests
[
1
].
slice
(
0
,
dests
[
1
].
length
-
1
)
}
}
var
maxL
=
Math
.
max
(
sources
.
length
,
dests
.
length
);
var
result
=
0
;
for
(
let
i
=
0
;
i
<
maxL
;
i
++
)
{
let
preValue
=
sources
.
length
>
i
?
sources
[
i
]
:
0
;
let
preNum
=
isNaN
(
Number
(
preValue
))
?
preValue
.
charCodeAt
()
:
Number
(
preValue
);
let
lastValue
=
dests
.
length
>
i
?
dests
[
i
]
:
0
;
let
lastNum
=
isNaN
(
Number
(
lastValue
))
?
lastValue
.
charCodeAt
()
:
Number
(
lastValue
);
if
(
preNum
<
lastNum
)
{
result
=
-
1
;
break
;
}
else
if
(
preNum
>
lastNum
)
{
result
=
1
;
break
;
}
}
return
result
;
}
export
default
function
appUpdate
(
loginApp
)
{
loginApp
.
showProcess
(
'正在检测版本更新'
,
10
)
/* 0-安卓 1-ios*/
let
appType
=
null
;
let
platform
=
uni
.
getSystemInfoSync
().
platform
;
let
hasLogin
=
loginApp
.
$store
.
state
.
hasLogin
;
console
.
log
(
loginApp
.
$store
.
state
.
hasLogin
);
if
(
platform
==
'android'
)
{
try
{
appType
=
"0"
;
api
.
postData
(
'/getAppVersion'
,
{
apptype
:
appType
,
appid
:
'__UNI__4557C88'
,
}).
then
((
res
)
=>
{
if
(
res
)
{
plus
.
runtime
.
getProperty
(
plus
.
runtime
.
appid
,
function
(
wgtinfo
)
{
let
client_version
=
parseInt
(
wgtinfo
.
version
);
let
now_version
=
parseInt
(
res
.
data
.
version
)
/* 提示版本更新 */
loginApp
.
showProcess
((
'客户端版本:'
+
client_version
+
'。'
),
30
)
loginApp
.
showProcess
((
'最新版本:'
+
now_version
+
'。'
),
40
)
let
verC
=
versionStringCompare
(
wgtinfo
.
version
,
res
.
data
.
version
+
''
);
var
flag_hot
=
true
;
console
.
log
(
verC
)
if
(
verC
>=
0
)
{
loginApp
.
showProcess
(
'无版本更新,欢迎使用格物云ERP'
,
100
)
uni
.
hideLoading
()
if
(
!
hasLogin
){
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
}
if
(
verC
<
0
)
{
loginApp
.
showProcess
(
'检测到最新版本'
,
90
)
uni
.
hideLoading
()
if
(
flag_hot
)
{
downWgt
(
res
.
data
.
url
,
loginApp
,
hasLogin
)
}
else
{
// 提醒用户更新
uni
.
showModal
({
title
:
'更新提示'
,
content
:
"当前存在最新版本,建议进行版本更新"
,
success
:
(
showResult
)
=>
{
if
(
showResult
.
confirm
)
{
loginApp
.
downLoad
=
true
var
dtask
=
plus
.
downloader
.
createDownload
(
res
.
data
.
url
,
{
method
:
'GET'
,
filename
:
'_doc/update/'
},
function
(
d
,
status
)
{
if
(
status
==
200
)
{
var
path
=
d
.
filename
;
//下载apk
plus
.
runtime
.
install
(
path
);
// 自动安装apk文件
}
else
{
plus
.
nativeUI
.
alert
(
'版本更新失败:'
+
status
);
loginApp
.
downLoad
=
false
}
});
dtask
.
addEventListener
(
"statechanged"
,
function
(
task
,
status
)
{
if
(
!
task
)
{
return
;
}
switch
(
task
.
state
)
{
case
1
:
loginApp
.
showProcess
(
'开始下载资源包'
,
0
)
break
;
case
2
:
loginApp
.
showProcess
(
'已经连接到服务器'
,
0
)
break
;
case
3
:
// 已接收到数据
let
progress
=
Math
.
floor
(
dtask
.
downloadedSize
*
100
/
dtask
.
totalSize
);
loginApp
.
showProcess
(
'正在下载'
,
progress
)
break
;
case
4
:
// 下载完成,打开文件完成更新动作.
plus
.
runtime
.
install
(
task
.
filename
);
plus
.
runtime
.
quit
()
break
;
}
},
false
);
dtask
.
start
();
}
else
{
if
(
!
hasLogin
){
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
}
}
})
}
}
});
}
}).
catch
((
err
)
=>
{
}).
finally
(()
=>
{
})
}
catch
(
e
)
{
uni
.
hideLoading
()
if
(
!
hasLogin
){
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
// loginApp.$Router.replaceAll({name:'login'})
// alert("error:" + e.message);
}
}
else
{
appType
=
"1"
;
try
{
api
.
postData
(
'/getAppVersion'
,
{
apptype
:
appType
,
appid
:
'__UNI__4557C88'
,
}).
then
((
res
)
=>
{
if
(
res
)
{
plus
.
runtime
.
getProperty
(
plus
.
runtime
.
appid
,
function
(
wgtinfo
)
{
let
client_version
=
parseInt
(
wgtinfo
.
version
);
let
now_version
=
parseInt
(
res
.
data
.
version
)
console
.
log
(
client_version
,
now_version
)
let
verC
=
versionStringCompare
(
wgtinfo
.
version
,
res
.
data
.
version
+
''
);
var
flag_hot
=
true
;
if
(
verC
>
0
)
{
loginApp
.
showProcess
(
'无版本更新,欢迎使用格物云ERP'
,
100
)
if
(
!
hasLogin
){
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
}
if
(
verC
<
0
)
{
if
(
flag_hot
)
{
downWgt
(
res
.
data
.
url
,
loginApp
,
hasLogin
)
}
else
{
uni
.
showModal
({
title
:
'更新提示'
,
content
:
"当前存在最新版本,建议进行版本更新"
,
success
:
(
showResult
)
=>
{
if
(
showResult
.
confirm
)
{
let
appurl
=
"https://itunes.apple.com/cn/app/com.gavelinfo.erp/1609168603"
plus
.
runtime
.
openURL
(
appurl
,
function
(
res
)
{
console
.
log
(
res
);
});
}
else
{
if
(
!
hasLogin
){
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
}
}
})
}
}
});
}
}).
catch
((
err
)
=>
{
}).
finally
(()
=>
{
})
}
catch
(
e
)
{
uni
.
hideLoading
()
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
}
}
function
downWgt
(
wgtUrl
,
loginApp
,
hasLogin
)
{
// plus.nativeUI.showWaiting("下载最新资源...");
uni
.
hideLoading
()
uni
.
showLoading
({
title
:
'开始热更新'
})
loginApp
.
showProcess
(
'开始版本热更新'
,
5
)
var
dtasks
=
plus
.
downloader
.
createDownload
(
wgtUrl
,
{
filename
:
"_doc/update/"
},
function
(
d
,
status
)
{
uni
.
hideLoading
()
if
(
status
==
200
)
{
console
.
log
(
"下载资源成功:"
+
d
.
filename
);
}
else
{
})
plus
.
nativeUI
.
alert
(
"下载资源失败!"
);
// loginApp.$Router.replaceAll({name:'login'})
}
plus
.
nativeUI
.
closeWaiting
();
})
if
(
!
dtasks
){
uni
.
hideLoading
()
if
(
!
hasLogin
){
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
}
}
dtasks
.
addEventListener
(
"statechanged"
,
function
(
task
,
status
)
{
if
(
!
task
)
{
return
;
}
switch
(
task
.
state
)
{
case
1
:
loginApp
.
showProcess
(
'开始下载资源包'
,
0
)
break
;
case
2
:
loginApp
.
showProcess
(
'已经连接到服务器'
,
0
)
break
;
case
3
:
// 已接收到数据
let
progress
=
Math
.
floor
(
dtasks
.
downloadedSize
*
100
/
dtasks
.
totalSize
);
loginApp
.
showProcess
(
'正在下载'
,
progress
)
break
;
case
4
:
installWgt
(
task
.
filename
,
loginApp
);
break
;
}
},
false
);
dtasks
.
start
();
}
// 更新应用资源
function
installWgt
(
path
,
loginApp
)
{
plus
.
nativeUI
.
showWaiting
(
"正在更新..."
);
plus
.
runtime
.
install
(
path
,{},
function
(){
plus
.
nativeUI
.
closeWaiting
();
console
.
log
(
"安装wgt文件成功!"
);
plus
.
nativeUI
.
alert
(
"应用资源更新完成!"
,
function
(){
plus
.
runtime
.
restart
();
});
},
function
(
e
){
plus
.
nativeUI
.
closeWaiting
();
console
.
log
(
"安装wgt文件失败["
+
e
.
code
+
"]:"
+
e
.
message
);
plus
.
nativeUI
.
alert
(
"安装wgt文件失败["
+
e
.
code
+
"]:"
+
e
.
message
);
loginApp
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
});
}
pages/login/cusmerLogin.vue
View file @
057a258a
...
...
@@ -304,13 +304,6 @@
console
.
log
(
resp
.
data
.
data
.
username
);
}
});
uni
.
setStorage
({
key
:
'ACCESS_TOKEN'
,
data
:
resp
.
data
.
data
.
token
,
success
:
function
()
{
console
.
log
(
resp
.
data
.
data
.
token
)
}
});
// 本地存储信息
uni
.
setStorage
({
key
:
'userName'
,
...
...
@@ -326,10 +319,19 @@
console
.
log
(
"用户名获取成功"
)
}
});
uni
.
setStorage
({
key
:
'ACCESS_TOKEN'
,
data
:
resp
.
data
.
data
.
token
,
success
:
function
()
{
console
.
log
(
resp
.
data
.
data
.
token
)
_this
.
$tip
.
success
(
'登录成功!'
)
_this
.
$Router
.
replaceAll
({
name
:
'index'
})
}
});
// this.$router.go(0)
//ACCESS_TOKEN
this
.
$tip
.
success
(
'登录成功!'
)
this
.
$Router
.
replaceAll
({
name
:
'index'
})
}
else
{
this
.
loading
=
false
;
this
.
$tip
.
alert
(
resp
.
data
.
message
||
"请求失败"
);
...
...
pages/login/login.vue
View file @
057a258a
...
...
@@ -240,13 +240,7 @@
console
.
log
(
res
.
data
.
data
.
username
);
}
});
uni
.
setStorage
({
key
:
'ACCESS_TOKEN'
,
data
:
res
.
data
.
data
.
token
,
success
:
function
()
{
console
.
log
(
res
.
data
.
data
.
token
)
}
});
// 本地存储信息
uni
.
setStorage
({
key
:
'userName'
,
...
...
@@ -262,17 +256,19 @@
console
.
log
(
"用户名获取成功"
)
}
});
uni
.
setStorage
({
key
:
'ACCESS_TOKEN'
,
data
:
res
.
data
.
data
.
token
,
success
:
function
()
{
_this
.
$tip
.
success
(
'登录成功!'
)
_this
.
$Router
.
replaceAll
({
name
:
'index'
})
console
.
log
(
res
.
data
.
data
.
token
)
}
});
//ACCESS_TOKEN
this
.
$tip
.
success
(
'登录成功!'
)
this
.
$Router
.
replaceAll
({
name
:
'index'
})
// #ifdef APP-PLUS
// this.saveClientId()
// #endif
// #ifndef APP-PLUS
this
.
$tip
.
success
(
'登录成功!'
)
this
.
$Router
.
replaceAll
({
name
:
'index'
})
// #endif
}
else
{
this
.
loading
=
false
;
this
.
$tip
.
alert
(
res
.
data
.
message
);
...
...
pages/login/update.vue
0 → 100644
View file @
057a258a
<
template
>
<view
class=
"page uodateMain"
>
<!-- 升级模态框 -->
<view
class=
"text-center"
>
<image
:src=
"imgsrc"
mode=
'aspectFit'
class=
"zai-logo "
></image>
<view
class=
"zai-title text-shadow"
>
欢迎格物云ERP
</view>
</view>
<!-- 进度条 -->
<view
class=
"progress"
>
<view
class=
"tips"
>
tips:
{{
text
}}
</view>
<view
class=
""
>
<view
class=
"uni-padding-wrap uni-common-mt"
>
<view
class=
"progress-box"
>
<progress
:percent=
"percent"
activeColor=
"#10AEFF"
stroke-width=
"8"
/>
</view>
<view
class=
"percent"
>
{{
percent
}}
%
</view>
</view>
</view>
</view>
</view>
</
template
>
<
script
>
import
appUpdate
from
'common/util/appUpdate.js'
export
default
{
onLoad
()
{
// this.showLoading()
// #ifdef APP-PLUS
setTimeout
(()
=>
{
appUpdate
(
this
)
},
500
)
// #endif
// #ifdef H5
this
.
$Router
.
replaceAll
({
name
:
'cusmerLogin'
})
// #endif
},
data
()
{
return
{
downLoad
:
false
,
imgsrc
:
"/static/image/logon.png"
,
percent
:
0
,
text
:
'正在检测版本'
}
},
methods
:
{
/* 修改进度 */
showProcess
(
text
,
percent
){
this
.
text
=
text
this
.
percent
=
percent
},
showLoading
(){
uni
.
showLoading
({
title
:
this
.
text
})
},
hideLoading
(){
uni
.
hideLoading
()
}
}
}
</
script
>
<
style
>
.percent
{
height
:
25px
;
line-height
:
25px
;
text-align
:
center
;
font-size
:
12px
;
}
.tips
{
height
:
30px
;
font-size
:
12px
;
}
.progress
{
width
:
100%
;
position
:
absolute
;
bottom
:
4vh
;
padding
:
20px
;
}
.zai-title
{
font-size
:
20px
;
color
:
#000000
;
text-align
:
center
;
}
.uodateMain
{
height
:
100vh
;
width
:
100vw
;
padding-top
:
80px
;
background-color
:
#fff
;
}
.zai-logo
{
/* width: 200upx; */
height
:
200
upx
;
}
</
style
>
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