App.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. <script>
  2. // app.js
  3. import { getUserId } from './utils'
  4. import { BASE_WS_API } from './config'
  5. import { T_SELECTED_ADDRESS } from './constant'
  6. export default {
  7. name: 'App',
  8. onLaunch(options) {
  9. // this.connectSocket()
  10. if (this.isLogin()) {
  11. this.$store.dispatch('auth/refrshUserInfoAction')
  12. }
  13. uni.getSystemInfo({
  14. success: (res) => {
  15. if (res.safeArea.top > 20 && res.model.indexOf('iPhone') !== -1) {
  16. this.globalData.isIphone = true
  17. }
  18. }
  19. })
  20. this.$store.dispatch('app/getSystermTerminal')
  21. // #ifdef H5
  22. this.globalData.terminal = 2
  23. // #endif
  24. // #ifdef APP || APP-NVUE
  25. this.globalData.terminal = 3
  26. // #endif
  27. // #ifdef MP
  28. this.globalData.terminal = 1
  29. // #endif
  30. },
  31. onShow() {
  32. // 判断浏览器环境
  33. // if (ua.search(/MicroMessenger/i) > -1 && !uni.getStorageSync("appType")) {
  34. // }
  35. // const state = util.getUrlKey('state')
  36. // const code = util.getUrlKey('code')
  37. // if ((state == 'needCode' || state == 'unNeedCode') && code) {
  38. // let path = window.location.href
  39. // if (path.indexOf('code=') > 0 && path.indexOf('&state=unNeedCode') > -1) {
  40. // http.mpLogin(null, code)
  41. // path = path.substring(0, path.indexOf('code=') - 1)
  42. // history.replaceState({}, '', path)
  43. // }
  44. // }
  45. // getUserId();
  46. },
  47. globalData: {
  48. // 定义全局请求队列
  49. requestQueue: [],
  50. // 是否正在进行登陆
  51. isLanding: false,
  52. // 购物车商品数量
  53. totalCartCount: 0,
  54. // 是否一直显示 弹窗
  55. isShowCommunityPopup: true,
  56. // 是否已经打开过绑定手机号弹窗
  57. isShowedBindMobilePopu: false,
  58. // 用户是否授权获取当前位置
  59. isHasLocationPermission: true,
  60. // 是否显示关注公众号
  61. isShowFollowOfficialAccount: false,
  62. // 压屏窗弹出次数
  63. communityPopupCount: 0,
  64. // 判断设备是否为 iPhone
  65. isIphone: false,
  66. // 画布设备 1 小程序,2 H5,3 App 4 电脑
  67. terminal: ''
  68. },
  69. data() {
  70. return {
  71. scene: ''
  72. }
  73. },
  74. mounted() {
  75. this.setUserLocation()
  76. this.$store.dispatch('app/getUserSystermInfo')
  77. const launchOptions = uni.getLaunchOptionsSync()
  78. this.scene = launchOptions.scene
  79. },
  80. methods: {
  81. connectSocket() {
  82. if (this.isLogin()) {
  83. this.$store.dispatch('customerService/joinCustomerServiceChat', {
  84. ref: this,
  85. wsHandle: uni.connectSocket({
  86. url: `${BASE_WS_API}/${getUserId()}`,
  87. complete: () => { }
  88. })
  89. })
  90. }
  91. },
  92. onOpen() {
  93. // console.log('onOpen连接成功');
  94. },
  95. onMessage(evt) {
  96. // console.log('onMessage收到消息', evt);
  97. // const data = JSON.parse(evt.data)
  98. // console.log(data)
  99. // if (data.status == 10400) {
  100. // uni.showToast({
  101. // title: '网络不给力,请检查网络连接',
  102. // icon: 'none'
  103. // }) // 弹出提示框
  104. // } else if (data.status == 13140) {
  105. // this.$store.dispatch('customerService/getChatList')
  106. // }
  107. },
  108. onError(errMsg) {
  109. // console.log('onError出错了');
  110. // uni.showLoading({
  111. // title: '断线了,正在重新连接......',
  112. // mask: true
  113. // })
  114. // uni.showToast({
  115. // title: 'Error出错了' + errMsg,
  116. // icon: 'none',
  117. // duration: 2000
  118. // })
  119. },
  120. onClose() {
  121. // console.log('onClose关闭了');
  122. this.timer && clearTimeout(this.timer)
  123. if (this.isLogin()) {
  124. this.timer = setTimeout(() => {
  125. this.$store.dispatch('customerService/joinCustomerServiceChat', {
  126. ref: '',
  127. wsHandle: uni.connectSocket({
  128. url: `${BASE_WS_API}/${getUserId()}`,
  129. complete: () => { }
  130. })
  131. })
  132. }, 2000)
  133. }
  134. },
  135. // 设置用户定位
  136. async setUserLocation() {
  137. // // #ifdef APP
  138. // this.useStorageLocation();
  139. // // #endif
  140. try {
  141. // #ifdef H5
  142. this.globalData.isHasLocationPermission = true
  143. // #endif
  144. await this.$store.dispatch('location/getCurrentLocation')
  145. } catch (error) {
  146. this.globalData.isHasLocationPermission = false
  147. const lastAddress = uni.getStorageSync(T_SELECTED_ADDRESS)
  148. if (lastAddress) {
  149. this.$store.dispatch('location/getDetailAddress', lastAddress.data)
  150. } else {
  151. // 后端兜底1
  152. }
  153. }
  154. setTimeout(() => {
  155. if (!this.$store.getters.currentCity) {
  156. this.useStorageLocation()
  157. }
  158. }, 2000)
  159. },
  160. // 使用本地数据
  161. useStorageLocation() {
  162. const lastAddress = uni.getStorageSync(T_SELECTED_ADDRESS)
  163. if (lastAddress) {
  164. this.$store.dispatch('location/getDetailAddress', lastAddress.data)
  165. }
  166. }
  167. }
  168. }
  169. </script>
  170. <style lang="less">
  171. @import './app.css';
  172. .tui-badge.tui-danger.tui-badge-scale {
  173. box-shadow: 0px 0 1upx #ed3f14;
  174. border: 4upx solid #fff;
  175. }
  176. .tui-toast-text {
  177. line-height: 1.5;
  178. }
  179. /* 隐藏头部 */
  180. uni-page-head {
  181. display: none;
  182. }
  183. uni-page-wrapper {
  184. height: 100%;
  185. }
  186. /* 轮播图指示点 */
  187. uni-swiper .uni-swiper-dots-horizontal {
  188. bottom: 20px !important;
  189. }
  190. /* uni-page-body {
  191. overflow: scroll;
  192. } */
  193. .uni-page-refresh--pulling,
  194. .uni-page-refresh--reached {
  195. z-index: 1019000;
  196. }
  197. // 自定义骨架屏
  198. .ske-loading {
  199. .child-loading {
  200. animation: loading 2s linear 0s infinite alternate;
  201. }
  202. }
  203. uni-rich-text img {
  204. max-width: 100% !important;
  205. }
  206. // 图片占位图
  207. .pic-img {
  208. width: 100%;
  209. height: 100%;
  210. }
  211. .default-img {
  212. background: url('./static/images/common/default.png') no-repeat center;
  213. background-size: 100% 100%;
  214. }
  215. .line1 {
  216. text-overflow: ellipsis;
  217. white-space: nowrap;
  218. overflow: hidden;
  219. }
  220. .wid {
  221. width: 100%;
  222. }
  223. .fs4 {
  224. font-size: 4upx;
  225. }
  226. .fs18 {
  227. font-size: 18upx;
  228. }
  229. .fs20 {
  230. font-size: 20upx;
  231. }
  232. .fs22 {
  233. font-size: 22upx;
  234. }
  235. .fs24 {
  236. font-size: 24upx;
  237. }
  238. .fs26 {
  239. font-size: 26upx;
  240. }
  241. .fs28 {
  242. font-size: 28upx;
  243. }
  244. .fs30 {
  245. font-size: 30upx;
  246. }
  247. .fs32 {
  248. font-size: 32upx;
  249. }
  250. .fs34 {
  251. font-size: 34upx;
  252. }
  253. .fs36 {
  254. font-size: 36upx;
  255. }
  256. .fs38 {
  257. font-size: 38upx;
  258. }
  259. .fs40 {
  260. font-size: 40upx;
  261. }
  262. .fs42 {
  263. font-size: 42upx;
  264. }
  265. .fs44 {
  266. font-size: 44upx;
  267. }
  268. .fs46 {
  269. font-size: 46upx;
  270. }
  271. .fs48 {
  272. font-size: 46upx;
  273. }
  274. .fs50 {
  275. font-size: 50upx;
  276. }
  277. .fs60 {
  278. font-size: 60upx;
  279. }
  280. .fs-bold {
  281. font-weight: bold;
  282. }
  283. .fs-weight-300 {
  284. font-weight: 300;
  285. }
  286. .fs-weight-200 {
  287. font-weight: 200;
  288. }
  289. .fs-weight-400 {
  290. font-weight: 400;
  291. }
  292. .flex-display {
  293. display: flex;
  294. }
  295. .flex-center {
  296. display: flex;
  297. justify-content: center;
  298. }
  299. .flex-items {
  300. display: flex;
  301. align-items: center;
  302. }
  303. .flex-items-plus {
  304. display: flex;
  305. justify-content: center;
  306. align-items: center;
  307. }
  308. .flex-start {
  309. display: flex;
  310. justify-content: flex-start;
  311. }
  312. .flex-end {
  313. display: flex;
  314. justify-content: flex-end;
  315. }
  316. .flex-end-plus {
  317. display: flex;
  318. justify-content: flex-end;
  319. align-items: center;
  320. }
  321. .flex-column {
  322. flex-direction: column
  323. }
  324. .flex-column-plus {
  325. display: flex;
  326. flex-direction: column
  327. }
  328. .flex-row {
  329. flex-direction: row
  330. }
  331. .flex-row-plus {
  332. display: flex;
  333. flex-direction: row
  334. }
  335. .flex-sp-around {
  336. justify-content: space-around;
  337. }
  338. .flex-sp-between {
  339. justify-content: space-between;
  340. }
  341. .text-align {
  342. text-align: center;
  343. }
  344. .flex-wrap-1 {
  345. display: flex;
  346. flex-wrap: wrap
  347. }
  348. .flex-nowrap-1 {
  349. display: flex;
  350. flex-wrap: nowrap
  351. }
  352. .align-end {
  353. display: flex;
  354. align-items: flex-end;
  355. }
  356. .align-sp-between {
  357. align-content: space-between;
  358. }
  359. .mar-top-5 {
  360. margin-top: 5upx;
  361. }
  362. .mar-top-10 {
  363. margin-top: 10upx;
  364. }
  365. .mar-top-20 {
  366. margin-top: 20upx;
  367. }
  368. .mar-top-30 {
  369. margin-top: 30upx;
  370. }
  371. .mar-top-32 {
  372. margin-top: 32upx;
  373. }
  374. .mar-top-36 {
  375. margin-top: 36upx;
  376. }
  377. .mar-top-40 {
  378. margin-top: 40upx;
  379. }
  380. .mar-top-50 {
  381. margin-top: 50upx;
  382. }
  383. .mar-top-60 {
  384. margin-top: 60upx;
  385. }
  386. .mar-top-70 {
  387. margin-top: 70upx;
  388. }
  389. .mar-top-100 {
  390. margin-top: 100upx;
  391. }
  392. .mar-top-percent40 {
  393. margin-top: 40%;
  394. }
  395. .mar-top-half {
  396. margin-top: 50%;
  397. }
  398. .mar-left-6 {
  399. margin-left: 6upx;
  400. }
  401. .mar-left-5 {
  402. margin-left: 5upx;
  403. }
  404. .mar-left-10 {
  405. margin-left: 10upx;
  406. }
  407. .mar-left-20 {
  408. margin-left: 20upx;
  409. }
  410. .mar-left-30 {
  411. margin-left: 30upx;
  412. }
  413. .mar-left-35 {
  414. margin-left: 35upx;
  415. }
  416. .mar-left-40 {
  417. margin-left: 40upx;
  418. }
  419. .mar-left-50 {
  420. margin-left: 50upx;
  421. }
  422. .mar-left-60 {
  423. margin-left: 60upx;
  424. }
  425. .mar-left-70 {
  426. margin-left: 70upx;
  427. }
  428. .mar-right-10 {
  429. margin-right: 10upx;
  430. }
  431. .mar-right-20 {
  432. margin-right: 20upx;
  433. }
  434. .mar-right-25 {
  435. margin-right: 25upx;
  436. }
  437. .mar-right-30 {
  438. margin-right: 30upx;
  439. }
  440. .mar-right-35 {
  441. margin-right: 35upx;
  442. }
  443. .mar-right-40 {
  444. margin-right: 40upx;
  445. }
  446. .mar-right-50 {
  447. margin-right: 50upx;
  448. }
  449. .pad-left-10 {
  450. padding-left: 10upx;
  451. }
  452. .pad-left-20 {
  453. padding-left: 20upx;
  454. }
  455. .pad-left-40 {
  456. padding-left: 40upx;
  457. }
  458. .pad-right-20 {
  459. padding-right: 20upx;
  460. }
  461. .pad-top-20 {
  462. padding-top: 20upx;
  463. }
  464. .pad-top-40 {
  465. padding-top: 40upx;
  466. }
  467. .pad-bot-20 {
  468. padding-bottom: 20upx;
  469. }
  470. .pad-topbot-20 {
  471. padding: 20upx 0upx;
  472. }
  473. .pad-topbot-5 {
  474. padding: 0upx 5upx;
  475. }
  476. .pad-topbot-10 {
  477. padding: 0upx 10upx;
  478. }
  479. .pad-topbot-50 {
  480. padding: 50upx 0upx;
  481. }
  482. .pad-bot-20 {
  483. padding-bottom: 20upx;
  484. }
  485. .pad-bot-30 {
  486. padding-bottom: 30upx;
  487. }
  488. .pad-bot-40 {
  489. padding-bottom: 40upx;
  490. }
  491. .pad-bot-100 {
  492. padding-bottom: 100upx;
  493. }
  494. .pad-bot-140 {
  495. padding-bottom: 140upx;
  496. }
  497. .bor-rad-30 {
  498. border-radius: 30upx;
  499. }
  500. .bor-rad-45 {
  501. border-radius: 45upx;
  502. }
  503. .bor-rad-half {
  504. border-radius: 50%;
  505. }
  506. .backColor {
  507. background-color: #009688;
  508. }
  509. .backColorFFF {
  510. background-color: #FFFFFF;
  511. }
  512. .pos-abs {
  513. position: absolute;
  514. }
  515. .bor-bot-line {
  516. border-bottom: #C8C7CC 1upx solid;
  517. }
  518. .bor-line-F7F7F7 {
  519. border-bottom: #F7F7F7 1upx solid;
  520. }
  521. .bor-line-E5E5E5 {
  522. border-bottom: #E5E5E5 1upx solid;
  523. }
  524. .borRig-line-E5E5E5 {
  525. border-right: #DDDDDD 2upx solid;
  526. }
  527. .borRig-line-20 {
  528. border-bottom: #F7F7F7 20upx solid;
  529. }
  530. .font-color-red {
  531. color: red;
  532. }
  533. .font-color-FFF {
  534. color: #FFFFFF;
  535. }
  536. .font-color-8A734A {
  537. color: #8A734A;
  538. }
  539. .font-color-71521B {
  540. color: #71521B;
  541. }
  542. .font-color-222 {
  543. color: #222222;
  544. }
  545. .font-color-333 {
  546. color: #333333;
  547. }
  548. .font-color-666 {
  549. color: #666666;
  550. }
  551. .font-color-999 {
  552. color: #999999;
  553. }
  554. .font-color-656 {
  555. color: #656565;
  556. }
  557. .font-color-DDD {
  558. color: #DDDDDD;
  559. }
  560. .font-color-CCC {
  561. color: #CCCCCC;
  562. }
  563. .font-color-FFEBC4 {
  564. color: #FFEBC4;
  565. }
  566. .font-color-1CC363 {
  567. color: #1CC363;
  568. }
  569. .font-color-47A7EE {
  570. color: #47A7EE;
  571. }
  572. .font-color-C5AA7B {
  573. color: #C5AA7B;
  574. }
  575. .font-color-FF7700 {
  576. color: #FF7700;
  577. }
  578. .font-color-FF7911 {
  579. color: #FF7911;
  580. }
  581. .font-color-80 {
  582. color: #808080;
  583. }
  584. .font-color-DD {
  585. color: #DD524D;
  586. }
  587. .font-color-C83732 {
  588. color: #C83732;
  589. }
  590. .font-color-3F {
  591. color: #3F536E;
  592. }
  593. .font-color-009 {
  594. color: #009688;
  595. }
  596. .font-weight-500 {
  597. font-weight: 500;
  598. }
  599. .font-weight-bold {
  600. font-weight: bold;
  601. }
  602. .overflow {
  603. overflow: hidden;
  604. text-overflow: ellipsis;
  605. white-space: nowrap;
  606. }
  607. .overflowNoDot {
  608. display: block;
  609. overflow: hidden;
  610. }
  611. .discountsPriceLine {
  612. text-decoration: line-through;
  613. }
  614. .border-bottom-Line {
  615. border-bottom: 1upx solid #EDEDED;
  616. }
  617. .decoration {
  618. text-decoration: line-through;
  619. }
  620. .anonymous {
  621. margin-top: 25upx;
  622. .uni-checkbox-input {
  623. border-color: #C5AA7B !important;
  624. width: 30upx;
  625. height: 30upx;
  626. }
  627. .uni-checkbox-input-checked:before {
  628. font-size: 30upx !important;
  629. }
  630. .uni-checkbox-input-checked {
  631. background: #C5AA7B;
  632. }
  633. }
  634. .footprint {
  635. .itemList {
  636. .uni-checkbox-input {
  637. border-color: #C5AA7B !important;
  638. width: 36upx;
  639. height: 36upx;
  640. border-radius: 50%;
  641. margin-right: 20upx;
  642. }
  643. .uni-checkbox-input-checked:before {
  644. font-size: 36upx !important;
  645. }
  646. .uni-checkbox-input-checked {
  647. background: #C5AA7B;
  648. }
  649. }
  650. }
  651. </style>