App.vue 5.7 KB

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