update.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view class="content">
  3. <view class="one">
  4. <uni-forms ref="valiForm" :rules="rules" :modelValue="form" labelWidth="80px">
  5. <uni-forms-item label="新密码" required name="newpassword">
  6. <uni-easyinput type="password" v-model="form.newpassword" placeholder="请输入新密码" />
  7. </uni-forms-item>
  8. <uni-forms-item label="确认密码" required name="password">
  9. <uni-easyinput type="password" v-model="form.password" placeholder="请输入确认密码" />
  10. </uni-forms-item>
  11. </uni-forms>
  12. <button class="button" type="primary" @click="submit('valiForm')">确认</button>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. form: {},
  21. // 校验规则
  22. rules: {
  23. newpassword: [{
  24. required: true,
  25. errorMessage: '新密码不能为空'
  26. }]
  27. },
  28. password: [{
  29. required: true,
  30. errorMessage: '确认密码不能为空'
  31. }]
  32. }
  33. },
  34. async onLoad() {
  35. const that = this;
  36. await that.searchToken();
  37. },
  38. methods: {
  39. async searchToken() {
  40. const that = this;
  41. uni.getStorage({
  42. key: 'token',
  43. success: function(res) {
  44. that.$set(that, `form`, res.data);
  45. },
  46. fail: function(err) {
  47. uni.showToast({
  48. title: err.errmsg,
  49. icon: 'error',
  50. duration: 2000
  51. });
  52. }
  53. })
  54. },
  55. // 确认修改
  56. submit(ref) {
  57. const that = this;
  58. that.$refs[ref].validate().then(async params => {
  59. if (that.form.newpassword == that.form.password) {
  60. let form = {
  61. _id: that.form._id,
  62. password: that.form.password
  63. }
  64. const res = await that.$api(`/User/rp`, 'POST', form);
  65. if (res.errcode == '0') {
  66. uni.showToast({
  67. title: '修改信息成功',
  68. icon: 'none'
  69. })
  70. that.toExit()
  71. } else {
  72. uni.showToast({
  73. title: res.errmsg,
  74. icon: 'none'
  75. })
  76. }
  77. } else {
  78. uni.showToast({
  79. title: '输入密码不一致 请重新输入',
  80. icon: 'none'
  81. })
  82. }
  83. }).catch(err => {
  84. console.log('err', err);
  85. })
  86. },
  87. // 退出登录
  88. toExit() {
  89. uni.removeStorage({
  90. key: 'token',
  91. success: function(res) {
  92. let url = `/pages/index/index`;
  93. uni.reLaunch({
  94. url
  95. })
  96. }
  97. });
  98. },
  99. }
  100. }
  101. </script>
  102. <style lang="scss">
  103. .content {
  104. display: flex;
  105. flex-direction: column;
  106. .one {
  107. padding: 3vw;
  108. .button {
  109. margin: 2vw 0 0 0;
  110. background-color: var(--f3CColor);
  111. color: var(--mainColor);
  112. font-size: var(--font14Size);
  113. }
  114. }
  115. }
  116. </style>