userInfo.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="agent_page">
  3. <div class="top">个人信息</div>
  4. <div class="content adffc">
  5. <div class="title">我的账户</div>
  6. <div class="box adfac">
  7. <div class="left">{{ firstWord }}</div>
  8. <div class="right">
  9. <p>{{ $store.state.user.realName }}</p>
  10. <p>{{ $store.state.user.mobile }}</p>
  11. </div>
  12. </div>
  13. <div class="item">
  14. <div class="i_title">用户名</div>
  15. <div class="i_text">{{ $store.state.user.realName }}</div>
  16. </div>
  17. <div class="item">
  18. <div class="i_title">手机号码</div>
  19. <div class="i_text">{{ $store.state.user.mobile }}</div>
  20. </div>
  21. <div class="pwd adfacjb">
  22. <div class="p_l">
  23. <p>密码</p>
  24. <p>当前为初始密码,安全性较低,您可以重置密码</p>
  25. </div>
  26. <div class="p_r adfac">
  27. <el-button type="primary" @click="resetPwd">重置密码</el-button>
  28. <el-button type="primary" @click="logout" style="margin-left: 10px;">退出登录</el-button>
  29. </div>
  30. </div>
  31. </div>
  32. <el-dialog width="484px" :visible.sync="show" title="重置密码" @close="cancel">
  33. <el-form :model="form" :rules="rules" ref="pwdRef" label-width="100px" style="margin: 0 25px;">
  34. <el-form-item label="原密码" prop="password">
  35. <el-input v-model="form.password" clearable placeholder="请输入原密码" show-password></el-input>
  36. </el-form-item>
  37. <el-form-item label="新密码" prop="newPassword">
  38. <el-input v-model="form.newPassword" clearable placeholder="请输入新密码" show-password></el-input>
  39. </el-form-item>
  40. <el-form-item label="确认密码" prop="surePassword">
  41. <el-input v-model="form.surePassword" clearable placeholder="请输入确认密码" show-password></el-input>
  42. </el-form-item>
  43. </el-form>
  44. <div class="demo-drawer__footer" style="display: flex;justify-content: end;">
  45. <el-button :loading="buttonLoading" type="primary" @click="submitForm">保 存</el-button>
  46. <el-button @click="cancel" style="margin-right: 5%;">取 消</el-button>
  47. </div>
  48. </el-dialog>
  49. </div>
  50. </template>
  51. <script setup name="">
  52. import { ref, getCurrentInstance, onMounted } from 'vue'
  53. import { updateUserPwd } from '@/api/agent/index.js'
  54. import { clearLoginInfo } from "@/utils";
  55. const { proxy } = getCurrentInstance();
  56. const firstWord = ref('')
  57. const show = ref(false)
  58. const form = ref({
  59. password: '',
  60. newPassword: '',
  61. surePassword: ''
  62. })
  63. const buttonLoading = ref(false)
  64. const pwdRef = ref(null)
  65. const rules = {
  66. password: [
  67. { required: true, message: '请输入原密码', trigger: 'blur' }
  68. ],
  69. newPassword: [
  70. { required: true, message: '请输入新密码', trigger: 'blur' }
  71. ],
  72. surePassword: [
  73. { required: true, message: '请再次确认密码', trigger: 'blur' }
  74. ]
  75. }
  76. const resetPwd = () => {
  77. show.value = true;
  78. }
  79. const submitForm = () => {
  80. proxy.$refs.pwdRef.validate(async (valid) => {
  81. if (valid) {
  82. if(form.value.newPassword !== form.value.surePassword) return proxy.$message.error('两次密码不一致')
  83. await updateUserPwd(form.value).then(res => {
  84. if(res.code!==0) return proxy.$message.error(res.msg);
  85. proxy.$message.success('修改成功,即将退出登录...');
  86. cancel();
  87. setTimeout(() => {
  88. logout();
  89. },1500)
  90. })
  91. } else {
  92. return false;
  93. }
  94. });
  95. }
  96. const cancel = () => {
  97. show.value = false;
  98. form.value = {
  99. password: '',
  100. newPassword: '',
  101. surePassword: ''
  102. }
  103. proxy.$refs.pwdRef.resetFields();
  104. }
  105. const logout = () => {
  106. proxy.$http.post("/logout").then(({ data: res }) => {
  107. if (res.code !== 0) {
  108. localStorage.removeItem();
  109. return proxy.$message.error(res.msg);
  110. }
  111. clearLoginInfo();
  112. proxy.$router.push({ name: "login" });
  113. })
  114. }
  115. onMounted(() => {
  116. firstWord.value = proxy.$store.state.user.realName.substr(0, 1);
  117. })
  118. </script>
  119. <style scoped lang="scss">
  120. .agent_page{
  121. .top{
  122. font-family: PingFang-SC, PingFang-SC;
  123. font-weight: bold;
  124. font-size: 14px;
  125. color: #393939;
  126. line-height: 14px;
  127. padding: 25px 27px;
  128. border-bottom: 1px solid #E5E7EB;
  129. }
  130. .content{
  131. width: 800px;
  132. margin: 0 auto;
  133. .title{
  134. font-family: PingFang-SC, PingFang-SC;
  135. font-weight: bold;
  136. font-size: 24px;
  137. color: #393939;
  138. line-height: 33px;
  139. margin-top: 80px;
  140. }
  141. .box{
  142. margin-top: 14px;
  143. padding: 31px 20px;
  144. background: #F4F4F4;
  145. border-radius: 12px;
  146. .left{
  147. width: 86px;
  148. height: 86px;
  149. background: #33A7A7;
  150. border-radius: 50%;
  151. font-family: PingFang-SC, PingFang-SC;
  152. font-weight: bold;
  153. font-size: 24px;
  154. color: #FFFFFF;
  155. line-height: 86px;
  156. text-align: center;
  157. }
  158. .right{
  159. margin-left: 20px;
  160. p{
  161. font-family: PingFang-SC, PingFang-SC;
  162. font-weight: bold;
  163. font-size: 20px;
  164. color: #252525;
  165. line-height: 28px;
  166. &:last-child{
  167. font-size: 16px;
  168. color: #7A7A7A;
  169. line-height: 22px;
  170. margin-top: 10px;
  171. }
  172. }
  173. }
  174. }
  175. .item{
  176. margin-top: 42px;
  177. .i_title{
  178. font-family: PingFang-SC, PingFang-SC;
  179. font-weight: bold;
  180. font-size: 16px;
  181. color: #252525;
  182. line-height: 22px;
  183. }
  184. .i_text{
  185. width: 100%;
  186. height: 42px;
  187. background: #FFFFFF;
  188. border-radius: 6px;
  189. border: 1px solid #E5E7EB;
  190. padding: 0 16px;
  191. font-family: PingFangSC, PingFang SC;
  192. font-weight: 400;
  193. font-size: 14px;
  194. color: #393939;
  195. line-height: 42px;
  196. margin-top: 13px;
  197. }
  198. }
  199. .pwd{
  200. margin-top: 41px;
  201. .p_l{
  202. p{
  203. font-family: PingFang-SC, PingFang-SC;
  204. font-weight: bold;
  205. font-size: 16px;
  206. color: #252525;
  207. line-height: 22px;
  208. &:last-child{
  209. font-size: 14px;
  210. color: #9D9D9D;
  211. line-height: 20px;
  212. margin-top: 25px;
  213. }
  214. }
  215. }
  216. }
  217. }
  218. }
  219. ::v-deep .el-dialog__title{
  220. font-weight: bold !important;
  221. }
  222. ::v-deep .el-dialog{
  223. margin-top: 25vh !important;
  224. }
  225. </style>