index.vue 12 KB

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