Browse Source

style(client): 优化首页的样式

yizhiyang 1 year ago
parent
commit
3fbb0838cc

+ 33 - 0
src/components/base-img/base-img.vue

@@ -0,0 +1,33 @@
+<template>
+  <view class="base-img">
+    <image :src="src" :mode="mode" :style="{ width, height, borderRadius }"></image>
+  </view>
+</template>
+
+<script>
+export default {
+  name: 'base-img',
+  props: {
+    src: {
+      type: String,
+      default: '',
+    },
+    width: {
+      type: String,
+      default: '',
+    },
+    height: {
+      type: String,
+      default: '',
+    },
+    borderRadius: {
+      type: String,
+      default: '',
+    },
+    mode: {
+      type: String,
+      default: '',
+    },
+  },
+};
+</script>

+ 13 - 0
src/components/base-list/base-list.vue

@@ -0,0 +1,13 @@
+<template>
+  <view class="base-list"> 111111111111111 </view>
+</template>
+
+<script>
+export default {};
+</script>
+
+<style lang="scss" scoped>
+.base-list {
+  border-radius: 8rpx;
+}
+</style>

+ 95 - 0
src/components/home-store/home-store.vue

@@ -0,0 +1,95 @@
+<template>
+  <view class="home-store">
+    <view class="image-box">
+      <base-img
+        mode="scaleToFill"
+        :src="item.logo"
+        borderRadius="8rpx 8rpx 0 0"
+        height="212rpx"
+        width="100%"
+      ></base-img>
+      <view class="mask-box">
+        <view class="fl-flex f-s-20">
+          <u-icon name="map" color="#fff" size="12"></u-icon>
+          <view class="u-m-l-10">{{ item.distance | mToKm }}</view>
+          <view class="mask-line"></view>
+          <view>养车</view>
+        </view>
+      </view>
+    </view>
+    <view class="home-list">
+      <view class="fl-flex fl-self-center">
+        <view class="f-s-28 text-primary text-cut-1 u-m-b-14">{{ item.address }}</view>
+        <view class="u-m-t-12">
+          <u--image src="/static/pages/home/home-hot.png" width="24rpx" height="24rpx"></u--image>
+        </view>
+      </view>
+      <view>
+        <view class="fl-flex" v-if="item.score">
+          <u-rate v-model="value" active-color="#ffa033" readonly allowHalf gutter="1"></u-rate>
+          <view class="f-s-24 text-999 u-m-l-5">({{ item.score }})</view>
+        </view>
+        <view class="f-s-26" style="color: #ffa033" v-else> 暂无评分</view>
+      </view>
+      <view class="u-m-t-14 f-s-24 text-999 text-cut-1">{{ item.address }}</view>
+    </view>
+  </view>
+</template>
+
+<script>
+export default {
+  props: {
+    item: {
+      type: Object,
+      default: () => {},
+    },
+  },
+  filters: {
+    mToKm(v) {
+      return (Number(v) / 1000).toFixed(2) + 'km';
+    },
+  },
+  data() {
+    return {
+      value: 3,
+    };
+  },
+  created() {
+    this.value = this.item.score;
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.home-store {
+  background-color: #ffffff;
+  border-radius: 8rpx;
+  margin-bottom: 24rpx;
+  .image-box {
+    position: relative;
+    height: 212rpx;
+
+    .mask-box {
+      width: 100%;
+      height: 44rpx;
+      line-height: 44rpx;
+      position: absolute;
+      bottom: 0;
+      left: 0;
+      background-color: rgba(0, 0, 0, 0.5);
+      color: #ffffff;
+      box-sizing: border-box;
+      padding-left: 12px;
+      .mask-line {
+        width: 2rpx;
+        height: 20rpx;
+        background: #ffffff;
+        margin: 12rpx;
+      }
+    }
+  }
+  .home-list {
+    padding: 16rpx;
+  }
+}
+</style>

+ 8 - 0
src/mixin/index.js

@@ -0,0 +1,8 @@
+const globalMixins = {
+  data() {
+    return {};
+  },
+  methods: {},
+};
+
+export default globalMixins;

+ 0 - 88
src/pages/tabbar/components/HotItem.vue

@@ -1,88 +0,0 @@
-<template>
-  <view class="container">
-    <view class="content">
-      <view class="img-box">
-        <!-- <image
-          :src="error || !loaded ? 'https://cdn.uviewui.com/uview/album/10.jpg' : item.logo"
-          mode="scaleToFill"
-        ></image> -->
-        <image class='img' mode="scaleToFill" :src='item.logo'></image>
-        <view class="name u-line-1">{{ item.name }}</view>
-      </view>
-      <view class="pd-10 address">{{ item.address }}</view>
-      <view class="pd-10 distance">{{ item.distance | mToKm }}</view>
-    </view>
-  </view>
-</template>
-
-<script>
-  export default {
-    props: {
-      item: {
-        type: Object,
-        default: () => {},
-      },
-    },
-    filters: {
-      mToKm(v) {
-        return (Number(v) / 1000).toFixed(2) + 'km';
-      },
-    },
-  };
-</script>
-
-<style lang="scss" scoped>
-  .container {
-    width: 100%;
-    box-sizing: border-box;
-
-    .content {
-      background-color: #ffffff;
-      width: 100%;
-      padding-bottom:20rpx;
-      border-radius:16rpx;
-      margin-bottom:24rpx;
-      box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(0,0,0,0.05);
-      .img-box {
-        position: relative;
-        height: 240rpx;
-        .img {
-          width: 100%;
-          height: 240rpx;
-          border-radius:16rpx 16rpx 0 0;
-        }
-
-        .name {
-          width: 100%;
-          position: absolute;
-          bottom: 0;
-          left: 0;
-          background-color: rgba(0, 0, 0, 0.2);
-          color: #ffffff;
-          padding: 10rpx;
-          box-sizing: border-box;
-          white-space: nowrap;
-          overflow: hidden;
-          text-overflow: ellipsis;
-        }
-      }
-
-      .address {
-        width:95%;
-        overflow: hidden;
-        text-overflow: ellipsis;
-        white-space: nowrap;
-        font-size: 24rpx;
-      }
-
-      .distance {
-        color: #1B5FC5;
-        font-weight: bold;
-      }
-
-      .pd-10 {
-        padding: 10rpx;
-      }
-    }
-  }
-</style>

+ 0 - 81
src/pages/tabbar/components/RecommendItem.vue

@@ -1,81 +0,0 @@
-<template>
-  <view class="container">
-    <view class="content">
-      <view class="img-box">
-        <!-- <image :src="error || !loaded ? 'https://cdn.uviewui.com/uview/album/10.jpg' : item.logo" mode="scaleToFill" /> -->
-        <image class='img' :src="item.logo " mode="scaleToFill" />
-        <view class="name u-line-1">{{ item.name }}</view>
-      </view>
-      <view class="pd-10 address">{{ item.address }}</view>
-      <view class="pd-10 distance">{{ item.distance | mToKm }}</view>
-    </view>
-  </view>
-</template>
-
-<script>
-export default {
-  props: {
-    item: {
-      type: Object,
-      default: () => {},
-    },
-  },
-  filters: {
-    mToKm(v) {
-      return (Number(v) / 1000).toFixed(2) + 'km';
-    },
-  },
-};
-</script>
-
-<style lang="scss" scoped>
-.container {
-  width: 100%;
-  box-sizing: border-box;
-  .content {
-    background-color: #ffffff;
-    width: 100%;
-    padding-bottom:20rpx;
-    border-radius:16rpx;
-    margin-bottom:24rpx;
-    box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(0,0,0,0.05);
-    .img-box {
-      position: relative;
-      height: 240rpx;
-      .img {
-        width: 100%;
-        height: 212rpx;
-        border-radius: 10rpx;
-      }
-      .name {
-        width: 100%;
-        position: absolute;
-        bottom: 0;
-        left: 0;
-        background-color: rgba(0, 0, 0, 0.2);
-        color: #ffffff;
-        padding: 10rpx;
-        box-sizing: border-box;
-        display: inline-block;
-        white-space: nowrap;
-        overflow: hidden;
-        text-overflow: ellipsis;
-      }
-    }
-    .address{
-      width:95%;
-      overflow:hidden;
-      text-overflow: ellipsis;
-      white-space: nowrap;
-      font-size:24rpx;
-    }
-    .distance{
-      color:#1B5FC5;
-      font-weight:bold;
-    }
-    .pd-10 {
-      padding: 10rpx;
-    }
-  }
-}
-</style>

+ 393 - 0
src/pages/tabbar/home copy.vue

@@ -0,0 +1,393 @@
+<template>
+  <view class="container">
+    <view class="container-top-box">
+      <view class="top-title">
+       <view class="address" @click.stop="manualGetLocation">
+          <span>{{ nowAddress }}</span>
+          <u-icon name="arrow-down-fill" color="#333333" size="16"></u-icon>
+        </view>
+        <view class="title">车旅程</view>
+        <view></view>
+      </view>
+      <view class="top-search">
+        <u-search
+          placeholder="请输入搜索内容"
+          :showAction="false"
+          v-model="keyword"
+          @click="$Router.push('/pagesHome/homeSearch')"
+          bgColor="#fff"
+          :disabled="true"
+        />
+      </view>
+
+      <view class="top-swiper-box">
+        <u-swiper :list="swiperUrlList" @click="handlerSwiperSkip" indicator circular />
+      </view>
+    </view>
+
+    <view class="container-tabbar-box">
+      <view class="tabar-box">
+        <view
+          class="tabbar-item"
+          v-for="(item, index) of categories"
+          :key="index"
+          @tap="handleMenuClick(item)"
+        >
+          <view class="item-img">
+            <image class="img" :src="item.icon"></image>
+          </view>
+          <view class="item-name">{{ item.name }}</view>
+        </view>
+      </view>
+    </view>
+
+    <view class="container-list-box">
+      <view class="item-box">
+        <view class="item-top">
+          <view class="top-title">热门推荐</view>
+          <view class="top-more" @click="$Router.push('/pagesHome/home/popularRecommend')">
+            <span>查看更多</span>
+            <u-icon name="arrow-right" color="#999999" size="14"></u-icon>
+          </view>
+        </view>
+        <view class="item-list">
+          <view
+            class="item"
+            v-for="(item, index) in homeData.recommends"
+            :key="item.id"
+            @click="$Router.push(`/pagesHome/marketer/index?id=${item.id}`)"
+          >
+            <hot-item v-if="index < 4" :item="item"></hot-item>
+          </view>
+        </view>
+        <u-empty
+          v-if="!homeData.recommends"
+          mode="data"
+          icon="http://cdn.uviewui.com/uview/empty/data.png"
+        >
+        </u-empty>
+      </view>
+
+      <view class="item-box">
+        <view class="item-top">
+          <view class="top-title">附近商家</view>
+          <view class="top-more" @click="$Router.push('/pagesHome/home/nearbyBusiness')">
+            <span>查看更多</span>
+            <u-icon name="arrow-right" color="#999999" size="14"></u-icon>
+          </view>
+        </view>
+        <view class="item-list">
+          <view
+            class="item"
+            v-for="(item, index) in homeData.nears"
+            :key="item.id"
+            @click="$Router.push(`/pagesHome/marketer/index?id=${item.id}`)"
+          >
+            <recommend-item v-if="index < 4" :item="item"></recommend-item>
+          </view>
+        </view>
+        <u-empty
+          v-if="!homeData.nears"
+          mode="data"
+          icon="http://cdn.uviewui.com/uview/empty/data.png"
+        >
+        </u-empty>
+      </view>
+    </view>
+  </view>
+</template>
+
+<script>
+import { getCurrentLocation, getHomePageApi, getSwiperListApi } from '@/api/client/home';
+import { getMapLocation } from '@/utils/mapUtil.js';
+import { inviteBind } from '@/api/client/mine.js';
+import RecommendItem from './components/RecommendItem.vue';
+import HotItem from './components/HotItem.vue';
+import { mapGetters } from 'vuex';
+export default {
+  components: { RecommendItem, HotItem },
+  data() {
+    return {
+      list: [],
+      keyword: '',
+      swiperUrlList: [], // 轮播图url列表
+      swiperList: [],
+      homeData: {
+        categories: [],
+        nears: [],
+        recommends: [],
+      },
+      queryParams: {
+        longitude: '',
+        latitude: '',
+        region: '',
+      },
+      nowAddress: '', //当前地址
+    };
+  },
+  computed: {
+    ...mapGetters(['location', 'userId', 'invitationCode']),
+    categories() {
+      let initData = this.homeData.categories.map(item => {
+        if (!item.icon) {
+          item.icon = 'level';
+        }
+        return item;
+      });
+      let result =
+        initData.length > 14
+          ? initData.splice(0, 14).concat([
+              {
+                id: 'all',
+                icon: 'grid-fill',
+                name: '全部',
+                type: {
+                  code: 'ALL',
+                  description: '全部',
+                },
+              },
+            ])
+          : initData.push({
+              id: 'all',
+              icon: 'grid-fill',
+              name: '全部',
+            });
+      return result;
+    },
+  },
+  onShow() {
+
+    // 如果 invitationCode 存在且不等于特殊值时执行代码
+    if (this.invitationCode) {
+      
+      let params = {
+        userId: this.invitationCode,
+        targetId: this.userId,
+        type: 1,
+      };
+      inviteBind(params).then(res => {
+        if (res && res.code == 200) {
+          uni.showToast({
+            title: '您已成功加入团队',
+            icon: 'success',
+            dration: 2000,
+          });
+        }
+        // console.log("绑定邀请码结果:", res);
+      });
+      this.$store.commit('SET_INVITATIONCODE', '');
+    } else {
+    
+    }
+  },
+  mounted() {
+    this.getSwiperList();
+    // 页面显示时  获取当前零维度
+    uni.getLocation({
+      type: 'gcj02',
+      success: res => {
+        let { longitude, latitude } = res;
+        this.queryParams.longitude = longitude;
+        this.queryParams.latitude = latitude;
+        // getCurrentLocation 获取当前编码region
+        this.handlerGetRegion(longitude, latitude);
+      },
+      fail: () => {
+        this.manualGetLocation();
+      },
+    });
+  },
+  methods: {
+    // 获取当前编码region
+    handlerGetRegion(longitude, latitude) {
+      let point = `${latitude},${longitude}`;
+      getCurrentLocation({
+        point,
+      }).then(res => {
+        let { city, district, id } = res.data;
+        this.queryParams.region = res.data.id;
+        if (district) {
+          this.nowAddress = district.name;
+        } else if (city) {
+          this.nowAddress = city.name;
+        } else {
+          this.nowAddress = '地图';
+        }
+        this.getHomeData(this.queryParams);
+        this.$store.commit('SET_LOCATION', {
+          longitude: longitude,
+          latitude: latitude,
+          region: res.data.id,
+          address: res.data.name,
+        });
+      });
+    },
+    /* 轮播图 */
+    getSwiperList() {
+      getSwiperListApi().then(res => {
+        this.swiperList = res.data;
+        res.data.map(rs => {
+          this.swiperUrlList.push(rs.viewUrl);
+        });
+      });
+    },
+    // 获取首页数据
+    getHomeData(location) {
+      getHomePageApi(location).then(res => {
+        this.homeData = res.data;
+        // 将分类数据做缓存处理
+        this.$store.commit('SET_CATEGORIES', this.homeData.categories);
+      });
+    },
+    // 手动选择城市
+    manualGetLocation() {
+      uni.chooseLocation({
+        success: res => {
+          let { longitude, latitude } = res;
+          this.queryParams.longitude = longitude.toFixed(5);
+          this.queryParams.latitude = latitude.toFixed(5);
+          this.handlerGetRegion(longitude.toFixed(5), latitude.toFixed(5));
+        },
+        fail: err => {},
+      });
+    },
+    // 点击swiper跳转
+    handlerSwiperSkip(e) {
+      console.log('@@@swiperList', this.swiperList[e]);
+    },
+    // 点击菜单
+    handleMenuClick(item) {
+      console.log('111111', item);
+      if (item.name === '全部') {
+        this.$Router.push('/pagesHome/category/index');
+      } else {
+        uni.navigateTo({
+          url: `/pagesHome/category/categoryStoreList?id=${item.id}&name=${item.name}`,
+        });
+      }
+      // 
+    },
+
+    /* 询价 */
+    btnClick() {
+      uni.navigateTo({
+        url: `/pages/client/clientUser/inquiry`,
+      });
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.container {
+  font-size: 28rpx;
+  min-height: calc(100vh - 30rpx);
+  background-color: #f9f9f9;
+  padding-bottom: 30rpx;
+  .container-top-box {
+    padding: 108rpx 32rpx 34rpx;
+    box-sizing: border-box;
+    background: linear-gradient(180deg, #d4e3ff 0%, #f0f1f9 53%, #f9f9f9);
+
+    .top-title {
+      display: grid;
+      grid-template-columns: 33% 33% 33%;
+      justify-content: space-between;
+      margin-bottom: 34rpx;
+      align-items: center;
+
+      .address {
+        display: flex;
+        color: #333333;
+      }
+
+      .title {
+        color: #0c1223;
+        font-weight: bold;
+        font-size: 34rpx;
+        text-align: center;
+      }
+    }
+
+    .top-search {
+      margin-bottom: 34rpx;
+    }
+
+    .top-swiper-box {
+      width: 100%;
+      height: 256rpx;
+      border-radius: 20rpx;
+      background-color: #fff;
+    }
+  }
+
+  .container-tabbar-box {
+    padding: 0 32rpx 0;
+
+    .tabar-box {
+      width: 100%;
+      border-radius: 20rpx;
+      padding: 12rpx 34rpx 32rpx;
+      box-sizing: border-box;
+      background-color: #fff;
+      display: grid;
+      grid-template-columns: repeat(5, 18%);
+      justify-content: space-between;
+      grid-gap: 24rpx 0;
+      box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(0, 0, 0, 0.05);
+      .tabbar-item {
+        text-align: center;
+
+        .item-img {
+          .img {
+            width: 56rpx;
+            height: 56rpx;
+          }
+        }
+
+        .item-name {
+          margin-top: 16rpx;
+          overflow: hidden;
+          text-overflow: ellipsis;
+          white-space: nowrap;
+        }
+      }
+    }
+  }
+
+  .container-list-box {
+    padding: 0 32rpx 0;
+    box-sizing: border-box;
+    .item-box {
+      margin-top: 32rpx;
+
+      .item-top {
+        display: flex;
+        justify-content: space-between;
+        align-items: center;
+        margin-bottom: 32rpx;
+        .top-title {
+          color: #0c1223;
+          font-size: 34rpx;
+          font-weight: bold;
+        }
+
+        .top-more {
+          display: flex;
+          color: #999999;
+          font-size: 24rpx;
+          align-items: center;
+        }
+      }
+      .item-list {
+        display: grid;
+        grid-template-columns: repeat(2, 47.81%);
+        justify-content: space-between;
+        .item {
+          border-radius: 16rpx;
+        }
+      }
+    }
+  }
+}
+</style>

+ 7 - 35
src/pages/tabbar/home.vue

@@ -2,9 +2,9 @@
   <view class="container">
     <view class="container-top-box">
       <view class="top-title">
-       <view class="address" @click.stop="manualGetLocation">
+        <view class="address" @click.stop="manualGetLocation">
           <span>{{ nowAddress }}</span>
-          <u-icon name="arrow-down-fill" color="#333333" size="16"></u-icon>
+          <u-icon name="arrow-down-fill" color="#333333" size="10"></u-icon>
         </view>
         <view class="title">车旅程</view>
         <view></view>
@@ -57,15 +57,9 @@
             :key="item.id"
             @click="$Router.push(`/pagesHome/marketer/index?id=${item.id}`)"
           >
-            <hot-item v-if="index < 4" :item="item"></hot-item>
+            <home-store v-if="index < 4" :item="item"></home-store>
           </view>
         </view>
-        <u-empty
-          v-if="!homeData.recommends"
-          mode="data"
-          icon="http://cdn.uviewui.com/uview/empty/data.png"
-        >
-        </u-empty>
       </view>
 
       <view class="item-box">
@@ -83,15 +77,9 @@
             :key="item.id"
             @click="$Router.push(`/pagesHome/marketer/index?id=${item.id}`)"
           >
-            <recommend-item v-if="index < 4" :item="item"></recommend-item>
+            <home-store v-if="index < 4" :item="item"></home-store>
           </view>
         </view>
-        <u-empty
-          v-if="!homeData.nears"
-          mode="data"
-          icon="http://cdn.uviewui.com/uview/empty/data.png"
-        >
-        </u-empty>
       </view>
     </view>
   </view>
@@ -99,13 +87,10 @@
 
 <script>
 import { getCurrentLocation, getHomePageApi, getSwiperListApi } from '@/api/client/home';
-import { getMapLocation } from '@/utils/mapUtil.js';
 import { inviteBind } from '@/api/client/mine.js';
-import RecommendItem from './components/RecommendItem.vue';
-import HotItem from './components/HotItem.vue';
 import { mapGetters } from 'vuex';
 export default {
-  components: { RecommendItem, HotItem },
+  name: 'home',
   data() {
     return {
       list: [],
@@ -139,7 +124,7 @@ export default {
           ? initData.splice(0, 14).concat([
               {
                 id: 'all',
-                icon: 'grid-fill',
+                icon: '/static/pages/home/home-all.png',
                 name: '全部',
                 type: {
                   code: 'ALL',
@@ -149,17 +134,15 @@ export default {
             ])
           : initData.push({
               id: 'all',
-              icon: 'grid-fill',
+              icon: '/static/pages/home/home-all.png',
               name: '全部',
             });
       return result;
     },
   },
   onShow() {
-
     // 如果 invitationCode 存在且不等于特殊值时执行代码
     if (this.invitationCode) {
-      
       let params = {
         userId: this.invitationCode,
         targetId: this.userId,
@@ -173,11 +156,9 @@ export default {
             dration: 2000,
           });
         }
-        // console.log("绑定邀请码结果:", res);
       });
       this.$store.commit('SET_INVITATIONCODE', '');
     } else {
-    
     }
   },
   mounted() {
@@ -257,7 +238,6 @@ export default {
     },
     // 点击菜单
     handleMenuClick(item) {
-      console.log('111111', item);
       if (item.name === '全部') {
         this.$Router.push('/pagesHome/category/index');
       } else {
@@ -265,14 +245,6 @@ export default {
           url: `/pagesHome/category/categoryStoreList?id=${item.id}&name=${item.name}`,
         });
       }
-      // 
-    },
-
-    /* 询价 */
-    btnClick() {
-      uni.navigateTo({
-        url: `/pages/client/clientUser/inquiry`,
-      });
     },
   },
 };

+ 12 - 19
src/pages/tabbar/mine/index.vue

@@ -74,19 +74,17 @@
       </base-card>
 
       <base-card padding="0rpx" marginBottom="24rpx">
-        <view class="mine-cell">
-          <u-cell-group v-for="(item, index) in LinkList" :key="index" :border="false">
-            <u-cell :title="item.title" @click="handleCell(item)" isLink :border="index !== 5">
-              <view slot="icon" class="u-m-r-10">
-                <u--image
-                  :src="`/static/pages/mine/${item.icon}.png`"
-                  width="38rpx"
-                  height="38rpx"
-                ></u--image>
-              </view>
-            </u-cell>
-          </u-cell-group>
-        </view>
+        <u-cell-group v-for="(item, index) in LinkList" :key="index" :border="false">
+          <u-cell :title="item.title" @click="handleCell(item)" isLink :border="index !== 5">
+            <view slot="icon" class="u-m-r-10">
+              <u--image
+                :src="`/static/pages/mine/${item.icon}.png`"
+                width="38rpx"
+                height="38rpx"
+              ></u--image>
+            </view>
+          </u-cell>
+        </u-cell-group>
       </base-card>
     </view>
   </view>
@@ -253,11 +251,6 @@ export default {
   }
 }
 ::v-deep .u-cell__title-text {
-  line-height: 48rpx !important;
-}
-.mine-cell {
-  ::v-deep .u-cell-group:nth-child(6) {
-    border-bottom: none !important;
-  }
+  line-height: 50rpx !important;
 }
 </style>

BIN
src/static/pages/home/home-all.png


BIN
src/static/pages/home/home-hot.png