index.vue 3.4 KB

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