5 changed files with 314 additions and 49 deletions
-
170src/pagesMember/address-form/address-form.vue
-
93src/pagesMember/address/address.vue
-
59src/services/address.ts
-
16src/stores/modules/address.ts
-
25src/types/address.d.ts
@ -0,0 +1,59 @@ |
|||
import type { AddressItem, AddressParams } from '@/types/address' |
|||
import { http } from '@/utils/http' |
|||
|
|||
/** |
|||
* 添加收货地址 |
|||
* @param data 请求参数 |
|||
*/ |
|||
export const postMemberAddressAPI = (data: AddressParams) => { |
|||
return http({ |
|||
method: 'POST', |
|||
url: '/member/address', |
|||
data, |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* 获取收货地址列表 |
|||
*/ |
|||
export const getMemberAddressAPI = () => { |
|||
return http<AddressItem[]>({ |
|||
method: 'GET', |
|||
url: '/member/address', |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* 获取收货地址详情 |
|||
* @param id 地址id(路径参数) |
|||
*/ |
|||
export const getMemberAddressByIdAPI = (id: string) => { |
|||
return http<AddressItem>({ |
|||
method: 'GET', |
|||
url: `/member/address/${id}`, |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* 修改收货地址 |
|||
* @param id 地址id(路径参数) |
|||
* @param data 表单数据(请求体参数) |
|||
*/ |
|||
export const putMemberAddressByIdAPI = (id: string, data: AddressParams) => { |
|||
return http({ |
|||
method: 'PUT', |
|||
url: `/member/address/${id}`, |
|||
data, |
|||
}) |
|||
} |
|||
|
|||
/** |
|||
* 删除收货地址 |
|||
* @param id 地址id(路径参数) |
|||
*/ |
|||
export const deleteMemberAddressByIdAPI = (id: string) => { |
|||
return http({ |
|||
method: 'DELETE', |
|||
url: `/member/address/${id}`, |
|||
}) |
|||
} |
@ -0,0 +1,16 @@ |
|||
import type { AddressItem } from '@/types/address' |
|||
import { defineStore } from 'pinia' |
|||
import { ref } from 'vue' |
|||
|
|||
export const useAddressStore = defineStore('address', () => { |
|||
const selectedAddress = ref<AddressItem>() |
|||
|
|||
const changeSelectedAddress = (val: AddressItem) => { |
|||
selectedAddress.value = val |
|||
} |
|||
|
|||
return { |
|||
selectedAddress, |
|||
changeSelectedAddress, |
|||
} |
|||
}) |
@ -0,0 +1,25 @@ |
|||
/** 添加收货地址: 请求参数 */ |
|||
export type AddressParams = { |
|||
/** 收货人姓名 */ |
|||
receiver: string |
|||
/** 联系方式 */ |
|||
contact: string |
|||
/** 省份编码 */ |
|||
provinceCode: string |
|||
/** 城市编码 */ |
|||
cityCode: string |
|||
/** 区/县编码 */ |
|||
countyCode: string |
|||
/** 详细地址 */ |
|||
address: string |
|||
/** 默认地址,1为是,0为否 */ |
|||
isDefault: number |
|||
} |
|||
|
|||
/** 收货地址项 */ |
|||
export type AddressItem = AddressParams & { |
|||
/** 收货地址 id */ |
|||
id: string |
|||
/** 省市区 */ |
|||
fullLocation: string |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue