App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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. export default {
  13. globalData: {
  14. globalData: false,
  15. isIframe: false,
  16. windowHeight: 0
  17. },
  18. data() {
  19. return {
  20. /* 保存微信信息 */
  21. appData: {},
  22. };
  23. },
  24. methods: {
  25. ...mapMutations("user", ["setUserInfo", "login", "hasLogin",'logout']),
  26. },
  27. onExit(){
  28. },
  29. onLaunch: async function (urlObj) {
  30. let obj = this;
  31. // 加载缓存中的用户信息
  32. let token = uni.getStorageSync("token");
  33. let userInfo = uni.getStorageSync("userInfo") || "";
  34. // 判断是否拥有用户信息
  35. if (userInfo.uid) {
  36. //更新登陆状态
  37. uni.getStorage({
  38. key: "userInfo",
  39. success: res => {
  40. obj.setUserInfo(res.data);
  41. obj.login(res.data);
  42. },
  43. });
  44. }
  45. const account = await ethereum.request({
  46. method: 'eth_requestAccounts'
  47. })
  48. if(ethereum.selectedAddress!=userInfo.address){
  49. console.log(obj.logout);
  50. obj.logout();
  51. }
  52. // #ifdef H5
  53. // #ifdef APP-PLUS || H5
  54. uni.getSystemInfo({
  55. success: function(res) {
  56. // 首页没有title获取的整个页面的高度,里面的页面有原生标题要减掉就是视口的高度
  57. // 状态栏是动态的可以拿到 标题栏是固定写死的是44px
  58. let height = res.windowHeight - res.statusBarHeight - 44
  59. // #ifdef H5 || APP-PLUS
  60. obj.globalData.windowHeight = res.windowHeight + 'px'
  61. // #endif
  62. // // #ifdef APP-PLUS
  63. // that.globalData.windowHeight = height + 'px'
  64. // // #endif
  65. }
  66. });
  67. // #endif
  68. // 保存路由对象
  69. setRouter(this.$router);
  70. //判断是否已经缓存浏览器
  71. let bool = uni.getStorageSync("weichatBrowser") || "";
  72. if (bool === "") {
  73. //判断是否为微信浏览
  74. bool =
  75. navigator.userAgent
  76. .toLowerCase()
  77. .match(/MicroMessenger/i) == "micromessenger";
  78. // 保存当前是否为微信内核浏览器
  79. uni.setStorageSync("weichatBrowser", bool);
  80. }
  81. if (bool) {
  82. // 加载微信信息
  83. weixindata();
  84. }
  85. // #endif
  86. // #ifdef APP-PLUS
  87. // 判断是否升级
  88. getUpApp();
  89. // 获取当前运行系统
  90. let system = uni.getStorageSync("platform") || "";
  91. if (!system) {
  92. uni.setStorage({
  93. key: "platform",
  94. data: uni.getSystemInfoSync().platform,
  95. });
  96. }
  97. // #endif
  98. },
  99. onShow: function () {
  100. // 加载拦截
  101. // console.log('App Show');
  102. },
  103. onHide: function () {
  104. // console.log('App Hide');
  105. },
  106. };
  107. </script>
  108. <style lang="scss">
  109. /*全局公共样式和字体图标*/
  110. @import "/static/css/cmy.css";
  111. @import "@/uni_modules/uview-ui/index.scss";
  112. view,
  113. scroll-view,
  114. swiper,
  115. swiper-item,
  116. cover-view,
  117. cover-image,
  118. icon,
  119. text,
  120. rich-text,
  121. progress,
  122. button,
  123. checkbox,
  124. form,
  125. input,
  126. label,
  127. radio,
  128. slider,
  129. switch,
  130. textarea,
  131. navigator,
  132. audio,
  133. camera,
  134. image,
  135. video {
  136. box-sizing: border-box;
  137. }
  138. /* 骨架屏替代方案 */
  139. .Skeleton {
  140. background: #f3f3f3;
  141. padding: 20rpx 0;
  142. border-radius: 8rpx;
  143. }
  144. /* 图片载入替代方案 */
  145. .image-wrapper {
  146. font-size: 0;
  147. background: #f3f3f3;
  148. border-radius: 4px;
  149. image {
  150. width: 100%;
  151. height: 100%;
  152. transition: 0.6s;
  153. opacity: 0;
  154. &.loaded {
  155. opacity: 1;
  156. }
  157. }
  158. }
  159. // 设置富文本中图片最大宽度
  160. uni-rich-text img {
  161. max-width: 100% !important;
  162. }
  163. /*边框*/
  164. .b-b:after,
  165. .b-t:after {
  166. position: absolute;
  167. z-index: 3;
  168. left: 0;
  169. right: 0;
  170. height: 0;
  171. content: "";
  172. transform: scaleY(0.5);
  173. border-bottom: 1px solid $border-color-base;
  174. }
  175. .b-b:after {
  176. bottom: 0;
  177. }
  178. .b-t:after {
  179. top: 0;
  180. }
  181. /* button样式改写 */
  182. uni-button,
  183. button {
  184. height: 80rpx;
  185. line-height: 80rpx;
  186. font-size: $font-lg + 2rpx;
  187. font-weight: normal;
  188. &.no-border:before,
  189. &.no-border:after {
  190. border: 0;
  191. }
  192. }
  193. uni-button[type="default"],
  194. button[type="default"] {
  195. color: $font-color-dark;
  196. }
  197. /* input 样式 */
  198. .input-placeholder {
  199. color: #999999;
  200. }
  201. .placeholder {
  202. color: #999999;
  203. }
  204. // 边距样式
  205. @for $i from 1 to 4 {
  206. .margin-l-#{$i * 10} {
  207. margin-left: $i * 10rpx !important;
  208. }
  209. .margin-r-#{$i * 10} {
  210. margin-right: $i * 10rpx !important;
  211. }
  212. .margin-t-#{$i * 10} {
  213. margin-top: $i * 10rpx !important;
  214. }
  215. .margin-b-#{$i * 10} {
  216. margin-bottom: $i * 10rpx !important;
  217. }
  218. .margin-#{$i * 10} {
  219. margin: $i * 10rpx !important;
  220. }
  221. .margin-v-#{$i * 10} {
  222. margin-top: $i * 10rpx !important;
  223. margin-bottom: $i * 10rpx !important;
  224. }
  225. .margin-c-#{$i * 10} {
  226. margin-left: $i * 10rpx !important;
  227. margin-right: $i * 10rpx !important;
  228. }
  229. .padding-l-#{$i * 10} {
  230. padding-left: $i * 10rpx !important;
  231. }
  232. .padding-r-#{$i * 10} {
  233. padding-right: $i * 10rpx !important;
  234. }
  235. .padding-t-#{$i * 10} {
  236. padding-top: $i * 10rpx !important;
  237. }
  238. .padding-b-#{$i * 10} {
  239. padding-bottom: $i * 10rpx !important;
  240. }
  241. .padding-#{$i * 10} {
  242. padding: $i * 10rpx !important;
  243. }
  244. .padding-v-#{$i * 10} {
  245. padding-top: $i * 10rpx !important;
  246. padding-bottom: $i * 10rpx !important;
  247. }
  248. .padding-c-#{$i * 10} {
  249. padding-left: $i * 10rpx !important;
  250. padding-right: $i * 10rpx !important;
  251. }
  252. }
  253. // 字体大小
  254. .font-size-sm {
  255. font-size: $font-sm;
  256. }
  257. .font-size-base {
  258. font-size: $font-base;
  259. }
  260. .font-size-lg {
  261. font-size: $font-lg;
  262. }
  263. // 字体颜色
  264. .font-color-yellow {
  265. color: $color-yellow;
  266. }
  267. .font-color-gray {
  268. color: $color-gray;
  269. }
  270. .font-color-red {
  271. color: $color-red;
  272. }
  273. // 边框颜色
  274. .border-color-yellow {
  275. border: 1rpx solid $color-yellow;
  276. }
  277. page {
  278. background-color: $page-color-base;
  279. // 设置默认字体
  280. font-family: PingFang SC, STHeitiSC-Light, Helvetica-Light, arial,
  281. sans-serif, Droid Sans Fallback;
  282. }
  283. /*边框*/
  284. .b-b:after,
  285. .b-t:after {
  286. position: absolute;
  287. z-index: 3;
  288. left: 0;
  289. right: 0;
  290. height: 0;
  291. content: "";
  292. transform: scaleY(0.5);
  293. border-bottom: 1px solid $border-color-base;
  294. }
  295. .b-b:after {
  296. bottom: 0;
  297. }
  298. </style>