小兔鲜电商项目(六)---结算、支付和会员中心

黑马vue3项目小兔鲜总结 对vue3小兔鲜项目的总结以及一些遇到的问题记录 阅读详情

目录

一、结算

路由配置

基础数据渲染

地址切换

打开弹框交互实现

地址激活交互实现

生成订单功能实现

二、支付

渲染基础数据

实现支付功能

支付携带参数

支付宝沙箱账号信息

支付结果展示

封装倒计时函数

三、会员中心

路由配置(包括三级路由配置)

会员中心

个人信息

用户订单

个人中心信息渲染

我的订单

基础订单列表实现

tab切换实现

分页逻辑

细节优化

默认三级路由设置

订单状态显示适配


一、结算

模板代码

<script setup>
const checkInfo = {}  // 订单对象
const curAddress = {}  // 地址对象

</script>

<template>
  <div class="xtx-pay-checkout-page">
    <div class="container">
      <div class="wrapper">
        <!-- 收货地址 -->
        <h3 class="box-title">收货地址</h3>
        <div class="box-body">
          <div class="address">
            <div class="text">
              <div class="none" v-if="!curAddress">您需要先添加收货地址才可提交订单。</div>
              <ul v-else>
                <li><span>收<i />货<i />人:</span>{{ curAddress.receiver }}</li>
                <li><span>联系方式:</span>{{ curAddress.contact }}</li>
                <li><span>收货地址:</span>{{ curAddress.fullLocation }} {{ curAddress.address }}</li>
              </ul>
            </div>
            <div class="action">
              <el-button size="large">切换地址</el-button>
              <el-button size="large">添加地址</el-button>
            </div>
          </div>
        </div>
        <!-- 商品信息 -->
        <h3 class="box-title">商品信息</h3>
        <div class="box-body">
          <table class="goods">
            <thead>
              <tr>
                <th width="520">商品信息</th>
                <th width="170">单价</th>
                <th width="170">数量</th>
                <th width="170">小计</th>
                <th width="170">实付</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="i in checkInfo.goods" :key="i.id">
                <td>
                  <a href="javascript:;" class="info">
                    <img :src="i.picture" alt="">
                    <div class="right">
                      <p>{{ i.name }}</p>
                      <p>{{ i.attrsText }}</p>
                    </div>
                  </a>
                </td>
                <td>&yen;{{ i.price }}</td>
                <td>{{ i.price }}</td>
                <td>&yen;{{ i.totalPrice }}</td>
                <td>&yen;{{ i.totalPayPrice }}</td>
              </tr>
            </tbody>
          </table>
        </div>
        <!-- 配送时间 -->
        <h3 class="box-title">配送时间</h3>
        <div class="box-body">
          <a class="my-btn active" href="javascript:;">不限送货时间:周一至周日</a>
          <a class="my-btn" href="javascript:;">工作日送货:周一至周五</a>
          <a class="my-btn" href="javascript:;">双休日、假日送货:周六至周日</a>
        </div>
        <!-- 支付方式 -->
        <h3 class="box-title">支付方式</h3>
        <div class="box-body">
          <a class="my-btn active" href="javascript:;">在线支付</a>
          <a class="my-btn" href="javascript:;">货到付款</a>
          <span style="color:#999">货到付款需付5元手续费</span>
        </div>
        <!-- 金额明细 -->
        <h3 class="box-title">金额明细</h3>
        <div class="box-body">
          <div class="total">
            <dl>
              <dt>商品件数:</dt>
              <dd>{{ checkInfo.summary?.goodsCount }}件</dd>
            </dl>
            <dl>
              <dt>商品总价:</dt>
              <dd>¥{{ checkInfo.summary?.totalPrice.toFixed(2) }}</dd>
            </dl>
            <dl>
              <dt>运<i></i>费:</dt>
              <dd>¥{{ checkInfo.summary?.postFee.toFixed(2) }}</dd>
            </dl>
            <dl>
              <dt>应付总额:</dt>
              <dd class="price">{{ checkInfo.summary?.totalPayPrice.toFixed(2) }}</dd>
            </dl>
          </div>
        </div>
        <!-- 提交订单 -->
        <div class="submit">
          <el-button type="primary" size="large" >提交订单</el-button>
        </div>
      </div>
    </div>
  </div>
  <!-- 切换地址 -->
  <!-- 添加地址 -->
</template>

<style scoped lang="scss">
.xtx-pay-checkout-page {
  margin-top: 20px;

  .wrapper {
    background: #fff;
    padding: 0 20px;

    .box-title {
      font-size: 16px;
      font-weight: normal;
      padding-left: 10px;
      line-height: 70px;
      border-bottom: 1px solid #f5f5f5;
    }

    .box-body {
      padding: 20px 0;
    }
  }
}

.address {
  border: 1px solid #f5f5f5;
  display: flex;
  align-items: center;

  .text {
    flex: 1;
    min-height: 90px;
    display: flex;
    align-items: center;

    .none {
      line-height: 90px;
      color: #999;
      text-align: center;
      width: 100%;
    }

    >ul {
      flex: 1;
      padding: 20px;

      li {
        line-height: 30px;

        span {
          color: #999;
          margin-right: 5px;

          >i {
            width: 0.5em;
            display: inline-block;
          }
        }
      }
    }

    >a {
      color: $xtxColor;
      width: 160px;
      text-align: center;
      height: 90px;
      line-height: 90px;
      border-right: 1px solid #f5f5f5;
    }
  }

  .action {
    width: 420px;
    text-align: center;

    .btn {
      width: 140px;
      height: 46px;
      line-height: 44px;
      font-size: 14px;

      &:first-child {
        margin-right: 10px;
      }
    }
  }
}

