Bladeren bron

调整接入页面逻辑

yangguanjin 1 week geleden
bovenliggende
commit
6c9c5817e9
3 gewijzigde bestanden met toevoegingen van 96 en 49 verwijderingen
  1. 18 0
      index.html
  2. 1 1
      src/api/login.ts
  3. 77 48
      src/pages/loading/index.vue

+ 18 - 0
index.html

@@ -21,6 +21,24 @@
 
   <body>
     <div id="app"><!--app-html--></div>
+    <script>
+      window.loadingLogin = function (params) {
+         if(!window.loginAppToken){
+           if (!window._loadingLoginTimer) {
+             window._loadingLoginTimer = setTimeout(() => {
+               window._loadingLoginTimer = null;
+               window.loadingLogin(params);
+             }, 500);
+           }
+         } else{
+           if (window._loadingLoginTimer) {
+             clearTimeout(window._loadingLoginTimer);
+             window._loadingLoginTimer = null;
+           }
+           window.loginAppToken(params);
+         }
+      }
+    </script>
     <script type="module" src="/src/main.ts"></script>
   </body>
 </html>

+ 1 - 1
src/api/login.ts

@@ -7,7 +7,7 @@ export const handleLogin = (data: { username: string; password: string }) => {
 }
 
 // 通过AppToken登录
