chenxiaochao 3 周之前
父节点
当前提交
750bc11142
共有 12 个文件被更改,包括 85 次插入76 次删除
  1. 0 0
      ceshi.txt
  2. 1 1
      env/.env.development
  3. 12 12
      src/App.vue
  4. 1 1
      src/api/auth.ts
  5. 4 4
      src/api/login.ts
  6. 1 1
      src/locale/index.ts
  7. 1 1
      src/pages-fg/login/login.vue
  8. 37 25
      src/pages/index/index.vue
  9. 8 8
      src/pages/me/me.vue
  10. 8 8
      src/store/auth.ts
  11. 12 12
      src/store/token.ts
  12. 0 3
      src/utils/i18n.ts

+ 0 - 0
ceshi.txt


+ 1 - 1
env/.env.development

@@ -6,4 +6,4 @@ VITE_DELETE_CONSOLE = false
6 6
 VITE_SHOW_SOURCEMAP = false
7 7
 
8 8
 # 后台请求地址
9
-VITE_SERVER_BASEURL = 'http://192.168.1.15:8080'
9
+VITE_SERVER_BASEURL = 'http://39.164.159.226:8088'

+ 12 - 12
src/App.vue

@@ -1,42 +1,42 @@
1 1
 <script setup lang="ts">
2 2
 import { onHide, onLaunch, onShow } from '@dcloudio/uni-app'
3 3
 import { navigateToInterceptor } from '@/router/interceptor'
4
-import { useTokenStore } from '@/store/token'
5 4
 import { useAuthStore } from '@/store/auth'
5
+import { useTokenStore } from '@/store/token'
6 6
 
7 7
 onLaunch((options) => {
8 8
   console.log('App.vue onLaunch', options)
9 9
   // 初始化 store
10 10
   const tokenStore = useTokenStore()
11 11
   const authStore = useAuthStore()
12
-  
12
+
13 13
   // 钉钉免登录逻辑
14 14
   async function handleDingTalkAutoLogin() {
15 15
     try {
16 16
       // 检查是否已经有有效的token
17 17
       if (!tokenStore.isTokenExpired.value) {
18
-        console.log('已有有效登录状态,无需重新登录');
19
-        return;
18
+        console.log('已有有效登录状态,无需重新登录')
19
+        return
20 20
       }
21
-      
22
-      console.log('尝试钉钉免登录...');
21
+
22
+      console.log('尝试钉钉免登录...')
23 23
       // 尝试钉钉免登录
24
-      await authStore.authDingTalkLogin();
25
-      console.log('钉钉免登录成功');
24
+      await authStore.authDingTalkLogin()
25
+      console.log('钉钉免登录成功')
26 26
     }
27 27
     catch (error) {
28
-      console.error('钉钉免登录失败,将跳转到登录页面:', error);
28
+      console.error('钉钉免登录失败,将跳转到登录页面:', error)
29 29
       // 免登录失败,跳转到登录页面
30 30
       // 注意:这里不立即跳转,避免影响应用启动性能
31 31
       // 路由拦截器会在页面跳转时处理未登录情况
32 32
     }
33 33
   }
34
-  
34
+
35 35
   // 执行钉钉免登录
36
-  handleDingTalkAutoLogin();
36
+  handleDingTalkAutoLogin()
37 37
 })