.goods {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;

  .info {
    display: flex;
    text-align: left;

    img {
      width: 70px;
      height: 70px;
      margin-right: 20px;
    }

    .right {
      line-height: 24px;

      p {
        &:last-child {
          color: #999;
        }
      }
    }
  }

  tr {
    th {
      background: #f5f5f5;
      font-weight: normal;
    }

    td,
    th {
      text-align: center;
      padding: 20px;
      border-bottom: 1px solid #f5f5f5;

      &:first-child {
        border-left: 1px solid #f5f5f5;
      }

      &:last-child {
        border-right: 1px solid #f5f5f5;
      }
    }
  }
}

.my-btn {
  width: 228px;
  height: 50px;
  border: 1px solid #e4e4e4;
  text-align: center;
  line-height: 48px;
  margin-right: 25px;
  color: #666666;
  display: inline-block;

  &.active,
  &:hover {
    border-color: $xtxColor;
  }
}

.total {
  dl {
    display: flex;
    justify-content: flex-end;
    line-height: 50px;

    dt {
      i {
        display: inline-block;
        width: 2em;
      }
    }

    dd {
      width: 240px;
      text-align: right;
      padding-right: 70px;

      &.price {
        font-size: 20px;
        color: $priceColor;
      }
    }
  }
}

.submit {
  text-align: right;
  padding: 60px;
  border-top: 1px solid #f5f5f5;
}

.addressWrapper {
  max-height: 500px;
  overflow-y: auto;
}

.text {
  flex: 1;
  min-height: 90px;
  display: flex;
  align-items: center;

  &.item {
    border: 1px solid #f5f5f5;
    margin-bottom: 10px;
    cursor: pointer;

    &.active,
    &:hover {
      border-color: $xtxColor;
      background: lighten($xtxColor, 50%);
    }

    >ul {
      padding: 10px;
      font-size: 14px;
      line-height: 30px;
    }
  }
}
</style>
路由配置

在router/index.js中配置路由关系

import Checkout from '@/views/Checkout/index.vue'
        {
          path:'checkout',
          component: Checkout
        }

在views/CartList/index.vue文件中配置路由跳转

<el-button size="large" type="primary" @click="$router.push('/checkout')">下单结算</el-button>
基础数据渲染

创建apis/checkout.js文件封装接口

import http from '@/utils/http'

// 获取详情接口
export const getCheckInfoAPI = () => {
  return http({
    url: '/member/order/pre'
  })
}

在views/Checkout/index.vue文件中获取数据

import {getCheckInfoAPI} from '@/apis/checkout'
import { onMounted, ref } from 'vue'

const checkInfo = ref({})  // 订单对象
const curAddress=ref({})  // 地址对象

const getCheckInfo =async ()=>{
  const res=await getCheckInfoAPI()
  checkInfo.value=res.result
  const item=checkInfo.value.userAddresses.find(item=>item.isDefault===0)
  curAddress.value=item
}
onMounted(()=>getCheckInfo())
地址切换
打开弹框交互实现

点击切换地址按钮,打开弹框,回显用户可选地址列表

在Checkout/index.vue文件中准备弹框组件

  <!-- 切换地址 -->
  <el-dialog title="切换收货地址" width="30%" center>
    <div class="addressWrapper">
      <div class="text item" v-for="item in checkInfo.userAddresses" :key="item.id">
        <ul>
          <li><span>收<i />货<i />人:</span>{{ item.receiver }} </li>
          <li><span>联系方式:</span>{{ item.contact }}</li>
          <li><span>收货地址:</span>{{ item.fullLocation + item.address }}</li>
        </ul>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button>取消</el-button>
        <el-button type="primary">确定</el-button>
      </span>
    </template>
  </el-dialog>

在Checkout/index.vue文件中控制弹窗打开

// 控制弹框打开
const showDialog =ref(false)
              <el-button size="large" @click="showDialog=true">切换地址</el-button>
  <el-dialog v-model="showDialog" title="切换收货地址" width="30%" center>
地址激活交互实现

点击切换地址,点击确定按钮,激活地址替换默认收获地址

事件绑定,动态渲染类名active实现选中激活效果

  <el-dialog v-model="showDialog" title="切换收货地址" width="30%" center>
    <div class="addressWrapper">
      <div class="text item" :class="{active:activeAddress.id===item.id}" @click="switchAddress(item)" v-for="item in checkInfo.userAddresses" :key="item.id">
        <ul>
          <li><span>收<i />货<i />人:</span>{{ item.receiver }} </li>
          <li><span>联系方式:</span>{{ item.contact }}</li>
          <li><span>收货地址:</span>{{ item.fullLocation + item.address }}</li>
        </ul>
      </div>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="showDialog=false">取消</el-button>
        <el-button type="primary" @click="confirm">确定</el-button>
      </span>
    </template>
  </el-dialog>
// 切换地址
const activeAddress=ref({})
const switchAddress=(item)=>{
  activeAddress.value=item
}
const confirm=()=>{
  curAddress.value=activeAddress.value
  showDialog.value=false
}
生成订单功能实现

        调用接口生成订单id,并且携带id跳转到支付页;调用更新购物车列表接口,更新购物车状态

模板代码

<script setup>
const payInfo = {}
</script>
 
 
<template>
  <div class="xtx-pay-page">
    <div class="container">
      <!-- 付款信息 -->
      <div class="pay-info">
        <span class="icon iconfont icon-queren2"></span>
        <div class="tip">
          <p>订单提交成功!请尽快完成支付。</p>
          <p>支付还剩 <span>24分30秒</span>, 超时后将取消订单</p>
        </div>
        <div class="amount">
          <span>应付总额:</span>
          <span>¥{{ payInfo.payMoney?.toFixed(2) }}</span>
        </div>
      </div>
      <!-- 付款方式 -->
      <div class="pay-type">
        <p class="head">选择以下支付方式付款</p>
        <div class="item">
          <p>支付平台</p>
          <a class="btn wx" href="javascript:;"></a>
          <a class="btn alipay" :href="payUrl"></a>
        </div>
        <div class="item">
          <p>支付方式</p>
          <a class="btn" href="javascript:;">招商银行</a>
          <a class="btn" href="javascript:;">工商银行</a>
          <a class="btn" href="javascript:;">建设银行</a>
          <a class="btn" href="javascript:;">农业银行</a>
          <a class="btn" href="javascript:;">交通银行</a>
        </div>
      </div>
    </div>
  </div>
