From 091b655a0fe232d7144921b22ed30744c433a29e Mon Sep 17 00:00:00 2001 From: Sun_sun <469361609@qq.com> Date: Mon, 20 Oct 2025 10:33:19 +0800 Subject: [PATCH] =?UTF-8?q?2025-10-20=20=E6=94=B6=E8=B4=A7=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/address.js | 4 ++ pages/my/shippingAddress.vue | 98 +++++++++++++++++++++++++++++------- util/api.js | 9 ++-- 3 files changed, 90 insertions(+), 21 deletions(-) diff --git a/api/address.js b/api/address.js index 7a9efcc..66d9eb7 100644 --- a/api/address.js +++ b/api/address.js @@ -9,6 +9,10 @@ const baseURL = "http://192.168.0.26:3000/api" export const addressAPI = { // 列表 getList: (params) => http.get(baseURL + '/addresses', params), + addAddress: (data) => http.post(baseURL + "/addresses", data), + getAddress: (id) => http.get(baseURL + `/addresses/${id}`), + editAddress: (data) => http.put(baseURL + `/addresses/${data.id}`, data), + delAddress: (id) => http.delete(baseURL + `/addresses/${id}`) } export default { diff --git a/pages/my/shippingAddress.vue b/pages/my/shippingAddress.vue index f09294b..e81a775 100644 --- a/pages/my/shippingAddress.vue +++ b/pages/my/shippingAddress.vue @@ -34,7 +34,8 @@ - + @@ -128,16 +131,42 @@ fontSize: '40rpx', lineHeight: '52px' } - + const msgRef = ref() const isManage = ref(false) const showDel = ref(false) const showForm = ref(false) const showRegitionPicker = ref(false) - const form = ref({}) + const form = ref({ + label: 0 + }) const handleAdd = () => { showForm.value = true } + const handleEdit = (item) => { + let data = { + id: item.id, + regionLabel: item.province_name + '/' + item.district_name + '/' + item.city_name, + province_code: item.province, + city_code: item.city, + district_code: item.district, + detailed_address: item.detailed_address, + recipient_name: item.receiver_name, + phone: item.receiver_phone, + is_default: item.is_default + } + if (item.label == '家') { + data.label = 0 + } + if (item.label == '公司') { + data.label = 1 + } + if (item.label == '学校') { + data.label = 2 + } + form.value = data + showForm.value = true + } const handleManage = () => { if (isManage.value) { ids.value = [] @@ -147,8 +176,18 @@ const showDelModel = () => { showDel.value = true } - const handleDel = () => { + const handleDel = async () => { // TODO 删除 + for (var i = 0; i < ids.value.length; i++) { + await addressAPI.delAddress(ids.value[i]) + } + msgRef.value.show({ + title: '删除成功', + type: 'success' + }) + isManage.value = false + ids.value = [] + loadData() } // 打开省市区选择 const openProvince = () => { @@ -157,14 +196,39 @@ // 选择省市区 const handleRegion = (e) => { form.value.regionLabel = e[0].label + "/" + e[1].label + "/" + e[2].label - form.value.province = e[0].value - form.value.city = e[1].value - form.value.district = e[2].value - form.value.district_id = e[2].value + form.value.province_code = e[0].value + form.value.city_code = e[1].value + form.value.district_code = e[2].value + } + + const handleChangeTag = (val) => { + form.value.label = val } // 确认提交 const handleSubmit = () => { - + if (form.value.id != null) { + addressAPI.editAddress(form.value).then(res => { + if (res.success) { + msgRef.value.show({ + title: '修改成功', + type: 'success' + }) + showForm.value = false + loadData() + } + }) + } else { + addressAPI.addAddress(form.value).then(res => { + if (res.success) { + msgRef.value.show({ + title: '添加成功', + type: 'success' + }) + showForm.value = false + loadData() + } + }) + } } const scrollHeight = ref(0) diff --git a/util/api.js b/util/api.js index a3fea76..52c2491 100644 --- a/util/api.js +++ b/util/api.js @@ -8,9 +8,6 @@ const token = uni.getStorageSync('token') const commonHeaders = { 'Content-Type': 'application/json' } -if (token) { - commonHeaders['Authorization'] = `Bearer ${token}` -} // 请求队列,用于管理loading let requestQueue = 0 @@ -68,7 +65,6 @@ const request = (config) => { // } let requestUrl = url - let queryString = '' if (Object.keys(params).length > 0) { @@ -78,6 +74,11 @@ const request = (config) => { requestUrl += (requestUrl.includes('?') ? '&' : '?') + queryString } + const currToken = uni.getStorageSync('token') + if (currToken) { + commonHeaders.Authorization = `Bearer ${currToken}` + } + // 合并请求头 const requestHeader = { ...commonHeaders,