App.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.getStorage({
  18. key: 'openid',
  19. success: function(res) {
  20. that.searchOpenid(res.data)
  21. },
  22. fail: function(err) {
  23. uni.login({
  24. success: async function(res) {
  25. if (res.code) {
  26. const aee = await that.$app('/wechat/api/login/app', 'GET', {
  27. js_code: res.code,
  28. config: that.$config.wx_projectkey
  29. })
  30. if (aee.errcode == '0') {
  31. uni.setStorage({
  32. key: "openid",
  33. data: aee.data.openid
  34. })
  35. that.searchOpenid(aee.data.openid)
  36. } else {
  37. uni.showToast({
  38. title: aee.errmsg,
  39. icon: 'none'
  40. })
  41. }
  42. } else {
  43. uni.showToast({
  44. title: res.errMsg,
  45. icon: 'none'
  46. })
  47. }
  48. }
  49. });
  50. }
  51. })
  52. },
  53. async searchOpenid(openid) {
  54. const that = this;
  55. const aee = await that.$api(`/login/wxapp/${openid}`, 'POST', {})
  56. if (aee.errcode == '0') {
  57. uni.setStorage({
  58. key: "token",
  59. data: aee.data
  60. })
  61. uni.reLaunch({
  62. url: `/pages/home/index`
  63. })
  64. } else {
  65. uni.showToast({
  66. title: aee.errmsg,
  67. icon: 'none'
  68. })
  69. }
  70. },
  71. // 强制更新
  72. forceUpdate() {
  73. const that = this;
  74. let system = uni.getSystemInfoSync();
  75. if (system.uniPlatform == 'mp-weixin') {
  76. const updateManager = uni.getUpdateManager();
  77. updateManager.onCheckForUpdate(function(res) {
  78. // 请求完新版本信息的回调
  79. console.log(res.hasUpdate);
  80. });
  81. updateManager.onUpdateReady(function(res) {
  82. uni.showModal({
  83. title: '更新提示',
  84. content: '新版本已经准备好,是否重启应用?',
  85. success(res) {
  86. if (res.confirm) {
  87. uni.clearStorage();
  88. updateManager.applyUpdate();
  89. }
  90. }
  91. });
  92. });
  93. updateManager.onUpdateFailed(function(res) {
  94. console.log(res);
  95. console.log('更新失败');
  96. });
  97. }
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. /*每个页面公共css */
  104. @import '@/uni_modules/uni-scss/index.scss';
  105. @import '@/common/css/iconfont.css';
  106. /* 公用 */
  107. .container {
  108. display: flex;
  109. flex-direction: column;
  110. box-sizing: border-box;
  111. width: 100vw;
  112. height: 100vh;
  113. }
  114. .textOne {
  115. overflow: hidden;
  116. white-space: nowrap;
  117. text-overflow: ellipsis;
  118. -o-text-overflow: ellipsis;
  119. }
  120. .textOver {
  121. overflow: hidden;
  122. text-overflow: ellipsis;
  123. word-break: break-all;
  124. display: -webkit-box;
  125. -webkit-box-orient: vertical;
  126. -webkit-line-clamp: 2;
  127. }
  128. // 弹框公共样式
  129. .uni-dialog-content {
  130. padding: 2vw !important;
  131. max-height: 40vh;
  132. overflow-y: auto;
  133. align-items: normal !important;
  134. box-sizing: border-box;
  135. }
  136. /* 设置整个项目的公用样式*/
  137. page {
  138. // font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  139. /* 窗口可用高度 */
  140. /* 有头有底 */
  141. --oneHeight: 100vh;
  142. /* 有头无底 */
  143. --twoHeight: 92vh;
  144. /* 可用窗口背景颜色 */
  145. --mainColor: #ffffff;
  146. /* 底部菜单背景颜色 */
  147. --footColor: #f1f1f1;
  148. /* 字体大小 */
  149. --font20Size: 20px;
  150. --font19Size: 19px;
  151. --font18Size: 18px;
  152. --font17Size: 17px;
  153. --font16Size: 16px;
  154. --font15Size: 15px;
  155. --font14Size: 14px;
  156. --font13Size: 13px;
  157. --font12Size: 12px;
  158. /* 颜色 */
  159. --f1Color: #f1f1f1;
  160. --f2Color: #f2f2f2;
  161. --f3Color: #f3f3f3;
  162. --f4Color: #f4f4f4;
  163. --f5Color: #f5f5f5;
  164. --f6Color: #f6f6f6;
  165. --f7Color: #f7f7f7;
  166. --f8Color: #f8f8f8;
  167. --f9Color: #f9f9f9;
  168. --f99Color: #999999;
  169. --f85Color: #858585;
  170. --f69Color: #696969;
  171. --f80Color: #808080;
  172. --fFB1Color: #7A7E83;
  173. --fDCColor: #DCDCDC;
  174. --fcColor: #cccccc;
  175. --f00Color: #000000;
  176. --fffColor: #ffffff;
  177. --f3CColor: #007AFF;
  178. --fF0Color: #FF0000;
  179. --f08Color: #008000;
  180. --f35BColor: #35BD7B;
  181. --f191Color: #191970;
  182. }
  183. </style>