App.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  1. <script>
  2. import Vue from 'vue';
  3. export default {
  4. onLaunch: function(options) {
  5. uni.removeStorageSync("token")
  6. uni.removeStorageSync("websitData")
  7. uni.removeStorageSync("websitIdSj")
  8. let that = this;
  9. console.log(options);
  10. // 小程序更新
  11. const updateManager = uni.getUpdateManager();
  12. // 请求完新版本信息
  13. updateManager.onCheckForUpdate(function(res) {
  14. // console.log(res.hasUpdate);
  15. });
  16. // 新的版本已经下载好
  17. updateManager.onUpdateReady(function(res) {
  18. uni.showModal({
  19. title: '更新提示',
  20. content: '新版本已经准备好,是否重启应用?',
  21. success(res) {
  22. if (res.confirm) {
  23. // 调用 applyUpdate 应用新版本并重启
  24. updateManager.applyUpdate();
  25. }
  26. },
  27. });
  28. });
  29. // 新的版本下载失败
  30. updateManager.onUpdateFailed(function(res) {
  31. that.$toast('更新失败!');
  32. });
  33. uni.getSystemInfo({
  34. success: function(e) {
  35. console.log(e);
  36. Vue.prototype.StatusBar = e.statusBarHeight;
  37. let custom = wx.getMenuButtonBoundingClientRect();
  38. Vue.prototype.Custom = custom;
  39. Vue.prototype.CustomBar =
  40. custom.bottom + custom.top - e.statusBarHeight + 4;
  41. //用来判断是否iphoneX类型的全面屏设备
  42. if (e.model.indexOf('iPhone X') == 0) {
  43. Vue.prototype.isIphoneX = 68;
  44. } else {
  45. Vue.prototype.isIphoneX = 0;
  46. }
  47. if (e.environment == 'wxwork') {
  48. uni.setStorageSync('is_qywx', true);
  49. } else {
  50. uni.setStorageSync('is_qywx', false);
  51. }
  52. },
  53. });
  54. // 企业微信端
  55. if (uni.getStorageSync('is_qywx') == true) {
  56. wx.qy.login({
  57. success: function(loginRes) {
  58. if (loginRes.code) {
  59. //发起网络请求
  60. that
  61. .$axios({
  62. url: '/user/auth',
  63. params: {
  64. code: loginRes.code,
  65. work: true,
  66. },
  67. })
  68. .then((authRes) => {
  69. // console.log(authRes);
  70. that.$store.commit('changeUserId', authRes.data.userId);
  71. that.$store.commit('changeUserInfo', authRes.data);
  72. uni.setStorageSync('userInfo', authRes.data);
  73. uni.setStorageSync('userId', authRes.data.userId);
  74. uni.setStorageSync('token', authRes.data.token);
  75. that.$isResolve();
  76. this.userWebsit(authRes.data)
  77. });
  78. } else {
  79. console.log('登录失败!' + loginRes.errMsg);
  80. }
  81. },
  82. });
  83. }
  84. // 微信端
  85. else {
  86. uni.login({
  87. provider: 'weixin',
  88. success: (loginRes) => {
  89. console.log(loginRes);
  90. console.log('是否从企业微信端进入:' + uni.getStorageSync('is_qywx'));
  91. that
  92. .$axios({
  93. url: '/user/auth',
  94. params: {
  95. code: loginRes.code,
  96. work: uni.getStorageSync('is_qywx'),
  97. },
  98. })
  99. .then((res) => {
  100. try {
  101. console.log(res);
  102. that.$store.commit('changeUserId', res.data.userId);
  103. that.$store.commit('changeUserInfo', res.data);
  104. uni.setStorageSync('userInfo', res.data);
  105. uni.setStorageSync('userId', res.data.userId);
  106. uni.setStorageSync('token', res.data.token);
  107. that.$isResolve();
  108. this.userWebsit(res.data)
  109. } catch (e) {
  110. console.error(e);
  111. }
  112. });
  113. },
  114. });
  115. }
  116. },
  117. onShow: function() {
  118. console.log('App Show');
  119. },
  120. onHide: function() {
  121. console.log('App Hide');
  122. },
  123. methods: {
  124. userWebsit(userInfo) {
  125. this.$axios({
  126. url: '/user/user/detail',
  127. method: 'get',
  128. params: {
  129. userId: userInfo.userId
  130. }
  131. }).then(resData => {
  132. this.$store.commit('changeUserInfo', resData?.data);
  133. uni.setStorageSync('userInfo', resData?.data);
  134. if(resData?.data?.adminWebsit?.websitId){
  135. this.$store.commit('changeWebsitObj', resData?.data?.adminWebsit);
  136. uni.setStorageSync('websitData', resData?.data?.adminWebsit);
  137. uni.setStorageSync("websitIdSj", resData?.data?.adminWebsit?.websitId);
  138. }else{
  139. uni.getLocation({
  140. type: 'gcj02',
  141. success: res => {
  142. this.$axios({
  143. url: '/user/userWebsit',
  144. method: 'post',
  145. params: {
  146. lat: res.latitude,
  147. lng: res.longitude,
  148. },
  149. }).then((res) => {
  150. if(res?.data){
  151. this.$store.commit('changeWebsitObj', res?.data);
  152. uni.setStorageSync('websitData', res?.data);
  153. uni.setStorageSync("websitIdSj", res?.data.websitId)
  154. }else{
  155. uni.reLaunch({
  156. url: "/pages/mywebsit/index"
  157. })
  158. }
  159. });
  160. },
  161. fail: err => {
  162. uni.getSetting({
  163. success: (res) => {
  164. if (!res.authSetting['scope.userLocation']) {
  165. uni.showModal({
  166. title: '是否授权当前位置',
  167. content: '需要获取您的地理位置,请确认授权,否则地图功能将无法使用',
  168. success: (tip) => {
  169. if (tip.confirm) {
  170. uni.openSetting({
  171. success: (data) => {
  172. if (data
  173. .authSetting[
  174. "scope.userLocation"
  175. ] === true) {
  176. this.$successToast(
  177. '授权成功');
  178. setTimeout(
  179. this
  180. .userWebsit,
  181. 1000
  182. )
  183. }
  184. }
  185. })
  186. }
  187. }
  188. })
  189. }
  190. }
  191. })
  192. }
  193. })
  194. }
  195. })
  196. }
  197. }
  198. };
  199. </script>
  200. <style>
  201. @import './static/style/utils';
  202. </style>
  203. <style lang="scss">
  204. @import '@/uni_modules/uview-ui/index.scss';
  205. /*每个页面公共css */
  206. .clearfix:after {
  207. content: '';
  208. display: block;
  209. height: 0;
  210. clear: both;
  211. visibility: hidden;
  212. }
  213. .ellipsis {
  214. overflow: hidden;
  215. white-space: nowrap;
  216. text-overflow: ellipsis;
  217. }
  218. .ellipsis-2 {
  219. display: -webkit-box;
  220. overflow: hidden;
  221. white-space: normal !important;
  222. text-overflow: ellipsis;
  223. word-wrap: break-word;
  224. -webkit-line-clamp: 2;
  225. -webkit-box-orient: vertical;
  226. }
  227. .ellipsis-3 {
  228. display: -webkit-box;
  229. overflow: hidden;
  230. white-space: normal !important;
  231. text-overflow: ellipsis;
  232. word-wrap: break-word;
  233. -webkit-line-clamp: 3;
  234. -webkit-box-orient: vertical;
  235. }
  236. .app-container {
  237. min-height: 100vh;
  238. font-size: 28rpx;
  239. color: #333333;
  240. font-family: 'Microsoft YaHei';
  241. }
  242. .bt-container {
  243. height: 100rpx;
  244. .container {
  245. position: fixed;
  246. bottom: 0;
  247. left: 0;
  248. z-index: 99;
  249. width: 100%;
  250. padding: 10rpx 30rpx;
  251. background: #ffffff;
  252. button {
  253. width: 690rpx;
  254. height: 80rpx;
  255. margin: 0;
  256. background: #6da7ff;
  257. border-radius: 80rpx;
  258. color: #ffffff;
  259. line-height: 80rpx;
  260. font-size: 30rpx;
  261. }
  262. }
  263. }
  264. .global-mask {
  265. position: fixed;
  266. top: 0;
  267. left: 0;
  268. z-index: 998;
  269. width: 100%;
  270. height: 100%;
  271. background: rgba($color: #000000, $alpha: 0.3);
  272. }
  273. .global-dialog {
  274. position: fixed;
  275. top: calc(50vh - 150rpx);
  276. left: 60rpx;
  277. z-index: 999;
  278. width: 630rpx;
  279. background: #ffffff;
  280. border-radius: 15rpx;
  281. overflow: hidden;
  282. .title {
  283. font-size: 36rpx;
  284. font-weight: 500;
  285. text-align: center;
  286. line-height: 100rpx;
  287. padding-bottom: 10rpx;
  288. }
  289. .content {
  290. .text {
  291. font-size: 32rpx;
  292. text-align: center;
  293. padding-bottom: 40rpx;
  294. }
  295. .form {
  296. padding: 0 40rpx;
  297. .item {
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. margin-bottom: 40rpx;
  302. input {
  303. width: 340rpx;
  304. height: 60rpx;
  305. border: 1px solid #eaeaea;
  306. border-radius: 10rpx;
  307. padding: 0 20rpx;
  308. }
  309. }
  310. }
  311. }
  312. .btn {
  313. border-top: 1px solid #eaeaea;
  314. display: flex;
  315. &>view {
  316. flex: 1;
  317. text-align: center;
  318. line-height: 100rpx;
  319. font-size: 32rpx;
  320. &.left {
  321. color: #666666;
  322. }
  323. &.right {
  324. color: #ffffff;
  325. background: #ff3f42;
  326. }
  327. }
  328. }
  329. }
  330. .goods-waterfall-list {
  331. padding: 20rpx 20rpx 0;
  332. box-sizing: border-box;
  333. display: flex;
  334. justify-content: space-between;
  335. .left,
  336. .right {
  337. display: flex;
  338. flex-direction: column;
  339. }
  340. .item {
  341. width: 348rpx;
  342. background: #ffffff;
  343. box-sizing: border-box;
  344. margin-bottom: 20rpx;
  345. border-radius: 20rpx;
  346. overflow: hidden;
  347. .image {
  348. width: 348rpx;
  349. height: 348rpx;
  350. flex-shrink: 0;
  351. position: relative;
  352. .img {
  353. width: 348rpx;
  354. height: 348rpx;
  355. display: block;
  356. }
  357. .water {
  358. width: 348rpx;
  359. height: 348rpx;
  360. display: block;
  361. position: absolute;
  362. left: 0;
  363. top: 0;
  364. z-index: 1;
  365. }
  366. }
  367. .content {
  368. padding: 15rpx 20rpx;
  369. .title {
  370. font-size: 30rpx;
  371. color: #333333;
  372. line-height: 36rpx;
  373. font-weight: 600;
  374. max-height: 72rpx;
  375. }
  376. .tags {
  377. display: flex;
  378. flex-wrap: wrap;
  379. .it {
  380. height: 28rpx;
  381. padding: 0 10rpx;
  382. line-height: 28rpx;
  383. border-radius: 10rpx;
  384. background: #e8e8e8;
  385. font-size: 20rpx;
  386. color: #666666;
  387. margin-right: 10rpx;
  388. margin-top: 10rpx;
  389. }
  390. }
  391. .tags2 {
  392. display: flex;
  393. flex-wrap: wrap;
  394. .it {
  395. height: 36rpx;
  396. padding: 0 6rpx;
  397. font-size: 24rpx;
  398. margin-right: 10rpx;
  399. border: 1px solid #fe781f;
  400. color: #fe781f;
  401. box-sizing: border-box;
  402. margin-top: 10rpx;
  403. display: flex;
  404. align-items: center;
  405. }
  406. }
  407. .price {
  408. display: flex;
  409. align-items: flex-end;
  410. margin-top: 10rpx;
  411. .price-1 {
  412. font-size: 32rpx;
  413. color: #ff3f42;
  414. line-height: 32rpx;
  415. }
  416. .price-2 {
  417. font-size: 26rpx;
  418. color: #666666;
  419. line-height: 26rpx;
  420. text-decoration: line-through;
  421. margin-left: 12rpx;
  422. }
  423. }
  424. .text {
  425. font-size: 24rpx;
  426. color: #999999;
  427. margin-top: 10rpx;
  428. }
  429. }
  430. }
  431. }
  432. .goods-row-list {
  433. padding: 20rpx 20rpx 0;
  434. box-sizing: border-box;
  435. .item {
  436. padding: 20rpx;
  437. background: #ffffff;
  438. border-radius: 20rpx;
  439. display: flex;
  440. margin-bottom: 20rpx;
  441. .image {
  442. width: 240rpx;
  443. height: 240rpx;
  444. flex-shrink: 0;
  445. position: relative;
  446. .img {
  447. width: 240rpx;
  448. height: 240rpx;
  449. display: block;
  450. }
  451. .water {
  452. width: 240rpx;
  453. height: 240rpx;
  454. display: block;
  455. position: absolute;
  456. left: 0;
  457. top: 0;
  458. z-index: 1;
  459. }
  460. }
  461. .right {
  462. flex: 1;
  463. display: flex;
  464. flex-direction: column;
  465. justify-content: space-between;
  466. margin-left: 20rpx;
  467. .title {
  468. font-size: 30rpx;
  469. color: #333333;
  470. line-height: 36rpx;
  471. font-weight: 600;
  472. max-height: 72rpx;
  473. }
  474. .tags {
  475. display: flex;
  476. flex-wrap: wrap;
  477. .it {
  478. height: 28rpx;
  479. padding: 0 10rpx;
  480. line-height: 28rpx;
  481. border-radius: 10rpx;
  482. background: #e8e8e8;
  483. font-size: 20rpx;
  484. color: #666666;
  485. margin-right: 10rpx;
  486. margin-top: 10rpx;
  487. }
  488. }
  489. .bottom {
  490. display: flex;
  491. align-items: flex-end;
  492. justify-content: space-between;
  493. .price {
  494. margin-top: 10rpx;
  495. .price-1 {
  496. font-size: 32rpx;
  497. color: #ff3f42;
  498. line-height: 32rpx;
  499. }
  500. .price-2 {
  501. font-size: 26rpx;
  502. color: #666666;
  503. line-height: 26rpx;
  504. text-decoration: line-through;
  505. margin-top: 6rpx;
  506. }
  507. }
  508. .text {
  509. font-size: 24rpx;
  510. color: #999999;
  511. }
  512. }
  513. }
  514. }
  515. }
  516. </style>