info.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <template>
  2. <hc-sys class="hc-my-info-page" :isNavBar="false">
  3. <uni-section title="基础信息" type="line" style="margin-top: 1px">
  4. <uni-list class="hc-my-info-list">
  5. <uni-list-item title="用户名称" :rightText="userInfo.realName" />
  6. <uni-list-item title="身份证号" :rightText="userInfo.idNumber" />
  7. <uni-list-item title="所属角色" :rightText="userInfo.roleName" />
  8. <uni-list-item title="登录账号" :rightText="userInfo.account" />
  9. <uni-list-item title="绑定手机" :rightText="userInfo.phone" />
  10. <uni-list-item title="所属部门" :rightText="userInfo.deptId" />
  11. </uni-list>
  12. </uni-section>
  13. <uni-section class="mt-1" title="CA签字体" type="line">
  14. <view class="px-3">
  15. <img class="h-180 max-w-full" :src="userInfo.signatureUrl" alt="" v-if="userInfo.signatureUrl">
  16. <text class="py-2 text-gray" v-else>无CA签字体</text>
  17. </view>
  18. </uni-section>
  19. <uni-collapse class="mt-3 mb-5">
  20. <uni-collapse-item title="修改密码">
  21. <view class="px-5 py-2">
  22. <uni-forms ref="formRef" :rules="formRules" :modelValue="formData" label-width="100" label-position="top">
  23. <uni-forms-item label="原始密码" required name="old">
  24. <uni-easyinput type="password" v-model="formData.old" placeholder="请输入原始密码" />
  25. </uni-forms-item>
  26. <uni-forms-item label="新的密码" required name="new1">
  27. <uni-easyinput type="password" v-model="formData.new1" placeholder="请输入新的密码" />
  28. </uni-forms-item>
  29. <uni-forms-item label="确认新密码" required name="new2">
  30. <uni-easyinput type="password" v-model="formData.new2" placeholder="请输入确认新密码" />
  31. </uni-forms-item>
  32. </uni-forms>
  33. <view class="form-btn-bar mb-2">
  34. <button type="primary" @click="submitPassword">确认修改</button>
  35. </view>
  36. </view>
  37. </uni-collapse-item>
  38. </uni-collapse>
  39. </hc-sys>
  40. </template>
  41. <script setup>
  42. import {ref} from "vue";
  43. import {onLoad} from '@dcloudio/uni-app'
  44. import {errorToast, formValidate, successToast} from "@/utils/tools";
  45. import mainApi from '~api/user/index';
  46. import {getObjValue} from "js-fast-way";
  47. import md5 from 'js-md5'
  48. //初始变量
  49. const formRef = ref(null)
  50. const userInfo = ref({});
  51. //渲染完成
  52. onLoad(() => {
  53. getUserData()
  54. formRef.value?.setRules(formRules.value)
  55. })
  56. //获取用户信息
  57. const getUserData = async () => {
  58. const {data} = await mainApi.queryCurrentUserData()
  59. userInfo.value = getObjValue(data)
  60. }
  61. //密码表单
  62. const formData = ref({
  63. old: '', new1: '', new2: ''
  64. })
  65. const formRules = ref({
  66. old: {
  67. rules: [{
  68. required: true,
  69. errorMessage: '原始密码不能为空'
  70. }]
  71. },
  72. new1: {
  73. rules: [
  74. {
  75. required: true,
  76. errorMessage: '新的密码不能为空'
  77. },
  78. {
  79. validateFunction: function(rule, value, data, callback) {
  80. if (value !== data.new2) {
  81. callback('两次输入的密码不一致')
  82. }
  83. return true
  84. }
  85. }
  86. ]
  87. },
  88. new2: {
  89. rules: [
  90. {
  91. required: true,
  92. errorMessage: '确认密码不能为空'
  93. },
  94. {
  95. validateFunction: function(rule, value, data, callback) {
  96. if (value !== data.new1) {
  97. callback('两次输入的密码不一致')
  98. }
  99. return true
  100. }
  101. }
  102. ]
  103. }
  104. })
  105. //确认修改密码
  106. const submitPassword = async () => {
  107. const res = await formValidate(formRef.value)
  108. if (!res) return
  109. uni.showLoading({title: '修改密码中...', mask: true});
  110. const {old, new1, new2} = formData.value
  111. const { error, code, msg } = await mainApi.updatePassword({
  112. oldPassword: md5(old),
  113. newPassword: md5(new1),
  114. newPassword1: md5(new2),
  115. plaintextPassword: new1,
  116. })
  117. uni.hideLoading();
  118. if (!error && code === 200) {
  119. formData.value = {}
  120. successToast('密码修改成功')
  121. } else {
  122. errorToast('修改失败:' + msg)
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. page {
  128. background: #EFEFF4;
  129. }
  130. </style>
  131. <style lang="scss">
  132. @import "@/style/my/info.scss";
  133. </style>