</template>
 
<style scoped lang="scss">
.xtx-pay-page {
  margin-top: 20px;
}
 
.pay-info {
 
  background: #fff;
  display: flex;
  align-items: center;
  height: 240px;
  padding: 0 80px;
 
  .icon {
    font-size: 80px;
    color: #1dc779;
  }
 
  .tip {
    padding-left: 10px;
    flex: 1;
 
    p {
      &:first-child {
        font-size: 20px;
        margin-bottom: 5px;
      }
 
      &:last-child {
        color: #999;
        font-size: 16px;
      }
    }
  }
 
  .amount {
    span {
      &:first-child {
        font-size: 16px;
        color: #999;
      }
 
      &:last-child {
        color: $priceColor;
        font-size: 20px;
      }
    }
  }
}
 
.pay-type {
  margin-top: 20px;
  background-color: #fff;
  padding-bottom: 70px;
 
  p {
    line-height: 70px;
    height: 70px;
    padding-left: 30px;
    font-size: 16px;
 
    &.head {
      border-bottom: 1px solid #f5f5f5;
    }
  }
 
  .btn {
    width: 150px;
    height: 50px;
    border: 1px solid #e4e4e4;
    text-align: center;
    line-height: 48px;
    margin-left: 30px;
    color: #666666;
    display: inline-block;
 
    &.active,
    &:hover {
      border-color: $xtxColor;
    }
 
    &.alipay {
      background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/7b6b02396368c9314528c0bbd85a2e06.png) no-repeat center / contain;
    }
 
    &.wx {
      background: url(https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/c66f98cff8649bd5ba722c2e8067c6ca.jpg) no-repeat center / contain;
    }
  }
}
</style>

配置路由

import Pay from '@/views/Pay/index.vue'
        {
          path: 'checkout',
          component: Checkout
        }

封装接口

// 创建订单
export const createOrderAPI = (data) => {
  return http({
    url: `/member/order`,
    method: 'POST',
    data
  })
}

点击按钮调用接口,得到订单id,携带id完成路由跳转

import {getCheckInfoAPI,createOrderAPI} from '@/apis/checkout'
import { useRouter } from 'vue-router'
import { useCartStore } from '@/stores/cartStore'
const cartStore=useCartStore()
const router=useRouter()
const createOrder=async ()=>{
  const res=await createOrderAPI({
    deliveryTimeType:1,
    payType:1,
    payChannel:1,
    buyerMessage:'',
    goods:checkInfo.value.goods.map(item=>{
      return {
        skuId:item.skuId,
        count:item.count
      }
    }),
    addressId:curAddress.value.id
  })
  const orderId=res.result.id
  router.push({
    path:'/pay',
    query:{
      id:orderId
    }
  })
  // 更新购物车
  cartStore.updateNewList()
}
        <!-- 提交订单 -->
        <div class="submit">
          <el-button @click="createOrder" type="primary" size="large" >提交订单</el-button>
        </div>

二、支付

渲染基础数据

创建apis/pay.js文件封装接口

import http from '@/utils/http'

export const getOrderAPI = (id) => {
  return http({
    url: `/member/order/${id}`
  })
}

关键数据渲染

import { getOrderAPI } from '@/apis/pay'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
// 获取订单数据
const route=useRoute()
const payInfo = ref({})
const getPayInfo=async()=>{
  const res=await getOrderAPI(route.query.id)
  payInfo.value=res.result
}
onMounted(()=>getPayInfo())
实现支付功能

流程:

支付携带参数
// 支付地址
const baseURL = 'http://pcapi-xiaotuxian-front-devtest.itheima.net/'
const backURL = 'http://127.0.0.1:5173/paycallback'
const redirectUrl = encodeURIComponent(backURL)
const payUrl = `${baseURL}pay/aliPay?orderId=${route.query.id}&redirect=${redirectUrl}`
支付宝沙箱账号信息

沙箱新账号如下:

账号scobys4865@sandbox.com
登录密码111111
支付密码111111
支付结果展示

配置路由:

<script setup>

</script>

<template>
  <div class="xtx-pay-page">
    <div class="container">
      <!-- 支付结果 -->
      <div class="pay-result">
        <span class="iconfont icon-queren2 green"></span>
        <span class="iconfont icon-shanchu red"></span>
        <p class="tit">支付成功</p>
        <p class="tip">我们将尽快为您发货,收货期间请保持手机畅通</p>
        <p>支付方式:<span>支付宝</span></p>
        <p>支付金额:<span>¥200.00</span></p>
        <div class="btn">
          <el-button type="primary" style="margin-right:20px">查看订单</el-button>
          <el-button>进入首页</el-button>
        </div>
        <p class="alert">
          <span class="iconfont icon-tip"></span>
          温馨提示:小兔鲜儿不会以订单异常、系统升级为由要求您点击任何网址链接进行退款操作,保护资产、谨慎操作。
        </p>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.pay-result {
  padding: 100px 0;
  background: #fff;
  text-align: center;
  margin-top: 20px;

  >.iconfont {
    font-size: 100px;
  }

  .green {
    color: #1dc779;
  }

  .red {
    color: $priceColor;
  }

  .tit {
    font-size: 24px;
  }

  .tip {
    color: #999;
  }

  p {
    line-height: 40px;
    font-size: 16px;
  }

  .btn {
    margin-top: 50px;
  }

  .alert {
    font-size: 12px;
    color: #999;
    margin-top: 50px;
  }
}
</style>

根据支付结果适配支付状态:

