App.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <script>
  2. import md5Libs from "uview-ui/libs/function/md5";
  3. export default {
  4. onLaunch: async function() {
  5. console.log('uview 版本', this.$u.config.v);
  6. // #ifdef H5
  7. if(window.location.hash != ''){
  8. let search = window.location.search.substring(1);
  9. try{
  10. if(search.indexOf('hashpath') != -1){
  11. let sea = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
  12. if(sea.hashpath && sea.code && sea.state){
  13. window.location.href = window.location.origin + window.location.pathname+'#'+sea.hashpath+'?code='+sea.code+'&state='+sea.state
  14. }
  15. }
  16. }catch(e){
  17. //TODO handle the exception
  18. }
  19. }
  20. // #endif
  21. let res = await this.$api.getConfig();
  22. if (!res.code) {
  23. return;
  24. }
  25. //主题做缓存
  26. let theme_key = md5Libs.md5(res.data.theme);
  27. if(!this.vuex_theme.key || this.vuex_theme.key != theme_key){
  28. this.$u.vuex('vuex_theme', {key:theme_key,value:res.data.theme});
  29. }
  30. this.$u.vuex('vuex_config', res.data);
  31. // #ifdef APP-PLUS
  32. let tabbar = this.$u.deepClone(this.vuex_config.tabbar);
  33. if (!tabbar) {
  34. this.$util.setTabbar(this.vuex_tabbar);
  35. return;
  36. }
  37. let num = 0;
  38. for (let i in tabbar.list) {
  39. try {
  40. let imagepath = await this.$util.image_cache(tabbar.list[i].image);
  41. let selectedImage = await this.$util.image_cache(tabbar.list[i].selectedImage);
  42. tabbar.list[i].image = imagepath;
  43. tabbar.list[i].selectedImage = selectedImage;
  44. num = i;
  45. } catch (e) {
  46. console.log(e);
  47. }
  48. }
  49. //全部下载成功使用服务器的导航,否则启用本地备用导航
  50. if (parseInt(num) + 1 == tabbar.list.length) {
  51. this.$util.setTabbar(tabbar);
  52. } else {
  53. this.$util.setTabbar(this.vuex_tabbar);
  54. }
  55. // #endif
  56. // #ifdef APP-PLUS
  57. let that=this;
  58. plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
  59. console.log(that.$u.http.config.baseUrl);
  60. console.log(widgetInfo.version);
  61. uni.request({
  62. url: that.$u.http.config.baseUrl+'/addons/cms/api.common/version',
  63. data: {
  64. version: widgetInfo.version,
  65. },
  66. success: (result) => {
  67. console.log(result);
  68. var data = result.data.data;
  69. if (data.update && data.wgtUrl) {
  70. uni.showModal({
  71. title: '更新提示',
  72. content: '有新的版本更新,请确认',
  73. showCancel: false,
  74. success(resmodal) {
  75. if(resmodal.confirm){
  76. plus.runtime.openURL(data.wgtUrl)
  77. }
  78. }
  79. })
  80. }
  81. // 只有apk包的时间
  82. if (data.update && data.pkgUrl && !data.wgtUrl) {
  83. uni.showModal({
  84. title: '更新提示',
  85. content: '有新的版本更新,请确认',
  86. showCancel: false,
  87. })
  88. var dtask = plus.downloader.createDownload(data.pkgUrl, {}, function(d, status) {
  89. // 下载完成
  90. if (status == 200) {
  91. plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(error) {
  92. uni.showToast({
  93. title: '安装失败',
  94. mask: false,
  95. duration: 1500
  96. });
  97. })
  98. } else {
  99. uni.showToast({
  100. title: '下载失败',
  101. mask: false,
  102. duration: 1500
  103. });
  104. }
  105. });
  106. dtask.start();
  107. }
  108. }
  109. });
  110. });
  111. // #endif
  112. },
  113. onShow: function() {
  114. console.log('App Show');
  115. },
  116. onHide: function() {
  117. console.log('App Hide');
  118. }
  119. };
  120. </script>
  121. <style lang="scss">
  122. @import 'uview-ui/index.scss';
  123. /*每个页面公共css */
  124. .u-bg-white {
  125. background-color: #ffffff;
  126. }
  127. .u-text-weight {
  128. font-weight: bold;
  129. }
  130. .u-line-height {
  131. line-height: 50rpx;
  132. }
  133. //数据为空的样式
  134. .fa-empty {
  135. padding-top: 45%;
  136. }
  137. .share-btn {
  138. padding: 0;
  139. margin: 0;
  140. border: 0;
  141. background-color: transparent;
  142. line-height: inherit;
  143. border-radius: 0;
  144. font-size: inherit;
  145. color: #999;
  146. }
  147. .share-btn::after {
  148. border: none;
  149. }
  150. // #ifdef MP-BAIDU
  151. .u-radio__icon-wrap,.u-checkbox__icon-wrap{
  152. line-height: 0;
  153. }
  154. // #endif
  155. </style>