Browse Source

增加app 更新,手动检查更新

pull/1/head
lijuncheng 11 months ago
parent
commit
d5d27b5eb2
  1. 9
      src/App.vue
  2. 13
      src/api/request2.js
  3. 116
      src/common/appUpdate.js
  4. 6
      src/pages/login/index.vue
  5. 120
      src/pages/setter/index.vue
  6. 2
      src/uni_modules/vk-uview-ui/components/u-cell-item/u-cell-item.vue

9
src/App.vue

@ -1,6 +1,13 @@
<script> <script>
// #ifdef APP-PLUS
import {
appUpdate
} from "@/common/appUpdate.js"
// #endif
export default { export default {
onLaunch: function() { onLaunch: function() {
console.log('App Launch') console.log('App Launch')
// , // ,
// #ifdef APP-PLUS // #ifdef APP-PLUS
@ -11,7 +18,9 @@
// plus.screen.lockOrientation('landscape-primary'); // plus.screen.lockOrientation('landscape-primary');
// // app // // app
// plus.screen.lockOrientation('portrait-primary'); // plus.screen.lockOrientation('portrait-primary');
appUpdate();
// #endif // #endif
}, },
onShow: function() { onShow: function() {
console.log('App Show') console.log('App Show')

13
src/api/request2.js

@ -3635,3 +3635,16 @@ export function getMainMessage() {
data: {}, data: {},
}); });
} }
/**
* app检查更新
* @param {*}
*
*/
export function appCheckUpdate() {
return uni.request({
url:"http://192.168.0.119:9527/appUpdate.json",
method:"GET",
data:{}
})
}

116
src/common/appUpdate.js

@ -0,0 +1,116 @@
import {
appCheckUpdate
} from '../api/request2.js';
export function appUpdate() {
let curversion = 0;
plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
const data = {
action: 'checkVersion',
appid: plus.runtime.appid,
appVersion: plus.runtime.version,
wgtVersion: widgetInfo.version,
versionCode: widgetInfo.versionCode
}
curversion=data.versionCode
appCheckUpdate().then(res => {
console.log("当前版本提示",curversion)
if (res.data) {
if (res.data.versionCode > Number(curversion)) {
var downUrl = res.data.downUrl;
var content = res.data.content;
var version =res.data.version
console.log("新版本提示")
uni.showModal({
title: "发现新版本:("+version+")",
content: content,
confirmText: "更新",
cancelText: "取消",
success: (res) => {
if (res.confirm) {
confirm(downUrl);
console.log('comfirm') //点击确定之后执行的代码
} else {
console.log('cancel') //点击取消之后执行的代码
}
}
})
} else {
uni.showToast({
title:"当前是最新版本"
})
console.log("没有新版本")
}
}
}).catch(error => {
console.log("版本错误", error)
})
})
}
export function confirm(downUrl) {
var downloadApkUrl = downUrl
var dtask = plus.downloader.createDownload(downloadApkUrl, {},
function(d, status) {
// 下载完成
if (status == 200) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(
d.filename), {}, {}, function(error) {
uni.showToast({
title: '安装失败',
duration: 1500
});
})
} else {
uni.showToast({
title: '更新失败',
duration: 1500
});
}
});
try {
dtask.start(); // 开启下载的任务
var prg = 0;
var showLoading = plus.nativeUI.showWaiting(
"正在下载"); //创建一个showWaiting对象
dtask.addEventListener('statechanged', function(
task,
status
) {
// 给下载任务设置一个监听 并根据状态 做操作
switch (task.state) {
case 1:
showLoading.setTitle("正在下载");
break;
case 2:
showLoading.setTitle("已连接到服务器");
break;
case 3:
prg = parseInt(
(parseFloat(task.downloadedSize) /
parseFloat(task.totalSize)) *
100
);
showLoading.setTitle(" 正在下载" + prg + "% ");
break;
case 4:
plus.nativeUI.closeWaiting();
//下载完成
break;
}
});
} catch (err) {
plus.nativeUI.closeWaiting();
uni.showToast({
title: '更新失败-03',
mask: false,
duration: 1500
});
}
}

6
src/pages/login/index.vue

@ -36,7 +36,7 @@
用户名 用户名
</view> </view>
<view> <view>
<input class="uni-input" placeholder="请输入用户名" v-model="username" /> <input class="uni-input" style="padding:25rpx" placeholder="请输入用户名" v-model="username" />
</view> </view>
</view> </view>
<view class="conone"> <view class="conone">
@ -44,8 +44,8 @@
<image class="icon_normal" src="../../static/icons_ui/icon_login_password.svg"></image> <image class="icon_normal" src="../../static/icons_ui/icon_login_password.svg"></image>
密码 密码
</view> </view>
<view class="uni-input-wrapper"> <view class="uni-input-wrapper" >
<input class="uni-input" placeholder="请输入密码" :password="showPassword" <input class="uni-input" style="padding:25rpx" placeholder="请输入密码" :password="showPassword"
v-model="password" /> v-model="password" />
<text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']" <text class="uni-icon" :class="[!showPassword ? 'uni-eye-active' : '']"
@click="changePassword">&#xe568;</text> @click="changePassword">&#xe568;</text>

120
src/pages/setter/index.vue