import { getOrderAPI } from '@/apis/pay'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
const route=useRoute()
const orderInfo=ref({})
const getOrderInfo=async ()=>{
  const res=await getOrderAPI(route.query.id)
  orderInfo.value=res.result
}
onMounted(()=>getOrderInfo())
        <span class="iconfont icon-queren2 green" v-if="$route.query.payResult==='true'"></span>
        <span class="iconfont icon-shanchu red" v-else></span>
        <p class="tit">支付{{ $route.query.payResult==='true'?'成功':'失败' }}</p>

获取订单数据渲染支付信息:

        orderInfo初始是一个空对象,orderInfo.payMoney是一个undefined,它没有toFixed方法,因此我们可以使用v-if条件渲染或者使用?可选链,如下:

        <p>支付金额:<span>¥{{ orderInfo.payMoney?.toFixed(2) }}</span></p>
封装倒计时函数

安装格式化插件:npm i dayjs

// 封装倒计时函数

import { computed, onUnmounted, ref } from "vue"
import dayjs from 'dayjs'
export const useCountDown = () => {
  // 响应式数据
  let timer = null
  const time = ref(0)
  // 格式化时间 x分x秒
  const formatTime = computed(() => dayjs.unix(time.value).format('mm分ss秒'))

  // 开启倒计时的函数
  const start = (currentTime) => {
    // 每隔1s就 -1
    time.value = currentTime
    timer = setInterval(() => {
      time.value--
    }, 1000)
  }
  // 组件销毁时清除定时器
  onUnmounted(() => {
    timer && clearInterval(timer)
  })
  return {
    formatTime, start
  }
}
import { useCountDown } from '@/composables/useCountDown'
const {formatTime,start}=useCountDown()
const getPayInfo=async()=>{
  const res=await getOrderAPI(route.query.id)
  payInfo.value=res.result
  // 初始化倒计时秒数
  start(res.result.countdown)
}
<p>支付还剩 <span>{{ formatTime }}</span>, 超时后将取消订单</p>

三、会员中心

路由配置(包括三级路由配置)

模板代码

会员中心

创建 src \views\Member\index.vue 文件,添加会员中心模板代码:

<script setup> </script>

<template>
  <div class="container">
    <div class="xtx-member-aside">
      <div class="user-manage">
        <h4>我的账户</h4>
        <div class="links">
          <RouterLink to="/member/user">个人中心</RouterLink>
        </div>
        <h4>交易管理</h4>
        <div class="links">
          <RouterLink to="/member/order">我的订单</RouterLink>
        </div>
      </div>
    </div>
    <div class="article">
      <!-- 三级路由的挂载点 -->
      <RouterView />
    </div>
  </div>
</template>

<style scoped lang="scss">
.container {
  display: flex;
  padding-top: 20px;

  .xtx-member-aside {
    width: 220px;
    margin-right: 20px;
    border-radius: 2px;
    background-color: #fff;

    .user-manage {
      background-color: #fff;

      h4 {
        font-size: 18px;
        font-weight: 400;
        padding: 20px 52px 5px;
        border-top: 1px solid #f6f6f6;
      }

      .links {
        padding: 0 52px 10px;
      }

      a {
        display: block;
        line-height: 1;
        padding: 15px 0;
        font-size: 14px;
        color: #666;
        position: relative;

        &:hover {
          color: $xtxColor;
        }

        &.active,
        &.router-link-exact-active {
          color: $xtxColor;

          &:before {
            display: block;
          }
        }

        &:before {
          content: '';
          display: none;
          width: 6px;
          height: 6px;
          border-radius: 50%;
          position: absolute;
          top: 19px;
          left: -16px;
          background-color: $xtxColor;
        }
      }
    }
  }

  .article {
    width: 1000px;
    background-color: #fff;
  }
}
</style>
个人信息

创建 src\views\Member\components\UserInfo.vue  文件,添加代码:

<script setup>
const userStore = {}
</script>

<template>
  <div class="home-overview">
    <!-- 用户信息 -->
    <div class="user-meta">
      <div class="avatar">
        <img :src="userStore.userInfo?.avatar" />
      </div>
      <h4>{{ userStore.userInfo?.account }}</h4>
    </div>
    <div class="item">
      <a href="javascript:;">
        <span class="iconfont icon-hy"></span>
        <p>会员中心</p>
      </a>
      <a href="javascript:;">
        <span class="iconfont icon-aq"></span>
        <p>安全设置</p>
      </a>
      <a href="javascript:;">
        <span class="iconfont icon-dw"></span>
        <p>地址管理</p>
      </a>
    </div>
  </div>
  <div class="like-container">
    <div class="home-panel">
      <div class="header">
        <h4 data-v-bcb266e0="">猜你喜欢</h4>
      </div>
      <div class="goods-list">
        <!-- <GoodsItem v-for="good in likeList" :key="good.id" :good="good" /> -->
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.home-overview {
  height: 132px;
  background: url(@/assets/images/center-bg.png) no-repeat center / cover;
  display: flex;

  .user-meta {
    flex: 1;
    display: flex;
    align-items: center;

    .avatar {
      width: 85px;
      height: 85px;
      border-radius: 50%;
      overflow: hidden;
      margin-left: 60px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    h4 {
      padding-left: 26px;
      font-size: 18px;
      font-weight: normal;
      color: white;
    }
  }

  .item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-around;

    &:first-child {
      border-right: 1px solid #f4f4f4;
    }

    a {
      color: white;
      font-size: 16px;
      text-align: center;

      .iconfont {
        font-size: 32px;
      }

      p {
        line-height: 32px;
      }
    }
  }
}

.like-container {
  margin-top: 20px;
  border-radius: 4px;
  background-color: #fff;
}

.home-panel {
  background-color: #fff;
  padding: 0 20px;
  margin-top: 20px;
  height: 400px;

  .header {
    height: 66px;
    border-bottom: 1px solid #f5f5f5;
    padding: 18px 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;

    h4 {
      font-size: 22px;
      font-weight: 400;
    }

  }

  .goods-list {
    display: flex;
    justify-content: space-around;
  }
}
</style>
用户订单

