App.vue 5.8 KB

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