App.vue 4.8 KB

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