index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <div class="login-container">
  3. <div class="login-card">
  4. <div class="content">
  5. <div class="title">
  6. <h3>Welcome to Camera Management System</h3>
  7. </div>
  8. <el-form
  9. ref="loginFormRef"
  10. :model="loginFormData"
  11. :rules="loginFormRules"
  12. @keyup.enter="handleLogin"
  13. >
  14. <el-form-item prop="name">
  15. <el-input
  16. v-model.trim="loginFormData.name"
  17. placeholder="Account"
  18. :prefix-icon="User"
  19. size="large"
  20. tabindex="1"
  21. type="text"
  22. />
  23. </el-form-item>
  24. <el-form-item prop="password" class="password-form-item">
  25. <el-input
  26. v-model.trim="loginFormData.password"
  27. placeholder="Password"
  28. :prefix-icon="Lock"
  29. show-password
  30. size="large"
  31. tabindex="2"
  32. type="password"
  33. />
  34. <div class="forget-password">
  35. <el-link type="primary" @click="dialogVisible = true" :underline="false">Forgot Password</el-link>
  36. </div>
  37. </el-form-item>
  38. <el-button
  39. :loading="loading"
  40. size="large"
  41. type="primary"
  42. class="login-btn"
  43. @click.prevent="handleLogin"
  44. >
  45. Login
  46. </el-button>
  47. <div class="login-tip">
  48. <span>For initial password, please refer to the manual or contact the administrator.</span>
  49. </div>
  50. </el-form>
  51. </div>
  52. </div>
  53. <!-- 忘记密码对话框 -->
  54. <el-dialog
  55. v-model="dialogVisible"
  56. title="Note"
  57. width="800px"
  58. :close-on-click-modal="false"
  59. :close-on-press-escape="false"
  60. @close="handleDialogClose"
  61. >
  62. <div class="forgot-password-dialog">
  63. <!-- <div class="device-password-title">Device Password</div>-->
  64. <div class="qrcode-container">
  65. <qrcode-vue
  66. :value="devicePassword"
  67. :size="160"
  68. :errorCorrectionLevel="level"
  69. />
  70. <span class="password-text">{{devicePassword}}</span>
  71. </div>
  72. <div class="reset-methods">
  73. <div class="methods-title">How to Reset Password:</div>
  74. <div class="method-item">
  75. <strong>Method 1:</strong> Open PC software spd.exe, enter the obtained device password into the UID input box, click make, and generate a 12-digit super password.
  76. </div>
  77. <div class="method-item">
  78. <strong>Method 2:</strong> Open mobile APP SPD, click "Enable QR code scanning", scan the QR code above to generate a 12-digit super password, or click the "Manual input" button, enter the device password, click confirm, and generate a super password.
  79. </div>
  80. </div>
  81. <div class="password-input-container">
  82. <el-input
  83. v-model="superPassword"
  84. placeholder="Enter Super Password"
  85. size="default"
  86. />
  87. </div>
  88. </div>
  89. <template #footer>
  90. <div class="dialog-footer">
  91. <el-button style="width: 250px" type="primary" @click="handleResetPassword">
  92. Reset to Default Password
  93. </el-button>
  94. </div>
  95. </template>
  96. </el-dialog>
  97. </div>
  98. </template>
  99. <script lang="ts" setup>
  100. import { reactive, ref } from 'vue'
  101. import { useRouter } from 'vue-router'
  102. import { useUserStore } from '@/stores/modules/user'
  103. import { ElMessage, ElDialog, type FormInstance, type FormRules } from 'element-plus'
  104. import { User, Lock } from '@element-plus/icons-vue'
  105. import { type LoginRequestData } from '@/api/types/login'
  106. import { setToken } from '@/utils/cache/cookies'
  107. import { setRouter } from '@/router'
  108. import type { TimeParaData } from '@/api/types/setting'
  109. import { format } from 'date-fns'
  110. import { getCameraDeviceInfo, PutTimePara } from '@/api/setting'
  111. import QrcodeVue from 'qrcode.vue'
  112. import { cameraResetPassword } from '@/api/setting'
  113. const router = useRouter()
  114. const loginFormRef = ref<FormInstance | null>(null)
  115. const loading = ref(false)
  116. const dialogVisible = ref(false)
  117. const loginFormData: LoginRequestData = reactive({
  118. name: '',
  119. password: '',
  120. code: ''
  121. })
  122. const devicePassword = ref('DEVICE_123456')
  123. const superPassword = ref('')
  124. const level = ref('H')
  125. const loginFormRules: FormRules = {
  126. name: [{ required: true, message: 'Please enter your account', trigger: 'blur' }],
  127. password: [
  128. { required: true, message: ' Please enter your password', trigger: 'blur' },
  129. { min: 1, max: 16, message: 'Length must be between 1 and 16 characters', trigger: 'blur' }
  130. ]
  131. }
  132. const handleDialogClose = () => {
  133. dialogVisible.value = false
  134. superPassword.value = ''
  135. }
  136. async function getDeviceInfo(){
  137. const res = await getCameraDeviceInfo()
  138. devicePassword.value = res.data.MacAddr.replace(/:/g, '')
  139. }
  140. onMounted(() => {
  141. getDeviceInfo()
  142. })
  143. function handleResetPassword() {
  144. cameraResetPassword({
  145. ResetPassword: superPassword.value
  146. }).then((res: string) => {
  147. if (res.data === 'ok\n') {
  148. ElMessage.success('Reset Password Successful')
  149. handleDialogClose()
  150. } else {
  151. ElMessage.error('Reset Password Failed!')
  152. }
  153. })
  154. }
  155. const handleLogin = () => {
  156. loginFormRef.value?.validate((valid: boolean, fields) => {
  157. if (valid) {
  158. loading.value = true
  159. useUserStore()
  160. .login(loginFormData)
  161. .then((res: string) => {
  162. if (res == 'ok\n') {
  163. ElMessage.success('Login Successful')
  164. const token = useUserStore().token
  165. setToken(token)
  166. setRouter()
  167. router.push({ path: '/' })
  168. const timeParaData: TimeParaData = {
  169. time: format(new Date(), 'yyyy-MM-dd-HH-mm-ss')
  170. }
  171. PutTimePara(timeParaData)
  172. } else {
  173. ElMessage.error('Incorrect username or password')
  174. }
  175. })
  176. .catch(() => {
  177. loginFormData.password = ''
  178. ElMessage.error('Login Failed')
  179. })
  180. .finally(() => {
  181. loading.value = false
  182. })
  183. } else {
  184. console.error('表单校验不通过', fields)
  185. }
  186. })
  187. }
  188. </script>
  189. <style lang="scss" scoped>
  190. .login-container {
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. height: 100vh;
  195. width: 100vw;
  196. background-color: #f5f7fa;
  197. .title {
  198. text-align: center;
  199. margin-bottom: 30px;
  200. h2 {
  201. color: #333;
  202. font-size: 24px;
  203. font-weight: 600;
  204. margin: 0;
  205. }
  206. }
  207. .login-card {
  208. width: 480px;
  209. border-radius: 12px;
  210. box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  211. background-color: #fff;
  212. overflow: hidden;
  213. transition: box-shadow 0.3s ease;
  214. &:hover {
  215. box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
  216. }
  217. .content {
  218. padding: 40px 50px;
  219. :deep(.el-form-item) {
  220. margin-bottom: 20px;
  221. }
  222. :deep(.el-input-group__append) {
  223. padding: 0;
  224. overflow: hidden;
  225. }
  226. .password-form-item {
  227. position: relative;
  228. margin-bottom: 8px;
  229. .forget-password {
  230. position: absolute;
  231. right: 0;
  232. top: 100%;
  233. padding-top: 1px;
  234. display: flex;
  235. justify-content: flex-end;
  236. :deep(.el-link) {
  237. font-size: 11px;
  238. &:hover {
  239. text-decoration: underline;
  240. }
  241. }
  242. }
  243. }
  244. .login-btn {
  245. width: 100%;
  246. margin-top: 32px;
  247. font-weight: 500;
  248. letter-spacing: 1px;
  249. transition: all 0.3s ease;
  250. &:hover {
  251. transform: translateY(-2px);
  252. box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
  253. }
  254. }
  255. .login-tip {
  256. text-align: center;
  257. font-size: 11px;
  258. margin-top: 16px;
  259. color: #999;
  260. }
  261. }
  262. }
  263. }
  264. /* 忘记密码对话框样式 */
  265. .forgot-password-dialog {
  266. padding: 0;
  267. box-sizing: border-box;
  268. .device-password-title {
  269. font-size: 14px;
  270. color: #666;
  271. margin-bottom: 16px;
  272. text-align: center;
  273. font-weight: 500;
  274. }
  275. .qrcode-container {
  276. display: flex;
  277. flex-direction: column; /* 改为纵向排列 */
  278. align-items: center; /* 居中对齐 */
  279. justify-content: center;
  280. margin-bottom: 28px;
  281. padding: 0 20px;
  282. gap: 10px;
  283. .password-text {
  284. font-size: 14px;
  285. color: #333;
  286. font-weight: 500;
  287. word-break: break-all; // 防止长密码换行问题
  288. text-align: center;
  289. max-width: 160px; // 与二维码同宽
  290. }
  291. }
  292. .reset-methods {
  293. margin-bottom: 28px;
  294. padding: 0 20px;
  295. text-align: left;
  296. .methods-title {
  297. font-size: 13px;
  298. margin-bottom: 12px;
  299. font-weight: 500;
  300. color: #333;
  301. text-align: left;
  302. }
  303. .method-item {
  304. font-size: 12px;
  305. line-height: 1.8;
  306. margin-bottom: 10px;
  307. color: #666;
  308. text-indent: 0;
  309. strong {
  310. color: #333;
  311. font-weight: 600;
  312. }
  313. }
  314. }
  315. .password-input-container {
  316. margin-bottom: 20px;
  317. display: flex;
  318. justify-content: center;
  319. padding: 0 20px;
  320. :deep(.el-input) {
  321. width: 100%;
  322. max-width: 340px;
  323. :deep(.el-input__wrapper) {
  324. box-shadow: none;
  325. border: 1px solid #e5e7eb;
  326. border-radius: 6px;
  327. padding: 0 12px;
  328. height: 40px;
  329. background-color: #fafbfc;
  330. transition: all 0.3s ease;
  331. &:hover {
  332. border-color: #d9d9d9;
  333. background-color: #fff;
  334. }
  335. :deep(.el-input__inner) {
  336. border: none;
  337. padding: 0;
  338. height: 40px;
  339. font-size: 13px;
  340. background-color: transparent;
  341. color: #333;
  342. &::placeholder {
  343. color: #b3b3b3;
  344. }
  345. }
  346. }
  347. :deep(.el-input__inner:focus) {
  348. color: #333;
  349. }
  350. }
  351. }
  352. }
  353. /* 对话框整体样式优化 */
  354. :deep(.el-dialog) {
  355. border-radius: 12px;
  356. overflow: hidden;
  357. box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12);
  358. .el-dialog__wrapper {
  359. backdrop-filter: blur(2px);
  360. }
  361. }
  362. /* 对话框标题样式 */
  363. :deep(.el-dialog__header) {
  364. padding: 9px 15px;
  365. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  366. margin: 0;
  367. border-bottom: none;
  368. margin-left: -20px;
  369. margin-right: -20px;
  370. margin-top: -20px;
  371. width: calc(100% + 40px);
  372. position: relative;
  373. left: -20px;
  374. display: flex;
  375. justify-content: space-between;
  376. align-items: center;
  377. overflow: visible;
  378. .el-dialog__title {
  379. color: white;
  380. font-size: 18px;
  381. font-weight: 600;
  382. flex: 1;
  383. margin: 0 30px;
  384. min-width: 0;
  385. }
  386. .el-dialog__headerbtn {
  387. position: static;
  388. top: auto;
  389. right: auto;
  390. transform: none;
  391. flex-shrink: 0;
  392. margin-left: 10px;
  393. .el-dialog__close {
  394. color: white;
  395. font-size: 25px;
  396. transition: all 0.3s ease;
  397. cursor: pointer;
  398. width: 32px;
  399. height: 32px;
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. &:hover {
  404. opacity: 0.8;
  405. transform: rotate(90deg);
  406. }
  407. }
  408. }
  409. }
  410. /* 对话框关闭按钮 - 关键修复 */
  411. :deep(.el-dialog__close) {
  412. color: white;
  413. font-size: 25px;
  414. cursor: pointer;
  415. transition: all 0.3s ease;
  416. position: relative;
  417. width: auto;
  418. height: auto;
  419. padding: 0px;
  420. border: none;
  421. background: none;
  422. outline: none;
  423. &:hover {
  424. opacity: 0.8;
  425. transform: rotate(90deg);
  426. }
  427. &:focus {
  428. outline: none;
  429. }
  430. }
  431. :deep(.el-dialog__body) {
  432. padding: 24px 0 0;
  433. background-color: #fff;
  434. }
  435. /* 对话框页脚样式 */
  436. :deep(.el-dialog__footer) {
  437. padding: 20px;
  438. background-color: #fff;
  439. text-align: center;
  440. border-top: 1px solid #f0f0f0;
  441. }
  442. /* 重置密码按钮样式 */
  443. :deep(.dialog-footer) {
  444. display: flex;
  445. justify-content: center;
  446. padding: 0;
  447. .el-button {
  448. width: 140px;
  449. height: 40px;
  450. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  451. border: none;
  452. color: white;
  453. font-size: 14px;
  454. font-weight: 500;
  455. border-radius: 6px;
  456. transition: all 0.3s ease;
  457. cursor: pointer;
  458. &:hover {
  459. transform: translateY(-2px);
  460. box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
  461. }
  462. &:active {
  463. transform: translateY(0);
  464. }
  465. }
  466. }
  467. </style>