吉安感知网项目-前端
shuishen
2026-02-03 89380e6260a75d1d3b94de687ebcc2f50d50659d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
<!-- 登录页 -->
<template>
  <view class="login-form-wrap">
    <div class="imageLogo">  <image src="@/static/images/login/loginLogo.svg" /></div>
    <image class="logo" :src="logoSvg" />
    <div class="title">低空经济服务一体化平台系统</div>
    <div class="user-name">
 
      <input v-model="loginForm.username" placeholder="请输入用户名" />
    </div>
    <div class="pass-word">
      <input
        v-model="loginForm.password"
        :type="showPassword ? 'text' : 'password'"
        placeholder="请输入密码"
      />
      <image :src="showPassword ? openPassword : showPasswordSvg" @click="toggleShowPassword" class="password-toggle-icon" />
    </div>
    <div class="remember-password">
      <label>
        <checkbox-group @change="toggleRemember">
          <checkbox
            :checked="rememberPassword"
            color="#1D6FE9"
            style="transform: scale(0.7)"
          />
        </checkbox-group>
        记住密码
      </label>
      <div class="forgotPassword" @click="goToForgotPassword">忘记密码?</div>
    </div>
 
    <button class="login-btn" :style="[inputStyle]" @tap="submit">登录</button>
  </view>
</template>
 
<script setup>
import { getAssetsImage } from "@/utils/index.js";
import {ticketLoginInterfaceApi} from '@/api/work/index.js'
import md5 from "js-md5";
import { loginByUsername } from "@/api/user/index.js";
import { useUserStore, useLocationStore } from "@/store/index.js";
import locationUtil from "@/utils/location.js";
import websocketService from "@/utils/websocket.js";
 
import { HOME_PATH, LOGIN_PATH, removeQueryString } from "@/router";
 
import logoSvg from "@/static/images/logo.svg";
import showPasswordSvg from "@/static/images/show-password.svg";
import openPassword from "@/static/images/openPassword.svg";
 
const agreed = ref(true);
 
const userStore = useUserStore();
const locationStore = useLocationStore();
const loginForm = ref({
  username: "",
  password: "",
});
const rememberPassword = ref(false);
const showPassword = ref(false);
const inputStyle = computed(() => {
  const style = {};
  if (loginForm.value.username && loginForm.value.password) {
    style.color = "#fff";
    style.backgroundColor = "#1D6FE9";
  }
  return style;
});
let redirect = HOME_PATH;
function toggleRemember(e) {
  rememberPassword.value = e.detail.value.length > 0;
}
 
function toggleShowPassword() {
  showPassword.value = !showPassword.value;
}
 
function goToForgotPassword() {
  uni.navigateTo({
    url: '/subPackages/userDetail/password/index'
  });
}
const loginFormGd = ref({
  username: "zhx",
  password: "123456",
});
async function submit() {
 
  if (!loginForm.value.username.trim()) {
    uni.showToast({
      title: "请输入用户名",
      icon: "none",
      duration: 2000,
    });
    return;
  }
 
  if (!loginForm.value.password.trim()) {
    uni.showToast({
      title: "请输入密码",
      icon: "none",
      duration: 2000,
    });
    return;
  }
  let userInfo = {
    tenantId: "000000",
    deptId: "",
    roleId: "",
    username: loginForm.value.username,
    password: loginForm.value.password,
    type: "account",
    code: "",
    key: "",
  };
 
  if (rememberPassword.value) {
    uni.setStorageSync("rememberedUser", {
      username: loginForm.value.username,
      password: loginForm.value.password,
    });
  } else {
    uni.removeStorageSync("rememberedUser");
  }
 
  try {
    const res = await loginByUsername(
      userInfo.tenantId,
      userInfo.deptId,
      userInfo.roleId,
      userInfo.username,
      // md5(userInfo.password),
      userInfo.password,
      userInfo.type,
      userInfo.key,
      userInfo.code
    );
    userStore.setUserInfo(res.data.data);
    // 请求位置权限并初始化位置服务
    try {
      // 请求位置权限
      const hasPermission = await locationUtil.requestLocationPermission();
      if (hasPermission) {
        console.log('获取位置权限成功');
        // 初始化位置服务
        await locationStore.initLocationService();
      } else {
        console.log('获取位置权限失败');
      }
    } catch (error) {
      console.error('处理位置服务失败:', error);
    }
 
 // 调用工单登录接口
    await gdLogin()
 
    uni.reLaunch({
      url: "/pages/work/index",
    });
  } catch (error) {
    const errorMsg =
      error.data?.msg
        ? error.data.msg
        : (error.data?.error_description && error.data.error_description !== "Bad credentials")
          ? error.data.error_description
          : "登录失败,请重试";
    uni.showToast({
      title: errorMsg,
      icon: "none",
      duration: 2000,
    });
    // 即使原始登录失败,也尝试调用工单登录接口
    await gdLogin();
  }
}
// 工单登录
async function gdLogin() {
  let userInfo = {
    tenantId: "000000",
    deptId: "",
    roleId: "",
    username: loginFormGd.value.username,
    password: loginFormGd.value.password,
    type: "account",
    code: "",
    key: "",
  };
  try {
    const res = await ticketLoginInterfaceApi(
      userInfo.tenantId,
      userInfo.deptId,
      userInfo.roleId,
      userInfo.username,
      md5(userInfo.password),
      userInfo.type,
      userInfo.key,
      userInfo.code
    );
    console.log('工单登录',res)
    // 存储工单token到用户信息中
    if (res.data?.access_token) {
      const currentUserInfo = userStore.$state.userInfo;
      userStore.setUserInfo({
        ...currentUserInfo,
        gd_access_token: res.data.access_token
      });
    }
  } catch (error) {
    const errorMsg =
      error.data?.error_description !== "Bad credentials"
        ? error.data?.error_description
        : "登录失败,请重试";
    console.error('工单登录失败:', errorMsg);
  }
}
// 从本地存储加载记住的密码
onMounted(() => {
  const savedUserInfo = uni.getStorageSync("rememberedUser");
  if (savedUserInfo) {
    loginForm.value.username = savedUserInfo.username;
    loginForm.value.password = savedUserInfo.password;
    rememberPassword.value = true;
  }
});
onLoad((options) => {
  if (options.redirect && removeQueryString(options.redirect) !== LOGIN_PATH) {
    redirect = decodeURIComponent(options.redirect);
  }
});
</script>
 
