日常生活的交流与学习

首页 新随笔 联系 管理

D:\Code\asp-vue-new\long.client\src\views\order\index.vue

<script setup lang="ts">
import { useOrder } from "@/stores/order"
const storeOrder = useOrder();

onMounted(async () => {
    // await storeOrder.setOrders();
    //                      👇 
    await storeOrder.setOrdersByMock();
})

</script>
<template>
    <div></div>
</template>
<style lang="css"></style>

src\stores\order.ts

import { useOrderApi } from '@/api/order'
import { defineStore } from 'pinia'
export const useOrder = defineStore('orderStore', {
  state: (): TOrderStoreState => ({
    orders: []
  }),
  actions: {
    getOrderById(id: number) {
    },
    getPickingTotalQuantityByOrderIdIdAndZdjhm(id: number, zdjhm: string) {
    },
    async setOrders() {
      const res = await useOrderApi().getOrders()
      this.orders = res.data
    },
    //           👇
    async setOrdersByMock() {
      const res = await useOrderApi().mockOrders()
      this.orders = res.data
    }
  }
})

src\api\order\index.ts


import request from '@/utils/request'
import mockOrderData from './mock'

export function useOrderApi() {
  return {
    getOrders: (params?: object) => {
      return request({
        url: '/api/Orders/allOrder',
        method: 'get',
        params
      })
    },
    // 👇
    mockOrders: (params?: object) => {
        //      👇
      return mockOrderData()
    }
  }
}

src\api\order\mock.ts

//                👇
export const mockOrderData = () => ({
  data: [
    {
      Id: 2,
      CreatorId: 0,
      CreationTime: '2024-07-18 10:39:49',
      LastModificationTime: '0001-01-01 00:00:00'
    }
  ]
})

export default mockOrderData
posted on 2024-08-07 21:45  lazycookie  阅读(5)  评论(0编辑  收藏  举报