diff --git a/src/assets/vue.svg b/src/assets/vue.svg index 770e9d333ee70e75fe7c0bad7fb13e4f6ed4627a..e6534fee53b926480465c31f0aff5b429eddb42c 100644 --- a/src/assets/vue.svg +++ b/src/assets/vue.svg @@ -1 +1,6 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/components/Crumb.vue b/src/components/Crumb.vue index 5d31a32785a743f257995ce659717898529a6844..81a4c08544a80548611d271f39603730679cedd4 100644 --- a/src/components/Crumb.vue +++ b/src/components/Crumb.vue @@ -1,33 +1,31 @@ - - - - + + + - \ No newline at end of file + } +} + diff --git a/src/components/Footer.vue b/src/components/Footer.vue index ee92e79c843fd8cdc7f4d0079cb45905397c7797..2c9aae48dae339f299f60dd22e87683f9a31dfd7 100644 --- a/src/components/Footer.vue +++ b/src/components/Footer.vue @@ -28,11 +28,9 @@ - - - \ No newline at end of file + diff --git a/src/components/Header.vue b/src/components/Header.vue index 38b0984104ff789a600ef101656b989c72eacbf7..40ec48912b40fd2d9265847c10cb81ff1b5886c2 100644 --- a/src/components/Header.vue +++ b/src/components/Header.vue @@ -10,8 +10,8 @@ @@ -28,15 +28,15 @@ - - \ No newline at end of file + diff --git a/src/components/home/JfTitle.vue b/src/components/home/JfTitle.vue index 4103044e815f23320bcb5ba503c9231445878147..74d4ae25c99365a9b256bb69f5ab6d2e857cef3e 100644 --- a/src/components/home/JfTitle.vue +++ b/src/components/home/JfTitle.vue @@ -12,21 +12,21 @@ - - \ No newline at end of file + diff --git a/src/components/home/List.vue b/src/components/home/List.vue index c8607496400273cd8b5f3751b062ec869222640d..bffa6f143662688b33ab51889e460c163ef33a6b 100644 --- a/src/components/home/List.vue +++ b/src/components/home/List.vue @@ -2,41 +2,37 @@ - - \ No newline at end of file + diff --git a/src/components/user/Cart.vue b/src/components/user/Cart.vue index 5857553fd2e4a1d4e7d8a1c445133bd8435e9bd7..0a48b3ce0d021ecc970b005b1722123ddf2ecb8e 100644 --- a/src/components/user/Cart.vue +++ b/src/components/user/Cart.vue @@ -14,7 +14,7 @@ 礼品信息 兑换分数 数量 - 小计 (鸡腿) + 小计(鸡腿) 操作 @@ -45,23 +45,63 @@ {{ item.coin }}
- - + - {{ item.total }} - + + +
{{ item.coin * item.total }} - 删除 + 删除 -
- 总计:{{ sum }}鸡腿 + +
+
+ 总计:{{ sum }}鸡腿 +
+
提交
+
+ +
+
购物车内暂无商品
-
提交
@@ -97,6 +137,8 @@ let shopGoods = ref([]); // stepNum.value += val; // } // } +// 判断有无商品 +let flag = false; // 商品长度 let lengthGoods = ref(0); // 全选 @@ -115,21 +157,29 @@ async function showYourGoods() { shopGoods.value = res.data; // 获取购物车商品列表长度 lengthGoods.value = res.data.length; + // 判断购物车内是否有商品 + if (res.data.length > 0) { + flag = true; + } else { + flag = false; + } } showYourGoods(); // 修改商品数量 -async function modifyCart(id, num) { +async function modifyCart(id, num, checkStatus, coin, status) { if (num > 0) { const res = await cartAddAPI({ productId: id, total: num, modified: 1, }); - if (res.code == 0) { - storeuserInfos.initCartTotal(res.data.total); - } else { - alert(res.message); + if (status == false) { + storeuserInfos.initCartTotal(1); + if (checkStatus) sum += coin; + } else if (status == true) { + storeuserInfos.subCartTotal(1); + if (checkStatus) sum -= coin; } } else { alert("商品数量不能减少了哟~"); @@ -138,13 +188,14 @@ async function modifyCart(id, num) { } // 删除商品 -async function deleteCart(id) { +async function deleteCart(id, status, coin, num) { const res = await deleteCartAPI(id); if (res.code == 0) { - storeuserInfos.initCartTotal(res.data.total); + storeuserInfos.subCartTotal(num); } else { alert(res.message); } + if (status) sum -= coin; showYourGoods(); } // 全选 @@ -152,11 +203,19 @@ function selectAll() { checkAll.value = !checkAll.value; if (checkAll.value == true) { for (const i = ref(0); i.value < lengthGoods.value; i.value++) { - checkList[i.value] = true; + if (checkList[i.value] != true) { + checkList[i.value] = true; + // console.log(i.value); + sum += shopGoods.value[i.value].coin * shopGoods.value[i.value].total; + } } } else { for (const i = ref(0); i.value < lengthGoods.value; i.value++) { - checkList[i.value] = false; + if (checkList[i.value] != false) { + checkList[i.value] = false; + // console.log(i.value); + sum -= shopGoods.value[i.value].coin * shopGoods.value[i.value].total; + } } } } diff --git a/src/main.js b/src/main.js index 0c0d25df571a28faba6b5c2d1a2af1cf5325faf4..62c4625a47011b63e7016a58e8f5ef1f7cfba883 100644 --- a/src/main.js +++ b/src/main.js @@ -1,12 +1,12 @@ -import { createApp } from 'vue' -import './style.css' -import App from './App.vue' +import { createApp } from "vue"; +import "./style.css"; +import App from "./App.vue"; import router from "./router"; -import pinia from './store' +import pinia from "./store"; //第二步:将createApp(App)通过一个变量提收 const app = createApp(App); //第三步:在app中使用rouer app.use(router); -app.use(pinia) -app.config.globalProperties.img = 'https://sc.wolfcode.cn' -app.mount('#app') +app.use(pinia); +app.config.globalProperties.img = "https://sc.wolfcode.cn"; +app.mount("#app"); diff --git a/src/request/api.js b/src/request/api.js index 3fd6e6fa6f1d0b2674e7920807bf30bc93ae38be..34f3b0cada531c2eef9f1c62291ef3803be85029 100644 --- a/src/request/api.js +++ b/src/request/api.js @@ -42,4 +42,5 @@ export const cartAddAPI = (data) => // 获取购物车内的商品 export const cartAPI = () => request.get("/shop/carts"); -export const deleteCartAPI = (id) => request.delete(`/shop/carts?productIds=${id}`); +export const deleteCartAPI = (id) => + request.delete(`/shop/carts?productIds=${id}`); diff --git a/src/store/index.js b/src/store/index.js index 9333ebe673131105da84281845236be67de62ec0..6ffe063915a1f6ec701276a18ed48998d6fb9159 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -1,10 +1,10 @@ -import {createPinia} from 'pinia' +import { createPinia } from "pinia"; // 创建pinia实例对象 -const pinia = createPinia() +const pinia = createPinia(); // 导出 // 引入插件 -import piniaPluginPersist from 'pinia-plugin-persist' +import piniaPluginPersist from "pinia-plugin-persist"; // 使用插件 -pinia.use(piniaPluginPersist) -export default pinia; \ No newline at end of file +pinia.use(piniaPluginPersist); +export default pinia; diff --git a/src/store/modules/loginModel.js b/src/store/modules/loginModel.js index 7a9f90b46bfe0e4a39b76128b1bdbfaedd28311b..efc35a6012119ff5e0cfe472ead3c38a0cef4c13 100644 --- a/src/store/modules/loginModel.js +++ b/src/store/modules/loginModel.js @@ -1,23 +1,21 @@ -import {defineStore} from "pinia" +import { defineStore } from "pinia"; export const loginModel = defineStore("loginModel", { - // 类似于Vue2组件中的data,用于存储全局状态数据,但有两个要求 - // 1. 必须是函数,目的是为了在服务端渲染的时候避免交叉请求导致的数据状态污染 - // 2. 必须是箭头函数,这样是为了更好的 TS 类型推导 - state: () => { + // 类似于Vue2组件中的data,用于存储全局状态数据,但有两个要求 + // 1. 必须是函数,目的是为了在服务端渲染的时候避免交叉请求导致的数据状态污染 + // 2. 必须是箭头函数,这样是为了更好的 TS 类型推导 + state: () => { return { - isShowLoginModel: false - } + isShowLoginModel: false, + }; + }, + getters: {}, + actions: { + changisShowLoginModelActions(val) { + this.isShowLoginModel = val; }, - getters: { - - }, - actions: { - changisShowLoginModelActions(val){ - this.isShowLoginModel=val; - } - } - // 2. 使用容器中的 state - // 3. 通过 getter 修改 state - // 4. 使用容器中的 action 同步和异步请求 - }) \ No newline at end of file + }, + // 2. 使用容器中的 state + // 3. 通过 getter 修改 state + // 4. 使用容器中的 action 同步和异步请求 +}); diff --git a/src/store/modules/loginStatus.js b/src/store/modules/loginStatus.js index ce3cf66947f2139fe95f6232a4ba2a69cbf550c7..9e3d5d8d5f5b333227914a6f3e1d733526fd37b1 100644 --- a/src/store/modules/loginStatus.js +++ b/src/store/modules/loginStatus.js @@ -1,19 +1,16 @@ -import {defineStore} from 'pinia' -export const loginStatus = defineStore('loginStatus',{ -state(){ -return { -// 先从本地获取登录凭证x-auth-token,如果有,说明用户登录,否则用户没有登录 -isLogined:localStorage.getItem("x-auth-token")?true:false - - -} -}, -getters:{ -}, -actions:{ -// 修改isLogined的值 -changIsLogined(val){ -this.isLogined = val -} -} -}) \ No newline at end of file +import { defineStore } from "pinia"; +export const loginStatus = defineStore("loginStatus", { + state() { + return { + // 先从本地获取登录凭证x-auth-token,如果有,说明用户登录,否则用户没有登录 + isLogined: localStorage.getItem("x-auth-token") ? true : false, + }; + }, + getters: {}, + actions: { + // 修改isLogined的值 + changIsLogined(val) { + this.isLogined = val; + }, + }, +}); diff --git a/src/store/modules/userInfos.js b/src/store/modules/userInfos.js index f8e661f3a319ac126046ea75f4c9ea1a6c2139b3..09702b348a5086f8fead11f7fff548125004b365 100644 --- a/src/store/modules/userInfos.js +++ b/src/store/modules/userInfos.js @@ -26,10 +26,12 @@ export const userInfos = defineStore("userInfos", { }, // 修改购物车的数量 initCartTotal(state) { - return (val) => state.cartTotal == val; + return (val) => (state.cartTotal += val); + }, + //减少购物车的数量 + subCartTotal(state) { + return (val) => (state.cartTotal -= val); }, - // 减少购物车的数量 - // outitCartTotal() {}, }, actions: { // 修改用户信息 diff --git a/src/style.css b/src/style.css index 51e9980a1c8977eb03b5589dfe5b8989119d8d11..8fed1dd3216ee688335c1f49ddb2d593c0508bc9 100644 --- a/src/style.css +++ b/src/style.css @@ -1,16 +1,17 @@ -*{ +* { margin: 0; padding: 0; box-sizing: border-box; - } - a{ +} +a { text-decoration: none; color: #333; - } - li{ +} +li { list-style: none; - } - input,button{ - border: 0; - outline: none; - } +} +input, +button { + border: 0; + outline: none; +} diff --git a/src/utils/index.js b/src/utils/index.js index 41204825281e4fb0d5635cec2b179bb75bef44cb..dc27dd38eab9554b644777c38acd0ca06f8709fe 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -1,7 +1,6 @@ // validatePhoneNumber这个方法用来验证手机号是否符合规则 -export const validatePhoneNumber = value =>{ - let reg = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; - return reg.test(value) -} - - +export const validatePhoneNumber = (value) => { + let reg = + /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; + return reg.test(value); +}; diff --git a/src/views/Free.vue b/src/views/Free.vue index 6323bac6e28d0c12f11267b27c86051a069c35b1..6eba4aa10dc2ac65d773d75dfcfcd12a69f9f59a 100644 --- a/src/views/Free.vue +++ b/src/views/Free.vue @@ -1,11 +1,7 @@ - - - - \ No newline at end of file +
专属福利
+ + + + + diff --git a/src/views/Order.vue b/src/views/Order.vue index 8818b45074b41bb786b89820f314b0d05cfb836f..02f86b5be4f393bfc63ea8c482f48884829599ae 100644 --- a/src/views/Order.vue +++ b/src/views/Order.vue @@ -1,12 +1,7 @@ - - - \ No newline at end of file + diff --git a/src/views/User.vue b/src/views/User.vue index d09eeb2ac08f01ddc466c7c54a1c8600590a44e5..18a26f256571eb8a828daf281e258446e6cc608e 100644 --- a/src/views/User.vue +++ b/src/views/User.vue @@ -1,7 +1,7 @@