创建 src\views\Member\components \UserOrder.vue 文件,添加代码:

<script setup>
// tab列表
const tabTypes = [
  { name: "all", label: "全部订单" },
  { name: "unpay", label: "待付款" },
  { name: "deliver", label: "待发货" },
  { name: "receive", label: "待收货" },
  { name: "comment", label: "待评价" },
  { name: "complete", label: "已完成" },
  { name: "cancel", label: "已取消" }
]
// 订单列表
const orderList = []

</script>

<template>
  <div class="order-container">
    <el-tabs>
      <!-- tab切换 -->
      <el-tab-pane v-for="item in tabTypes" :key="item.name" :label="item.label" />

      <div class="main-container">
        <div class="holder-container" v-if="orderList.length === 0">
          <el-empty description="暂无订单数据" />
        </div>
        <div v-else>
          <!-- 订单列表 -->
          <div class="order-item" v-for="order in orderList" :key="order.id">
            <div class="head">
              <span>下单时间:{{ order.createTime }}</span>
              <span>订单编号:{{ order.id }}</span>
              <!-- 未付款,倒计时时间还有 -->
              <span class="down-time" v-if="order.orderState === 1">
                <i class="iconfont icon-down-time"></i>
                <b>付款截止: {{order.countdown}}</b>
              </span>
            </div>
            <div class="body">
              <div class="column goods">
                <ul>
                  <li v-for="item in order.skus" :key="item.id">
                    <a class="image" href="javascript:;">
                      <img :src="item.image" alt="" />
                    </a>
                    <div class="info">
                      <p class="name ellipsis-2">
                        {{ item.name }}
                      </p>
                      <p class="attr ellipsis">
                        <span>{{ item.attrsText }}</span>
                      </p>
                    </div>
                    <div class="price">¥{{ item.realPay?.toFixed(2) }}</div>
                    <div class="count">x{{ item.quantity }}</div>
                  </li>
                </ul>
              </div>
              <div class="column state">
                <p>{{ order.orderState }}</p>
                <p v-if="order.orderState === 3">
                  <a href="javascript:;" class="green">查看物流</a>
                </p>
                <p v-if="order.orderState === 4">
                  <a href="javascript:;" class="green">评价商品</a>
                </p>
                <p v-if="order.orderState === 5">
                  <a href="javascript:;" class="green">查看评价</a>
                </p>
              </div>
              <div class="column amount">
                <p class="red">¥{{ order.payMoney?.toFixed(2) }}</p>
                <p>(含运费:¥{{ order.postFee?.toFixed(2) }})</p>
                <p>在线支付</p>
              </div>
              <div class="column action">
                <el-button  v-if="order.orderState === 1" type="primary"
                  size="small">
                  立即付款
                </el-button>
                <el-button v-if="order.orderState === 3" type="primary" size="small">
                  确认收货
                </el-button>
                <p><a href="javascript:;">查看详情</a></p>
                <p v-if="[2, 3, 4, 5].includes(order.orderState)">
                  <a href="javascript:;">再次购买</a>
                </p>
                <p v-if="[4, 5].includes(order.orderState)">
                  <a href="javascript:;">申请售后</a>
                </p>
                <p v-if="order.orderState === 1"><a href="javascript:;">取消订单</a></p>
              </div>
            </div>
          </div>
          <!-- 分页 -->
          <div class="pagination-container">
            <el-pagination background layout="prev, pager, next" />
          </div>
        </div>
      </div>

    </el-tabs>
  </div>

</template>

