App.vue 4.9 KB

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