소스 검색

修改完善了代码

chillqi 2 년 전
부모
커밋
2dac8266bc

+ 10 - 5
src/api/coupon.ts

@@ -1,38 +1,43 @@
 import {axios} from '../utils/request'
 import {COUPON_MODULE} from './_prefix'
 
+// 获取已有优惠券
 export const getCoupons = () => {
     return axios.get(`${COUPON_MODULE}/`, )
         .then(res => {
-            return res;
+            return res
         })
 }
 
+// 查看优惠券组(剩余数量大于0、未领取过的优惠券组/门店下优惠券组/全部优惠券组)
 export const getCouponGroups = () => {
     return axios.get(`${COUPON_MODULE}/group`, )
         .then(res => {
-            return res;
+            return res
         })
 }
 
+// 创建优惠券
 export const createCoupons = payload => {
     return axios.post(`${COUPON_MODULE}/`, payload,
         {headers: {'Content-Type': 'application/json'}})
         .then(res => {
-            return res;
+            return res
         })
 }
 
+// 领取优惠券
 export const receiveCouponGroup = couponGroupId => {
     return axios.post(`${COUPON_MODULE}/receive/?couponGroupId=${couponGroupId}`)
         .then(res => {
-            return res;
+            return res
         })
 }
 
+// 获取门店下可用优惠券
 export const getAvailableCouponsByStoreId = storeId => {
     return axios.get(`${COUPON_MODULE}/available/?storeId=${storeId}`)
         .then(res => {
-            return res;
+            return res
         })
 }

+ 15 - 15
src/api/order.ts

@@ -1,60 +1,60 @@
 import {axios} from '../utils/request'
 import {ORDER_MODULE} from './_prefix'
 
-//创建订单
+// 创建订单
 export const createOrder = payload => {
     return axios.post(`${ORDER_MODULE}/`, payload,
         {headers: {'Content-Type': 'application/json'}})
         .then(res => {
-            return res;
+            return res
         })
 }
 
-//订单支付
+// 订单支付
 export const payOrder = (orderId, couponId) => {
     return axios.post(`${ORDER_MODULE}/pay/?orderId=${orderId}&couponId=${couponId}`)
         .then(res => {
-            return res;
+            return res
         })
 }
 
-//预计算价格
+// 预计算价格
 export const calculateOrder = (orderId, couponId) => {
     return axios.get(`${ORDER_MODULE}/calculate/?orderId=${orderId}&couponId=${couponId}`)
         .then(res => {
-            return res;
+            return res
         })
 }
 
-//获取用户下订单
+// 获取全部订单(用户下订单/门店下订单/全部订单)
 export const getAllOrder = () => {
     return axios.get(`${ORDER_MODULE}/`, )
         .then(res => {
-            return res;
+            return res
         })
 }
 
-//获取单个订单
+// 根据订单Id获取单个订单
 export const getOrderById = orderId => {
     return axios.get(`${ORDER_MODULE}/${orderId}`, )
         .then(res => {
-            return res;
+            return res
         })
 }
 
-//订单发货
+// 订单发货
 export const deliverOrder = orderId => {
     return axios.post(`${ORDER_MODULE}/deliver/?orderId=${orderId}`)
         .then(res => {
-            return res;
+            return res
         })
 }
 
-//订单收货
+// 订单收货
 export const getOrder = orderId => {
     return axios.post(`${ORDER_MODULE}/get/?orderId=${orderId}`)
         .then(res => {
-            return res;
+            return res
         })
 }
 
