update.vue 2.7 KB

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