setPassword.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="set-password-container">
  3. <view class="header">设置密码</view>
  4. <view class="form">
  5. <input v-model="password" type="password" placeholder="请输入新密码" class="input" />
  6. <input v-model="confirmPassword" type="password" placeholder="请确认新密码" class="input" />
  7. <button class="submit-btn" @click="submit">确认设置</button>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. password: '',
  16. confirmPassword: ''
  17. }
  18. },
  19. methods: {
  20. submit() {
  21. if (!this.password || this.password.length < 6) {
  22. uni.showToast({ title: '密码至少6位', icon: 'none' })
  23. return
  24. }
  25. if (this.password !== this.confirmPassword) {
  26. uni.showToast({ title: '两次密码不一致', icon: 'none' })
  27. return
  28. }
  29. uni.request({
  30. url: 'http://localhost:9527/api/setPassword',
  31. method: 'POST',
  32. data: {
  33. uid: uni.getStorageSync('uid'),
  34. password: this.password
  35. },
  36. success: (res) => {
  37. if (res.statusCode === 200 && res.data.code === 200) {
  38. uni.showToast({ title: '设置成功', icon: 'success' })
  39. setTimeout(() => uni.navigateBack(), 1000)
  40. } else {
  41. uni.showToast({ title: res.data.message || '设置失败', icon: 'none' })
  42. }
  43. }
  44. })
  45. }
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. .set-password-container {
  51. min-height: 100vh;
  52. background: #f7f8fa;
  53. padding: 40rpx 0;
  54. }
  55. .header {
  56. text-align: center;
  57. font-size: 36rpx;
  58. font-weight: bold;
  59. margin-bottom: 40rpx;
  60. background: #fff;
  61. padding: 32rpx 0;
  62. }
  63. .form {
  64. background: #fff;
  65. border-radius: 20rpx;
  66. margin: 0 32rpx;
  67. padding: 40rpx 32rpx;
  68. box-shadow: 0 4rpx 16rpx rgba(0,0,0,0.04);
  69. display: flex;
  70. flex-direction: column;
  71. gap: 32rpx;
  72. }
  73. .input {
  74. width: 100%;
  75. height: 80rpx;
  76. border: 1rpx solid #eee;
  77. border-radius: 12rpx;
  78. padding: 0 24rpx;
  79. font-size: 30rpx;
  80. background: #f7f8fa;
  81. }
  82. .submit-btn {
  83. width: 100%;
  84. background: #409EFF;
  85. color: #fff;
  86. border-radius: 12rpx;
  87. font-size: 32rpx;
  88. margin-top: 16rpx;
  89. height: 80rpx;
  90. }
  91. </style>