From b3d1d587f9386f1716ebdcf94de63c30095bb12e Mon Sep 17 00:00:00 2001 From: wei <1937506227@qq.com> Date: Sat, 25 Oct 2025 17:49:57 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9C=B0=E5=9D=80=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=94=B6=E8=B4=A7=E5=9C=B0=E5=9D=80=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=A1=B5=E9=9D=A2=E5=8F=8A=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor(键盘组件): 优化键盘组件逻辑并添加与store的交互 fix(购物车): 修复购物车数量修改逻辑及结算流程 style: 调整多个页面的z-index值及样式细节 perf(验证工具): 优化validates函数返回布尔值的处理逻辑 --- components/keyboard/keyboard copy.vue | 205 ++++++++++++++ components/keyboard/keyboard.vue | 13 +- libs/api/index.js | 31 ++ libs/utils/index.js | 24 +- md.md | 0 pages.json | 6 + pages/allDish/allDish.vue | 106 +++++-- pages/deliveryAddress/addDeliveryAddress.scss | 150 ++++++++++ pages/deliveryAddress/addDeliveryAddress.vue | 264 ++++++++++++++++++ pages/deliveryAddress/deliveryAddress.vue | 2 +- pages/home/home.scss | 10 +- pages/home/home.vue | 114 ++++++-- pages/login/login.vue | 4 +- .../personallInformation.scss | 8 +- pages/shoppingCart/shoppingCart.scss | 2 +- pages/shoppingCart/shoppingCart.vue | 122 ++++++-- store/index.js | 5 + uni.scss | 1 - 18 files changed, 965 insertions(+), 102 deletions(-) create mode 100644 components/keyboard/keyboard copy.vue create mode 100644 md.md create mode 100644 pages/deliveryAddress/addDeliveryAddress.scss create mode 100644 pages/deliveryAddress/addDeliveryAddress.vue diff --git a/components/keyboard/keyboard copy.vue b/components/keyboard/keyboard copy.vue new file mode 100644 index 0000000..3670a0a --- /dev/null +++ b/components/keyboard/keyboard copy.vue @@ -0,0 +1,205 @@ + + + + + diff --git a/components/keyboard/keyboard.vue b/components/keyboard/keyboard.vue index ab11333..d4c90ac 100644 --- a/components/keyboard/keyboard.vue +++ b/components/keyboard/keyboard.vue @@ -1,10 +1,13 @@ + + + + diff --git a/pages/deliveryAddress/deliveryAddress.vue b/pages/deliveryAddress/deliveryAddress.vue index e8a3ba6..594bc1c 100644 --- a/pages/deliveryAddress/deliveryAddress.vue +++ b/pages/deliveryAddress/deliveryAddress.vue @@ -131,7 +131,7 @@ function optionTap(item) { */ function onGotoAdd() { uni.navigateTo({ - url: "/pages/addAddress/addAddress", + url: "/pages/deliveryAddress/addDeliveryAddress", }); } diff --git a/pages/home/home.scss b/pages/home/home.scss index 295b542..58a3a81 100644 --- a/pages/home/home.scss +++ b/pages/home/home.scss @@ -293,7 +293,7 @@ opacity: 0.5; position: absolute; right: -8rpx; - z-index: $z-index-below; + z-index: -1; } .title { font-size: 33rpx; @@ -433,7 +433,7 @@ width: 88%; height: 1px; background-color: #D6D6D6; - z-index: $z-index-below; + z-index: -1; } .line-two { position: absolute; @@ -442,7 +442,7 @@ width: 88%; height: 1px; background-color: #D6D6D6; - z-index: $z-index-below; + z-index: -1; } .add { width: 58rpx; @@ -534,7 +534,7 @@ width: 88%; height: 1px; background-color: #D6D6D6; - z-index: $z-index-below; + z-index: -1; } .line-two { position: absolute; @@ -543,7 +543,7 @@ width: 88%; height: 1px; background-color: #D6D6D6; - z-index: $z-index-below; + z-index: -1; } .minus { width: 58rpx; diff --git a/pages/home/home.vue b/pages/home/home.vue index aad3123..6a28584 100644 --- a/pages/home/home.vue +++ b/pages/home/home.vue @@ -315,13 +315,57 @@ function changeSwiper(e) { } /** - * 点击确认按钮时,将输入框的值赋值给商品项的sum属性 - * @param e 事件对象 + * 确定购买数量 + * @param value 购买数量 + * @param item 商品项 */ -function determine(value, item) { - console.log(value, 333); +async function determine(value, item) { + const isPass = validates([ + () => item.stock != -1 && value > item.stock && "采购数量不能大于库存数量", + () => item.stock == 0 && "库存数量为0无法添加", + ]); + + if (!isPass) { + return; + } + + item.sum = value; + isShowkeyboard.value = false; + + const data = { + quantity: value, + specId: item.id, + Chuxiao: item.chuxiao, + warehouseId: uni.getStorageSync("warehousId"), + addrId: uni.getStorageSync("addressId"), + isUpdate: 1, + isChuxiao: false, + }; + if (!data.specId) { + uni.showModal({ + title: "提示", + content: "当前商品规格错误,请稍候再试", + showCancel: false, + confirmText: "确定", + }); + } + if (!data.warehouseId || !data.addrId) { + uni.showModal({ + title: "提示", + content: "请先选择收货地址,再添加商品", + showCancel: false, + confirmText: "确定", + }); + } + const res = await addCartApi(data); + if (res.code !== "0") { + return; + } + // store.changeCartList(res.data); + initCartInfo(); } + /** * 选择地址 */ @@ -468,10 +512,12 @@ async function toCart(item, diff) { confirmText: "确定", }); } - const res = addCartApi(data); + const res = await addCartApi(data); if (res.code !== "0") { - initCartInfo(); + return; } + store.changeCartList(res.data.items); + // initCartInfo(); } /** @@ -484,31 +530,32 @@ async function initCartInfo() { }; const res = await getCartInfoApi(data); - if (res.code !== "0") + if (res.code !== "0") { return; + } store.changeCartList(res.data); } -/** - * - * @param {InputEvent} e - * @param {{specs: {sum: number}[]}} item - */ -function onChangeGoods(e, item, index) { - const value = e.detail.value * 1; - if (Number.isNaN(value)) - return; - if (value >= item.specs[index].stock) { - uni.showToast({ - icon: "none", - title: "采购数量不能大于库存数量", - }); - // item.specs[0].sum = item.specs[0].stock; - return; - } - item.specs[index].sum = value; -} +// /** +// * +// * @param {InputEvent} e +// * @param {{specs: {sum: number}[]}} item +// */ +// function onChangeGoods(e, item, index) { +// const value = e.detail.value * 1; +// if (Number.isNaN(value)) +// return; +// if (value >= item.specs[index].stock) { +// uni.showToast({ +// icon: "none", +// title: "采购数量不能大于库存数量", +// }); +// // item.specs[0].sum = item.specs[0].stock; +// return; +// } +// item.specs[index].sum = value; +// } /** * 创建购物车小球的动画 @@ -810,7 +857,7 @@ onShow(async () => { {{ item.specs[0].sum }} @@ -859,12 +906,23 @@ onShow(async () => { - --> + + {{ item.specs[specsIndex].sum }} + + diff --git a/pages/login/login.vue b/pages/login/login.vue index 5e89337..2c0fec2 100644 --- a/pages/login/login.vue +++ b/pages/login/login.vue @@ -426,7 +426,7 @@ page { input { border-bottom:solid 1px #f6f6f6; width:90%; - z-index: $z-index-low; + z-index: 1; } .header { margin: 90rpx 0 90rpx 0rpx; @@ -543,7 +543,7 @@ input { flex-direction: column; .login-btn { width: 100%; - z-index: $z-index-head !important; + z-index: 10 !important; border-radius: 100px; border: none; background-color: #06CA64; diff --git a/pages/personalInformation/personallInformation.scss b/pages/personalInformation/personallInformation.scss index 39b38c4..f4d391b 100644 --- a/pages/personalInformation/personallInformation.scss +++ b/pages/personalInformation/personallInformation.scss @@ -393,7 +393,7 @@ position: absolute; right: 10rpx; bottom: 10rpx; - z-index: $z-index-max; + z-index: $z-index-toast; } } @@ -408,7 +408,7 @@ width: 60rpx; height: 60rpx; border-radius: 50%; - z-index: $z-index-max; + z-index: $z-index-toast; } /* 新版样式 */ @@ -753,7 +753,7 @@ position: absolute; right: 10rpx; bottom: 10rpx; - z-index: $z-index-max; + z-index: $z-index-toast; } } @@ -768,7 +768,7 @@ width: 60rpx; height: 60rpx; border-radius: 50%; - z-index: $z-index-max; + z-index: $z-index-toast; } } diff --git a/pages/shoppingCart/shoppingCart.scss b/pages/shoppingCart/shoppingCart.scss index 8f3344d..5fe3fa8 100644 --- a/pages/shoppingCart/shoppingCart.scss +++ b/pages/shoppingCart/shoppingCart.scss @@ -226,7 +226,7 @@ width: 100%; // bottom: 90rpx; background: #fff; - z-index: $z-index-tab; + // z-index: $z-index-tab; /* padding-bottom: 20rpx; */ padding: 0 14rpx 10rpx; box-sizing: border-box; diff --git a/pages/shoppingCart/shoppingCart.vue b/pages/shoppingCart/shoppingCart.vue index 741a8e8..adbdd4c 100644 --- a/pages/shoppingCart/shoppingCart.vue +++ b/pages/shoppingCart/shoppingCart.vue @@ -2,6 +2,7 @@ import { onLoad, onShow } from "@dcloudio/uni-app"; import { ref } from "vue"; import customTabBar from "@/components/custom-tab-bar/my-tab-bar.vue"; +import keyboard from "@/components/keyboard/keyboard.vue"; import navv from "@/components/nav/nav.vue"; // import topTitle from "@/components/topTitle/topTitle.vue"; import { @@ -13,7 +14,7 @@ import { getUserInfoApi, previewApi, } from "@/libs/api"; -import { sleep } from "@/libs/utils"; +import { sleep, validates } from "@/libs/utils"; import useStore from "@/store"; const store = useStore(); @@ -49,7 +50,7 @@ const totalPrice = ref(0); /** * 选中的购物车项 */ -const checkedItems = ref([]); +// const checkedItems = ref([]); /** * 选中所有购物车项 */ @@ -67,6 +68,10 @@ const cartCount = ref(0); * 是否显示购物车小球 */ const showBall = ref(false); +/** + * 是否显示键盘 + */ +const isShowkeyboard = ref(false); /** * 购物车小球的动画 */ @@ -160,17 +165,68 @@ function onTouchMove(e, index) { } /** * 购物车项选择事件 - * @param index 购物车项索引 + * @param item 购物车项 */ -async function onCheckboxChange(index) { - cartLists.value[index].checked = !cartLists.value[index].checked; +async function onCheckboxChange(item) { + // cartLists.value[index].checked = !cartLists.value[index].checked; + item.checked = !item.checked; store.changeCartList(cartLists.value.filter(item => item.checked)); - checkedItems.value = store.cartList.map(item => item.id); - await preview(checkedItems.value); + const checkedItems = store.cartList.map(item => item.id); + await preview(checkedItems); inspectCheck(); } -function onShowKeyboard() {} +/** + * 确定购买数量 + * @param value 购买数量 + * @param item 商品项 + */ +async function determine(value, item) { + const isPass = validates([ + () => item.stock != -1 && value > item.stock && "采购数量不能大于库存数量", + () => item.stock == 0 && "库存数量为0无法添加", + ]); + + if (!isPass) { + return; + } + + item.sum = value; + isShowkeyboard.value = false; + + const data = { + quantity: value, + specId: item.id, + Chuxiao: item.chuxiao, + warehouseId: uni.getStorageSync("warehousId"), + addrId: uni.getStorageSync("addressId"), + isUpdate: 1, + isChuxiao: false, + }; + if (!data.specId) { + uni.showModal({ + title: "提示", + content: "当前商品规格错误,请稍候再试", + showCancel: false, + confirmText: "确定", + }); + } + if (!data.warehouseId || !data.addrId) { + uni.showModal({ + title: "提示", + content: "请先选择收货地址,再添加商品", + showCancel: false, + confirmText: "确定", + }); + } + + const res = await addCartApi(data); + if (res.code !== "0") { + return; + } + // store.changeCartList(res.data); + initCartInfo(); +} /** * 购物车项增加事件 @@ -300,17 +356,14 @@ async function onSelectAllGoods() { cartLists.value = cartLists.value.map(item => ({ ...item, checked: checkedAll.value })); // cartLists.value[index].checked = !cartLists.value[index].checked; store.changeCartList(cartLists.value.filter(item => item.checked)); - checkedItems.value = store.cartList.map(item => item.id); - - await preview(checkedItems.value); + const checkedItems = store.cartList.map(item => item.id); + await preview(checkedItems); inspectCheck(); } /** * 结算 */ function onGotoOrder() { - console.log(123); - if (store.cartList.length == 0) { uni.showToast({ title: "下单商品不能为空", @@ -365,13 +418,15 @@ function onDeleteCart() { if (res.cancel) { return; } + + const checkedItems = store.cartList.filter(item => item.checked).map(item => item.id); const res2 = await deleteFromCartApi({ - ids: checkedItems.value.join(","), + ids: checkedItems.join(","), }); if (res2.code !== "0") { return; } - cartLists.value = cartLists.value.filter(item => !checkedItems.value.includes(item.id)); + cartLists.value = cartLists.value.filter(item => !checkedItems.includes(item.id)); initCartInfo(); }, }); @@ -422,6 +477,7 @@ async function toCart(item, diff) { if (res.code !== "0") { return; } + // store.changeCartList(res.data) initCartInfo(); } @@ -536,7 +592,7 @@ async function getUserInfo() { * 初始化购物车列表 */ async function initCartInfo() { - checkedItems.value = []; + // checkedItems.value = []; // isLoading.value = true; const res = await getCartInfoApi({ warehouseId: uni.getStorageSync("warehousId"), @@ -544,21 +600,23 @@ async function initCartInfo() { }); if (res.code === "0") { - checkedItems.value = res.data.map(each => each.id); - // 修改购物车列表 - store.changeCartList(res.data); + let checkedItems = res.data.map(each => each.id); + // isLoading.value = false; cartLists.value = res.data.map(each => ({ ...each, checked: true, isTouchMove: false, })); - totalPrice.value = res.data.reduce((acc, cur) => acc + cur.amount, 0); - if (checkedItems.value.length) { - await preview(checkedItems.value); + + if (checkedItems.length) { + // 修改购物车列表 + store.changeCartList(cartLists.value); + totalPrice.value = res.data.reduce((acc, cur) => acc + cur.amount, 0).toFixed(2); + await preview(checkedItems); } else { - checkedItems.value = []; + checkedItems = []; // genOrder.value = false; serviceFee.value = 0; shippingFee.value = 0; @@ -614,6 +672,7 @@ onShow(() => { // cartList.value = []; // inShow.value = true; getUserInfo(); + // initCartInfo(); }); onLoad(() => { @@ -625,7 +684,7 @@ onLoad(() => {