@@ -62,6 +62,6 @@ export const getOrder = orderId => {
 export const commentOrder = payload => {
     return axios.post(`${ORDER_MODULE}/comment`, null, {params: payload})
         .then(res => {
-            return res;
+            return res
         })
 }

+ 4 - 4
src/api/product.ts

@@ -6,7 +6,7 @@ export const createProduct = payload => {
     return axios.post(`${PRODUCT_MODULE}/`, payload,
         {headers: {'Content-Type': 'application/json'}})
         .then(res => {
-            return res;
+            return res
         })
 }
 
@@ -14,11 +14,11 @@ export const createProduct = payload => {
 export const getProductsByStoreId = storeId => {
     return axios.get(`${PRODUCT_MODULE}/?storeId=${storeId}`)
         .then(res => {
-            return res;
+            return res
         })
 }
 
-// 根据Id获取商品信息
+// 根据商品Id获取商品信息
 export const getProductById = productId => {
     return axios.get(`${PRODUCT_MODULE}/${productId}`)
         .then(res => {
@@ -34,7 +34,7 @@ export const addStock = (id, number) => {
         })
 }
 
-//获取商品评论
+//根据商品Id获取商品评论
 export const getCommentsById = productId => {
     return axios.get(`${PRODUCT_MODULE}/comment/?productId=${productId}`)
         .then(res => {

+ 4 - 4
src/api/store.ts

@@ -6,7 +6,7 @@ export const createStore = payload => {
     return axios.post(`${STORE_MODULE}/`, payload,
         {headers: {'Content-Type': 'application/json'}})
         .then(res => {
-            return res;
+            return res
         })
 }
 
@@ -14,14 +14,14 @@ export const createStore = payload => {
 export const getAllStore = () => {
     return axios.get(`${STORE_MODULE}/`, )
         .then(res => {
-            return res;
+            return res
         })
 }
 
-// 获取指定商店
+// 根据商店Id获取指定商店
 export const getStoreById = storeId => {
     return axios.get(`${STORE_MODULE}/${storeId}`)
         .then(res => {
-            return res;
+            return res
         })
 }

+ 4 - 3
src/api/tools.ts

@@ -1,7 +1,7 @@
 import {axios} from '../utils/request'
 import {API_MODULE} from './_prefix'
 
-// 上传文件
+// 上传图片文件
 export const uploadImage = payload => {
     return axios.post(`${API_MODULE}/images`, payload, {
         headers:{
@@ -9,13 +9,14 @@ export const uploadImage = payload => {
         }
     })
         .then(res => {
-            return res;
+            return res
         })
 }
 
+// 获取excel的链接
 export const getExcelUrl = () => {
     return axios.get(`${API_MODULE}/excel`, )
         .then(res => {
-            return res;
+            return res
         })
 }

+ 7 - 23
src/api/user.ts

@@ -5,47 +5,31 @@ import {USER_MODULE} from './_prefix'
 export const userLogin = payload => {
     return axios.post(`${USER_MODULE}/login`,null, {params: payload})
         .then(res => {
-            if(res.code == '400'){
-                throw new Error('密码错误!')
-            } else {
-                return res
-            }
+            return res
         })
 }
 
-
+// 用户注册
 export const userRegister = payload => {
     return axios.post(`${USER_MODULE}/register`, payload,
                     {headers: {'Content-Type': 'application/json'}})
         .then(res => {
-            if(res.code == '400'){
-                throw new Error('注册失败!')
-            } else {
-                return res
-            }
+            return res
         })
 }
 
-
+// 获取用户信息
 export const userInfo = () => {
     return axios.get(`${USER_MODULE}`)
         .then(res => {
-            if(res.code == '400'){
-                throw new Error('个人信息获取失败!')
-            } else {
-                return res
-            }
+            return res
         })
 }
 
-
+// 更新用户信息
 export const userInfoUpdate = payload => {
     return axios.post(`${USER_MODULE}`, payload, {headers: {'Content-Type': 'application/json'}})
         .then(res => {
-            if (res.code == '400') {
-                throw new Error('个人信息更新失败!')
-            } else {
-                return res
-            }
+            return res
         })
 }

+ 2 - 0
src/components/CommentItem.vue

@@ -24,6 +24,7 @@ function parseTime(time: string) {
 }
 </script>
 
+
 <template>
   <el-card class="comment-item-card" :body-style="{ padding: '0px' }" shadow="hover">
     <div class="comment-item-main">
@@ -44,6 +45,7 @@ function parseTime(time: string) {
 
 </template>
 
+
 <style scoped>
 .comment-item-card {
   margin: 20px;

+ 4 - 18
src/components/Header.vue

@@ -1,6 +1,8 @@
 <script setup lang="ts">
-import {User, Discount, SwitchButton, Document} from "@element-plus/icons-vue";
 import {router} from '../router'
+import {User, Discount, SwitchButton, Document} from "@element-plus/icons-vue"
+
+const role = sessionStorage.getItem('role')
 
 function logout() {
   ElMessageBox.confirm(
@@ -18,18 +20,9 @@ function logout() {
   ).then(() => {
     sessionStorage.setItem('token', '')
     router.push({path: "/login"})
-  }).catch(() => {
-    // do nothing
   })
 }
 
-function search() {
-  //todo: search
-
-}
-
-const role = sessionStorage.getItem('role')
-
 function parseRole() {
   if (role === 'MANAGER') {
     return "管理员"
@@ -41,13 +34,11 @@ function parseRole() {
     return "CEO"
   }
 }
-
 </script>
 
-<template>
 
+<template>
   <el-header class="custom-header" height="20">
-
     <el-row :gutter="10" :justify="'space-around'">
 
       <el-col :span="3" class="header-icon">
@@ -86,17 +77,13 @@ function parseRole() {
           <el-icon :size="35" color="white" ><SwitchButton /></el-icon>
         </a>
       </el-col>
-
     </el-row>
 
-
-
   </el-header>
 </template>
 
 
 <style scoped>
-
 .custom-header {
   background-color: #409eff;
   border-bottom-left-radius: 20px;
@@ -129,5 +116,4 @@ function parseRole() {
   align-items:center;
   justify-content: center;
 }
-
 </style>

+ 50 - 48
src/components/OrderItem.vue

@@ -1,9 +1,9 @@
 <script setup lang="ts">
-import {deliverOrder, getOrder, getOrderById, payOrder, commentOrder, calculateOrder} from "../api/order.ts";
-import {ref, computed} from "vue";
-import {getAvailableCouponsByStoreId} from "../api/coupon.ts";
-import {ElTable} from "element-plus";
-import {RefreshRight} from "@element-plus/icons-vue";
+import {ref, computed} from "vue"
+import {ElTable} from "element-plus"
+import {RefreshRight} from "@element-plus/icons-vue"
+import {deliverOrder, getOrder, getOrderById, payOrder, commentOrder, calculateOrder} from "../api/order.ts"
+import {getAvailableCouponsByStoreId} from "../api/coupon.ts"
 
 const props = defineProps({
   orderId: {
@@ -13,6 +13,7 @@ const props = defineProps({
 })
 
 const role = sessionStorage.getItem("role")
+
 const orderDialogVisible = ref(false)
 const commentDialogVisible = ref(false)
 
@@ -58,48 +59,6 @@ function getOrderDetail() {
   })
 }
 
-// 对于变化的内容使用计算属性返回响应式结果
-const statusText = computed(() => {
-  switch (status.value) {
-    case 'UNPAID':
-      return "待顾客支付"
-    case 'UNSEND':
-      return "待商家发货"
-    case 'UNGET':
-      return "待顾客收货"
-    case 'UNCOMMENT':
-      return "待顾客评价"
-    case 'DONE':
-      return "已完成"
-    default:
-      return "状态标签"
-  }
-})
-
-function parseTime(time) {
-  if (time === null) {
-    return "暂未完成"
-  }
-  let times = time.split(/T|\./)
-  return times[0] + " " + times[1]
-}
-
-function parseType() {
-  if (type.value === 'DELIVERY') {
-    return "快递到家"
-  } else if (type.value === 'PICKUP') {
-    return "到店自取"
-  }
-}
-
-function parseNull(value) {
-  if (value === null) {
-    return "/"
-  } else {
-    return value
-  }
-}
-
 function handlePay() {
   orderDialogVisible.value = true
   getAvailableCouponList()
@@ -269,8 +228,51 @@ function parseOrderType(type) {
     return "快递到家"
   }
 }
+
+// 对于变化的内容使用计算属性返回响应式结果
+const statusText = computed(() => {
+  switch (status.value) {
+    case 'UNPAID':
+      return "待顾客支付"
+    case 'UNSEND':
+      return "待商家发货"
+    case 'UNGET':
+      return "待顾客收货"
+    case 'UNCOMMENT':
+      return "待顾客评价"
+    case 'DONE':
+      return "已完成"
+    default:
+      return "状态标签"
+  }
+})
+
+function parseTime(time) {
+  if (time === null) {
+    return "暂未完成"
+  }
+  let times = time.split(/T|\./)
+  return times[0] + " " + times[1]
+}
+
+function parseType() {
+  if (type.value === 'DELIVERY') {
+    return "快递到家"
+  } else if (type.value === 'PICKUP') {
+    return "到店自取"
+  }
+}
+
+function parseNull(value) {
+  if (value === null) {
+    return "/"
+  } else {
+    return value
+  }
+}
 </script>
 
+
 <template>
   <el-card class="order-item-card" shadow="hover">
 
@@ -434,8 +436,8 @@ function parseOrderType(type) {
 
 </template>
 
-<style scoped>
 
+<style scoped>
 .order-item-card {
   margin: 20px;
   border-radius: 8px;

+ 18 - 18
src/components/ProductItem.vue

@@ -2,6 +2,7 @@
 import {ref} from "vue";
 import {getProductById} from "../api/product.ts";
 
+// 使用props接收父界面传来的数据
 const props = defineProps({
   productId: {
     type: Number,
@@ -20,23 +21,19 @@ const category = ref()
 const price = ref()
 const photoUrl = ref('')
 
-getProductDetail()
+getProductById(props.productId).then(res => {
+  storeId.value = res.result.storeId
+  name.value = res.result.name
+  photoUrlList.value = res.result.photoUrlList
+  rating.value = res.result.rating
+  number.value = res.result.number
+  salesAmount.value = res.result.salesAmount
+  stock.value = res.result.stock
+  category.value = res.result.category
+  price.value = res.result.price
 
-function getProductDetail() {
-  getProductById(props.productId).then(res => {
-    storeId.value = res.result.storeId
-    name.value = res.result.name
-    photoUrlList.value = res.result.photoUrlList
-    rating.value = res.result.rating
-    number.value = res.result.number
-    salesAmount.value = res.result.salesAmount
-    stock.value = res.result.stock
-    category.value = res.result.category
-    price.value = res.result.price
-
-    photoUrl.value = photoUrlList.value[0]
-  })
-}
+  photoUrl.value = photoUrlList.value[0]
+})
 
 function parseCategory(category) {
   if (category === 'FOOD') {
@@ -57,6 +54,7 @@ function parseCategory(category) {
 }
 </script>
 
+
 <template>
   <el-card class="product-item-card" shadow="hover">
     <div class="photo-div">
@@ -79,7 +77,8 @@ function parseCategory(category) {
               text-color="#ff9900"
               score-template="{value} 分"
               size="small"
-          />(共 {{ number }} 人打分)
+          />
+          (共 {{ number }} 人打分)
         </el-descriptions-item>
         <el-descriptions-item style="font-size: 10px" label="销量">
           {{ salesAmount }} 件
@@ -92,9 +91,10 @@ function parseCategory(category) {
   </el-card>
 </template>
 
+
 <style scoped>
 .product-item-card {
-  margin: 10px;
+  margin: 8px;
   border-radius: 8px;
   min-width: 31%;
 }

+ 11 - 14
src/components/StoreItem.vue

@@ -2,6 +2,7 @@
 import {ref} from "vue"
 import {getStoreById} from "../api/store.ts"
 
+// 使用props接收父界面传来的数据
 const props = defineProps({
   storeId: {
     type: Number,
@@ -15,27 +16,22 @@ const rating = ref(0)
 const number = ref(0)
 const location = ref('')
 
-getStoreDetail()
-
-function getStoreDetail() {
-  getStoreById(props.storeId).then(res => {
-    console.log(res)
-    name.value = res.result.name
-    logoUrl.value = res.result.logoUrl
-    rating.value = res.result.rating
-    number.value = res.result.number
-    location.value = res.result.location
-  })
-}
-
+getStoreById(props.storeId).then(res => {
+  name.value = res.result.name
+  logoUrl.value = res.result.logoUrl
+  rating.value = res.result.rating
+  number.value = res.result.number
+  location.value = res.result.location
+})
 </script>
 
+
 <template>
   <el-card class="store-item-card" :body-style="{ padding: '0px' }" shadow="hover">
     <el-image class="logo-image" :src="logoUrl"/>
 
     <div style="padding: 14px">
-      <h1> {{name}} </h1>
+      <h1> {{ name }} </h1>
       <el-descriptions :column="1">
         <el-descriptions-item style="font-size: 10px" label="评分">
           <el-rate
@@ -56,6 +52,7 @@ function getStoreDetail() {
   </el-card>
 </template>
 
+
 <style scoped>
 .store-item-card {
   margin: 20px;

+ 2 - 0
src/views/coupon/AllCoupon.vue

@@ -120,6 +120,7 @@ function receiveCoupon(couponGroupId) {
 }
 </script>
 
+
 <template>
   <div>
     <el-button @click="toCreateCoupon()" v-if="role === 'MANAGER' || role === 'STAFF'"
@@ -246,6 +247,7 @@ function receiveCoupon(couponGroupId) {
   </div>
 </template>
 
+
 <style scoped>
 .create-coupon-button {
   width: 100px;

+ 6 - 5
src/views/order/AllOrder.vue

@@ -1,8 +1,8 @@
 <script setup lang="ts">
-import {ref} from "vue";
-import {getAllOrder} from "../../api/order.ts";
-import OrderItem from "../../components/OrderItem.vue";
-import {getExcelUrl} from "../../api/tools.ts";
+import {ref} from "vue"
+import {getAllOrder} from "../../api/order.ts"
+import {getExcelUrl} from "../../api/tools.ts"
+import OrderItem from "../../components/OrderItem.vue"
 
 const role = sessionStorage.getItem("role")
 
@@ -16,9 +16,9 @@ getAllOrder().then(res => {
 getExcelUrl().then(res => {
   excelUrl.value = res.result
 })
-
 </script>
 
+
 <template>
   <el-main>
     <div v-if="role === 'STAFF' || role === 'MANAGER' || role === 'CEO'">
@@ -34,6 +34,7 @@ getExcelUrl().then(res => {
   </el-main>
 </template>
 
+
 <style scoped>
 .order-item-list {
   display: flex;

+ 9 - 14
src/views/product/CreateProduct.vue

@@ -1,13 +1,11 @@
 <script setup lang="ts">
-import {useRouter} from "vue-router";
-import {ref, computed} from "vue";
-import {Back, UploadFilled} from "@element-plus/icons-vue";
-import {createProduct} from "../../api/product.ts";
-import {uploadImage} from "../../api/tools.ts";
+import {ref, computed} from "vue"
+import {router} from '../../router'
+import {Back, UploadFilled} from "@element-plus/icons-vue"
+import {createProduct} from "../../api/product.ts"
+import {uploadImage} from "../../api/tools.ts"
 
-const router = useRouter();
-
-const storeId = router.currentRoute.value.params.storeId;
+const storeId = router.currentRoute.value.params.storeId
 const name = ref('')
 const category = ref()
 const price = ref()
@@ -19,7 +17,6 @@ const hasNameInput = computed(() => name.value != '')
 const hasCategoryInput = computed(() => category.value != null)
 const hasPriceInput = computed(() => price.value != '')
 const hasImageFile = computed(() => imageFileList.value.length != 0)
-
 const createProductDisabled = computed(() => {
   return !(hasNameInput.value && hasCategoryInput.value && hasPriceInput.value && hasImageFile.value);
 })
@@ -74,11 +71,8 @@ function toBackPage() {
 
 <template>
   <el-main>
-    <el-button @click="toBackPage()"
-               type="primary" circle plain>
-      <el-icon>
-        <Back/>
-      </el-icon>
+    <el-button @click="toBackPage()" type="primary" circle plain>
+      <el-icon><Back/></el-icon>
     </el-button>
 
     <h1 class="create-product-title">新建商品</h1>
@@ -138,6 +132,7 @@ function toBackPage() {
   </el-main>
 </template>
 
+
 <style scoped>
 .create-product-title {
   margin-left: 25%;

+ 71 - 69
src/views/product/ProductDetail.vue

@@ -1,17 +1,17 @@
 <script setup lang="ts">
-import {useRouter} from "vue-router";
-import {ref, onMounted, computed} from "vue";
-import {addStock, getProductById} from "../../api/product.ts";
-import {Back, RefreshRight} from "@element-plus/icons-vue";
-import {ElTable} from "element-plus";
-import {calculateOrder, createOrder, payOrder} from "../../api/order.ts";
-import {getAvailableCouponsByStoreId} from "../../api/coupon.ts";
-import {getCommentsById} from "../../api/product.ts";
-import CommentItem from "../../components/CommentItem.vue";
-
-const router = useRouter();
+import {ref, onMounted, computed} from "vue"
+import {router} from '../../router'
+import {Back, RefreshRight} from "@element-plus/icons-vue"
+import {ElTable} from "element-plus"
+import {addStock, getProductById} from "../../api/product.ts"
+import {calculateOrder, createOrder, payOrder} from "../../api/order.ts"
+import {getAvailableCouponsByStoreId} from "../../api/coupon.ts"
+import {getCommentsById} from "../../api/product.ts"
+import CommentItem from "../../components/CommentItem.vue"
+
 const role = sessionStorage.getItem("role")
-const productId = router.currentRoute.value.params.productId;
+
+const productId = router.currentRoute.value.params.productId
 const productVO = ref()
 const storeId = ref(0)
 const name = ref('')
@@ -37,23 +37,20 @@ const couponId = ref(0)
 const addStockNumber = ref('')
 
 const hasTypeInput = computed(() => type.value != null)
-const hasAddStockInput = computed(() => addStockNumber.value != '')
-
 const amountLegal = computed(() => amount.value <= stock.value)
-
 const createOrderDisabled = computed(() => {
-  return !(amountLegal.value && hasTypeInput.value);
+  return !(amountLegal.value && hasTypeInput.value)
 })
 
+const hasAddStockInput = computed(() => addStockNumber.value != '')
 const addStockDisabled = computed(() => {
-  return !(hasAddStockInput.value);
+  return !(hasAddStockInput.value)
 })
 
 const commentList = ref([])
 
 getCommentsById(productId).then(res => {
   commentList.value = res.result
-  console.log(res)
 })
 
 getProductDetail()
@@ -75,24 +72,7 @@ function getProductDetail() {
   })
 }
 
-function parseCategory(category) {
-  if (category === 'FOOD') {
-    return "食品"
-  } else if (category === 'CLOTHES') {
-    return "服饰"
-  } else if (category === 'FURNITURE') {
-    return "家具"
-  } else if (category === 'ELECTRONICS') {
-    return "电子产品"
-  } else if (category === 'ENTERTAINMENT') {
-    return "娱乐"
-  } else if (category === 'SPORTS') {
-    return "体育产品"
-  } else if (category === 'LUXURY') {
-    return "奢侈品"
-  }
-}
-
+// 添加库存按钮
 function AddStock() {
   addStock(productId, addStockNumber.value).then(res => {
     if (res.code === '000') {
@@ -113,12 +93,13 @@ function AddStock() {
   })
 }
 
+// 创建订单按钮
 function handleCreateOrder() {
   const payload = {
     productId: productId,
     amount: amount.value,
     type: type.value
-  };
+  }
   createOrder(payload).then(res => {
     if (res.code === '000') {
       ElMessage({
@@ -140,10 +121,11 @@ function handleCreateOrder() {
   })
 }
 
-const showForm = ref(false);
+const showForm = ref(false)
 const isLoading = ref(false)
 const refreshButtonVisible = ref(false)
 
+// 确定订单按钮
 function handleConfirmOrder() {
   payOrder(orderId.value, couponId.value).then(res => {
     if (res.code === '000') {
@@ -154,10 +136,10 @@ function handleConfirmOrder() {
       })
       isLoading.value = true
       refreshButtonVisible.value = true
-      const paymentWindow = window.open('', '_blank');
-      paymentWindow.document.write(res.result);
-      paymentWindow.document.forms[0].submit(); // 提交表单
-      showForm.value = false; // 隐藏表单
+      const paymentWindow = window.open('', '_blank')
+      paymentWindow.document.write(res.result)
+      paymentWindow.document.forms[0].submit() // 提交表单
+      showForm.value = false // 隐藏表单
     } else if (res.code === '400') {
       ElMessage({
         message: res.msg,
@@ -169,7 +151,7 @@ function handleConfirmOrder() {
 }
 
 function refreshPage() {
-  location.reload();
+  location.reload()
 }
 
 function handlePayDialogClose() {
@@ -180,32 +162,8 @@ function handlePayDialogClose() {
 }
 
 onMounted(() => {
-  showForm.value = true; // 组件加载后显示表单
-});
-
-function parseOrderType(type) {
-  if (type === "PICKUP") {
-    return "到店自提"
-  } else if (type === "DELIVERY") {
-    return "快递到家"
-  }
-}
-
-function parseCouponType(type) {
-  if (type === "FULL_REDUCTION") {
-    return "满减"
-  } else if (type === "SPECIAL") {
-    return "折扣"
-  }
-}
-
-function parseNull(value) {
-  if (value === null) {
-    return "/"
-  } else {
-    return value
-  }
-}
+  showForm.value = true // 组件加载后显示表单
+})
 
 // 处理优惠券
 interface Coupon {
@@ -242,11 +200,54 @@ const handleCurrentChange = (val: Coupon | undefined) => {
   })
 }
 
+function parseCategory(category) {
+  if (category === 'FOOD') {
+    return "食品"
+  } else if (category === 'CLOTHES') {
+    return "服饰"
+  } else if (category === 'FURNITURE') {
+    return "家具"
+  } else if (category === 'ELECTRONICS') {
+    return "电子产品"
+  } else if (category === 'ENTERTAINMENT') {
+    return "娱乐"
+  } else if (category === 'SPORTS') {
+    return "体育产品"
+  } else if (category === 'LUXURY') {
+    return "奢侈品"
+  }
+}
+
+function parseOrderType(type) {
+  if (type === "PICKUP") {
+    return "到店自提"
+  } else if (type === "DELIVERY") {
+    return "快递到家"
+  }
+}
+
+function parseCouponType(type) {
+  if (type === "FULL_REDUCTION") {
+    return "满减"
+  } else if (type === "SPECIAL") {
+    return "折扣"
+  }
+}
+
+function parseNull(value) {
+  if (value === null) {
+    return "/"
+  } else {
+    return value
+  }
+}
+
 function toBackPage() {
   router.push("/storeDetail/" + storeId.value)
 }
 </script>
 
+
 <template>
   <el-container>
     <el-aside width="25%" class="page-aside">
@@ -421,6 +422,7 @@ function toBackPage() {
   </el-container>
 </template>
 
+
 <style scoped>
 .page-aside {
   border-right: lightgrey solid 1px;

+ 9 - 9
src/views/store/AllStore.vue

@@ -1,23 +1,26 @@
 <script setup lang="ts">
 import {ref} from "vue"
+import {router} from '../../router'
 import {getAllStore} from "../../api/store.ts"
-import {useRouter} from "vue-router"
+import StoreItem from "../../components/StoreItem.vue"
 
 const role = sessionStorage.getItem("role")
-const router = useRouter()
 
 const storeList = ref()
 
+// 获取商店列表
 getAllStore().then(res => {
-  storeList.value = res.result;
+  storeList.value = res.result
 })
 
+// 点击创建商店按钮,跳转到创建商店界面
 function toCreateStorePage() {
-  router.push("/createStore");
+  router.push("/createStore")
 }
 
+// 点击商店卡片,跳转到对应的商店界面
 function toStoreDetailPage(storeId: Number) {
-  router.push("/storeDetail/" + storeId);
+  router.push("/storeDetail/" + storeId)
 }
 </script>
 
@@ -32,9 +35,7 @@ function toStoreDetailPage(storeId: Number) {
     </div>
 
     <div class="store-item-list">
-      <StoreItem
-          v-for="storeVO in storeList" :storeId="storeVO.id"
-          @click="toStoreDetailPage(storeVO.id)"/>
+      <StoreItem v-for="storeVO in storeList" :storeId="storeVO.id" @click="toStoreDetailPage(storeVO.id)"/>
     </div>
   </el-main>
 </template>
@@ -43,7 +44,6 @@ function toStoreDetailPage(storeId: Number) {
 <style scoped>
 .add-store-button {
   margin-left: 30px;
-
 }
 
 .store-item-list {

+ 16 - 25
src/views/store/CreateStore.vue

@@ -1,25 +1,24 @@
 <script setup lang="ts">
 import {computed, ref} from 'vue'
 import {router} from '../../router'
-import {Back, UploadFilled} from "@element-plus/icons-vue";
+import {Back, UploadFilled} from "@element-plus/icons-vue"
 import {createStore} from "../../api/store.ts"
 import {uploadImage} from "../../api/tools.ts"
 
-// 输入框值
+// 输入框值(需要前端阻拦不合法输入)
 const name = ref('')
 const location = ref('')
 const imageFileList = ref([])
 const logoUrl = ref('')
 
-// 用于前端阻拦不合法输入
 const hasNameInput = computed(() => name.value != '')
 const hasLocationInput = computed(() => location.value != '')
 const hasImageFile = computed(() => logoUrl.value != '')
-
 const createDisabled = computed(() => {
-  return !(hasNameInput.value && hasLocationInput.value && hasImageFile.value);
+  return !(hasNameInput.value && hasLocationInput.value && hasImageFile.value)
 })
 
+// 创建商店按钮触发
 function handleCreateStore() {
   const payload = {
     name: name.value,
@@ -33,10 +32,10 @@ function handleCreateStore() {
         type: 'success',
         center: true,
       })
-      name.value = '';
-      location.value = '';
-      logoUrl.value = '';
-      imageFileList.value.splice(0);
+      name.value = ''
+      location.value = ''
+      logoUrl.value = ''
+      imageFileList.value.splice(0)
     } else if (res.code === '400') {
       ElMessage({
         message: res.msg,
@@ -44,19 +43,16 @@ function handleCreateStore() {
         center: true,
       })
     }
-  });
+  })
 }
 
 function handleChange(file, fileList) {
-  console.log(file)
-  console.log(fileList)
   imageFileList.value = fileList
-  let formData = new FormData();
-  formData.append('file', file.raw);
+  let formData = new FormData()
+  formData.append('file', file.raw)
   uploadImage(formData).then(res => {
-    logoUrl.value = res.result;
-  });
-  console.log(imageFileList.value)
+    logoUrl.value = res.result
+  })
 }
 
 function handleExceed() {
@@ -74,8 +70,7 @@ function toBackPage() {
 
 <template>
   <el-main>
-    <el-button @click="toBackPage()"
-               type="primary" circle plain>
+    <el-button @click="toBackPage()" type="primary" circle plain>
       <el-icon><Back/></el-icon>
     </el-button>
 
@@ -84,15 +79,11 @@ function toBackPage() {
     <el-form label-position="left" label-width="90px" size="large" class="create-store-form">
 
       <el-form-item label="商店名">
-        <el-input id="name" v-model="name"
-                  required
-                  placeholder="请输入商店名"/>
+        <el-input id="name" v-model="name" required placeholder="请输入商店名"/>
       </el-form-item>
 
       <el-form-item label="商店地址">
-        <el-input id="location" v-model="location"
-                  required
-                  placeholder="楼层-门牌号 如:3楼-305"/>
+        <el-input id="location" v-model="location" required placeholder="楼层-门牌号 如:3楼-305"/>
       </el-form-item>
 
       <el-form-item label="商店Logo">

+ 6 - 6
src/views/store/StoreDetail.vue

@@ -1,13 +1,13 @@
 <script setup lang="ts">
-
-import {getStoreById} from "../../api/store.ts"
-import {useRouter} from "vue-router"
 import {ref} from "vue"
+import {router} from '../../router'
+import {getStoreById} from "../../api/store.ts"
 import {getProductsByStoreId} from "../../api/product.ts"
 import {Back} from "@element-plus/icons-vue"
+import ProductItem from "../../components/ProductItem.vue"
 
-const router = useRouter();
 const role = sessionStorage.getItem("role")
+// 从当前router地址中获得storeId参数值
 const storeId = router.currentRoute.value.params.storeId
 const storeVO = ref()
 const name = ref('')
@@ -34,8 +34,8 @@ function toCreateProductPage() {
   router.push("/createProduct/" + storeId)
 }
 
-function toProductDetailPage(productId: Number) {
-  router.push("/productDetail/" + productId);
+function toProductDetailPage(productId) {
+  router.push("/productDetail/" + productId)
 }
 
 function toBackPage() {

+ 57 - 63
src/views/user/Dashboard.vue

@@ -11,6 +11,8 @@ const tel = ref('')
 const address = ref('')
 const regTime = ref()
 
+const newName = ref('')
+
 const displayInfoCard = ref(false)
 
 const password = ref('')
@@ -20,87 +22,78 @@ const hasPasswordInput = computed(() => password.value != '');
 const hasConfirmPasswordInput = computed(() => confirmPassword.value != '');
 const isPasswordIdentical = computed(() => password.value == confirmPassword.value);
 
-userInfo()
-    .then(res => {
-      name.value = res.result.name
-      tel.value = res.result.phone
-      storeName.value = res.result.storeName
-      address.value = res.result.address
-      regTime.value = parseTime(res.result.createTime)
-    })
-    .catch(e => {
-      console.error(e.message)
-      //todo: 处理错误
-    })
+getUserInfo()
 
-function updateInfo() {
+function getUserInfo() {
+  userInfo().then(res => {
+    name.value = res.result.name
+    tel.value = res.result.phone
+    storeName.value = res.result.storeName
+    address.value = res.result.address
+    regTime.value = parseTime(res.result.createTime)
+
+    newName.value = name.value
+  })
+}
 
+function updateInfo() {
   const payload = {
-    name: name.value,
+    name: newName.value,
     password: null,
     address: address.value,
   }
 
-  userInfoUpdate(payload)
-      .then(() => {
-        ElMessage({
-          customClass: 'customMessage',
-          type: 'success',
-          message: '更新成功!',
-        })
-      })
-      .catch(e => {
-        console.error(e.message)
-        ElMessage({
-          customClass: 'customMessage',
-          type: 'error',
-          message: '更新失败!',
-        })
+  userInfoUpdate(payload).then(res => {
+    if (res.code === '000') {
+      ElMessage({
+        customClass: 'customMessage',
+        type: 'success',
+        message: '更新成功!',
       })
-      .finally(() => {
-        userInfo().then(res => {
-          name.value = res.result.name
-        })
+      getUserInfo()
+    } else if (res.code === '400') {
+      ElMessage({
+        customClass: 'customMessage',
+        type: 'error',
+        message: '更新失败!',
       })
+    }
+  })
 }
 
 function updatePassword() {
-
   const payload = {
     name: null,
     password: password.value,
     address: null
   }
 
-  userInfoUpdate(payload)
-      .then(() => {
-
-        ElMessageBox.alert(
-            `请重新登录`,
-            '修改成功',
-            {
-              customClass: "customDialog",
-              confirmButtonText: '跳转到登录',
-              type: "success",
-              showClose: false,
-              roundButton: true,
-              center: true
-
-            }).then(() => router.push({path: "/login"}))
-
-      })
-      .catch(e => {
-        console.error(e.message)
-        ElMessage({
-          customClass: 'customMessage',
-          type: 'error',
-          message: '更新失败!',
-        })
-      })
-      .finally(() => {
-        password.value = ''
-        confirmPassword.value = ''
+  userInfoUpdate(payload).then(res => {
+    if (res.code === '000') {
+      password.value = ''
+      confirmPassword.value = ''
+      ElMessageBox.alert(
+          `请重新登录`,
+          '修改成功',
+          {
+            customClass: "customDialog",
+            confirmButtonText: '跳转到登录',
+            type: "success",
+            showClose: false,
+            roundButton: true,
+            center: true
+
+          }).then(() => router.push({path: "/login"}))
+    } else if (res.code === '400') {
+      ElMessage({
+        customClass: 'customMessage',
+        type: 'error',
+        message: '更新失败!',
       })
+      password.value = ''
+      confirmPassword.value = ''
+    }
+  })
 }
 
 function parseRole() {
@@ -121,6 +114,7 @@ function parseTime(time) {
 }
 </script>
 
+
 <template>
   <el-main class="main-container">
     <el-card class="aside-card">
@@ -178,7 +172,7 @@ function parseTime(time) {
       <el-form>
         <el-form-item>
           <label for="name">昵称</label>
-          <el-input type="text" id="name" v-model="name"/>
+          <el-input type="text" id="name" v-model="newName"/>
         </el-form-item>
 
         <el-form-item>

+ 44 - 65
src/views/user/Login.vue

@@ -1,80 +1,58 @@
 <script setup lang="ts">
-import {ElForm, ElFormItem} from "element-plus";
-import {ref, computed} from 'vue';
+import {ElForm, ElFormItem} from "element-plus"
+import {ref, computed} from 'vue'
 import {router} from '../../router'
-import {userInfo, userLogin} from "../../api/user.ts";
+import {userInfo, userLogin} from "../../api/user.ts"
 
-// 输入框值
+// 输入框值(需要在前端拦截不合法输入:是否为空+额外规则)
 const tel = ref('')
 const password = ref('')
 
-// 用于前端阻拦不合法输入
-const hasTelInput = computed(() => tel.value != '');
-const hasPasswordInput = computed(() => password.value != '');
-
-const chinaMobileRegex = /^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[189])\d{8}$/;
-const telLegal = computed(() => chinaMobileRegex.test(tel.value));
-
-// 密码有就行
-const passwordLegal = hasPasswordInput;
-
+// 电话号码是否为空
+const hasTelInput = computed(() => tel.value != '')
+// 密码是否为空
+const hasPasswordInput = computed(() => password.value != '')
+// 电话号码的规则
+const chinaMobileRegex = /^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[189])\d{8}$/
+const telLegal = computed(() => chinaMobileRegex.test(tel.value))
+// 密码不设置特殊规则
+// 登录按钮可用性
 const loginDisabled = computed(() => {
-  return !(telLegal.value && passwordLegal.value);
-});
+  return !(hasTelInput.value && telLegal.value && hasPasswordInput.value)
+})
 
-async function handleLogin() {
+// 登录按钮触发
+function handleLogin() {
   const payload = {
     phone: tel.value,
-    password: password.value,
+    password: password.value
   }
 
-  userLogin(payload)
-      .then(res => {
-        const token = res.result
-        sessionStorage.setItem('token', token)
-
-        userInfo().then(res => {
-          sessionStorage.setItem('name', res.result.name)
-          sessionStorage.setItem('role', res.result.role)
-          router.push({path: "/allStore"})
-        }).catch(e => {
-          console.log(e.message)
-          ElMessageBox.alert(
-              e.message,
-              '错误提示',
-              {
-                confirmButtonText: '好的',
-                type: "error",
-                showClose: false,
-                roundButton: true,
-                center: true
-              }
-          ).then(() => {
-            // 清空用户密码
-            password.value = ''
-          })
-        })
+  userLogin(payload).then(res => {
+    if (res.code === '000') {
+      ElMessage({
+        message: "登录成功!",
+        type: 'success',
+        center: true,
+      })
+      const token = res.result
+      sessionStorage.setItem('token', token)
 
+      userInfo().then(res => {
+        sessionStorage.setItem('name', res.result.name)
+        sessionStorage.setItem('role', res.result.role)
+        router.push({path: "/allStore"})
       })
-      .catch(e => {
-        console.log(e.message)
-        ElMessageBox.alert(
-            e.message,
-            '错误提示',
-            {
-              confirmButtonText: '好的',
-              type: "error",
-              showClose: false,
-              roundButton: true,
-              center: true
-            }
-        ).then(() => {
-          // 清空用户密码
-          password.value = ''
-        })
+    } else if (res.code === '400') {
+      ElMessage({
+        message: res.msg,
+        type: 'error',
+        center: true,
       })
+      password.value = ''
+    }
+  })
 }
-
 </script>
 
 
@@ -113,11 +91,8 @@ async function handleLogin() {
   </el-main>
 </template>
 
-<style scoped>
-.bgimage {
-  background-image: url("../../assets/shopping-1s-1084px.svg");
-}
 
+<style scoped>
 .main-frame {
   width: 100%;
   height: 100%;
@@ -127,6 +102,10 @@ async function handleLogin() {
   justify-content: center;
 }
 
+.bgimage {
+  background-image: url("../../assets/shopping-1s-1084px.svg");
+}
+
 .login-card {
   width: 60%;
   padding: 10px;

+ 42 - 54
src/views/user/Register.vue

@@ -1,8 +1,9 @@
 <script setup lang="ts">
-import {ref, computed} from 'vue';
+import {ref, computed} from 'vue'
 import {router} from '../../router'
-import {userRegister} from "../../api/user.ts";
+import {userRegister} from "../../api/user.ts"
 
+// 输入框值(需要在前端拦截不合法输入:是否为空+额外规则)
 const name = ref('')
 const identity = ref('')
 const tel = ref('')
@@ -10,22 +11,29 @@ const address = ref('')
 const password = ref('')
 const confirmPassword = ref('')
 
-const chinaMobileRegex = /^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[189])\d{8}$/;
-
-const hasTelInput = computed(() => tel.value != '');
-const hasPasswordInput = computed(() => password.value != '');
-const hasConfirmPasswordInput = computed(() => confirmPassword.value != '');
-const hasAddressInput = computed(() => address.value != '');
+// 电话号码是否为空
+const hasTelInput = computed(() => tel.value != '')
+// 密码是否为空
+const hasPasswordInput = computed(() => password.value != '')
+// 重复密码是否为空
+const hasConfirmPasswordInput = computed(() => confirmPassword.value != '')
+// 地址是否为空
+const hasAddressInput = computed(() => address.value != '')
+// 身份是否为空
 const hasIdentityChosen = computed(() => identity.value != '')
-
-const telLegal = computed(() => chinaMobileRegex.test(tel.value));
-const isPasswordIdentical = computed(() => password.value == confirmPassword.value);
-
+// 电话号码的规则
+const chinaMobileRegex = /^1(3[0-9]|4[579]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[189])\d{8}$/
+const telLegal = computed(() => chinaMobileRegex.test(tel.value))
+// 重复密码的规则
+const isPasswordIdentical = computed(() => password.value == confirmPassword.value)
+// 注册按钮可用性
 const registerDisabled = computed(() => {
-  return !(telLegal.value && hasPasswordInput.value && isPasswordIdentical.value && hasAddressInput.value && hasIdentityChosen.value)
-});
+  return !(hasTelInput.value && hasPasswordInput.value && hasConfirmPasswordInput && hasAddressInput.value &&
+      hasIdentityChosen.value && telLegal.value && isPasswordIdentical.value)
+})
 
-async function handleRegister() {
+// 注册按钮触发
+function handleRegister() {
   const payload = {
     role: identity.value,
     name: name.value,
@@ -35,42 +43,26 @@ async function handleRegister() {
     createTime: new Date().getTime()
   }
 
-  userRegister(payload)
-      .then(() => {
-        ElMessageBox.alert(
-            `${name.value},感谢您的注册!`,
-            '注册成功',
-            {
-              confirmButtonText: '跳转到登录',
-              type: "success",
-              showClose: false,
-              roundButton: true,
-              center: true
-            }
-        ).then(() => {
-          // 跳转去登录
-          router.push({path: "/login"})
-        })
+  userRegister(payload).then(res => {
+    if (res.code === '000') {
+      ElMessage({
+        message: "注册成功!请登录账号",
+        type: 'success',
+        center: true,
       })
-      .catch(e => {
-        console.log(e)
-        ElMessageBox.alert(
-            e.message,
-            '错误提示',
-            {
-              confirmButtonText: '好的',
-              type: "error",
-              showClose: false,
-              roundButton: true,
-              center: true
-            }
-        )
+      router.push({path: "/login"})
+    } else if (res.code === '400') {
+      ElMessage({
+        message: res.msg,
+        type: 'error',
+        center: true,
       })
+    }
+  })
 }
-
-
 </script>
 
+
 <template>
   <el-main class="main-frame bgimage">
     <el-card class="login-card">
@@ -129,7 +121,6 @@ async function handleRegister() {
 
             <el-col :span="15">
               <el-form-item>
-
                 <label for="address">
                   地址
                 </label>
@@ -138,7 +129,6 @@ async function handleRegister() {
                           placeholder="请输入地址"/>
               </el-form-item>
             </el-col>
-
           </el-row>
 
           <el-form-item>
@@ -183,11 +173,6 @@ async function handleRegister() {
 
 
 <style scoped>
-
-.bgimage {
-  background-image: url("../../assets/shopping-1s-1084px.svg");
-}
-
 .main-frame {
   width: 100%;
   height: 100%;
@@ -197,6 +182,10 @@ async function handleRegister() {
   justify-content: center;
 }
 
+.bgimage {
+  background-image: url("../../assets/shopping-1s-1084px.svg");
+}
+
 .login-card {
   width: 60%;
   padding: 10px;
@@ -218,5 +207,4 @@ async function handleRegister() {
   align-items: center;
   justify-content: right;
 }
-
 </style>