App.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <script>
  2. export default {
  3. data() {
  4. return {
  5. getOn:true,
  6. }
  7. },
  8. onLaunch: function(param) {
  9. },
  10. onShow: function() {
  11. // #ifdef MP
  12. // 检查是否升级
  13. this.checkForUpdate();
  14. // #endif
  15. // 进入小程序,如果需要推送客服,请求客户信息,获取最新的微伴ID
  16. if( this.$checkAccess.getFollowQrcode() ){
  17. if( !this.getOn ) return ;
  18. this.getOn = false;
  19. // 判断数据
  20. this.$http.request('api/custom/get_info').then((callback)=>{
  21. this.getOn = true;
  22. if( callback.code == 'success' ){
  23. if( !callback.data.userpic ) callback.data.userpic = "../../static/icon/doctor.png";
  24. // 赋值
  25. this.userInfo = callback.data;
  26. // 存储登录标识
  27. uni.setStorageSync('userInfo',callback.data);
  28. }
  29. });
  30. }
  31. },
  32. onHide: function() {
  33. console.log('App Hide');
  34. },
  35. methods:{
  36. // 检查是否升级
  37. checkForUpdate(){
  38. const _this = this;
  39. // 获取升级管理实例
  40. const updateManager = uni.getUpdateManager();
  41. // 请求版本回调
  42. updateManager.onCheckForUpdate(function(res){
  43. console.log(res);
  44. // 如果有版本升级
  45. if( res && res.hasUpdate ){
  46. uni.showModal({
  47. title:"更新提示",
  48. content:"检测到新版,点击确认升级程序",
  49. showCancel:false,
  50. success(res){
  51. if(res.confirm){
  52. uni.showLoading({title:"程序更新中"});
  53. // 判断是否准备好升级
  54. updateManager.onUpdateReady(function(res){
  55. // 关闭加载
  56. uni.hideLoading();
  57. // 当新版本下载完成,调用该方法会强制当前uni-app应用上新版本并重启
  58. updateManager.applyUpdate();
  59. })
  60. updateManager.onUpdateFailed(function(err){
  61. // 关闭加载
  62. uni.hideLoading();
  63. })
  64. }
  65. }
  66. })
  67. }
  68. })
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="less">
  74. /*每个页面公共css */
  75. page{
  76. font-family: Arial, Helvetica, sans-serif;
  77. background: #F5F5F5;
  78. }
  79. // 到底了
  80. .to_bottom{
  81. height: 40rpx;
  82. color: #999999;
  83. display: block;
  84. font-size: 20rpx;
  85. margin-top: 20rpx;
  86. line-height: 40rpx;
  87. text-align: center;
  88. padding-bottom: 160rpx;
  89. }
  90. </style>