jiajunchen hace 3 semanas
padre
commit
c9e8cff22d
Se han modificado 2 ficheros con 246 adiciones y 25 borrados
  1. 16
    25
      src/router/index.ts
  2. 230
    0
      src/view/login/Register.vue

+ 16
- 25
src/router/index.ts Ver fichero

@@ -705,7 +705,12 @@ const router = createRouter({
705 705
 			component: () => import('@/view/dati/examCheck/fcbkdatistart.vue')
706 706
 		},
707 707
 
708
-
708
+		{
709
+			path: '/guest-register',
710
+			name: '游客模式(答题)',
711
+			component: () => import('@/view/login/Register.vue'),
712
+			meta: { guestMode: true }
713
+		}
709 714
 	]
710 715
 })
711 716
 function isInWeCom(): boolean {
@@ -714,17 +719,16 @@ function isInWeCom(): boolean {
714 719
 // 路由守卫
715 720
 router.beforeEach(async (to, from, next) => {
716 721
 
717
-	/*
718
-		const requiresWeCom = to.matched.some(record => record.meta.requiresWeCom);
719
-
720
-		if (requiresWeCom && typeof wx === 'undefined') {
721
-			console.warn('该页面需在企业微信内打开');
722
-			// 可以跳转提示页或者 Toast 提示
723
-			return next(false);
722
+	const token1 = localStorage.getItem('token');
723
+	const isWeCom = isInWeCom();
724
+	if (to.path === '/fcbkdatistart') {
725
+		// 如果不在企微中,且没有有效 token,且不是已经在游客页
726
+		if (!isWeCom && (!token1 || !isTokenValid(token1)) && from.path !== '/guest-register') {
727
+			console.log('【游客模式】非企微访问 fcbkdatistart,跳转游客注册');
728
+			return next('/guest-register');
724 729
 		}
725 730
 
726
-		wxReady((requestSignature().data))
727
-	*/
731
+	}
728 732
 	function isTokenValid(token : string) : boolean {
729 733
 		try {
730 734
 			// 检查 token 是否为合法 JWT 格式(3段)
@@ -787,21 +791,8 @@ router.beforeEach(async (to, from, next) => {
787 791
 		return null; // 或者抛出错误,根据你的业务需求
788 792
 	}
789 793
 	console.log(to);
790
-	if (to.path == '/Home1'||to.path=='/yinhuan/todo_detail/index'|| to.path == '/lz-rcd-detail'||to.path == '/emergencyResources'||to.path == '/cardManager/specialWork'||to.path == '/cardManager/equipment'||to.path == '/cardManager/engineer') {
791
-		console.log("++++++判断一下是不是企微或者掌上山钢扫码:"+isInWeCom());
792
-		/*const token = localStorage.getItem('token');
793
-		// 判断是否已经初始化过用户信息
794
-		const hasUserInfo = !!localStorage.getItem('userId');
795
-		if (hasUserInfo) {
796
-			// @ts-ignore
797
-			if (token && isTokenValid(token)) {
798
-				next();
799
-				return;
800
-			}
801
-		}*/
802
-
803
-		// const userId=ref('3E4C4009430211B28E367D90704E23CA')
804
-
794
+	if (to.path == '/Home1'||to.path=='/yinhuan/todo_detail/index'|| to.path == '/lz-rcd-detail'||to.path == '/emergencyResources'||to.path == '/cardManager/specialWork'
795
+		||to.path == '/cardManager/equipment'||to.path == '/cardManager/engineer') {
805 796
 		const userId=ref(import.meta.env.VITE_USER_ID)
806 797
 		console.log(userId.value);
807 798
 		console.log("当前环境:");

+ 230
- 0
src/view/login/Register.vue Ver fichero

@@ -0,0 +1,230 @@
1
+<template>
2
+  <div class="login-container">
3
+    <div class="login-content">
4
+      <div class="login-box">
5
+        <div class="login-header">
6
+          <img src="../../assets/logo.png" alt="logo" class="logo" />
7
+          <h2>请填写您的信息</h2>
8
+          <p class="subtitle">用于记录考试参与情况</p>
9
+        </div>
10
+
11
+        <van-form @submit="onSubmit" class="login-form">
12
+          <van-cell-group inset>
13
+            <van-field
14
+              v-model="formData.userCode"
15
+              name="userCode"
16
+              placeholder="请输入您的工号"
17
+              :rules="[{ required: true, message: '请输入工号' }]"
18
+            >
19
+              <template #left-icon>
20
+                <van-icon name="idcard-o" />
21
+              </template>
22
+            </van-field>
23
+            <van-field
24
+              v-model="formData.userName"
25
+              name="userName"
26
+              placeholder="请输入您的姓名"
27
+              :rules="[{ required: true, message: '请输入姓名' }]"
28
+            >
29
+              <template #left-icon>
30
+                <van-icon name="contact" />
31
+              </template>
32
+            </van-field>
33
+          </van-cell-group>
34
+          <div class="submit-btn">
35
+            <van-button
36
+              round
37
+              block
38
+              type="primary"
39
+              native-type="submit"
40
+              :loading="isLoading"
41
+            >
42
+              确认进入
43
+            </van-button>
44
+          </div>
45
+        </van-form>
46
+      </div>
47
+    </div>
48
+  </div>
49
+</template>
50
+
51
+<script setup lang="ts">
52
+import { ref } from 'vue'
53
+import { useRouter, useRoute } from 'vue-router'
54
+import { showToast } from 'vant'
55
+
56
+const router = useRouter()
57
+const route = useRoute()
58
+const isLoading = ref(false)
59
+
60
+const formData = ref({
61
+  userCode: '',
62
+  userName: ''
63
+})
64
+
65
+async function onSubmit() {
66
+  if (!formData.value.userCode.trim() || !formData.value.userName.trim()) {
67
+    showToast('请完整填写工号和姓名')
68
+    return
69
+  }
70
+
71
+  try {
72
+    isLoading.value = true
73
+
74
+    // 模拟生成一个临时 token 或直接标记为游客
75
+    const tempToken = `guest_${Date.now()}`
76
+
77
+    // 保存游客信息
78
+    localStorage.setItem('token', tempToken)
79
+    localStorage.setItem('userCode', formData.value.userCode.trim())
80
+    localStorage.setItem('userName', formData.value.userName.trim())
81
+    localStorage.setItem('userId', 'guest') // 标记为游客
82
+    localStorage.setItem('guestMode', 'true') // 可选:显式标记游客模式
83
+
84
+    showToast({
85
+      type: 'success',
86
+      message: '信息提交成功'
87
+    })
88
+
89
+    // 跳回原扫码页面(/fcbkdatistart),保留原始 query 参数
90
+    // 注意:route.query 中应包含 examId, testRole 等参数(如果从该页跳转而来)
91
+    // 如果不是从 fcbkdatistart 进来的,可默认跳首页或提示
92
+
93
+    const targetPath = '/sgsafeh5/fcbkdatistart'
94
+    const originalQuery = route.query // 如果是从 fcbkdatistart 跳过来的,query 会保留
95
+
96
+    // 更健壮的方式:检查是否有必要参数,否则跳首页
97
+    if (originalQuery.examId) {
98
+      await router.replace({ path: targetPath, query: originalQuery })
99
+    } else {
100
+
101
+    }
102
+  } catch (error) {
103
+    console.error('游客信息提交失败:', error)
104
+    showToast('提交失败,请重试')
105
+  } finally {
106
+    isLoading.value = false
107
+  }
108
+}
109
+</script>
110
+
111
+<style lang="scss" scoped>
112
+/* 样式保持不变,仅微调标题 */
113
+.login-container {
114
+  height: 100vh;
115
+  width: 100vw;
116
+  display: flex;
117
+  align-items: center;
118
+  justify-content: center;
119
+  background: linear-gradient(135deg, #1890ff 0%, #1d39c4 100%);
120
+  position: relative;
121
+  overflow: hidden;
122
+
123
+  &::before {
124
+    content: '';
125
+    position: absolute;
126
+    width: 200%;
127
+    height: 200%;
128
+    top: -50%;
129
+    left: -50%;
130
+    background: url('@/assets/login-bg.svg') repeat;
131
+    opacity: 0.1;
132
+    animation: move 10s linear infinite;
133
+  }
134
+}
135
+
136
+.login-content {
137
+  position: relative;
138
+  z-index: 1;
139
+  width: 100%;
140
+  padding: 20px;
141
+}
142
+
143
+.login-box {
144
+  width: 100%;
145
+  max-width: 400px;
146
+  margin: 0 auto;
147
+  padding: 30px 24px;
148
+  background: rgba(255, 255, 255, 0.9);
149
+  backdrop-filter: blur(10px);
150
+  border-radius: 16px;
151
+  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
152
+
153
+  .login-header {
154
+    text-align: center;
155
+    margin-bottom: 32px;
156
+
157
+    .logo {
158
+      width: 64px;
159
+      height: 64px;
160
+      margin-bottom: 16px;
161
+    }
162
+
163
+    h2 {
164
+      font-size: 24px;
165
+      color: #1a1a1a;
166
+      margin: 0 0 8px;
167
+      font-weight: 600;
168
+    }
169
+
170
+    .subtitle {
171
+      font-size: 14px;
172
+      color: #666;
173
+      margin: 0;
174
+    }
175
+  }
176
+
177
+  :deep(.van-cell-group) {
178
+    background: transparent;
179
+
180
+    .van-field {
181
+      background: rgba(255, 255, 255, 0.8);
182
+      border-radius: 8px;
183
+      margin-bottom: 16px;
184
+
185
+      &:last-child {
186
+        margin-bottom: 0;
187
+      }
188
+
189
+      .van-field__left-icon {
190
+        margin-right: 8px;
191
+        color: #666;
192
+      }
193
+    }
194
+  }
195
+
196
+  .submit-btn {
197
+    margin-top: 24px;
198
+
199
+    .van-button {
200
+      height: 44px;
201
+      font-size: 16px;
202
+      background: linear-gradient(135deg, #1890ff 0%, #1d39c4 100%);
203
+      border: none;
204
+
205
+      &--loading {
206
+        opacity: 0.8;
207
+      }
208
+    }
209
+  }
210
+}
211
+
212
+@keyframes move {
213
+  0% {
214
+    transform: translate(0, 0);
215
+  }
216
+  100% {
217
+    transform: translate(-50%, -50%);
218
+  }
219
+}
220
+
221
+@media screen and (max-width: 480px) {
222
+  .login-box {
223
+    padding: 24px 16px;
224
+
225
+    .login-header h2 {
226
+      font-size: 20px;
227
+    }
228
+  }
229
+}
230
+</style>

Loading…
Cancelar
Guardar