App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. const that = this;
  5. that.forceUpdate();
  6. },
  7. onShow: function() {
  8. const that = this;
  9. that.search();
  10. },
  11. onHide: function() {
  12. console.log('App Hide')
  13. },
  14. methods: {
  15. search() {
  16. const that = this;
  17. uni.login({
  18. success: function(res) {
  19. if (res.code) {
  20. uni.getStorage({
  21. key: 'openid',
  22. success: function(res) {},
  23. fail: async function(err) {
  24. const aee = await that.$api('/tool/app', 'GET', {
  25. js_code: res.code,
  26. config: that.$config.wx_projectkey
  27. })
  28. if (aee.errcode == '0') {
  29. uni.setStorage({
  30. key: "openid",
  31. data: aee.data.openid
  32. })
  33. } else {
  34. uni.showToast({
  35. title: aee.errmsg,
  36. icon: 'none'
  37. })
  38. }
  39. }
  40. })
  41. } else {
  42. uni.showToast({
  43. title: res.errMsg,
  44. icon: 'none'
  45. })
  46. }
  47. }
  48. });
  49. },
  50. // 强制更新
  51. forceUpdate() {
  52. const that = this;
  53. let system = uni.getSystemInfoSync();
  54. if (system.uniPlatform == 'mp-weixin') {
  55. const updateManager = uni.getUpdateManager();
  56. updateManager.onCheckForUpdate(function(res) {
  57. // 请求完新版本信息的回调
  58. console.log(res.hasUpdate);
  59. });
  60. updateManager.onUpdateReady(function(res) {
  61. uni.showModal({
  62. title: '更新提示',
  63. content: '新版本已经准备好,是否重启应用?',
  64. success(res) {
  65. if (res.confirm) {
  66. uni.clearStorage();
  67. updateManager.applyUpdate();
  68. }
  69. }
  70. });
  71. });
  72. updateManager.onUpdateFailed(function(res) {
  73. console.log(res);
  74. console.log('更新失败');
  75. });
  76. }
  77. }
  78. }
  79. }
  80. </script>
  81. <style lang="scss">
  82. /*每个页面公共css */
  83. @import '@/uni_modules/uni-scss/index.scss';
  84. @import '@/common/css/font-icon.css';
  85. /* 公用 */
  86. .container {
  87. display: flex;
  88. flex-direction: column;
  89. box-sizing: border-box;
  90. width: 100vw;
  91. height: 100vh;
  92. }
  93. .textOver {
  94. overflow: hidden;
  95. text-overflow: ellipsis;
  96. word-break: break-all;
  97. display: -webkit-box;
  98. -webkit-box-orient: vertical;
  99. -webkit-line-clamp: 2;
  100. }
  101. // 弹框公共样式
  102. .uni-dialog-content {
  103. padding: 2vw !important;
  104. max-height: 40vh;
  105. overflow-y: auto;
  106. align-items: normal !important;
  107. box-sizing: border-box;
  108. }
  109. /* 设置整个项目的公用样式*/
  110. page {
  111. /* 窗口可用高度 */
  112. /* 有头有底 */
  113. --oneHeight: 100vh;
  114. /* 有头无底 */
  115. --twoHeight: 92vh;
  116. /* 可用窗口背景颜色 */
  117. --mainColor: #ffffff;
  118. /* 底部菜单背景颜色 */
  119. --footColor: #f1f1f1;
  120. /* 字体大小 */
  121. --font20Szie: 20px;
  122. --font19Szie: 19px;
  123. --font18Szie: 18px;
  124. --font17Size: 17px;
  125. --font16Size: 16px;
  126. --font15Size: 15px;
  127. --font14Size: 14px;
  128. --font13Size: 13px;
  129. --font12Size: 12px;
  130. /* 颜色 */
  131. --f1Color: #f1f1f1;
  132. --f2Color: #f2f2f2;
  133. --f3Color: #f3f3f3;
  134. --f4Color: #f4f4f4;
  135. --f5Color: #f5f5f5;
  136. --f6Color: #f6f6f6;
  137. --f7Color: #f7f7f7;
  138. --f8Color: #f8f8f8;
  139. --f9Color: #f9f9f9;
  140. --f99Color: #999999;
  141. --f85Color: #858585;
  142. --f80Color: #808080;
  143. --fDCColor: #DCDCDC;
  144. --fcColor: #cccccc;
  145. --f00Color: #000000;
  146. --fffColor: #ffffff;
  147. --f3CColor: #007AFF;
  148. --fFB1Color: #7A7E83;
  149. --fF0Color: #FF0000;
  150. }
  151. </style>