feat: 打包成apk时支持版本升级
This commit is contained in:
parent
c3947502da
commit
c481034133
|
@ -5,43 +5,49 @@
|
||||||
</uni-segmented-control>
|
</uni-segmented-control>
|
||||||
<view style="height: 8rpx;"></view>
|
<view style="height: 8rpx;"></view>
|
||||||
<uni-section>
|
<uni-section>
|
||||||
<view v-if="current==0" style="background-color;:white">
|
<view v-if="current==0" style="background-color;:white">
|
||||||
<uni-forms ref="form1" :modelValue="formData" label-position="left" border :rules="rules1">
|
<uni-forms ref="form1" :modelValue="formData" label-position="left" border :rules="rules1">
|
||||||
<uni-forms-item required label="用户名" name="username">
|
<uni-forms-item required label="用户名" name="username">
|
||||||
<uni-easyinput type="text" v-model="formData.username" placeholder="请输入用户名" />
|
<uni-easyinput type="text" v-model="formData.username" placeholder="请输入用户名" />
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
<uni-forms-item required label="密码" name="password">
|
<uni-forms-item required label="密码" name="password">
|
||||||
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入密码" />
|
<uni-easyinput type="password" v-model="formData.password" placeholder="请输入密码" />
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
</uni-forms>
|
</uni-forms>
|
||||||
</view>
|
</view>
|
||||||
<view v-if="current==1" style="background-color;:white">
|
<view v-if="current==1" style="background-color;:white">
|
||||||
<uni-forms ref="form2" :modelValue="formData2" label-position="left" border :rules="rules2">
|
<uni-forms ref="form2" :modelValue="formData2" label-position="left" border :rules="rules2">
|
||||||
<uni-forms-item label="手机号" name="phone" required>
|
<uni-forms-item label="手机号" name="phone" required>
|
||||||
<uni-easyinput type="number" v-model="formData2.phone" placeholder="请输入手机号" />
|
<uni-easyinput type="number" v-model="formData2.phone" placeholder="请输入手机号" />
|
||||||
</uni-forms-item>
|
</uni-forms-item>
|
||||||
<uni-forms-item label="验证码" name="code" required>
|
<uni-forms-item label="验证码" name="code" required>
|
||||||
<view style="display: flex;">
|
<view style="display: flex;">
|
||||||
<view style="width: 60%;">
|
<view style="width: 60%;">
|
||||||
<uni-easyinput type="number" v-model="formData2.code" placeholder="请输入验证码" />
|
<uni-easyinput type="number" v-model="formData2.code" placeholder="请输入验证码" />
|
||||||
|
</view>
|
||||||
|
<view style="width: 40%;display: flex;justify-content: center;align-items: center;">
|
||||||
|
<span @click="getCode">{{content}}</span>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view style="width: 40%;display: flex;justify-content: center;align-items: center;">
|
</uni-forms-item>
|
||||||
<span @click="getCode">{{content}}</span>
|
</uni-forms>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
|
||||||
</uni-forms-item>
|
|
||||||
</uni-forms>
|
|
||||||
</view>
|
|
||||||
</uni-section>
|
</uni-section>
|
||||||
<button style="background-color:#2979ff;color:white" @click="login(current)">登录</button>
|
<button style="background-color:#2979ff;color:white" @click="login(current)">登录</button>
|
||||||
<!-- <view style="text-align: center;margin-top: 20rpx;">
|
<!-- <view style="text-align: center;margin-top: 20rpx;">
|
||||||
<uni-icons type="weixin" size="36" color="green" @click="wxmpLogin"></uni-icons>
|
<uni-icons type="weixin" size="36" color="green" @click="wxmpLogin"></uni-icons>
|
||||||
<view style="text-align: center;font-size: 32rpx;">微信登陆</view>
|
<view style="text-align: center;font-size: 32rpx;">微信登陆</view>
|
||||||
</view> -->
|
</view> -->
|
||||||
|
<view v-show="dShow" style="position: fixed;top: 0;left: 0;width: 100%;height: 100%;background: rgba(0, 0, 0, .5);z-index: 999;">
|
||||||
|
<view style="position: absolute;padding: 50rpx;background: #ffffff;display: inline-block;margin: auto;top: 40%;left: 50%;transform: translateX(-50%);">
|
||||||
|
下载中 请勿退出 {{percentVal}}%
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import config from '/utils/config';
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
@ -52,7 +58,7 @@
|
||||||
formData2: {},
|
formData2: {},
|
||||||
timer: null,
|
timer: null,
|
||||||
time: 30,
|
time: 30,
|
||||||
rules1:{
|
rules1: {
|
||||||
username: {
|
username: {
|
||||||
rules: [{
|
rules: [{
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -66,7 +72,7 @@
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
rules2:{
|
rules2: {
|
||||||
phone: {
|
phone: {
|
||||||
rules: [{
|
rules: [{
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -80,17 +86,17 @@
|
||||||
}]
|
}]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
wxmp_openid: null
|
wxmp_openid: null,
|
||||||
|
dShow: false,
|
||||||
|
percentVal: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
var that = this
|
var that = this
|
||||||
var autoLoading = options.autoLoading;
|
var autoLoading = options.autoLoading;
|
||||||
if(autoLoading != 'no'){
|
that.checkVersion();
|
||||||
// #ifdef APP-PLUS
|
if (autoLoading != 'no') {
|
||||||
that.appLogin()
|
// #ifdef APP-PLUS || H5
|
||||||
// #endif
|
|
||||||
// #ifdef H5
|
|
||||||
that.appLogin()
|
that.appLogin()
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
|
@ -110,6 +116,82 @@
|
||||||
// #endif
|
// #endif
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
checkVersion() {
|
||||||
|
let that = this;
|
||||||
|
uni.getSystemInfo({
|
||||||
|
success(res) {
|
||||||
|
uni.setStorageSync("vuex_version", res.appVersion)
|
||||||
|
// #ifdef APP-PLUS
|
||||||
|
if (res.platform == 'android') {
|
||||||
|
that.$api.apkCheck().then(res1 => {
|
||||||
|
if (res.appWgtVersion != res1.version) {
|
||||||
|
uni.showModal({
|
||||||
|
title: "版本更新",
|
||||||
|
content: '有新的版本发布, 请下载新版本',
|
||||||
|
confirmText: '立即更新',
|
||||||
|
cancelText: '稍后进行',
|
||||||
|
success: function(res2) {
|
||||||
|
if (res2.confirm) {
|
||||||
|
let fullurl = res1.file
|
||||||
|
if (res1.file.indexOf("http") == -1) {
|
||||||
|
fullurl = config.baseUrl + res1.file
|
||||||
|
}
|
||||||
|
that.dShow =
|
||||||
|
true // show变量控制一个下载进度弹框(这个UI样式自己写即可)
|
||||||
|
uni.hideTabBar()
|
||||||
|
// 创建一个下载任务,并根据后端返回的apk静态资源地址filePath进行下载
|
||||||
|
var dtask = plus.downloader.createDownload(
|
||||||
|
fullurl, {},
|
||||||
|
function(d, status) {
|
||||||
|
// 下载完成
|
||||||
|
if (status == 200) {
|
||||||
|
that.dShow =
|
||||||
|
false // 下载完成再把下载进度弹框关闭即可
|
||||||
|
uni.showTabBar();
|
||||||
|
plus.runtime.install(plus.io
|
||||||
|
.convertLocalFileSystemURL(
|
||||||
|
d
|
||||||
|
.filename), {}, {},
|
||||||
|
function(error) {
|
||||||
|
uni.showToast({
|
||||||
|
title: '安装失败',
|
||||||
|
duration: 1500
|
||||||
|
});
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
uni.showToast({
|
||||||
|
title: '更新失败',
|
||||||
|
duration: 1500
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function onStateChanged(download, status) {
|
||||||
|
|
||||||
|
if (status == 200) {
|
||||||
|
const totalSize = download.totalSize
|
||||||
|
let nowSize = download.downloadedSize
|
||||||
|
that.percentVal = nowSize / 17700000 *
|
||||||
|
100 > 99 ? 99 : (nowSize /
|
||||||
|
17700000 * 100).toFixed(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
dtask.addEventListener("statechanged",
|
||||||
|
onStateChanged, false);
|
||||||
|
dtask.start();
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
// #endif
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
wxmpLogin() {
|
wxmpLogin() {
|
||||||
var that = this;
|
var that = this;
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
|
@ -119,20 +201,22 @@
|
||||||
uni.login({
|
uni.login({
|
||||||
provider: 'weixin',
|
provider: 'weixin',
|
||||||
success: (loginRes) => {
|
success: (loginRes) => {
|
||||||
that.$api.wxmpLogin({code: loginRes.code}).then(res=>{
|
that.$api.wxmpLogin({
|
||||||
|
code: loginRes.code
|
||||||
|
}).then(res => {
|
||||||
uni.setStorageSync('access', res.access)
|
uni.setStorageSync('access', res.access)
|
||||||
that.$api.getUserInfo().then(res=>{
|
that.$api.getUserInfo().then(res => {
|
||||||
uni.setStorageSync('userInfo', res)
|
uni.setStorageSync('userInfo', res)
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/index/index'
|
url: '/pages/index/index'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}).catch(e => {
|
||||||
|
this.wxmp_openid = e.data.wxmp_openid
|
||||||
})
|
})
|
||||||
}).catch(e=>{
|
|
||||||
this.wxmp_openid = e.data.wxmp_openid
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
complete:function(){
|
complete: function() {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -151,7 +235,7 @@
|
||||||
if (secret) {
|
if (secret) {
|
||||||
that.$api.loginSecret(JSON.parse(secret)).then(res => {
|
that.$api.loginSecret(JSON.parse(secret)).then(res => {
|
||||||
uni.setStorageSync('access', res.access)
|
uni.setStorageSync('access', res.access)
|
||||||
that.$api.getUserInfo().then(res=>{
|
that.$api.getUserInfo().then(res => {
|
||||||
uni.setStorageSync('userInfo', res)
|
uni.setStorageSync('userInfo', res)
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/index/index'
|
url: '/pages/index/index'
|
||||||
|
@ -160,10 +244,10 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
complete:function(){
|
complete: function() {
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
},
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onClickItem(e) {
|
onClickItem(e) {
|
||||||
|
@ -205,11 +289,11 @@
|
||||||
},
|
},
|
||||||
login() {
|
login() {
|
||||||
var that = this;
|
var that = this;
|
||||||
if(that.current == 1){
|
if (that.current == 1) {
|
||||||
that.$refs.form2.validate().then(res0=>{
|
that.$refs.form2.validate().then(res0 => {
|
||||||
that.$api.codeLogin(res0).then(res=>{
|
that.$api.codeLogin(res0).then(res => {
|
||||||
uni.setStorageSync('access', res.access)
|
uni.setStorageSync('access', res.access)
|
||||||
that.$api.getUserInfo().then(res=>{
|
that.$api.getUserInfo().then(res => {
|
||||||
uni.setStorageSync('userInfo', res)
|
uni.setStorageSync('userInfo', res)
|
||||||
that.bindXX()
|
that.bindXX()
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
|
@ -217,23 +301,22 @@
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(err =>{
|
}).catch(err => {
|
||||||
console.log('表单错误信息:', err);
|
console.log('表单错误信息:', err);
|
||||||
})
|
})
|
||||||
}
|
} else if (that.current == 0) {
|
||||||
else if(that.current == 0){
|
that.$refs.form1.validate().then(res0 => {
|
||||||
that.$refs.form1.validate().then(res0=>{
|
that.$api.login(res0).then(res => {
|
||||||
that.$api.login(res0).then(res=>{
|
|
||||||
uni.setStorageSync('access', res.access)
|
uni.setStorageSync('access', res.access)
|
||||||
that.bindXX()
|
that.bindXX()
|
||||||
that.$api.getUserInfo().then(res=>{
|
that.$api.getUserInfo().then(res => {
|
||||||
uni.setStorageSync('userInfo', res)
|
uni.setStorageSync('userInfo', res)
|
||||||
uni.reLaunch({
|
uni.reLaunch({
|
||||||
url: '/pages/index/index'
|
url: '/pages/index/index'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}).catch(err =>{
|
}).catch(err => {
|
||||||
console.log('表单错误信息:', err);
|
console.log('表单错误信息:', err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -241,17 +324,17 @@
|
||||||
ranStr(e) {
|
ranStr(e) {
|
||||||
//形参e,需要产生随机字符串的长度
|
//形参e,需要产生随机字符串的长度
|
||||||
//如果没有传参,默认生成32位长度随机字符串
|
//如果没有传参,默认生成32位长度随机字符串
|
||||||
e = e || 32;
|
e = e || 32;
|
||||||
//模拟随机字符串库
|
//模拟随机字符串库
|
||||||
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789",
|
var t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz0123456789",
|
||||||
a = t.length,//字符串t的长度,随机数生成最大值
|
a = t.length, //字符串t的长度,随机数生成最大值
|
||||||
n = "";
|
n = "";
|
||||||
for (let i = 0; i < e; i++) {
|
for (let i = 0; i < e; i++) {
|
||||||
//随机生成长度为e的随机字符串拼接
|
//随机生成长度为e的随机字符串拼接
|
||||||
n += t.charAt(Math.floor(Math.random() * a));
|
n += t.charAt(Math.floor(Math.random() * a));
|
||||||
}
|
}
|
||||||
//返回随机组合字符串
|
//返回随机组合字符串
|
||||||
return n
|
return n
|
||||||
},
|
},
|
||||||
bindXX() {
|
bindXX() {
|
||||||
let that = this;
|
let that = this;
|
||||||
|
@ -282,9 +365,11 @@
|
||||||
}).catch(e => {})
|
}).catch(e => {})
|
||||||
// #endif
|
// #endif
|
||||||
// #ifdef MP-WEIXIN
|
// #ifdef MP-WEIXIN
|
||||||
if(this.wxmp_openid != null) {
|
if (this.wxmp_openid != null) {
|
||||||
this.$api.bindWxmp({"openid": this.wxmp_openid}).then(res=>{
|
this.$api.bindWxmp({
|
||||||
|
"openid": this.wxmp_openid
|
||||||
|
}).then(res => {
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// #endif
|
// #endif
|
||||||
|
@ -295,4 +380,4 @@
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
</style>
|
</style>
|
|
@ -11,6 +11,8 @@ export default {
|
||||||
codeLogin:(data) => http('/auth/login_sms_code/', 'POST', data),
|
codeLogin:(data) => http('/auth/login_sms_code/', 'POST', data),
|
||||||
wxmpLogin: (data) => http('/auth/login_wxmp/', 'POST', data, true, false), //微信小程序登录
|
wxmpLogin: (data) => http('/auth/login_wxmp/', 'POST', data, true, false), //微信小程序登录
|
||||||
wxmpClogin: (data) => http('/auth/login_wxmp/', 'POST', data, true, false), //微信小程序登录(自动创建账号)
|
wxmpClogin: (data) => http('/auth/login_wxmp/', 'POST', data, true, false), //微信小程序登录(自动创建账号)
|
||||||
|
apkCheck: ()=>http('/system/apk/'), //apk检查
|
||||||
|
|
||||||
getTicket:(data) => http('/wf/ticket/', 'GET', data),
|
getTicket:(data) => http('/wf/ticket/', 'GET', data),
|
||||||
ticketCreate:(data)=>http('/wf/ticket/', 'POST', data),
|
ticketCreate:(data)=>http('/wf/ticket/', 'POST', data),
|
||||||
ticketHandle:(id,data)=>http(`/wf/ticket/${id}/handle/`, 'POST', data),
|
ticketHandle:(id,data)=>http(`/wf/ticket/${id}/handle/`, 'POST', data),
|
||||||
|
|
Loading…
Reference in New Issue