App.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <script>
  2. /**
  3. * vuex管理登陆状态,具体可以参考官方登陆模板示例
  4. */
  5. import { mapMutations } from "vuex";
  6. // #ifdef H5
  7. import { weixindata, setRouter } from "./utils/wxAuthorized";
  8. // #endif
  9. // #ifdef APP-PLUS
  10. import { getUpApp } from "./utils/upApp.js";
  11. // #endif
  12. import detectEthereumProvider from '@metamask/detect-provider'
  13. export default {
  14. data() {
  15. return {
  16. /* 保存微信信息 */
  17. appData: {},
  18. };
  19. },
  20. methods: {
  21. ...mapMutations("user", ["setUserInfo", "login", "hasLogin",'logout']),
  22. },
  23. onExit(){
  24. },
  25. onLaunch: function (urlObj) {
  26. let obj = this;
  27. // 加载缓存中的用户信息
  28. let userInfo = uni.getStorageSync("userInfo") || "";
  29. // 判断是否拥有用户信息
  30. if (userInfo.address) {
  31. //更新登陆状态
  32. uni.getStorage({
  33. key: "userInfo",
  34. success: res => {
  35. obj.setUserInfo(res.data);
  36. obj.login(res.data);
  37. },
  38. });
  39. }
  40. ethereum.request({
  41. method: 'eth_requestAccounts'
  42. }).then((account) => {
  43. if(ethereum.selectedAddress!=userInfo.address){
  44. obj.logout();
  45. }
  46. });
  47. // #ifdef H5
  48. // 保存路由对象
  49. setRouter(this.$router);
  50. //判断是否已经缓存浏览器
  51. let bool = uni.getStorageSync("weichatBrowser") || "";
  52. if (bool === "") {
  53. //判断是否为微信浏览
  54. bool =
  55. navigator.userAgent
  56. .toLowerCase()
  57. .match(/MicroMessenger/i) == "micromessenger";
  58. // 保存当前是否为微信内核浏览器
  59. uni.setStorageSync("weichatBrowser", bool);
  60. }
  61. if (bool) {
  62. // 加载微信信息
  63. weixindata();
  64. }
  65. // #endif
  66. // #ifdef APP-PLUS
  67. // 判断是否升级
  68. getUpApp();
  69. // 获取当前运行系统
  70. let system = uni.getStorageSync("platform") || "";
  71. if (!system) {
  72. uni.setStorage({
  73. key: "platform",
  74. data: uni.getSystemInfoSync().platform,
  75. });
  76. }
  77. // #endif
  78. },
  79. onShow: function () {
  80. // 加载拦截
  81. // console.log('App Show');
  82. },
  83. onHide: function () {
  84. // console.log('App Hide');
  85. },
  86. };
  87. </script>
  88. <style lang="scss">
  89. /*全局公共样式和字体图标*/
  90. @import "/static/css/cmy.css";
  91. @import "@/uni_modules/uview-ui/index.scss";
  92. view,
  93. scroll-view,
  94. swiper,
  95. swiper-item,
  96. cover-view,
  97. cover-image,
  98. icon,
  99. text,
  100. rich-text,
  101. progress,
  102. button,
  103. checkbox,
  104. form,
  105. input,
  106. label,
  107. radio,
  108. slider,
  109. switch,
  110. textarea,
  111. navigator,
  112. audio,
  113. camera,
  114. image,
  115. video {
  116. box-sizing: border-box;
  117. }
  118. // 设置富文本中图片最大宽度
  119. uni-rich-text img {
  120. max-width: 100% !important;
  121. }
  122. /* button样式改写 */
  123. uni-button,
  124. button {
  125. height: 80rpx;
  126. line-height: 80rpx;
  127. font-size: $font-lg + 2rpx;
  128. font-weight: normal;
  129. &.no-border:before,
  130. &.no-border:after {
  131. border: 0;
  132. }
  133. }
  134. uni-button[type="default"],
  135. button[type="default"] {
  136. color: $font-color-dark;
  137. }
  138. /* input 样式 */
  139. .placeholder {
  140. color: #999999;
  141. }
  142. // 边距样式
  143. @for $i from 1 to 4 {
  144. .margin-l-#{$i * 10} {
  145. margin-left: $i * 10rpx !important;
  146. }
  147. .margin-r-#{$i * 10} {
  148. margin-right: $i * 10rpx !important;
  149. }
  150. .margin-t-#{$i * 10} {
  151. margin-top: $i * 10rpx !important;
  152. }
  153. .margin-b-#{$i * 10} {
  154. margin-bottom: $i * 10rpx !important;
  155. }
  156. .margin-#{$i * 10} {
  157. margin: $i * 10rpx !important;
  158. }
  159. .margin-v-#{$i * 10} {
  160. margin-top: $i * 10rpx !important;
  161. margin-bottom: $i * 10rpx !important;
  162. }
  163. .margin-c-#{$i * 10} {
  164. margin-left: $i * 10rpx !important;
  165. margin-right: $i * 10rpx !important;
  166. }
  167. .padding-l-#{$i * 10} {
  168. padding-left: $i * 10rpx !important;
  169. }
  170. .padding-r-#{$i * 10} {
  171. padding-right: $i * 10rpx !important;
  172. }
  173. .padding-t-#{$i * 10} {
  174. padding-top: $i * 10rpx !important;
  175. }
  176. .padding-b-#{$i * 10} {
  177. padding-bottom: $i * 10rpx !important;
  178. }
  179. .padding-#{$i * 10} {
  180. padding: $i * 10rpx !important;
  181. }
  182. .padding-v-#{$i * 10} {
  183. padding-top: $i * 10rpx !important;
  184. padding-bottom: $i * 10rpx !important;
  185. }
  186. .padding-c-#{$i * 10} {
  187. padding-left: $i * 10rpx !important;
  188. padding-right: $i * 10rpx !important;
  189. }
  190. }
  191. // 字体大小
  192. .font-size-sm {
  193. font-size: $font-sm;
  194. }
  195. .font-size-base {
  196. font-size: $font-base;
  197. }
  198. .font-size-lg {
  199. font-size: $font-lg;
  200. }
  201. // 字体颜色
  202. .font-color-yellow {
  203. color: $color-yellow !important;
  204. }
  205. .font-color-gray {
  206. color: $color-gray !important;
  207. }
  208. .font-color-red {
  209. color: $color-red !important;
  210. }
  211. // 边框颜色
  212. .border-color-yellow {
  213. border: 1rpx solid $color-yellow;
  214. }
  215. page {
  216. // background-color: $page-color-base;
  217. width: 100%;
  218. // background: url('./static/img/bg.png') no-repeat;
  219. background-size: 100% 100%;
  220. // 设置默认字体
  221. font-family: PingFang SC, STHeitiSC-Light, Helvetica-Light, arial,
  222. sans-serif, Droid Sans Fallback;
  223. }
  224. </style>