index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="o-w o-h">
  3. <!-- 首页 -->
  4. <k-home ref="kHomeRef" v-show="$S_tabbar_tabIdx === 0"></k-home>
  5. <!-- 购物车 -->
  6. <k-car v-show="$S_tabbar_tabIdx === 1"></k-car>
  7. <!-- 我的 -->
  8. <k-mine class="o-w o-h" v-show="$S_tabbar_tabIdx === 2"></k-mine>
  9. <!-- 底部导航栏 -->
  10. <k-tabbar />
  11. </view>
  12. </template>
  13. <script>
  14. // 导入登录方法
  15. import appLogin from '@/common/login.js';
  16. // 引入我的
  17. import kMine from './mine/index.vue';
  18. // 引入首页
  19. import kHome from './home/index.vue';
  20. // 引入购物车
  21. import kCar from './car/index.vue';
  22. // 引入底部导航栏
  23. import kTabbar from '@/components/common/k-tabbar/k-tabbar.vue';
  24. export default {
  25. // 注册组件
  26. components: {
  27. kMine,
  28. kHome,
  29. kCar,
  30. kTabbar
  31. },
  32. computed: {
  33. // 获取vuex的数据,用作控制组件的显示和隐藏
  34. $S_tabbar_tabIdx() {
  35. return this.$M_GS('common', '$S_tabbar_tabIdx');
  36. }
  37. },
  38. async onLoad(options) {
  39. let clientId = options.clientId;
  40. let flag = options.flag;
  41. // 如果是扫小程序码进来的
  42. if (options.scene) {
  43. const { scene } = options;
  44. clientId = scene.split('-')[0];
  45. // 如果存在优惠券
  46. if (scene.indexOf('-') !== -1) {
  47. flag = scene.split('-')[1];
  48. }
  49. }
  50. // 登录
  51. const appLoginData = await appLogin({ clientId, flag });
  52. // 初始化home页面的数据
  53. this.$refs.kHomeRef.init(appLoginData);
  54. },
  55. // 分享小程序
  56. onShareAppMessage(res) {
  57. return {
  58. title: '申泽智能售卖',
  59. path: '/pages/index',
  60. success(res) {
  61. uni.showToast({
  62. title: '分享成功'
  63. });
  64. },
  65. fail(res) {
  66. uni.showToast({
  67. title: '分享失败',
  68. icon: 'none'
  69. });
  70. }
  71. };
  72. }
  73. };
  74. </script>