-export const loginByAppToken = (data: { appToken: string }) => {
+export const loginByAppToken = (data: any) => {
   return httpPost('/system/auth/loginByAppToken', data)
 }
 

+ 77 - 48
src/pages/loading/index.vue

@@ -17,26 +17,27 @@
     </view>
   </view>
 
-  <!-- WEB模式:输入框界面 -->
+  <!-- WEB模式:确认界面 -->
   <view v-else class="form-container">
     <view class="status-bar-placeholder" :style="{ height: statusBarHeight + 'px' }" />
     <view class="form-content">
-      <text class="form-title">请输入登录信息</text>
+      <text class="form-title">确认登录信息</text>
       <view class="input-group">
-        <text class="input-label">用户ID</text>
+        <text class="input-label">用户信息</text>
         <input
           class="form-input"
-          v-model="inputUserId"
-          placeholder="请输入用户ID"
+          v-model="inputUserInfo"
+          placeholder="请输入用户信息JSON"
           placeholder-style="color: #bbb"
         />
       </view>
       <view class="input-group">
-        <text class="input-label">用户名</text>
+        <text class="input-label">密码</text>
         <input
           class="form-input"
-          v-model="inputUsername"
-          placeholder="请输入用户名"
+          v-model="inputPassword"
+          type="password"
+          placeholder="请输入密码"
           placeholder-style="color: #bbb"
         />
       </view>
@@ -57,17 +58,27 @@ defineOptions({
   name: 'loading',
 })
 
+interface PayloadData {
+  token?: string
+  userId?: string
+  username?: string
+  [key: string]: any
+}
+
 const statusText = ref('正在加载...')
 const fromType = ref('APP')
 
+// 解析后的payload
+const payload = ref<PayloadData>({})
+
 // WEB模式表单
-const inputUserId = ref('')
-const inputUsername = ref('')
+const inputUserInfo = ref('')
+const inputPassword = ref('')
 
-// URL参数(APP模式用)
-const urlToken = ref('')
-const urlUserId = ref('')
-const urlUsername = ref('')
+const loginAppToken = (params: { token: string; userId: string; username: string }) => {
+  doLogin(params.token, params.userId, params.username, '', 'APP')
+}
+window.loginAppToken = loginAppToken
 
 // 状态栏高度
 const statusBarHeight = ref(20)
@@ -76,51 +87,73 @@ statusBarHeight.value = systemInfo.statusBarHeight || 20
 
 const userStore = useUserStore()
 
-onLoad((options) => {
+onLoad((options: any) => {
   fromType.value = options?.from || 'WEB'
-  urlToken.value = options?.token || ''
-  urlUserId.value = options?.userId || ''
-  urlUsername.value = options?.username || ''
-
-  // WEB模式:预填URL参数到表单
-  if (fromType.value !== 'APP') {
-    inputUserId.value = urlUserId.value
-    inputUsername.value = urlUsername.value
-  }
-
-  // APP模式:直接登录
-  if (fromType.value === 'APP') {
-    if (!urlToken.value) {
-      statusText.value = '缺少token参数'
-      return
-    }
-    doLogin(urlToken.value)
-  }
 })
 
 // WEB模式:点击继续
 const handleWebSubmit = () => {
-  if (!inputUserId.value.trim()) {
-    statusText.value = '请输入用户ID'
+  if (!inputUserInfo.value.trim()) {
+    statusText.value = '请输入用户信息'
+    uni.showToast({ title: statusText.value, icon: 'none' })
     return
   }
-  if (!inputUsername.value.trim()) {
-    statusText.value = '请输入用户名'
+  let userInfo: any
+  try {
+    console.log('inputUserInfo.value.trim()', inputUserInfo.value.trim())
+    userInfo = JSON.parse(inputUserInfo.value.trim())
+  } catch {
+    statusText.value = '用户信息JSON格式错误'
+    uni.showToast({ title: statusText.value, icon: 'none' })
+    return
+  }
+  const userId = userInfo.userId || userInfo.user_id || ''
+  const username = userInfo.username || userInfo.user_name || ''
+  if (!userId) {
+    statusText.value = '用户信息中缺少userId'
+    uni.showToast({ title: statusText.value, icon: 'none' })
+    return
+  }
+  if (!inputPassword.value.trim()) {
+    statusText.value = '请输入密码'
+    uni.showToast({ title: statusText.value, icon: 'none' })
     return
   }
   statusText.value = ''
-  doLogin(urlToken.value, inputUserId.value.trim(), inputUsername.value.trim())
+  doLogin(
+    payload.value.token || '',
+    userId,
+    username,
+    inputPassword.value.trim(),
+    'WEB',
+  )
 }
 
 // appToken登录
-const doLogin = async (appToken: string, extraUserId?: string, extraUsername?: string) => {
+const doLogin = async (
+  appToken: string,
+  extraUserId?: string,
+  extraUsername?: string,
+  password?: string,
+  mode?: 'APP' | 'WEB',
+) => {
   try {
+    if (fromType.value !== 'APP') {
+      uni.showLoading({ title: '加载中...', mask: true })
+    }
     statusText.value = '正在加载...'
-    const loginRes: any = await loginByAppToken({ appToken })
+    const loginRes: any = await loginByAppToken({
+      appToken,
+      userId: extraUserId,
+      username: extraUsername,
+      password: password,
+      mode: mode,
+    })
     const loginData = loginRes?.data
 
     if (!loginRes || loginRes.code !== 0 || !loginData) {
       statusText.value = '加载失败: ' + (loginRes?.msg || '未知错误')
+      uni.showToast({ title: statusText.value, icon: 'none' })
       return
     }
 
@@ -144,6 +177,10 @@ const doLogin = async (appToken: string, extraUserId?: string, extraUsername?: s
   } catch (error) {
     console.error('[LoadingPage] 加载失败:', error)
     statusText.value = '加载失败,请重试'
+  } finally {
+    if (fromType.value !== 'APP') {
+      uni.hideLoading()
+    }
   }
 }
 
@@ -220,7 +257,6 @@ const fetchDeptMembers = async (deptId: string) => {
   color: #333;
 }
 
-// WEB模式表单样式
 .form-container {
   min-height: 100vh;
   background-color: #fff;
@@ -275,11 +311,4 @@ const fetchDeptMembers = async (deptId: string) => {
   font-size: 16px;
   color: #fff;
 }
-
-.error-text {
-  margin-top: 12px;
-  font-size: 14px;
-  color: #ff4d4f;
-  text-align: center;
-}
 </style>