index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="pwd-retrieve-container">
  3. <uni-forms ref="form" :value="user" labelWidth="80px">
  4. <uni-forms-item name="oldPassword" :label="i18('旧密码')">
  5. <uni-easyinput type="password" v-model="user.oldPassword" :placeholder="i18('请输入旧密码')" />
  6. </uni-forms-item>
  7. <uni-forms-item name="newPassword" :label="i18('新密码')">
  8. <uni-easyinput type="password" v-model="user.newPassword" :placeholder="i18('请输入新密码')" />
  9. </uni-forms-item>
  10. <uni-forms-item name="confirmPassword" :label="i18('确认密码')">
  11. <uni-easyinput type="password" v-model="user.confirmPassword" :placeholder="i18('请确认新密码')" />
  12. </uni-forms-item>
  13. <button type="primary" style="background: #0E9F9B;color: white" @click="submit">{{i18('提交')}}</button>
  14. <view style="bottom: 80px;position: absolute;left: 10px;right:10px">
  15. <button type="warn" @click="" style="background: #0E9F9B;color: white" @click="deleteUser">{{i18('注销账号')}}</button>
  16. </view>
  17. <view style="bottom: 10px;position: absolute;left: 10px;right:10px">
  18. <button type="warn" @click="" style="background: #0E9F9B;color: white" @click="handleLogout">{{i18('退出登录')}}</button>
  19. </view>
  20. </uni-forms>
  21. </view>
  22. </template>
  23. <script>
  24. import { updateUserPwd } from "@/api/system/user"
  25. import i18 from '@/utils/i18.js'
  26. export default {
  27. data() {
  28. return {
  29. user: {
  30. oldPassword: undefined,
  31. newPassword: undefined,
  32. confirmPassword: undefined
  33. },
  34. rules: {
  35. oldPassword: {
  36. rules: [{
  37. required: true,
  38. errorMessage: i18('旧密码不能为空')
  39. }]
  40. },
  41. newPassword: {
  42. rules: [{
  43. required: true,
  44. errorMessage: i18('新密码不能为空'),
  45. },
  46. {
  47. minLength: 6,
  48. maxLength: 20,
  49. errorMessage: i18('长度在 6 到 20 个字符')
  50. }
  51. ]
  52. },
  53. confirmPassword: {
  54. rules: [{
  55. required: true,
  56. errorMessage: i18('确认密码不能为空')
  57. }, {
  58. validateFunction: (rule, value, data) => data.newPassword === value,
  59. errorMessage: i18('两次输入的密码不一致')
  60. }
  61. ]
  62. }
  63. }
  64. }
  65. },
  66. onReady() {
  67. this.$refs.form.setRules(this.rules)
  68. },
  69. onShow(){
  70. uni.setNavigationBarTitle({
  71. title: this.$t('page.modifypwd')
  72. })
  73. },
  74. methods: {
  75. i18(text){
  76. return i18(text)
  77. },
  78. submit() {
  79. this.$refs.form.validate().then(res => {
  80. updateUserPwd(this.user.oldPassword, this.user.newPassword).then(response => {
  81. this.$modal.msgSuccess("修改成功")
  82. })
  83. })
  84. },
  85. handleLogout() {
  86. this.$modal.confirm('确定注销并退出系统吗?').then(() => {
  87. this.$store.dispatch('LogOut').then(() => {
  88. this.$tab.reLaunch('/pages/index')
  89. })
  90. })
  91. },
  92. deleteUser() {
  93. this.$modal.confirm('确定删除账号吗?').then(() => {
  94. this.$store.dispatch('DeleteUser').then(() => {
  95. this.$tab.reLaunch('/pages/index')
  96. })
  97. })
  98. }
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. page {
  104. background-color: #ffffff;
  105. }
  106. .pwd-retrieve-container {
  107. padding-top: 36rpx;
  108. padding: 15px;
  109. }
  110. </style>