<style lang="scss" scoped>
.login-form-wrap {
  position: relative;
  text-align: center;
  height: 100%;
  width: 100%;
.imageLogo {
  width: 425rpx;
  height: 316rpx;
  position: absolute;
  right: 0;
  image{
    width: 100%;
    height: 100%;
  }
}
  .logo {
    width: 134rpx;
    height: 134rpx;
    margin: 0 auto;
    margin-top: 286rpx;
    margin-bottom: 16px;
  }
 
  .lowerRightCorner {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 425.61rpx;
    height: 316.46rpx;
  }
 
  .title {
    font-family: "PangMen";
    font-weight: 400;
    font-size: 52rpx;
    line-height: 82rpx;
    letter-spacing: 1px;
    text-shadow: 0px 8rpx 8rpx rgba(0, 0, 0, 0.18);
    text-align: center;
    font-style: normal;
    text-transform: none;
    color: #161B2C;
    text-align: center;
    margin-bottom: 106rpx;
  }
.user-name{
  margin-bottom: 40rpx;
}
  .pass-word{
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  .user-name,
  .pass-word {
    display: flex;
    //justify-content: center;
    align-items: center;
    margin-left: 62rpx;
    margin-right: 58rpx;
    height: 100rpx;
    background: #F1F4F9;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    padding: 0 22rpx;
 
    image {
      width: 40rpx;
      height: 40rpx;
      margin-right: 12rpx;
    }
 
    :deep(uni-input) {
      height: 40rpx;
      line-height: 40rpx;
      width: 80%;
      margin-top: 20rpx;
      padding: 0 !important;
    }
 
    :deep(input) {
      height: 40rpx;
      line-height: 40rpx;
      width: 80%;
      margin-top: 20rpx;
      padding: 0 !important;
      margin: 0 !important;
    }
 
    :deep(.uni-input-placeholder) {
      font-size: 32rpx;
      color: #e3e3e3;
      font-weight: 500;
    }
  }
 
  .remember-password {
    display: flex;
    justify-content:space-between;
    align-items: center;
    margin-left: 62rpx;
    margin-right: 58rpx;
    margin-top: 20rpx;
 
    font-weight: 400;
    font-size: 28rpx;
    color: #86909C;
 
    label {
      display: flex;
      align-items: center;
    }
  }
 
  input {
    @apply pb-6rpx mb-10rpx text-left;
  }
 
  .tips {
    @apply mt-8rpx mb-60rpx;
    color: $u-info;
  }
 
  .login-btn {
    z-index: 1;
    @apply flex items-center justify-center py-12rpx px-0 text-30rpx border-none;
    background: #1d6fe9;
    color: white;
    width: 670rpx;
    height: 76rpx;
    border-radius: 8rpx 8rpx 8rpx 8rpx;
    margin-top: 184rpx;
    font-size: 28rpx;
    font-weight: 400;
    font-family: Source Han Sans CN, Source Han Sans CN;
    &::after {
      @apply border-none;
    }
  }
 
  .wechat-login-btn {
    z-index: 1;
    @apply flex items-center justify-center py-12rpx px-0 text-30rpx border-none;
    background: #07C160;
    color: white;
    width: 590rpx;
    height: 76rpx;
    border-radius: 40rpx 40rpx 40rpx 40rpx;
    margin-top: 30rpx;
 
    &::after {
      @apply border-none;
    }
  }
 
  .alternative {
    @apply flex justify-between mt-30rpx;
    color: $u-tips-color;
  }
}
 
.login-type-wrap {
  @apply flex justify-between pt-350rpx px-150rpx pb-150rpx;
 
  .item {
    @apply flex items-center flex-col text-28rpx;
    color: $u-content-color;
  }
}
 
.hint {
  @apply px-40rpx py-20rpx text-24rpx;
  color: $u-tips-color;
 
  .link {
    color: $u-warning;
  }
}
.forgotPassword {
  font-family: PingFang SC, PingFang SC;
  font-weight: 500;
  font-size: 28rpx;
  color: #4E5969;
}
</style>