index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div class="security-setting-container">
  3. <!-- 顶部返回 -->
  4. <div class="page-header">
  5. <el-button link @click="handleBack">
  6. <el-icon><ArrowLeft /></el-icon>
  7. <span>返回</span>
  8. </el-button>
  9. <span class="page-title">安全设置</span>
  10. </div>
  11. <div class="page-content">
  12. <!-- 企业信息头部 -->
  13. <div class="company-header">
  14. <div class="company-logo">
  15. <el-icon :size="30" color="#999"><OfficeBuilding /></el-icon>
  16. </div>
  17. <div class="company-info">
  18. <div class="company-name">{{ companyData.companyName }}</div>
  19. <el-tag type="danger" size="small">{{ companyData.role }}</el-tag>
  20. </div>
  21. </div>
  22. <!-- 登录密码 -->
  23. <div class="setting-card">
  24. <div class="setting-icon">
  25. <el-icon :size="20" color="#fff"><Grid /></el-icon>
  26. </div>
  27. <div class="setting-content">
  28. <div class="setting-title">登录密码</div>
  29. <div class="setting-desc">建议您定期更换密码,设置安全性高的密码可以使帐号更安全</div>
  30. </div>
  31. <el-button type="danger" @click="handleModifyPassword">修改</el-button>
  32. </div>
  33. <!-- 安全手机 -->
  34. <div class="setting-card">
  35. <div class="setting-icon">
  36. <el-icon :size="20" color="#fff"><Grid /></el-icon>
  37. </div>
  38. <div class="setting-content">
  39. <div class="setting-title">安全手机{{ securityData.phone }}</div>
  40. <div class="setting-desc">安全手机可以用于登录帐号,重置密码或其他安全验证</div>
  41. </div>
  42. <el-button type="danger" @click="handleChangePhone">更换</el-button>
  43. </div>
  44. </div>
  45. <!-- 修改密码弹窗 -->
  46. <el-dialog v-model="passwordDialogVisible" title="修改登录密码" width="450px">
  47. <el-form ref="passwordFormRef" :model="passwordForm" :rules="passwordRules" label-width="100px">
  48. <el-form-item label="原密码" prop="oldPassword">
  49. <el-input v-model="passwordForm.oldPassword" type="password" show-password placeholder="请输入原密码" />
  50. </el-form-item>
  51. <el-form-item label="新密码" prop="newPassword">
  52. <el-input v-model="passwordForm.newPassword" type="password" show-password placeholder="请输入新密码" />
  53. </el-form-item>
  54. <el-form-item label="确认密码" prop="confirmPassword">
  55. <el-input v-model="passwordForm.confirmPassword" type="password" show-password placeholder="请再次输入新密码" />
  56. </el-form-item>
  57. </el-form>
  58. <template #footer>
  59. <el-button @click="passwordDialogVisible = false">取消</el-button>
  60. <el-button type="danger" @click="handleSavePassword">确定</el-button>
  61. </template>
  62. </el-dialog>
  63. <!-- 修改手机弹窗 -->
  64. <el-dialog v-model="phoneDialogVisible" title="修改安全手机" width="450px">
  65. <el-form ref="phoneFormRef" :model="phoneForm" :rules="phoneRules" label-width="100px">
  66. <el-form-item label="新手机号" prop="phone">
  67. <el-input v-model="phoneForm.phone" placeholder="请输入新手机号" />
  68. </el-form-item>
  69. <el-form-item label="验证码" prop="code">
  70. <div class="code-input">
  71. <el-input v-model="phoneForm.code" placeholder="请输入验证码" />
  72. <el-button type="danger" :disabled="countdown > 0" @click="handleSendCode">
  73. {{ countdown > 0 ? `${countdown}s后重发` : '获取验证码' }}
  74. </el-button>
  75. </div>
  76. </el-form-item>
  77. </el-form>
  78. <template #footer>
  79. <el-button @click="phoneDialogVisible = false">取消</el-button>
  80. <el-button type="danger" @click="handleSavePhone">确定</el-button>
  81. </template>
  82. </el-dialog>
  83. </div>
  84. </template>
  85. <script setup lang="ts">
  86. import { ref, reactive } from 'vue'
  87. import { useRouter } from 'vue-router'
  88. import { ArrowLeft, OfficeBuilding, Grid } from '@element-plus/icons-vue'
  89. import { ElMessage } from 'element-plus'
  90. const router = useRouter()
  91. const companyData = reactive({ companyName: '中国南方电网', role: '采购负责人' })
  92. const securityData = reactive({ phone: '180****7722' })
  93. const passwordDialogVisible = ref(false)
  94. const passwordFormRef = ref()
  95. const passwordForm = reactive({ oldPassword: '', newPassword: '', confirmPassword: '' })
  96. const validateConfirmPassword = (_rule: any, value: string, callback: any) => {
  97. if (value !== passwordForm.newPassword) {
  98. callback(new Error('两次输入的密码不一致'))
  99. } else {
  100. callback()
  101. }
  102. }
  103. const passwordRules = {
  104. oldPassword: [{ required: true, message: '请输入原密码', trigger: 'blur' }],
  105. newPassword: [{ required: true, message: '请输入新密码', trigger: 'blur' }, { min: 6, max: 20, message: '密码长度为6-20位', trigger: 'blur' }],
  106. confirmPassword: [{ required: true, message: '请再次输入新密码', trigger: 'blur' }, { validator: validateConfirmPassword, trigger: 'blur' }]
  107. }
  108. const phoneDialogVisible = ref(false)
  109. const phoneFormRef = ref()
  110. const phoneForm = reactive({ phone: '', code: '' })
  111. const countdown = ref(0)
  112. const phoneRules = {
  113. phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }, { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }],
  114. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  115. }
  116. const handleBack = () => { router.push('/enterprise/companyInfo') }
  117. const handleModifyPassword = () => { router.push('/enterprise/securitySetting/resetPassword') }
  118. const handleSavePassword = async () => { const valid = await passwordFormRef.value?.validate(); if (!valid) return; ElMessage.success('密码修改成功'); passwordDialogVisible.value = false }
  119. const handleChangePhone = () => { router.push('/enterprise/securitySetting/changePhone') }
  120. const handleSendCode = () => { if (!phoneForm.phone) { ElMessage.warning('请先输入手机号'); return }; countdown.value = 60; const timer = setInterval(() => { countdown.value--; if (countdown.value <= 0) clearInterval(timer) }, 1000); ElMessage.success('验证码已发送') }
  121. const handleSavePhone = async () => { const valid = await phoneFormRef.value?.validate(); if (!valid) return; ElMessage.success('手机号修改成功'); phoneDialogVisible.value = false }
  122. </script>
  123. <style scoped lang="scss">
  124. .security-setting-container { background: #f5f5f5; min-height: 100%; }
  125. .page-header { background: #fff; padding: 15px 20px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #eee; .page-title { font-size: 16px; font-weight: bold; color: #333; } }
  126. .page-content { padding: 20px; }
  127. .company-header { display: flex; align-items: center; gap: 15px; padding: 20px; background: #fff; border-radius: 8px; margin-bottom: 15px; .company-logo { width: 50px; height: 50px; border-radius: 8px; background: #f5f5f5; display: flex; align-items: center; justify-content: center; border: 1px solid #eee; } .company-info { .company-name { font-size: 16px; font-weight: bold; color: #333; margin-bottom: 5px; } } }
  128. .setting-card { display: flex; align-items: center; gap: 15px; padding: 20px; background: #fff; border-radius: 8px; margin-bottom: 15px; .setting-icon { width: 40px; height: 40px; border-radius: 8px; background: #e60012; display: flex; align-items: center; justify-content: center; } .setting-content { flex: 1; .setting-title { font-size: 15px; font-weight: 500; color: #333; margin-bottom: 5px; } .setting-desc { font-size: 13px; color: #999; } } }
  129. .code-input { display: flex; gap: 10px; .el-input { flex: 1; } }
  130. </style>