Explorar el Código

智能柜项目提交

skyline hace 4 meses
padre
commit
8300e6d89f

+ 14 - 1
haha-miniapp/pom.xml

@@ -91,7 +91,20 @@
             <artifactId>sa-token-spring-boot3-starter</artifactId>
             <version>1.39.0</version>
         </dependency>
-        
+
+        <!-- Sa-Token 整合 RedisTemplate -->
+        <dependency>
+            <groupId>cn.dev33</groupId>
+            <artifactId>sa-token-redis-template</artifactId>
+            <version>1.44.0</version>
+        </dependency>
+
+        <!-- 提供 Redis 连接池 -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-pool2</artifactId>
+        </dependency>
+
         <!-- Sa-Token 整合 Redis(使用 jackson 序列化) -->
         <dependency>
             <groupId>cn.dev33</groupId>

+ 15 - 14
haha-miniapp/src/main/resources/application.yml

@@ -10,18 +10,19 @@ spring:
     driver-class-name: com.mysql.cj.jdbc.Driver
   
   # Redis 配置
-  redis:
-    host: server.kuaiyuman.cn
-    port: 6379
-    password: KtXA^Zx!TZmLEy(@JjB@2(TVG0kdy5)&
-    database: 8
-    timeout: 10000
-    lettuce:
-      pool:
-        max-active: 8
-        max-wait: -1
-        max-idle: 8
-        min-idle: 0
+  data:
+    redis:
+      host: server.kuaiyuman.cn
+      port: 6379
+      password: KtXA^Zx!TZmLEy(@JjB@2(TVG0kdy5)&
+      database: 8
+      timeout: 10000
+      lettuce:
+        pool:
+          max-active: 8
+          max-wait: -1
+          max-idle: 8
+          min-idle: 0
   
   # 数据库初始化
   sql:
@@ -78,12 +79,12 @@ haha:
   api:
     app-id: 2601051549145878
     app-secret: 06e1be59332b00de0baad82002cdbcb5
-    base-url: https://api.hahalingshou.com/v1
+    base-url: http://api.hahabianli.com/
 
 # Sa-Token 配置
 sa-token:
   # token 名称(同时也是 cookie 名称)
-  token-name: haha-token-KuaiyuMan
+  token-name: access_token
   # token 有效期(单位:秒)- 7天
   timeout: 604800
   # token 临时有效期(单位:秒)

+ 1 - 1
haha-mp/src/App.vue

@@ -28,7 +28,7 @@ onHide(() => {
  * 如果未登录且当前不在登录页,则跳转到登录页
  */
 const checkLoginStatus = () => {
-  const token = uni.getStorageSync('haha-token-KuaiyuMan');
+  const token = uni.getStorageSync('access_token');
   
   // 获取当前页面路径
   const pages = getCurrentPages();

+ 7 - 1
haha-mp/src/pages/orderDetail/orderDetail.vue

@@ -120,6 +120,7 @@
 <script setup lang="ts">
 import { ref, onMounted } from 'vue';
 import { getOrderDetail, OrderInfo } from '../../api/order';
+import { checkAuth } from '../../utils/auth';
 
 const order = ref<OrderInfo | null>(null);
 const loading = ref(false);
@@ -204,9 +205,14 @@ const loadOrderDetail = async () => {
 };
 
 /**
- * 页面加载时获取订单详情
+ * 页面加载时检查登录状态并获取订单详情
  */
 onMounted(() => {
+  // 检查登录状态
+  if (!checkAuth()) {
+    return;
+  }
+  
   const pages = getCurrentPages();
   const currentPage = pages[pages.length - 1] as any;
   const options = currentPage.options || {};

+ 8 - 1
haha-mp/src/pages/orders/orders.vue

@@ -58,6 +58,7 @@
 <script setup lang="ts">
 import { ref, onMounted } from 'vue';
 import { getOrderList, OrderInfo } from '../../api/order';
+import { checkAuth } from '../../utils/auth';
 
 const orders = ref<OrderInfo[]>([]);
 const loading = ref(false);
@@ -127,9 +128,15 @@ const loadOrders = async () => {
 };
 
 /**
- * 页面加载时获取订单列表
+ * 页面加载时检查登录状态并获取订单列表
  */
 onMounted(() => {
+  // 检查登录状态,未登录会自动跳转到登录页
+  if (!checkAuth('/pages/orders/orders')) {
+    return;
+  }
+  
+  // 已登录,加载订单列表
   loadOrders();
 });
 

+ 10 - 1
haha-mp/src/pages/refund/refund.vue

@@ -46,7 +46,8 @@
 </template>
 
 <script setup lang="ts">
-import { ref } from 'vue';
+import { ref, onMounted } from 'vue';
+import { checkAuth } from '../../utils/auth';
 
 const selectedReason = ref('');
 
@@ -61,6 +62,14 @@ const handleReasonChange = (e: any) => {
   selectedReason.value = e.detail.value;
 };
 
+/**
+ * 页面加载时检查登录状态
+ */
+onMounted(() => {
+  // 检查登录状态,未登录会自动跳转到登录页
+  checkAuth();
+});
+
 const submitRefund = () => {
   if (!selectedReason.value) {
     uni.showToast({

+ 3 - 3
haha-mp/src/utils/auth.ts

@@ -7,21 +7,21 @@
  * 获取本地存储的token
  */
 export const getToken = (): string => {
-  return uni.getStorageSync('haha-token-KuaiyuMan') || '';
+  return uni.getStorageSync('access_token') || '';
 };
 
 /**
  * 保存token到本地存储
  */
 export const setToken = (token: string): void => {
-  uni.setStorageSync('haha-token-KuaiyuMan', token);
+  uni.setStorageSync('access_token', token);
 };
 
 /**
  * 清除本地存储的token
  */
 export const removeToken = (): void => {
-  uni.removeStorageSync('haha-token-KuaiyuMan');
+  uni.removeStorageSync('access_token');
 };
 
 /**

+ 1 - 1
haha-mp/src/utils/request.ts

@@ -41,7 +41,7 @@ export const request = <T = any>(config: RequestConfig): Promise<T> => {
     // 添加token到请求头
     const token = getToken();
     if (token) {
-      header['haha-token-KuaiyuMan'] = token;
+      header['access_token'] = token;
     }
     
     // 添加Content-Type