diff --git a/api/address.js b/api/address.js
new file mode 100644
index 0000000..68a5d51
--- /dev/null
+++ b/api/address.js
@@ -0,0 +1,30 @@
+import request from './request';
+
+// 通用工具:处理接口返回可能存在的数据包裹
+function unwrapList(response) {
+ if (!response) return [];
+ if (Array.isArray(response)) return response;
+ if (Array.isArray(response?.data)) return response.data;
+ if (Array.isArray(response?.list)) return response.list;
+ return [];
+}
+
+export function fetchAddressList() {
+ return request('xcx/addresses', 'GET', {
+ page: 1,
+ page_size: 99
+ }).then(unwrapList);
+}
+
+export function createAddress(data) {
+ return request('xcx/address', 'POST', data);
+}
+
+export function updateAddress(addressId, data) {
+ return request(`xcx/address/${addressId}`, 'PUT', data);
+}
+
+export function deleteAddress(addressId) {
+ return request(`xcx/address/${addressId}`, 'DELETE');
+}
+
diff --git a/pages.json b/pages.json
index 28f8814..352f417 100644
--- a/pages.json
+++ b/pages.json
@@ -31,6 +31,12 @@
"navigationBarTitleText": "我的"
}
},
+ {
+ "path": "pages/address/index",
+ "style": {
+ "navigationBarTitleText": "地址管理"
+ }
+ },
{
"path": "pages/my/editInfo/index",
"style": {
diff --git a/pages/address/index.vue b/pages/address/index.vue
new file mode 100644
index 0000000..407573c
--- /dev/null
+++ b/pages/address/index.vue
@@ -0,0 +1,618 @@
+
+
+
+
+
+
+ 正在加载地址
+
+
+
+ 📭
+ 还没有添加任何地址
+ 新增地址后即可在下单时快速选择
+
+
+
+
+
+
+
+ {{ formatRegion(item) }}
+ {{ item.detail_address }}
+ 邮编:{{ item.postal_code }}
+ 更新于 {{ item.updated_at || item.created_at || '--' }}
+
+
+ 编辑
+ 删除
+ 设为默认
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 收货人
+
+
+
+
+ 手机号
+
+
+
+
+ 所在地区
+
+
+
+ {{ regionText || '请选择省市区' }}
+
+ ›
+
+
+
+
+
+ 邮编
+
+
+
+
+ 详细地址
+
+
+
+
+
+ 设为默认地址
+ 下单时将优先选择该地址
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 350d590..e6486c4 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -239,19 +239,38 @@ export default {
this.shopList = res.list
})
},
+ async userIsLogin(){
+ const token = await uni.getStorageSync('access_token')
+ if(token){
+ return
+ } else {
+ uni.navigateTo({
+ url: '/pages/login/index'
+ })
+ }
+ },
changeSearch(index) {
this.searchType = index
},
changeSearch2(index) {
this.searchType2 = index
},
- handelLike(row) {
- request('xcx/product/like', 'post', {
- product_id: row.id,
- type: row.is_liked ? 2 : 1
- }).then((res) => {
- row.is_liked = !row.is_liked
+ async handelLike(row) {
+ this.userIsLogin().then((res) => {
+ request('xcx/product/like', 'post', {
+ product_id: row.id,
+ type: row.is_liked ? 2 : 1
+ }).then((res) => {
+ const liked = !row.is_liked
+ row.is_liked = liked
+ if (liked) {
+ row.like_count += 1
+ } else if (row.like_count > 0) {
+ row.like_count -= 1
+ }
+ })
})
+
}
}
}
diff --git a/pages/login/index.vue b/pages/login/index.vue
index bd12c2a..cb569f3 100644
--- a/pages/login/index.vue
+++ b/pages/login/index.vue
@@ -64,7 +64,7 @@ export default {
const result = await request('xcx/quick_login', 'POST', loginData);
await wx.setStorageSync('access_token', result.token);
- await wx.setStorageSync('is_personal_information_complete', result.result.is_personal_information_complete);
+ await wx.setStorageSync('is_personal_information_complete', result.is_personal_information_complete);
if (result.is_personal_information_complete) {
wx.navigateBack();
} else {
diff --git a/pages/my/index.vue b/pages/my/index.vue
index ec4678f..0863d22 100644
--- a/pages/my/index.vue
+++ b/pages/my/index.vue
@@ -167,7 +167,7 @@
快捷功能
-
+
{{ action.icon }}
{{ action.label }}
@@ -201,7 +201,7 @@ export default {
],
quickActions: [
{ icon: '💳', label: '我的钱包' },
- { icon: '📍', label: '地址管理' },
+ { icon: '📍', label: '地址管理', path: '/pages/address/index' },
{ icon: '🔔', label: '消息通知' },
{ icon: '❓', label: '帮助中心' }
],
@@ -383,6 +383,18 @@ export default {
uni.navigateTo({
url: url
});
+ },
+ handleQuickAction(action) {
+ if (action.path) {
+ this.navigateTo(action.path);
+ return;
+ }
+ this.$nextTick(() => {
+ uni.showToast({
+ title: '功能开发中',
+ icon: 'none'
+ });
+ });
}
}
};