@ -4,30 +4,22 @@
<image src="/static/avatar.png" class="tx"></image> <image src="/static/avatar.png" class="tx"></image>
<!-- <view class="text">admin</view> --> <!-- <view class="text">admin</view> -->
</view> </view>
<view> <view class="">
<uni-list> <u-cell-group >
<!-- <uni-list-item title="工号" clickable @click="onClick" :rightText="usermsg.phoneNumber"></uni-list-item> --> <u-cell-item icon="account-fill" title="姓名" :arrow="false">{{userName}}</u-cell-item>
<uni-list-item title="姓名" clickable :rightText="userName" thumb="/static/icon_personal_name.png"> <u-cell-item v-if="userInfo!=null" icon="file-text" title="部门" :arrow="false">{{userInfo.dept.name}}</u-cell-item>
</uni-list-item> <u-cell-item v-if="userInfo!=null" icon="photo" title="岗位" :arrow="false">{{(userInfo.posts || []).map(post => post.name).join(',')}}</u-cell-item>
<u-cell-item icon="level" v-if="userInfo!=null" title="角色" :arrow="false">{{(userInfo.roles || []).map(role => role.name).join(',')}}</u-cell-item>
<uni-list-item v-if="userInfo!=null" title="部门" :rightText="userInfo.dept.name" <u-cell-item icon="trash" title="清除缓存" @click="clear()" ></u-cell-item>
thumb="/static/icon_personal_password.png"></uni-list-item> <u-cell-item icon="edit-pen" title="修改密码" @click="modifiedPassWord()" ></u-cell-item>
<uni-list-item v-if="userInfo!=null" title="岗位" <u-cell-item icon="order" title="版本号" :arrow="false">{{version}}</u-cell-item>
:rightText="(userInfo.posts || []).map(post => post.name).join(',')" <!-- #ifdef APP -->
thumb="/static/icon_personal_password.png"></uni-list-item> <u-cell-item icon="reload" title="检查更新" @click="update">{{version}}</u-cell-item>
<uni-list-item v-if="userInfo!=null" title="角色" <!-- #endif -->
:rightText="(userInfo.roles || []).map(role => role.name).join(',')"
thumb="/static/icon_personal_password.png"></uni-list-item> </u-cell-group>
<uni-list-item title="" clickable rightText="清除缓存" thumb="/static/icon_personal_name.png"
@click="clear"></uni-list-item>
<uni-list-item rightText="修改密码" link to="/pages/setter/passwordpage"
thumb="/static/icon_personal_password.png"></uni-list-item>
<!-- <uni-list-item title="服务器地址"
thumb="/static/icon_personal_password.png"></uni-list-item> -->
<!-- <uni-list-item title="参数设置" link to="/pages/setter/setterDetail"
thumb="/static/icon_personal_setting.png"></uni-list-item> -->
</uni-list>
</view> </view>
<view> <view>
<button class="footbtn" @click="handlerlogout">退出登录</button> <button class="footbtn" @click="handlerlogout">退出登录</button>
</view> </view>
@ -47,20 +39,31 @@
import { import {
removeToken removeToken
} from '@/common/utils/auth' } from '@/common/utils/auth'
// #ifdef APP-PLUS
import {
appUpdate
} from "@/common/appUpdate.js"
// #endif
import { import {
ref, ref,
reactive, reactive,
nextTick nextTick,
createApp
} from "vue"; } from "vue";
import { import {
onLoad onLoad
} from "@dcloudio/uni-app"; } from "@dcloudio/uni-app";
const app = createApp({});
// app.component({
// });
const userName = ref(store.state.user.name); const userName = ref(store.state.user.name);
let test = ref("123"); let test = ref("123");
let version = ref();
let userInfo = ref(null); let userInfo = ref(null);
onLoad(() => { onLoad(() => {
getAppVersion()
getUserProfile().then(res => { getUserProfile().then(res => {
userInfo.value = res.data userInfo.value = res.data
// nextTick(()=>{ // nextTick(()=>{
@ -75,15 +78,23 @@
function handlerlogout() { function handlerlogout() {
store.dispatch('LogOut', {}).then(() => { store.dispatch('LogOut', {}).then(() => {
clearStorage(); clearStorage();
// #ifdef H5
uni.reLaunch({ uni.reLaunch({
url: '../login/index' url: '../login/index'
}) })
// #endif
// #ifdef APP
plus.runtime.quit()
// #endif
}) })
}; };
function clearStorage() { function clearStorage() {
uni.clearStorageSync() uni.clearStorageSync()
removeToken(); removeToken();
}; };
function clear() { function clear() {
@ -93,44 +104,29 @@
}) })
} }
function getAppVersion() {
const systemInfo = uni.getSystemInfoSync();
// #ifdef H5
version.value = systemInfo.appVersion;
console.log(systemInfo.appVersion, '版本号');
// #endif
// #ifdef APP
version.value = systemInfo.appWgtVersion;
// #endif
}
function update() {
console.log("update");
appUpdate()
}
function modifiedPassWord() {
uni.navigateTo({
url:"./passwordpage"
})
}
// export default {
// data() {
// return {
// userName: '',
// usermsg: {}
// }
// },
// onLoad() {
// },
// created() {
// this.userName = this.$store.getters.name
// },
// methods: {
// handlerlogout() {
// this.$store.dispatch('LogOut', params).then(() => {
// uni.reLaunch({
// url: '../login/index'
// })
// this.clearStorage();
// })
// },
// clearStorage() {
// uni.clearStorageSync()
// localStorage.clear();
// sessionStorage.clear();
// removeToken();
// },
// clear(){
// clearCacheData()
// uni.showToast({
// title:""
// })
// }
// }
// }
</script> </script>
<style> <style>

2
src/uni_modules/vk-uview-ui/components/u-cell-item/u-cell-item.vue

@ -221,7 +221,7 @@ export default {
width: 100%; width: 100%;
padding: 10rpx 10rpx 10rpx 10rpx ; padding: 10rpx 10rpx 10rpx 10rpx ;
font-size: 30rpx; font-size: 30rpx;
line-height: 40rpx; line-height: 60rpx;
color: $u-content-color; color: $u-content-color;
background-color: #fff; background-color: #fff;
text-align: left; text-align: left;

Loading…
Cancel
Save