Blame view

泰额版/Food Labeling Management App UniApp/src/pages/more/change-password.vue 8.1 KB
59e51671   “wangming”   1
1
2
3
4
5
6
7
8
  <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">
f64eecbf   杨鑫   前端更新
9
            <text class="page-title">{{ t('password.changeTitle') }}</text>
59e51671   “wangming”   1
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
            <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">
f64eecbf   杨鑫   前端更新
27
            <text class="label">{{ t('password.current') }}</text>
59e51671   “wangming”   1
28
29
30
31
32
            <view class="input-wrap">
              <input
                v-model="currentPassword"
                class="input"
                :type="showCurrent ? 'text' : 'password'"
f64eecbf   杨鑫   前端更新
33
                :placeholder="t('password.currentPlaceholder')"
59e51671   “wangming”   1
34
35
36
37
38
39
40
41
42
                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">
f64eecbf   杨鑫   前端更新
43
            <text class="label">{{ t('password.new') }}</text>
59e51671   “wangming”   1
44
45
46
47
48
            <view class="input-wrap">
              <input
                v-model="newPassword"
                class="input"
                :type="showNew ? 'text' : 'password'"
f64eecbf   杨鑫   前端更新
49
50
                :placeholder="t('password.newPlaceholder')"
                placeholder-class="placeholder-cls"
59e51671   “wangming”   1
51
52
53
54
55
56
57
58
              />
              <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">
f64eecbf   杨鑫   前端更新
59
            <text class="label">{{ t('password.confirm') }}</text>
59e51671   “wangming”   1
60
61
62
63
64
            <view class="input-wrap">
              <input
                v-model="confirmPassword"
                class="input"
                :type="showConfirm ? 'text' : 'password'"
f64eecbf   杨鑫   前端更新
65
66
                :placeholder="t('password.confirmPlaceholder')"
                placeholder-class="placeholder-cls"
59e51671   “wangming”   1
67
68
69
70
71
72
73
74
75
              />
              <view class="eye-btn" @click="showConfirm = !showConfirm">
                <AppIcon name="eye" size="sm" :color="showConfirm ? 'primary' : 'gray'" />
              </view>
            </view>
          </view>
        </view>
  
        <view class="tips-card">
f64eecbf   杨鑫   前端更新
76
77
78
79
80
          <text class="tips-title">{{ t('password.requirements') }}</text>
          <text class="tips-item">{{ t('password.reqLength') }}</text>
          <text class="tips-item">{{ t('password.reqCase') }}</text>
          <text class="tips-item">{{ t('password.reqNumber') }}</text>
          <text class="tips-item tips-last">{{ t('password.reqSpecial') }}</text>
59e51671   “wangming”   1
81
82
83
84
85
86
87
        </view>
  
        <view
          class="submit-btn"
          :class="{ disabled: !canSubmit }"
          @click="handleSubmit"
        >
f64eecbf   杨鑫   前端更新
88
          <text class="submit-btn-text">{{ t('password.update') }}</text>
59e51671   “wangming”   1
89
90
91
92
93
94
95
96
97
        </view>
      </view>
  
      <SideMenu v-model="isMenuOpen" />
    </view>
  </template>
  
  <script setup lang="ts">
  import { ref, computed } from 'vue'
f64eecbf   杨鑫   前端更新
98
  import { useI18n } from 'vue-i18n'
59e51671   “wangming”   1
99
100
101
102
103
104
105
  import AppIcon from '../../components/AppIcon.vue'
  import SideMenu from '../../components/SideMenu.vue'
  import LocationPicker from '../../components/LocationPicker.vue'
  import { getStatusBarHeight } from '../../utils/statusBar'
  import { usAppChangePassword } from '../../services/usAppAuth'
  
  const statusBarHeight = getStatusBarHeight()
f64eecbf   杨鑫   前端更新
106
  const { t } = useI18n()
59e51671   “wangming”   1
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  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)
  
  /** 与文档「Password Requirements」一致:8+、大小写、数字、特殊字符 */
  function newPasswordMeetsComplexity(p: string): boolean {
    if (p.length < 8) return false
    if (!/[A-Z]/.test(p)) return false
    if (!/[a-z]/.test(p)) return false
    if (!/[0-9]/.test(p)) return false
    if (!/[^A-Za-z0-9]/.test(p)) return false
    return true
  }
  
  const canSubmit = computed(() => {
    return currentPassword.value.length > 0
      && newPasswordMeetsComplexity(newPassword.value)
      && confirmPassword.value === newPassword.value
  })
  
  const goBack = () => {
    const pages = getCurrentPages()
    if (pages.length > 1) {
      uni.navigateBack()
    } else {
      uni.redirectTo({ url: '/pages/more/profile' })
    }
  }
  
  const handleSubmit = async () => {
    if (!canSubmit.value) return
  
    if (newPassword.value !== confirmPassword.value) {
f64eecbf   杨鑫   前端更新
145
      uni.showToast({ title: t('password.mismatch'), icon: 'none' })
59e51671   “wangming”   1
146
147
148
      return
    }
    if (newPassword.value === currentPassword.value) {
f64eecbf   杨鑫   前端更新
149
      uni.showToast({ title: t('password.sameAsCurrent'), icon: 'none' })
59e51671   “wangming”   1
150
151
152
153
      return
    }
    if (!newPasswordMeetsComplexity(newPassword.value)) {
      uni.showToast({
f64eecbf   杨鑫   前端更新
154
        title: t('password.notMeetRequirements'),
59e51671   “wangming”   1
155
156
157
158
159
        icon: 'none',
      })
      return
    }
  
f64eecbf   杨鑫   前端更新
160
    uni.showLoading({ title: t('password.updating'), mask: true })
59e51671   “wangming”   1
161
162
163
164
165
166
167
    try {
      await usAppChangePassword({
        currentPassword: currentPassword.value,
        newPassword: newPassword.value,
        confirmNewPassword: confirmPassword.value,
      })
      uni.hideLoading()
f64eecbf   杨鑫   前端更新
168
      uni.showToast({ title: t('password.updated'), icon: 'success' })
59e51671   “wangming”   1
169
170
171
172
173
174
      setTimeout(() => {
        uni.navigateBack()
      }, 1200)
    } catch (e: unknown) {
      uni.hideLoading()
      const msg = e instanceof Error ? e.message : String(e)
f64eecbf   杨鑫   前端更新
175
      uni.showToast({ title: msg || t('password.updateFailed'), icon: 'none', duration: 2500 })
59e51671   “wangming”   1
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
    }
  }
  </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>