change-password.vue 6.86 KB
<template>
  <view class="page">
    <view class="header-hero" :style="{ paddingTop: statusBarHeight + 'px' }">
      <view class="top-bar">
        <view class="top-left" @click="goBack">
          <AppIcon name="chevronLeft" size="sm" color="white" />
        </view>
        <view class="top-center">
          <text class="page-title">Change Password</text>
          <LocationPicker />
        </view>
        <view class="top-right" @click="isMenuOpen = true">
          <AppIcon name="menu" size="sm" color="white" />
        </view>
      </view>
    </view>

    <view class="content">
      <view class="lock-icon-wrap">
        <view class="lock-circle">
          <AppIcon name="lock" size="lg" color="white" />
        </view>
      </view>

      <view class="form-card">
        <view class="form-group">
          <text class="label">Current Password</text>
          <view class="input-wrap">
            <input
              v-model="currentPassword"
              class="input"
              :type="showCurrent ? 'text' : 'password'"
              placeholder="Enter current password"
              placeholder-class="placeholder-cls"
            />
            <view class="eye-btn" @click="showCurrent = !showCurrent">
              <AppIcon name="eye" size="sm" :color="showCurrent ? 'primary' : 'gray'" />
            </view>
          </view>
        </view>

        <view class="form-group">
          <text class="label">New Password</text>
          <view class="input-wrap">
            <input
              v-model="newPassword"
              class="input"
              :type="showNew ? 'text' : 'password'"
              placeholder="Enter new password"
              placeholder-cls="placeholder-cls"
            />
            <view class="eye-btn" @click="showNew = !showNew">
              <AppIcon name="eye" size="sm" :color="showNew ? 'primary' : 'gray'" />
            </view>
          </view>
        </view>

        <view class="form-group form-group-last">
          <text class="label">Confirm New Password</text>
          <view class="input-wrap">
            <input
              v-model="confirmPassword"
              class="input"
              :type="showConfirm ? 'text' : 'password'"
              placeholder="Confirm new password"
              placeholder-cls="placeholder-cls"
            />
            <view class="eye-btn" @click="showConfirm = !showConfirm">
              <AppIcon name="eye" size="sm" :color="showConfirm ? 'primary' : 'gray'" />
            </view>
          </view>
        </view>
      </view>

      <view class="tips-card">
        <text class="tips-title">Password Requirements</text>
        <text class="tips-item">At least 8 characters long</text>
        <text class="tips-item">Contains uppercase and lowercase letters</text>
        <text class="tips-item">Contains at least one number</text>
        <text class="tips-item tips-last">Contains at least one special character</text>
      </view>

      <view
        class="submit-btn"
        :class="{ disabled: !canSubmit }"
        @click="handleSubmit"
      >
        <text class="submit-btn-text">Update Password</text>
      </view>
    </view>

    <SideMenu v-model="isMenuOpen" />
  </view>
</template>

<script setup lang="ts">
import { ref, computed } from 'vue'
import AppIcon from '../../components/AppIcon.vue'
import SideMenu from '../../components/SideMenu.vue'
import LocationPicker from '../../components/LocationPicker.vue'
import { getStatusBarHeight } from '../../utils/statusBar'

const statusBarHeight = getStatusBarHeight()
const isMenuOpen = ref(false)

const currentPassword = ref('')
const newPassword = ref('')
const confirmPassword = ref('')
const showCurrent = ref(false)
const showNew = ref(false)
const showConfirm = ref(false)

const canSubmit = computed(() => {
  return currentPassword.value.length > 0
    && newPassword.value.length >= 8
    && confirmPassword.value === newPassword.value
})

const goBack = () => {
  const pages = getCurrentPages()
  if (pages.length > 1) {
    uni.navigateBack()
  } else {
    uni.redirectTo({ url: '/pages/more/profile' })
  }
}

const handleSubmit = () => {
  if (!canSubmit.value) return

  if (newPassword.value !== confirmPassword.value) {
    uni.showToast({ title: 'Passwords do not match', icon: 'none' })
    return
  }

  uni.showLoading({ title: 'Updating...' })
  setTimeout(() => {
    uni.hideLoading()
    uni.showToast({ title: 'Password updated!', icon: 'success' })
    setTimeout(() => {
      uni.navigateBack()
    }, 1500)
  }, 1000)
}
</script>

<style scoped>
.page {
  min-height: 100vh;
  background: #f9fafb;
}

.header-hero {
  background: linear-gradient(135deg, var(--theme-primary), var(--theme-primary-dark));
  padding: 16rpx 32rpx 24rpx;
}

.top-bar {
  height: 96rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.top-left,
.top-right {
  width: 64rpx;
  height: 64rpx;
  border-radius: 999rpx;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
}

.top-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.page-title {
  font-size: 34rpx;
  font-weight: 600;
  color: #fff;
}

.content {
  padding: 48rpx;
}

.lock-icon-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 40rpx;
}

.lock-circle {
  width: 120rpx;
  height: 120rpx;
  background: var(--theme-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.form-card {
  background: #fff;
  padding: 32rpx;
  border-radius: 20rpx;
  margin-bottom: 32rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
}

.form-group {
  margin-bottom: 32rpx;
}

.form-group-last {
  margin-bottom: 0;
}

.label {
  font-size: 28rpx;
  font-weight: 500;
  color: #374151;
  display: block;
  margin-bottom: 12rpx;
}

.input-wrap {
  display: flex;
  align-items: center;
  background: #f3f4f6;
  border-radius: 16rpx;
  padding-right: 16rpx;
}

.input {
  flex: 1;
  height: 96rpx;
  padding: 0 24rpx;
  font-size: 30rpx;
  background: transparent;
}

.placeholder-cls {
  color: #9ca3af;
}

.eye-btn {
  width: 64rpx;
  height: 64rpx;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.tips-card {
  background: #eff6ff;
  padding: 28rpx 32rpx;
  border-radius: 16rpx;
  margin-bottom: 40rpx;
}

.tips-title {
  font-size: 26rpx;
  font-weight: 600;
  color: var(--theme-primary);
  display: block;
  margin-bottom: 16rpx;
}

.tips-item {
  font-size: 24rpx;
  color: #4b5563;
  display: block;
  margin-bottom: 8rpx;
  padding-left: 20rpx;
}

.tips-last {
  margin-bottom: 0;
}

.submit-btn {
  width: 100%;
  height: 96rpx;
  background: var(--theme-primary);
  border-radius: 16rpx;
  display: flex;
  align-items: center;
  justify-content: center;
}

.submit-btn.disabled {
  opacity: 0.5;
}

.submit-btn-text {
  font-size: 32rpx;
  font-weight: 600;
  color: #ffffff;
  line-height: 1;
}
</style>