<style scoped lang="scss">
.order-container {
  padding: 10px 20px;

  .pagination-container {
    display: flex;
    justify-content: center;
  }

  .main-container {
    min-height: 500px;

    .holder-container {
      min-height: 500px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}

.order-item {
  margin-bottom: 20px;
  border: 1px solid #f5f5f5;

  .head {
    height: 50px;
    line-height: 50px;
    background: #f5f5f5;
    padding: 0 20px;
    overflow: hidden;

    span {
      margin-right: 20px;

      &.down-time {
        margin-right: 0;
        float: right;

        i {
          vertical-align: middle;
          margin-right: 3px;
        }

        b {
          vertical-align: middle;
          font-weight: normal;
        }
      }
    }

    .del {
      margin-right: 0;
      float: right;
      color: #999;
    }
  }

  .body {
    display: flex;
    align-items: stretch;

    .column {
      border-left: 1px solid #f5f5f5;
      text-align: center;
      padding: 20px;

      >p {
        padding-top: 10px;
      }

      &:first-child {
        border-left: none;
      }

      &.goods {
        flex: 1;
        padding: 0;
        align-self: center;

        ul {
          li {
            border-bottom: 1px solid #f5f5f5;
            padding: 10px;
            display: flex;

            &:last-child {
              border-bottom: none;
            }

            .image {
              width: 70px;
              height: 70px;
              border: 1px solid #f5f5f5;
            }

            .info {
              width: 220px;
              text-align: left;
              padding: 0 10px;

              p {
                margin-bottom: 5px;

                &.name {
                  height: 38px;
                }

                &.attr {
                  color: #999;
                  font-size: 12px;

                  span {
                    margin-right: 5px;
                  }
                }
              }
            }

            .price {
              width: 100px;
            }

            .count {
              width: 80px;
            }
          }
        }
      }

      &.state {
        width: 120px;

        .green {
          color: $xtxColor;
        }
      }

      &.amount {
        width: 200px;

        .red {
          color: $priceColor;
        }
      }

      &.action {
        width: 140px;

        a {
          display: block;

          &:hover {
            color: $xtxColor;
          }
        }
      }
    }
  }
}
</style>

配置路由

import Member from '@/views/Member/index.vue'
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'
        {
          path: 'member',
          component: Member,
          children: [
            {
              path: 'user',
              component: UserInfo
            }, {
              path: 'order',
              component: UserOrder
            }
          ]
        }
个人中心信息渲染

在apis/user.js中封装猜你喜欢接口

export const getLikeListAPI = ({ limit = 4 }) => {
  return http({
    url: '/goods/relevant',
    params: {
      limit
    }
  })
}
import { useUserStore } from '@/stores/userStore'
import { getLikeListAPI } from '@/apis/user'
import { onMounted, ref } from 'vue'
import GoodsItem from '@/views/Home/components/GoodsItem.vue'
const userStore=useUserStore()
const likeList=ref([])
const getLikeList=async ()=>{
  const res=await getLikeListAPI({limit:4})
  likeList.value=res.result
}
onMounted(()=>getLikeList())
      <div class="goods-list">
        <GoodsItem v-for="good in likeList" :key="good.id" :goods="good" />
      </div>
我的订单
基础订单列表实现

封装接口:

import http from "@/utils/http"

/*
params: {
  orderState:0,
  page:1,
  pageSize:2
}
*/
export const getUserOrder = (params) => {
  return http({
    url: '/member/order',
    method: 'GET',
    params
  })
}

准备基础请求参数:

// 订单列表
const orderList = ref([])
const params=ref({
  orderState:0,
  page:1,
  pageSize:2
})

调用接口请求数据(这里需要把http中的timeout改高,实测20000可以通过):

import { getUserOrder } from '@/apis/order'
import { onMounted, ref } from 'vue'
const getOrderList=async ()=>{
  const res=await getUserOrder(params.value)
  orderList.value=res.result.items
}
onMounted(()=>getOrderList())
tab切换实现
// tab切换
const tabChange=(type)=>{
  params.value.orderState=type
  getOrderList()
}
  <div class="order-container">
    <el-tabs @tab-change="tabChange">
分页逻辑
const total=ref(0)
const getOrderList=async ()=>{
  const res=await getUserOrder(params.value)
  orderList.value=res.result.items
  total.value=res.result.counts
}
// 页数切换
const pageChange=(page)=>{
  params.value.page=page
  getOrderList()
}
          <!-- 分页 -->
          <div class="pagination-container">
            <el-pagination :total="total" @current-change="pageChange" :page-size="params.pageSize" background layout="prev, pager, next" />
          </div>
细节优化
默认三级路由设置

效果:当路由path为二级路由路径member的时候,右侧可以显示个人中心三级路由对应的组件

我们可以将嵌套路由的path置空

        {
          path: 'member',
          component: Member,
          children: [
            {
              path: '',
              component: UserInfo
            }, {
              path: 'order',
              component: UserOrder
            }
          ]
        }
        <h4>我的账户</h4>
        <div class="links">
          <RouterLink to="/member">个人中心</RouterLink>
        </div>
订单状态显示适配
// 创建格式化函数
const fomartPayState = (payState) => {
  const stateMap = {
    1: '待付款',
    2: '待发货',
    3: '待收货',
    4: '待评价',
    5: '已完成',
    6: '已取消'
  }
  return stateMap[payState]
}
              <div class="column amount">
                <p class="red">¥{{ order.payMoney?.toFixed(2) }}</p>
                <p>(含运费:¥{{ order.postFee?.toFixed(2) }})</p>
                <p>在线支付</p>
              </div>
vue项目实战-小兔鲜电商前台 本项目是学习的黑马程序员的项目,是vue电商前端项目在这个电商前端项目中,我参与了一些亮点功能的设计和开发。这些经验使我对前端开发有了更深入的了解,并且激发了我在未来学习和成长的渴望。通过实现长页面吸顶交互、图片懒加载、通用组件封装等功能,我意识到前端开发是一个充满创意和挑战的领域。我非常渴望深入学习和掌握新的前端技术,例如移动端开发、前端框架、数据可视化等方面,以提供更好的用户体验和高效的代码实现。此外,我对前端性能优化和安全性有着浓厚的兴趣。 阅读详情

相关推荐

Vue3 + ElementPlus + Pinia 小兔鲜电商项目 视频教程 下载

│ Day4-14.详情页-图片预览组件-props适配和整体总结.mp4。│ Day4-12.详情页-图片预览组件-放大镜-滑块跟随移动.mp4。│ Day4-13.详情页-图片预览组件-放大镜-大图效果实现.mp4。│ Day7-08.拓展课-SKU组件-点击规格更新选中状态.mp4。│ Day7-10.拓展课-SKU组件-初始化时更新禁用状态.mp4。│ Day4-09.详情页-热榜区-基础组件封装和数据渲染.mp4。

2401_84572204的博客 1289

黑马程序员前端 Vue3 小兔鲜电商项目——(十一)支付页

黑马程序员前端 Vue3 小兔鲜电商项目——(十一)支付页

赵士杰——成功并非一蹴而就,而是在持之以恒的努力中逐渐实现。 2927

小兔鲜项目总结

小兔鲜是一个基于Vue3的电商实战项目,模拟生鲜电商平台的核心功能。项目采用Vue3技术栈,包括Pinia状态管理、VueRouter路由、ElementPlus组件库等。主要功能模块有首页展示、商品分类筛选、商品详情、登录认证、购物车和支付流程等。项目结构清晰,包含apis接口管理、components可复用组件、stores全局状态等目录。通过组件化开发实现了首页轮播、商品列表等模块,并运用图片懒加载优化性能。购物车模块区分登录/未登录状态,实现本地与接口数据的同步。项目还包含完整的登录认证流程,通过P

2403_89086078的博客 996

小兔鲜项目总结——项目亮点

电商平台项目有大量的商品图片, 同时加载和渲染全部的图片资源会挤占带宽, 首页白屏与加载时间过长,用户体验感不好, 同时还会浪费用户的流量,有些用户并不想全部看完,全部加载会耗费大量流量。所以需要使用到图片懒加载。将懒加载指令封装为插件是为了方便在项目各个组件中的使用。(1)懒加载:只有当图片出现在视口区域才会发送图片的网络请求,将图片的src替换成接口返回的图片地址。

Kong08242022的博客 3658

redhawk-sc使用简介

数据完整性对结果的准确性有很大影响,所以一定要保证数据完整性,Redhawk-sc在跑完后,Report里有Data Integrity界面,在这个界面会看到设计数据和库文件的数据完整性,在相应的报告中会有没有覆盖到的数据情况,要对每一项仔细检查,保证输入数据没有问题。文件一般加密,用户唯一需要选择的是文件的corner。其中,cell lef除了常规的standard cell,还有如DTCD,BTSV和clamp等cell的lef,不可缺失,否则data integrity将不是100%。

weixin_48518726的博客 3204

别再手动拆解字节了!用博图这个功能指令,5分钟搞定ARRAY转BOOL数组

本文详细介绍了西门子博图中`ARRAY_TO_BOOL`功能指令的高效应用,帮助工程师快速实现ARRAY到BOOL数组的转换。通过实战案例和参数配置指南,展示了如何5分钟内完成传统方法需半小时的任务,大幅提升PLC编程效率,特别适用于通信报文解析和设备状态监控。

weixin_42653691的博客 270

小兔鲜电商实战:结算流程、微信支付/支付宝沙箱与会员中心实现

在电商系统开发中,交易闭环的完整性远比页面展示更为关键。从购物车勾选到订单确认,结算流程需要后端计算真实价格并生成订单快照,避免前端与后端数据不一致。支付环节则涉及微信支付、支付宝等不同渠道的接入,小程序需传递openid,APP支付则需区分参数差异,支付宝沙箱则提供了安全便捷的测试环境。支付后的回调通知必须验签、解密并确保幂等性,订单状态机才能可靠流转。会员中心作为用户资产入口,通过聚合接口高效展示订单数量与个人信息。本文以实际的电商项目为例,详细讲解结算流程、支付接入、回调处理、幂等设计以及会员中心的实

weixin_30846347的博客 286

查看电脑mac地址+主机名+用户名并导出

张三:李四,应公司要求,今天下班前必须将这张表格里面用户电脑的mac地址统计出来!李四:我该怎么办呢?一个一个查看,太没有效率了吧!对了,我可以做一个bat脚本啊!

拥抱着青春 1990

推荐文章:探索未来电商的高效之路 —— 小兔鲜电商项目(Vite + Vue3)

推荐文章:探索未来电商的高效之路 —— 小兔鲜电商项目(Vite + Vue3) 【下载地址】小兔鲜电商项目ViteVue3-开源前端实践 欢迎来到小兔鲜电商项目!本项目是一个采用现代化前端技术栈构建的电子商务应用示例。我们基于[Vite](https://vitejs.dev/),结合[Vue.js 3](https:...

gitblog_09803的博客 1047

分子模拟入门教程 | 低调使用 建议收藏

该方法只需要原子的核电荷和少数模拟的环境参数作为输入,所有的性质都是通过求解薛定谔方程得到的,不需要使用任何经验参数。经典的原子水平的分子模拟已经成为提高我们对材料科学和生命系统中分子过程理解的最流行的方法之一。全原子模拟是一种非常强大的以原子分辨率呈现信息的方法,因为在原子模拟中,一个粒子代表一个特定的原子。随着计算机硬件和模拟技术的快速发展,分子模拟不仅可以解决基本的、常规的化学问题,还可以应用于各种复杂体系。然而,由于问题的复杂性以及严重依赖于现象的现实情况,最好是逐案确定合适的模拟方法。

pysonger的博客 789

RK3399驱动开发 | 19 - 阿美林7寸mipi屏幕调试(基于linux4.4.194内核)

NULL

Mculover666的博客(嵌入式) 2671

【亲测免费】 小兔鲜电商项目(Vite + Vue3) - 开源前端实践

小兔鲜电商项目(Vite + Vue3) - 开源前端实践 【下载地址】小兔鲜电商项目ViteVue3-开源前端实践 欢迎来到小兔鲜电商项目!本项目是一个采用现代化前端技术栈构建的电子商务应用示例。我们基于[Vite](https://vitejs.dev/),结合[Vue.js 3](https://vuejs.org...

gitblog_09799的博客 1018

【原创】关于西门子S120 的电气图纸设计

我们首先要了解一下模块的基本信息:SINAMICS 功率模块 PM240-2 三相交流380-480V+10/-10% 47-63Hz;至此,我们选择的驱动系统配置的资料都已经查找完毕,接下来就是根据每个部件的功能接口和我们需要实现的功能画出接线连接图,这样关于伺服电机控制,硬件部分设计就完成了。2)FSA - FSC 型功率模块 PM240-2 的屏蔽连接板外形尺寸图,所有数据以毫米(英寸)为单位。1)FSA 型功率模块 PM240-2 的外形尺寸图,所有数据以毫米(英寸)为单位。

Qinmingyue13的博客 2650

⑨-订单页--小兔鲜电商项目实战

第一步、新建购物车订单页,src\views\Checkout\index.vue。

2301_78301373的博客 1010

2024年ERP管理系统职业技能大赛软件测试赛项-测试报告

【说明本次测试的最终测试结果总结、测试过程中遇到的重要问题以及如何解决、被测系统的质量结论、个人的收获以及团队的得失等】【说明编写本测试报告的目的和实际读者】【说明本次测试实际人员安排及主要职责】【说明本次测试使用的测试用例设计方法】【说明本次测试使用的测试方法】【针对本次测试进行Bug汇总】【针对本次测试进行用例汇总】【说明本项目的背景情况】【说明本次测试的实际。

Code is fun. 797

电磁场仿真软件:COMSOL Multiphysics_(17).时域与频域分析

时域和频域分析是电磁场仿真中非常重要的两种方法,每种方法都有其独特的应用场景和优势。时域分析适用于瞬态响应和宽带信号的分析,而频域分析则适用于稳态响应和窄带信号的分析。在COMSOL Multiphysics中,通过合理设置物理场接口、材料属性、边界条件、网格划分和求解器,可以高效地进行这两种分析,并通过傅里叶变换将时域结果转换为频域结果,进一步拓展仿真应用的范围。合理的性能优化措施,如网格划分优化和并行计算,可以显著提高仿真的效率和准确性。

kkchenjj的博客 1989

Vue3小兔鲜电商前台项目总结

在directives内定义懒加载插件import { useIntersectionObserver } from '@vueuse/core',懒加载的核心逻辑是当图片进入到视口区域,就把url赋值给src,但是这样做会存在重复监听的问题,useIntersectionObserver对于元素的监听是一直存在的,除非手动停止监听,存在内存浪费 虽然图片已经加载完毕了,但是鼠标滑动时仍然在监听。解决方案,加入stop,让他对于已经加载好的图片停止监听,不再重复监听。例如,将home页拆分。

cozy666的博客 1803

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

小兔鲜儿Vue3.0前端电商项目实战

小兔鲜儿Vue3.0实现了电商平台主线业务功能,电商首页、一级分类、二级分类、商品详情、购物车、结算、支付、个人中心、订单管理、订单详情。 项目采用前后端分离模式,前台使用了VUE3.0技术栈构建,自己封装的UI组件库,接入了QQ登录,支付宝支付业务,以及前端SKU解决方案,本地线上购物车解决方案 后台接口基本完毕,但是数据缺乏(分类,商品),所以会有一些本地mock数据。 采用vuex来管理购物车和用户数据,vuex的使用会淋漓尽致。 使用vue3.0来开发,所以小兔鲜儿项目,会很 鲜嫩 酸爽 。 但是会

IT大神帅杰的博客 1万+

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

【小兔鲜电商前台 | 项目笔记】第十天

前言:小兔鲜电商前台项目是一个基于Vue的PC端项目,本系列文章我将总结我在这个项目中学到的知识点,写项目笔记。如果你正好在学Vue或想从零搭建一个前端项目,希望本系列文章可以帮助到你。

A923A的博客 433

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

vue3踩坑笔记:电商平台小兔鲜项目回顾与总结

该商城是一个综合性的B2C电商平台,有登录功能,进入首页可查看商品列表,商品分类,以及在商详页进行商品的选购、结算、与支付。个人中心包含会员信息及会员订单等。共计20+页面,8+模块,上百个接口的封装调用。背景: 电商平台项目有大量的商品图与详情图, 同时大量加载与渲染图片资源会挤占带宽, 首页白屏与加载时间过长,体验不好, 所以需要使用到图片懒加载。封装成vue指令是为了在项目各文件中更便捷使用。原理:图片懒加载,当滚动时元素出现在视口中时,才需要src替换成接口返回的图片地址。

weixin_67442598的博客 666

Vue 3 实战:从零到一构建电商项目小兔鲜

本文详细介绍了如何使用Vue 3从零开始构建电商项目小兔鲜,涵盖项目初始化、核心功能开发、支付流程、性能优化及部署上线等关键环节。通过实战案例展示Vue 3与TypeScript、Pinia、Vite等技术的结合应用,帮助开发者快速掌握现代前端开发的最佳实践。

weixin_30512965的博客 266

手把手教你做小兔鲜网站(vue3实战)

1、路由配置:三级路由2、个人中心信息渲染( 个人信息 部分直接使用Pinia中的数据, 猜你喜欢 部分走接口获取)3、tab切换获取状态数据并渲染4、分页逻辑实现然后就ok了终于写完了,这下可以好好玩黑神话悟空了。

cghhbvcgjb的博客 2382

项目介绍(小兔仙儿PC)

目的:了解下项目的基本功能。电商发展十余年,是个成熟的模式,小兔鲜儿是B2C电商平台,综合品类平台。平台理念:(品质)新鲜、(价格)亲民、(物流)快捷。总结:完成电商支付闭环。

lzping_719的专栏 1006

小兔鲜电商购物平台

通过判断localstorage中是否存在token判断用户登录状态,token失效自动跳转登录页。

qq_44957788的博客 336

Vue3电商实战:从购物车到支付与会员中心的完整订单闭环开发

在电商前端项目中,购物车负责选品,而真正的交易闭环从结算页开始。理解订单状态流转、前端状态管理与接口交互的配合,是构建高可用交易链路的关键。Vue 3与Pinia的组合提供了强大的响应式数据流,让确认订单、地址选择、金额计算和防重复提交等复杂场景变得可控。支付页面的核心在于状态反馈与轮询机制,会员中心则聚合订单管理与用户信息。本文以“小兔鲜”项目为背景,按实际开发顺序拆解结算、支付、会员中心三个模块的实现方案,梳理从提交订单到查看订单全过程中的技术要点与高频问题排查思路,帮助工程实践者快速搭建完整的订单闭环

weixin_27379781的博客 296

小兔鲜电商实战:结算、支付与会员中心的交易闭环设计

电商系统的核心价值最终体现在交易闭环上,从购物车到订单结算,再到支付回调与会员资产沉淀,每一步都依赖严谨的数据一致性与状态管理。订单状态机规范了流程流转,支付异步回调的验签与幂等设计保障了资金安全,而在高并发场景下,基于条件更新的并发控制技术则避免了超卖与重复处理。这些原理不仅适用于电商,也是所有分布式系统设计的通用基石。在实际工程中,金额计算需统一使用BigDecimal避免精度丢失,库存扣减应采用数据库行级锁,优惠券生命周期需通过条件更新实现原子性操作。本文结合小兔鲜项目,围绕结算聚合接口、支付回调处理

weixin_29279047的博客 185
上一篇: 小兔鲜电商项目(五)---购物车
下一篇: Nodejs - 01:Buffer、fs模块、HTTP模块
01star️
博客等级 码龄3年 96粉丝 63原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值