index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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: [
  106. { required: true, message: '请输入新密码', trigger: 'blur' },
  107. { min: 6, max: 20, message: '密码长度为6-20位', trigger: 'blur' }
  108. ],
  109. confirmPassword: [
  110. { required: true, message: '请再次输入新密码', trigger: 'blur' },
  111. { validator: validateConfirmPassword, trigger: 'blur' }
  112. ]
  113. };
  114. const phoneDialogVisible = ref(false);
  115. const phoneFormRef = ref();
  116. const phoneForm = reactive({ phone: '', code: '' });
  117. const countdown = ref(0);
  118. const phoneRules = {
  119. phone: [
  120. { required: true, message: '请输入手机号', trigger: 'blur' },
  121. { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
  122. ],
  123. code: [{ required: true, message: '请输入验证码', trigger: 'blur' }]
  124. };
  125. const handleBack = () => {
  126. router.push('/enterprise/companyInfo');
  127. };
  128. const handleModifyPassword = () => {
  129. router.push('/enterprise/securitySetting/resetPassword');
  130. };
  131. const handleSavePassword = async () => {
  132. const valid = await passwordFormRef.value?.validate();
  133. if (!valid) return;
  134. ElMessage.success('密码修改成功');
  135. passwordDialogVisible.value = false;
  136. };
  137. const handleChangePhone = () => {
  138. router.push('/enterprise/securitySetting/changePhone');
  139. };
  140. const handleSendCode = () => {
  141. if (!phoneForm.phone) {
  142. ElMessage.warning('请先输入手机号');
  143. return;
  144. }
  145. countdown.value = 60;
  146. const timer = setInterval(() => {
  147. countdown.value--;
  148. if (countdown.value <= 0) clearInterval(timer);
  149. }, 1000);
  150. ElMessage.success('验证码已发送');
  151. };
  152. const handleSavePhone = async () => {
  153. const valid = await phoneFormRef.value?.validate();
  154. if (!valid) return;
  155. ElMessage.success('手机号修改成功');
  156. phoneDialogVisible.value = false;
  157. };
  158. </script>
  159. <style scoped lang="scss">
  160. .security-setting-container {
  161. background: #f5f5f5;
  162. min-height: 100%;
  163. width: 1200px;
  164. margin: 0 auto;
  165. }
  166. .page-header {
  167. background: #fff;
  168. padding: 15px 20px;
  169. display: flex;
  170. align-items: center;
  171. gap: 10px;
  172. border-bottom: 1px solid #eee;
  173. .page-title {
  174. font-size: 16px;
  175. font-weight: bold;
  176. color: #333;
  177. }
  178. }
  179. .page-content {
  180. padding: 20px;
  181. }
  182. .company-header {
  183. display: flex;
  184. align-items: center;
  185. gap: 15px;
  186. padding: 20px;
  187. background: #fff;
  188. border-radius: 8px;
  189. margin-bottom: 15px;
  190. .company-logo {
  191. width: 50px;
  192. height: 50px;
  193. border-radius: 8px;
  194. background: #f5f5f5;
  195. display: flex;
  196. align-items: center;
  197. justify-content: center;
  198. border: 1px solid #eee;
  199. }
  200. .company-info {
  201. .company-name {
  202. font-size: 16px;
  203. font-weight: bold;
  204. color: #333;
  205. margin-bottom: 5px;
  206. }
  207. }
  208. }
  209. .setting-card {
  210. display: flex;
  211. align-items: center;
  212. gap: 15px;
  213. padding: 20px;
  214. background: #fff;
  215. border-radius: 8px;
  216. margin-bottom: 15px;
  217. .setting-icon {
  218. width: 40px;
  219. height: 40px;
  220. border-radius: 8px;
  221. background: #e60012;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. }
  226. .setting-content {
  227. flex: 1;
  228. .setting-title {
  229. font-size: 15px;
  230. font-weight: 500;
  231. color: #333;
  232. margin-bottom: 5px;
  233. }
  234. .setting-desc {
  235. font-size: 13px;
  236. color: #999;
  237. }
  238. }
  239. }
  240. .code-input {
  241. display: flex;
  242. gap: 10px;
  243. .el-input {
  244. flex: 1;
  245. }
  246. }
  247. </style>