App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <script>
  2. /**
  3. * vuex管理登陆状态,具体可以参考官方登陆模板示例
  4. */
  5. import { mapMutations } from 'vuex';
  6. // #ifdef H5
  7. import { weixindata } from './utils/wxAuthorized';
  8. // #endif
  9. export default {
  10. data() {
  11. return {};
  12. },
  13. methods: {
  14. ...mapMutations(['login', 'hasLogin', 'setUserInfo', 'shopClick'])
  15. },
  16. onLaunch: function(urlObj) {
  17. let obj = this;
  18. // 加载缓存中的用户信息
  19. let userInfo = uni.getStorageSync('userInfo') || '';
  20. let token = uni.getStorageSync('token');
  21. console.log(uni.getStorageSync('userInfo'),'app')
  22. console.log(uni.getStorageSync('token'),"app")
  23. // function getCookie(cname) {
  24. // var name = cname + '=';
  25. // var ca = document.cookie.split(';');
  26. // for (var i = 0; i < ca.length; i++) {
  27. // var c = ca[i].trim();
  28. // if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
  29. // }
  30. // return '';
  31. // }
  32. // 判断是否拥有用户信息
  33. if (userInfo.user_id) {
  34. // 更新登录信息
  35. obj.login();
  36. //更新登陆状态
  37. uni.getStorage({
  38. key: 'userInfo',
  39. success: res => {
  40. obj.setUserInfo(res.data.user);
  41. }
  42. });
  43. }
  44. // #ifdef H5
  45. //判断是否已经缓存浏览器
  46. let bool = uni.getStorageSync('weichatBrowser') || '';
  47. if (bool === '') {
  48. //判断是否为微信浏览
  49. bool = navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger';
  50. // 保存当前是否为微信内核浏览器
  51. uni.setStorageSync('weichatBrowser', bool);
  52. }
  53. // 判断是否为微信浏览器
  54. if (bool) {
  55. // 加载微信注册信息
  56. weixindata();
  57. }
  58. // #endif
  59. },
  60. onShow: function() {
  61. // 加载拦截
  62. // console.log('App Show');
  63. },
  64. onHide: function() {
  65. // console.log('App Hide');
  66. }
  67. };
  68. </script>
  69. <style lang="scss">
  70. /*全局公共样式和字体图标*/
  71. @import '/static/css/cmy.css';
  72. view,
  73. scroll-view,
  74. swiper,
  75. swiper-item,
  76. cover-view,
  77. cover-image,
  78. icon,
  79. text,
  80. rich-text,
  81. progress,
  82. button,
  83. checkbox,
  84. form,
  85. input,
  86. label,
  87. radio,
  88. slider,
  89. switch,
  90. textarea,
  91. navigator,
  92. audio,
  93. camera,
  94. image,
  95. video {
  96. box-sizing: border-box;
  97. }
  98. /* 骨架屏替代方案 */
  99. .Skeleton {
  100. background: #f3f3f3;
  101. padding: 20rpx 0;
  102. border-radius: 8rpx;
  103. }
  104. /* 图片载入替代方案 */
  105. .image-wrapper {
  106. font-size: 0;
  107. background: #f3f3f3;
  108. border-radius: 4px;
  109. image {
  110. width: 100%;
  111. height: 100%;
  112. transition: 0.6s;
  113. opacity: 0;
  114. &.loaded {
  115. opacity: 1 !important;
  116. }
  117. }
  118. }
  119. // 设置富文本中图片最大宽度
  120. uni-rich-text img {
  121. max-width: 100% !important;
  122. }
  123. /*边框*/
  124. .b-b:after,
  125. .b-t:after {
  126. position: absolute;
  127. z-index: 3;
  128. left: 0;
  129. right: 0;
  130. height: 0;
  131. content: '';
  132. transform: scaleY(0.5);
  133. border-bottom: 1px solid $border-color-base;
  134. }
  135. .b-b:after {
  136. bottom: 0;
  137. }
  138. .b-t:after {
  139. top: 0;
  140. }
  141. /* button样式改写 */
  142. uni-button,
  143. button {
  144. height: 80rpx;
  145. line-height: 80rpx;
  146. font-size: $font-lg + 2rpx;
  147. font-weight: normal;
  148. &.no-border:before,
  149. &.no-border:after {
  150. border: 0;
  151. }
  152. }
  153. uni-button[type='default'],
  154. button[type='default'] {
  155. color: $font-color-dark;
  156. }
  157. /* input 样式 */
  158. .input-placeholder {
  159. color: #999999;
  160. }
  161. .placeholder {
  162. color: #999999;
  163. }
  164. // 边距样式
  165. @for $i from 1 to 4 {
  166. .margin-l-#{$i * 10} {
  167. margin-left: $i * 10rpx !important;
  168. }
  169. .margin-r-#{$i * 10} {
  170. margin-right: $i * 10rpx !important;
  171. }
  172. .margin-t-#{$i * 10} {
  173. margin-top: $i * 10rpx !important;
  174. }
  175. .margin-b-#{$i * 10} {
  176. margin-bottom: $i * 10rpx !important;
  177. }
  178. .margin-#{$i * 10} {
  179. margin: $i * 10rpx !important;
  180. }
  181. .margin-v-#{$i * 10} {
  182. margin-top: $i * 10rpx !important;
  183. margin-bottom: $i * 10rpx !important;
  184. }
  185. .margin-c-#{$i * 10} {
  186. margin-left: $i * 10rpx !important;
  187. margin-right: $i * 10rpx !important;
  188. }
  189. .padding-l-#{$i * 10} {
  190. padding-left: $i * 10rpx !important;
  191. }
  192. .padding-r-#{$i * 10} {
  193. padding-right: $i * 10rpx !important;
  194. }
  195. .padding-t-#{$i * 10} {
  196. padding-top: $i * 10rpx !important;
  197. }
  198. .padding-b-#{$i * 10} {
  199. padding-bottom: $i * 10rpx !important;
  200. }
  201. .padding-#{$i * 10} {
  202. padding: $i * 10rpx !important;
  203. }
  204. .padding-v-#{$i * 10} {
  205. padding-top: $i * 10rpx !important;
  206. padding-bottom: $i * 10rpx !important;
  207. }
  208. .padding-c-#{$i * 10} {
  209. padding-left: $i * 10rpx !important;
  210. padding-right: $i * 10rpx !important;
  211. }
  212. }
  213. // 字体大小
  214. .font-size-sm {
  215. font-size: $font-sm;
  216. }
  217. .font-size-base {
  218. font-size: $font-base;
  219. }
  220. .font-size-lg {
  221. font-size: $font-lg;
  222. }
  223. // 字体颜色
  224. .font-color-yellow {
  225. color: $color-yellow;
  226. }
  227. .font-color-gray {
  228. color: $color-gray;
  229. }
  230. .font-color-red {
  231. color: $color-red;
  232. }
  233. // 边框颜色
  234. .border-color-yellow {
  235. border: 1rpx solid $color-yellow;
  236. }
  237. // 修改默认背景颜色
  238. uni-page-wrapper,
  239. page {
  240. background-color: $page-color-base;
  241. }
  242. </style>