38 38
 onShow((options) => {
39
-  console.log('App.vue onShow', options)
39
+  // console.log('App.vue onShow', options)
40 40
   // 处理直接进入页面路由的情况:如h5直接输入路由、微信小程序分享后进入等
41 41
   // https://github.com/unibest-tech/unibest/issues/192
42 42
   if (options?.path) {

+ 1 - 1
src/api/auth.ts

@@ -25,4 +25,4 @@ export function getCaptcha() {
25 25
  */
26 26
 export function login(loginForm: ILoginForm) {
27 27
   return http.post<IAuthLoginRes>('/login', loginForm)
28
-}
28
+}

+ 4 - 4
src/api/login.ts

@@ -94,15 +94,15 @@ export function getDingTalkCode() {
94 94
   return new Promise<{ code: string }>((resolve, reject) => {
95 95
     // #ifdef H5
96 96
     // H5环境下,模拟获取code,实际项目中可能需要通过URL参数或其他方式获取
97
-    console.warn('H5环境下,需要手动传入钉钉code');
98
-    resolve({ code: 'mock-dingtalk-code' });
97
+    console.warn('H5环境下,需要手动传入钉钉code')
98
+    resolve({ code: 'mock-dingtalk-code' })
99 99
     // #endif
100 100
     // #ifdef APP-PLUS
101 101
     // 钉钉小程序环境下,调用钉钉SDK获取code
102 102
     plus.dingtalk.getAuthCode({
103 103
       success: (res: { code: string }) => resolve(res),
104
-      fail: (err: any) => reject(new Error(JSON.stringify(err)))
105
-    });
104
+      fail: (err: any) => reject(new Error(JSON.stringify(err))),
105
+    })
106 106
     // #endif
107 107
   })
108 108
 }

+ 1 - 1
src/locale/index.ts

@@ -37,7 +37,7 @@ export function getTemplateByKey(key: string) {
37 37
 
38 38
   try {
39 39
     const keyList = key.split('.')
40
-    let result = keyList.reduce((pre, cur) => {
40
+    const result = keyList.reduce((pre, cur) => {
41 41
       return pre && typeof pre === 'object' ? pre[cur] : undefined
42 42
     }, message)
43 43
     // 确保返回的是字符串类型

+ 1 - 1
src/pages-fg/login/login.vue

@@ -220,7 +220,7 @@ function validateForm() {
220 220
 
221 221
       <!-- 登录按钮 -->
222 222
       <view class="login-actions">
223
-        <wd-button type="primary" block round :loading="authStore.loginLoading" @click="validateForm">
223
+        <wd-button type="primary" round block :loading="authStore.loginLoading" @click="validateForm">
224 224
           {{ authStore.loginLoading ? '登录中...' : '登录' }}
225 225
         </wd-button>
226 226
       </view>

+ 37 - 25
src/pages/index/index.vue

@@ -30,6 +30,15 @@ interface MenuItem {
30 30
   children?: MenuItem[]
31 31
   /** 图标颜色 */
32 32
   iconColor?: string
33
+  /** 组件路径 */
34
+  component?: string
35
+  /** 元信息 */
36
+  meta?: {
37
+    /** 标题 */
38
+    title?: string
39
+    /** 图标 */
40
+    icon?: string
41
+  }
33 42
 }
34 43
 
35 44
 // 菜单数据
@@ -49,10 +58,14 @@ async function fetchMenuData() {
49 58
     const response = await http<MenuItem[]>({
50 59
       url: '/getRouters',
51 60
       method: 'GET',
61
+      data: {
62
+        source: 1,
63
+      }
52 64
     })
53 65
     menuData.value = response.data
54 66
     console.log('菜单数据:', response)
55 67
   } catch (err) {
68
+
56 69
     console.error('获取菜单失败:', err)
57 70
     // 接口调用失败时使用mock数据
58 71
     // menuData.value = mockMenuData
@@ -76,16 +89,19 @@ function handleMenuItemClick(menu: MenuItem) {
76 89
     url: '/pages/schedule/view/index',
77 90
   })
78 91
   // 根据菜单ID执行相应操作
79
-  // if (menu.url) {
80
-  //   uni.navigateTo({
81
-  //     url: menu.url,
82
-  //   })
83
-  // } else {
84
-  //   uni.showToast({
85
-  //     title: `点击了${menu.meta?.title || menu.name}`,
86
-  //     icon: 'none',
87
-  //   })
88
-  // }
92
+
93
+  if (menu.component) {
94
+    console.log('component:', menu.component)
95
+    uni.navigateTo({
96
+      url: menu.component,
97
+    })
98
+  }
99
+  else {
100
+    uni.showToast({
101
+      title: `点击了${menu.meta?.title || menu.name}`,
102
+      icon: 'none',
103
+    })
104
+  }
89 105
 }
90 106
 onMounted(async () => {
91 107
   // fetchMenuData()
@@ -100,17 +116,16 @@ onLoad(async () => {
100 116
     <!-- 菜单内容 -->
101 117
     <view class="p-2">
102 118
       <block v-if="loading">
103
-        <view class="text-center p-16">
104
-          <wd-loading size="large" type="ring"></wd-loading>
105
-          <text class="text-gray-500 text-sm mt-4 inline-block">加载中...</text>
119
+        <view class="p-16 text-center">
120
+          <wd-loading size="large" type="ring" />
121
+          <text class="mt-4 inline-block text-sm text-gray-500">加载中...</text>
106 122
         </view>
107 123
       </block>
108 124
       <block v-else-if="error">
109
-        <view class="text-center p-16">
110
-          <wd-icon name="info-circle" size="60" color="#909399"></wd-icon>
111
-          <text class="text-gray-500 text-sm mt-4 inline-block">{{
112
-            error
113
-          }}</text>
125
+
126
+        <view class="p-16 text-center">
127
+          <wd-icon name="info-circle" size="60" color="#909399" />
128
+          <text class="mt-4 inline-block text-sm text-gray-500">{{ error }}</text>
114 129
         </view>
115 130
       </block>
116 131
       <block v-else>
@@ -126,16 +141,14 @@ onLoad(async () => {
126 141
             <wd-grid-item
127 142
               v-for="item in group.children"
128 143
               :key="item.id"
129
-              @click="handleMenuItemClick(item)"
130 144
               class="menu-item"
145
+              @click="handleMenuItemClick(item)"
131 146
             >
132 147
               <wd-card
133 148
                 size="small"
134 149
                 :border="false"
135 150
                 class="menu-card"
136
-                :style="{
137
-                  backgroundColor: (item.iconColor || '#4CAF50') + '20',
138
-                }"
151
+                :style="{ backgroundColor: `${item.iconColor || '#4CAF50'}20` }"
139 152
               >
140 153
                 <wd-icon
141 154
                   :name="item.meta?.icon || item.icon"
@@ -143,9 +156,7 @@ onLoad(async () => {
143 156
                   size="30"
144 157
                 />
145 158
               </wd-card>
146
-              <text class="text-xs text-center mt-1">{{
147
-                item.meta?.title || item.name
148
-              }}</text>
159
+              <text class="mt-1 text-center text-xs">{{ item.meta?.title || item.name }}</text>
149 160
             </wd-grid-item>
150 161
           </wd-grid>
151 162
         </wd-card>
@@ -174,3 +185,4 @@ onLoad(async () => {
174 185
   padding: 0;
175 186
 }
176 187
 </style>
188
+

+ 8 - 8
src/pages/me/me.vue

@@ -1,11 +1,9 @@
1 1
 <script lang="ts" setup>
2 2
 import { storeToRefs } from 'pinia'
3
-import { ref } from 'vue'
4 3
 import { LOGIN_PAGE } from '@/router/config'
5 4
 import { useUserStore } from '@/store'
6 5
 import { useTokenStore } from '@/store/token'
7 6
 
8
-
9 7
 definePage({
10 8
   style: {
11 9
     navigationBarTitleText: '我的',
@@ -40,7 +38,7 @@ function getIconText(iconName: string): string {
40 38
     'data-board': '动',
41 39
     'star': '收',
42 40
     'customer-service': '客',
43
-    'setting': '设'
41
+    'setting': '设',
44 42
   }
45 43
   return iconMap[iconName] || iconName.charAt(0)
46 44
 }
@@ -48,7 +46,7 @@ function getIconText(iconName: string): string {
48 46
 function handleFeature(featureName: string) {
49 47
   uni.showToast({
50 48
     title: `点击了${featureName}`,
51
-    icon: 'none'
49
+    icon: 'none',
52 50
   })
53 51
 }
54 52
 
@@ -81,7 +79,7 @@ async function handleLogout() {
81 79
         })
82 80
         // 使用reLaunch清除所有页面栈并跳转到登录页
83 81
         uni.reLaunch({
84
-          url: LOGIN_PAGE
82
+          url: LOGIN_PAGE,
85 83
         })
86 84
       }
87 85
     },
@@ -100,7 +98,9 @@ async function handleLogout() {
100 98
         </view>
101 99
         <!-- 右侧人员信息 -->
102 100
         <view class="user-details">
103
-          <view class="username">{{ userInfo.nickname || '游客' }}</view>
101
+          <view class="username">
102
+            {{ userInfo.nickname || '游客' }}
103
+          </view>
104 104
           <view class="user-meta">
105 105
             <text class="user-role">{{ userInfo.username || '普通用户' }}</text>
106 106
           </view>
@@ -117,13 +117,13 @@ async function handleLogout() {
117 117
         </view>
118 118
         <view class="feature-right">
119 119
           <text v-if="item.badge" class="feature-badge">{{ item.badge }}</text>
120
-          <text v-if="item.dot" class="notification-dot"></text>
120
+          <text v-if="item.dot" class="notification-dot" />
121 121
           <text class="arrow">></text>
122 122
         </view>
123 123
       </view>
124 124
     </view>
125 125
     <!-- 退出登录按钮 -->
126
-    <view class="logout-section px-4 mb-8">
126
+    <view class="logout-section mb-8 px-4">
127 127
       <button v-if="tokenStore.hasLogin" type="primary" class="w-full" @click="handleLogout">
128 128
         退出登录
129 129
       </button>

+ 8 - 8
src/store/auth.ts

@@ -67,24 +67,24 @@ export const useAuthStore = defineStore(
67 67
      */
68 68
     const authDingTalkLogin = async (code?: string) => {
69 69
       try {
70
-        loginLoading.value = true;
71
-        const res = await tokenStore.dingTalkLogin(code);
70
+        loginLoading.value = true
71
+        const res = await tokenStore.dingTalkLogin(code)
72 72
         uni.showToast({
73 73
           title: '登录成功',
74 74
           icon: 'success',
75
-        });
76
-        return res;
75
+        })
76
+        return res
77 77
       }
78 78
       catch (error) {
79
-        console.error('钉钉登录失败:', error);
79
+        console.error('钉钉登录失败:', error)
80 80
         uni.showToast({
81 81
           title: '钉钉登录失败,请重试',
82 82
           icon: 'error',
83
-        });
84
-        throw error;
83
+        })
84
+        throw error
85 85
       }
86 86
       finally {
87
-        loginLoading.value = false;
87
+        loginLoading.value = false
88 88
       }
89 89
     }
90 90
 

+ 12 - 12
src/store/token.ts

@@ -5,13 +5,13 @@ import type { IAuthLoginRes } from '@/api/types/login'
5 5
 import { defineStore } from 'pinia'
6 6
 import { computed, ref } from 'vue' // 修复:导入 computed
7 7
 import {
8
+  dingTalkLogin as _dingTalkLogin,
8 9
   login as _login,
9 10
   logout as _logout,
10 11
   refreshToken as _refreshToken,
11 12
   wxLogin as _wxLogin,
12
-  getWxCode,
13
-  dingTalkLogin as _dingTalkLogin,
14 13
   getDingTalkCode,
14
+  getWxCode,
15 15
 } from '@/api/login'
16 16
 import { isDoubleTokenRes, isSingleTokenRes } from '@/api/types/login'
17 17
 import { useUserStore } from './user'
@@ -192,24 +192,24 @@ export const useTokenStore = defineStore(
192 192
     const dingTalkLogin = async (code?: string) => {
193 193
       try {
194 194
         // 如果没有传入code,则自动获取
195
-        const authCode = code || (await getDingTalkCode()).code;
196
-        console.log('钉钉登录-code: ', authCode);
197
-        const res = await _dingTalkLogin(authCode);
198
-        console.log('钉钉登录-res: ', res);
199
-        await _postLogin(res);
195
+        const authCode = code || (await getDingTalkCode()).code
196
+        console.log('钉钉登录-code: ', authCode)
197
+        const res = await _dingTalkLogin(authCode)
198
+        console.log('钉钉登录-res: ', res)
199
+        await _postLogin(res)
200 200
         uni.showToast({
201 201
           title: '登录成功',
202 202
           icon: 'success',
203
-        });
204
-        return res;
203
+        })
204
+        return res
205 205
       }
206 206
       catch (error) {
207
-        console.error('钉钉登录失败:', error);
207
+        console.error('钉钉登录失败:', error)
208 208
         uni.showToast({
209 209
           title: '钉钉登录失败,请重试',
210 210
           icon: 'error',
211
-        });
212
-        throw error;
211
+        })
212
+        throw error
213 213
       }
214 214
     }
215 215
 

+ 0 - 3
src/utils/i18n.ts

@@ -1,10 +1,7 @@
1
-import { t } from '@/locale/index'
2
-
3 1
 /** 非vue 文件使用 i18n */
4 2
 export function testI18n() {
5 3
   // 下面同样生效
6 4
   uni.showModal({
7 5
     title: 'i18n 测试',
8
-    content: t('i18n.title'),
9 6
   })
10 7
 }