From 03839624edffdcd41f0ad9c4c25db62d96041737 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=9D=8E=E4=BC=8A=E5=B8=86?=
<15818603+Osborn-lyf@user.noreply.gitee.com>
Date: Fri, 16 Oct 2026 08:53:45 +0800
Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=AE=A2=E6=9C=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
package-lock.json | 16 +
package.json | 1 +
src/App.vue | 10 +-
src/api/auth.ts | 8 +
src/hooks/use-message-inbox.ts | 52 ++-
src/manifest.json | 4 +
src/pages/change-password/index.vue | 10 +
.../change-password/use-change-password.ts | 17 +-
.../device/components/device-header/index.vue | 26 +-
.../detail/use-device-bluetooth-sync.ts | 39 +-
src/pages/device/device-presence.ts | 43 +--
src/pages/device/use-device.ts | 2 +
src/pages/forgot-password/index.vue | 6 +-
.../forgot-password/use-forgot-password.ts | 33 +-
.../edit/components/region-picker/index.vue | 180 ++++++++++
.../components/region-picker/region-data.ts | 61 ++++
src/pages/mine/edit/index.vue | 50 +--
src/pages/mine/edit/use-edit-profile.ts | 25 +-
src/pages/mine/index.vue | 32 --
src/pages/mine/mine.scss | 97 +----
src/pages/mine/notify/index.vue | 1 +
src/pages/mine/notify/notify.scss | 9 +-
src/pages/mine/notify/notify.utils.ts | 13 +-
src/pages/mine/notify/use-notify.ts | 50 ++-
src/pages/mine/privacy/use-privacy.ts | 16 +-
.../phone/use-set-password-phone.ts | 89 +----
.../mine/set-password/use-set-password.ts | 67 +---
.../verify/use-set-password-verify.ts | 9 +-
src/pages/mine/support/index.vue | 83 +++--
src/pages/mine/support/support.scss | 41 ++-
src/pages/mine/support/support.types.ts | 4 +-
src/pages/mine/support/support.utils.ts | 65 +++-
src/pages/mine/support/use-support-voice.ts | 336 ++++++++++++++++++
src/pages/mine/support/use-support.ts | 3 +-
src/pages/mine/use-mine.ts | 54 +--
src/static/通知 (1).png | Bin 0 -> 6153 bytes
src/utils/message-push-cache.ts | 58 +++
src/utils/message-push.ts | 114 ++++++
src/utils/message-socket.ts | 95 +++--
src/utils/static-assets.ts | 4 +-
src/utils/z2-ble-protocol.ts | 24 +-
src/utils/z2-ble.ts | 11 +-
42 files changed, 1375 insertions(+), 483 deletions(-)
create mode 100644 src/pages/mine/edit/components/region-picker/index.vue
create mode 100644 src/pages/mine/edit/components/region-picker/region-data.ts
create mode 100644 src/pages/mine/support/use-support-voice.ts
create mode 100644 src/static/通知 (1).png
create mode 100644 src/utils/message-push-cache.ts
create mode 100644 src/utils/message-push.ts
diff --git a/package-lock.json b/package-lock.json
index ed5eb19..0a16b22 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -24,6 +24,7 @@
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-xhs": "3.0.0-5020420260813003",
"@dcloudio/uni-quickapp-webview": "3.0.0-5020420260813003",
+ "element-china-area-data": "^6.1.0",
"vue": "^3.4.21",
"vue-i18n": "^9.1.9"
},
@@ -6856,6 +6857,12 @@
"node": ">=10"
}
},
+ "node_modules/china-division": {
+ "version": "2.7.0",
+ "resolved": "https://registry.npmjs.org/china-division/-/china-division-2.7.0.tgz",
+ "integrity": "sha512-4uUPAT+1WfqDh5jytq7omdCmHNk3j+k76zEG/2IqaGcYB90c2SwcixttcypdsZ3T/9tN1TTpBDoeZn+Yw/qBEA==",
+ "license": "MIT"
+ },
"node_modules/chokidar": {
"version": "3.6.0",
"resolved": "https://registry.npmmirror.com/chokidar/-/chokidar-3.6.0.tgz",
@@ -7413,6 +7420,15 @@
"integrity": "sha512-vUNKPrUzw8ByEMOxloq0a71iD/mPuPxVkbDm3G5YhnxTzOw/I6qAg2MUS0cYj/c267lWmw26yW4Vv7foxTxPLg==",
"license": "ISC"
},
+ "node_modules/element-china-area-data": {
+ "version": "6.1.0",
+ "resolved": "https://registry.npmjs.org/element-china-area-data/-/element-china-area-data-6.1.0.tgz",
+ "integrity": "sha512-IkpcjwQv2A/2AxFiSoaISZ+oMw1rZCPUSOg5sOCwT5jKc96TaawmKZeY81xfxXsO0QbKxU5LLc6AirhG52hUmg==",
+ "license": "MIT",
+ "dependencies": {
+ "china-division": "^2.7.0"
+ }
+ },
"node_modules/emittery": {
"version": "0.8.1",
"resolved": "https://registry.npmmirror.com/emittery/-/emittery-0.8.1.tgz",
diff --git a/package.json b/package.json
index 2871fdc..6edc36d 100644
--- a/package.json
+++ b/package.json
@@ -53,6 +53,7 @@
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
"@dcloudio/uni-mp-xhs": "3.0.0-5020420260813003",
"@dcloudio/uni-quickapp-webview": "3.0.0-5020420260813003",
+ "element-china-area-data": "^6.1.0",
"vue": "^3.4.21",
"vue-i18n": "^9.1.9"
},
diff --git a/src/App.vue b/src/App.vue
index 7e1ae94..7992e57 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -1,6 +1,11 @@
diff --git a/src/api/auth.ts b/src/api/auth.ts
index 3bf25aa..c654a69 100644
--- a/src/api/auth.ts
+++ b/src/api/auth.ts
@@ -31,3 +31,11 @@ export function logout() {
method: 'POST',
})
}
+
+/** POST /app/auth/cancelAccount — 注销账号 */
+export function cancelAccount() {
+ return request({
+ url: '/app/auth/cancelAccount',
+ method: 'POST',
+ })
+}
diff --git a/src/hooks/use-message-inbox.ts b/src/hooks/use-message-inbox.ts
index 431878a..4b0dfd4 100644
--- a/src/hooks/use-message-inbox.ts
+++ b/src/hooks/use-message-inbox.ts
@@ -1,14 +1,30 @@
-import { ref } from 'vue'
+import { computed, ref } from 'vue'
import { fetchUnreadMessageCount } from '@/api/message'
-import { connectMessageSocket, disconnectMessageSocket, onMessagePush } from '@/utils/message-socket'
+import {
+ connectMessageSocket,
+ disconnectMessageSocket,
+ isMessageSocketConnected,
+ isMessageSocketConnecting,
+ onMessagePush,
+} from '@/utils/message-socket'
+import {
+ clearPushCache,
+ getCachedPushCount,
+ pushCacheCount,
+ rememberPushPayload,
+} from '@/utils/message-push-cache'
export const unreadMessageCount = ref(0)
+export const hasUnreadMessages = computed(
+ () => unreadMessageCount.value > 0 || pushCacheCount.value > 0,
+)
let inboxInitialized = false
let refreshingUnread = false
let lastUnreadRefreshAt = 0
+let pendingPushUnread = 0
-const UNREAD_REFRESH_MIN_GAP_MS = 5000
+const UNREAD_REFRESH_MIN_GAP_MS = 15000
export async function refreshUnreadMessageCount(force = false): Promise {
const now = Date.now()
@@ -19,30 +35,48 @@ export async function refreshUnreadMessageCount(force = false): Promise
refreshingUnread = true
try {
const count = await fetchUnreadMessageCount()
- unreadMessageCount.value = typeof count === 'number' ? count : Number(count) || 0
+ const serverCount = typeof count === 'number' ? count : Number(count) || 0
+ const cached = getCachedPushCount()
+ if (serverCount > 0) {
+ pendingPushUnread = 0
+ unreadMessageCount.value = serverCount
+ } else {
+ pendingPushUnread = cached
+ unreadMessageCount.value = Math.max(serverCount, cached)
+ }
lastUnreadRefreshAt = Date.now()
} catch {
- unreadMessageCount.value = 0
+ unreadMessageCount.value = pendingPushUnread
} finally {
refreshingUnread = false
}
return unreadMessageCount.value
}
+function handleIncomingPush(payload: Parameters[0]) {
+ if (!rememberPushPayload(payload)) return
+ pendingPushUnread = getCachedPushCount()
+ unreadMessageCount.value = Math.max(unreadMessageCount.value, pendingPushUnread)
+}
+
export function setupMessageInbox() {
- connectMessageSocket()
if (!inboxInitialized) {
inboxInitialized = true
- onMessagePush(() => {
- void refreshUnreadMessageCount()
+ onMessagePush((payload) => {
+ handleIncomingPush(payload)
})
void refreshUnreadMessageCount(true)
- return
+ }
+
+ if (!isMessageSocketConnected() && !isMessageSocketConnecting()) {
+ connectMessageSocket()
}
}
export function teardownMessageInbox() {
disconnectMessageSocket()
+ clearPushCache()
unreadMessageCount.value = 0
+ pendingPushUnread = 0
inboxInitialized = false
}
diff --git a/src/manifest.json b/src/manifest.json
index 36cb0f4..fe2b659 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -39,6 +39,7 @@
"",
"",
"",
+ "",
"",
"",
"",
@@ -69,6 +70,9 @@
},
"scope.userLocation" : {
"desc" : "你的位置信息将用于在地图上选择家庭位置"
+ },
+ "scope.record" : {
+ "desc" : "你的麦克风将用于在线客服语音输入"
}
},
"requiredPrivateInfos" : [
diff --git a/src/pages/change-password/index.vue b/src/pages/change-password/index.vue
index 99b1cda..44aa38c 100644
--- a/src/pages/change-password/index.vue
+++ b/src/pages/change-password/index.vue
@@ -7,6 +7,8 @@
+ 8-20位字符,须包含字母、数字、符号中的至少2种。
+
@@ -38,6 +40,14 @@ const { password, confirmPassword, submit } = useChangePassword()
margin-bottom: 48rpx;
}
+.auth-form-page__hint {
+ display: block;
+ margin-top: 16rpx;
+ font-size: 24rpx;
+ color: $color-text-secondary;
+ line-height: 1.5;
+}
+
.auth-form-page__btn {
margin-top: 16rpx;
}
diff --git a/src/pages/change-password/use-change-password.ts b/src/pages/change-password/use-change-password.ts
index 2b34937..28633ee 100644
--- a/src/pages/change-password/use-change-password.ts
+++ b/src/pages/change-password/use-change-password.ts
@@ -1,18 +1,20 @@
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
import { getErrorMessage } from '@/utils/api-error'
-import { isValidPassword } from '@/utils/validate'
+import { isValidStrongPassword } from '@/utils/validate'
import { resetPasswordByToken } from './change-password.api'
export function useChangePassword() {
const password = ref('')
const confirmPassword = ref('')
const resetToken = ref('')
+ const fromPrivacy = ref(false)
const loading = ref(false)
onLoad((query) => {
const raw = (query?.resetToken as string) || ''
resetToken.value = raw ? decodeURIComponent(raw) : ''
+ fromPrivacy.value = query?.from === 'privacy'
if (!resetToken.value) {
uni.showToast({ title: '请先完成验证码校验', icon: 'none' })
setTimeout(() => uni.navigateBack(), 1500)
@@ -24,8 +26,11 @@ export function useChangePassword() {
uni.showToast({ title: '重置令牌无效', icon: 'none' })
return
}
- if (!isValidPassword(password.value)) {
- uni.showToast({ title: '密码至少 6 位', icon: 'none' })
+ if (!isValidStrongPassword(password.value)) {
+ uni.showToast({
+ title: '密码需8-20位,且包含字母、数字、符号中至少2种',
+ icon: 'none',
+ })
return
}
if (password.value !== confirmPassword.value) {
@@ -40,8 +45,12 @@ export function useChangePassword() {
newPassword: password.value,
confirmPassword: confirmPassword.value,
})
- uni.showToast({ title: '修改成功', icon: 'success' })
+ uni.showToast({ title: '密码修改成功', icon: 'success' })
setTimeout(() => {
+ if (fromPrivacy.value) {
+ uni.navigateBack({ delta: 2 })
+ return
+ }
uni.reLaunch({ url: '/pages/login/index' })
}, 800)
} catch (err) {
diff --git a/src/pages/device/components/device-header/index.vue b/src/pages/device/components/device-header/index.vue
index 5fc6c9c..0f22abf 100644
--- a/src/pages/device/components/device-header/index.vue
+++ b/src/pages/device/components/device-header/index.vue
@@ -49,6 +49,7 @@
:src="staticAssets.iconNotify"
mode="aspectFit"
/>
+
@@ -151,6 +157,7 @@
import { staticAssets } from '@/utils/static-assets'
import AvatarActionSheet from './components/avatar-action-sheet/index.vue'
import NicknameDialog from './components/nickname-dialog/index.vue'
+import RegionPicker from './components/region-picker/index.vue'
import { useEditProfile } from './use-edit-profile'
const today = new Date().toISOString().slice(0, 10)
@@ -162,7 +169,7 @@ const {
maskedPhone,
genderText,
locationText,
- regionValue,
+ regionPickerVisible,
avatarSheetVisible,
nicknameDialogVisible,
onOpenAvatarSheet,
@@ -173,7 +180,8 @@ const {
onConfirmNickname,
onPickGender,
onBirthdayChange,
- onRegionChange,
+ onOpenRegionPicker,
+ onConfirmRegion,
onChangePhone,
onSave,
} = useEditProfile()
diff --git a/src/pages/mine/edit/use-edit-profile.ts b/src/pages/mine/edit/use-edit-profile.ts
index 0d9a527..e1e9cdf 100644
--- a/src/pages/mine/edit/use-edit-profile.ts
+++ b/src/pages/mine/edit/use-edit-profile.ts
@@ -49,18 +49,13 @@ export function useEditProfile() {
const form = ref(createEmptyForm())
const avatarSheetVisible = ref(false)
const nicknameDialogVisible = ref(false)
+ const regionPickerVisible = ref(false)
const maskedPhone = computed(() => maskPhone(form.value.phonenumber))
const genderText = computed(() => GENDER_LABELS[form.value.gender] || '未知')
const locationText = computed(() =>
formatLocation(form.value.province, form.value.city, form.value.district),
)
- const regionValue = computed(() => {
- const { province, city, district } = form.value
- if (province && city && district) return [province, city, district]
- return []
- })
-
async function loadProfile() {
if (loading.value) return
loading.value = true
@@ -158,11 +153,14 @@ export function useEditProfile() {
form.value.birthday = e.detail.value
}
- function onRegionChange(e: { detail: { value: string[] } }) {
- const [province, city, district] = e.detail.value
- form.value.province = province || ''
- form.value.city = city || ''
- form.value.district = district || ''
+ function onOpenRegionPicker() {
+ regionPickerVisible.value = true
+ }
+
+ function onConfirmRegion(value: { province: string; city: string; district: string }) {
+ form.value.province = value.province
+ form.value.city = value.city
+ form.value.district = value.district
}
function onChangePhone() {
@@ -214,7 +212,7 @@ export function useEditProfile() {
maskedPhone,
genderText,
locationText,
- regionValue,
+ regionPickerVisible,
avatarSheetVisible,
nicknameDialogVisible,
onOpenAvatarSheet,
@@ -225,7 +223,8 @@ export function useEditProfile() {
onConfirmNickname,
onPickGender,
onBirthdayChange,
- onRegionChange,
+ onOpenRegionPicker,
+ onConfirmRegion,
onChangePhone,
onSave,
}
diff --git a/src/pages/mine/index.vue b/src/pages/mine/index.vue
index 825116b..4a8ce5b 100644
--- a/src/pages/mine/index.vue
+++ b/src/pages/mine/index.vue
@@ -27,35 +27,6 @@
-
-
- {{ item.value }}
- {{ item.label }}
-
-
-
-
-
-
-
-
- {{ action.label }}
-
-
-
diff --git a/src/pages/mine/notify/notify.scss b/src/pages/mine/notify/notify.scss
index 75a3f9c..1332ba1 100644
--- a/src/pages/mine/notify/notify.scss
+++ b/src/pages/mine/notify/notify.scss
@@ -77,7 +77,14 @@
}
.notify-page__empty,
-.notify-page__loading,
+.notify-page__loading {
+ margin: 32rpx;
+ padding: 24rpx;
+ border-radius: 16rpx;
+ background: #f7f8fa;
+ text-align: center;
+}
+
.notify-page__footer-tip {
padding: 80rpx 32rpx;
text-align: center;
diff --git a/src/pages/mine/notify/notify.utils.ts b/src/pages/mine/notify/notify.utils.ts
index 72d112a..798f60a 100644
--- a/src/pages/mine/notify/notify.utils.ts
+++ b/src/pages/mine/notify/notify.utils.ts
@@ -1,14 +1,11 @@
import type { AppMessageVo } from '@/types/message'
+import { buildMessageFromPush, normalizeMessageId } from '@/utils/message-push'
-export function normalizeMessageId(message: AppMessageVo): string {
- const raw = message.messageId
- if (raw === undefined || raw === null || raw === '') return ''
- return String(raw)
-}
+export { buildMessageFromPush, normalizeMessageId }
export function isUnreadMessage(message: AppMessageVo): boolean {
const flag = message.readFlag
- return flag === 0 || flag === '0' || flag === false
+ return flag === 0 || flag === '0'
}
export function formatNotifyTime(message: AppMessageVo): string {
@@ -16,7 +13,9 @@ export function formatNotifyTime(message: AppMessageVo): string {
if (!raw) return ''
const text = String(raw).trim()
if (/^\d{2}:\d{2}$/.test(text)) return text
- const date = new Date(text)
+
+ const date = /^\d{13,}$/.test(text) ? new Date(Number(text)) : new Date(text)
if (Number.isNaN(date.getTime())) return text
return `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
}
+
diff --git a/src/pages/mine/notify/use-notify.ts b/src/pages/mine/notify/use-notify.ts
index 22828c2..1a7032a 100644
--- a/src/pages/mine/notify/use-notify.ts
+++ b/src/pages/mine/notify/use-notify.ts
@@ -1,11 +1,25 @@
import { onShow, onUnload } from '@dcloudio/uni-app'
import { computed, ref } from 'vue'
-import { fetchMessagePage, markAllMessagesRead, markMessageRead } from '@/api/message'
+import {
+ fetchMessagePage,
+ markAllMessagesRead,
+ markMessageRead,
+} from '@/api/message'
import { refreshUnreadMessageCount } from '@/hooks/use-message-inbox'
import { getErrorMessage } from '@/utils/api-error'
import { onMessagePush } from '@/utils/message-socket'
+import {
+ clearPushCache,
+ forgetCachedMessage,
+ mergeCachedMessages,
+ rememberPushPayload,
+} from '@/utils/message-push-cache'
import type { AppMessageVo } from '@/types/message'
-import { formatNotifyTime, isUnreadMessage, normalizeMessageId } from './notify.utils'
+import {
+ formatNotifyTime,
+ isUnreadMessage,
+ normalizeMessageId,
+} from './notify.utils'
const PAGE_SIZE = 20
@@ -36,17 +50,18 @@ export function useNotify() {
pageNum: pageNum.value,
pageSize: PAGE_SIZE,
})
- total.value = nextTotal
+ const mergedRows = mergeCachedMessages(rows)
if (reset) {
- messages.value = rows
+ messages.value = mergedRows
} else {
const map = new Map()
- for (const item of [...messages.value, ...rows]) {
+ for (const item of [...messages.value, ...mergedRows]) {
const id = normalizeMessageId(item)
if (id) map.set(id, item)
}
messages.value = Array.from(map.values())
}
+ total.value = Math.max(nextTotal, messages.value.length)
const homeName = rows.find((item) => item.homeName)?.homeName
if (homeName) sectionTitle.value = homeName
if (rows.length > 0) {
@@ -76,10 +91,11 @@ export function useNotify() {
if (isUnreadMessage(message)) {
try {
await markMessageRead(messageId)
+ forgetCachedMessage(messageId)
messages.value = messages.value.map((item) =>
normalizeMessageId(item) === messageId ? { ...item, readFlag: '1' } : item,
)
- await refreshUnreadMessageCount()
+ await refreshUnreadMessageCount(true)
} catch (err) {
uni.showToast({ title: getErrorMessage(err, '标记已读失败'), icon: 'none' })
}
@@ -96,19 +112,33 @@ export function useNotify() {
async function onMarkAllRead() {
try {
await markAllMessagesRead()
+ clearPushCache()
messages.value = messages.value.map((item) => ({ ...item, readFlag: '1' }))
- await refreshUnreadMessageCount()
+ await refreshUnreadMessageCount(true)
uni.showToast({ title: '已全部标为已读', icon: 'none' })
} catch (err) {
uni.showToast({ title: getErrorMessage(err, '操作失败'), icon: 'none' })
}
}
+ function prependPushMessage(payload: Parameters[0]) {
+ const incoming = rememberPushPayload(payload)
+ if (!incoming) return
+
+ const incomingId = normalizeMessageId(incoming)
+ const exists = messages.value.some((item) => normalizeMessageId(item) === incomingId)
+ if (exists) return
+
+ messages.value = mergeCachedMessages(messages.value)
+ total.value = messages.value.length
+ }
+
onShow(() => {
- void onRefresh()
- unsubscribePush = onMessagePush(() => {
- void onRefresh()
+ unsubscribePush?.()
+ unsubscribePush = onMessagePush((payload) => {
+ prependPushMessage(payload)
})
+ void onRefresh()
})
onUnload(() => {
diff --git a/src/pages/mine/privacy/use-privacy.ts b/src/pages/mine/privacy/use-privacy.ts
index c67197f..df7ce72 100644
--- a/src/pages/mine/privacy/use-privacy.ts
+++ b/src/pages/mine/privacy/use-privacy.ts
@@ -1,6 +1,6 @@
import { onShow } from '@dcloudio/uni-app'
import { computed, ref } from 'vue'
-import { logout } from '@/api/auth'
+import { cancelAccount, logout } from '@/api/auth'
import { fetchProfile } from '@/api/profile'
import { getErrorMessage } from '@/utils/api-error'
import { teardownMessageInbox } from '@/hooks/use-message-inbox'
@@ -58,7 +58,7 @@ export function usePrivacy() {
function onItemTap(itemId: string) {
if (itemId === 'password') {
- uni.navigateTo({ url: '/pages/mine/set-password/verify/index' })
+ uni.navigateTo({ url: '/pages/forgot-password/index?from=privacy' })
return
}
if (itemId === 'phone') {
@@ -72,7 +72,17 @@ export function usePrivacy() {
confirmColor: '#f04438',
success: (res) => {
if (!res.confirm) return
- uni.showToast({ title: '注销功能待对接', icon: 'none' })
+ void (async () => {
+ try {
+ await cancelAccount()
+ teardownMessageInbox()
+ clearStoredToken()
+ uni.showToast({ title: '账号已注销', icon: 'success' })
+ uni.reLaunch({ url: '/pages/login/index' })
+ } catch (err) {
+ uni.showToast({ title: getErrorMessage(err, '注销失败'), icon: 'none' })
+ }
+ })()
},
})
}
diff --git a/src/pages/mine/set-password/phone/use-set-password-phone.ts b/src/pages/mine/set-password/phone/use-set-password-phone.ts
index 3562742..b79a283 100644
--- a/src/pages/mine/set-password/phone/use-set-password-phone.ts
+++ b/src/pages/mine/set-password/phone/use-set-password-phone.ts
@@ -1,85 +1,18 @@
-import { onShow } from '@dcloudio/uni-app'
-import { computed, ref } from 'vue'
-import { fetchProfile } from '@/api/profile'
-import { useSmsCode } from '@/hooks/use-sms-code'
-import { SMS_CODE_SCENE } from '@/types/api'
-import { getErrorMessage } from '@/utils/api-error'
-import { isValidSmsCode } from '@/utils/validate'
-import { verifySetPasswordCode } from '../set-password.api'
-
-function maskPhone(phone: string): string {
- const digits = phone.replace(/\D/g, '')
- if (digits.length < 7) return phone
- return digits.replace(/(\d{3})\d{4}(\d+)/, '$1****$2')
-}
+import { onLoad } from '@dcloudio/uni-app'
+import { ref } from 'vue'
+/** 兼容旧入口,统一跳转到忘记密码流程 */
export function useSetPasswordPhone() {
- const boundPhone = ref('')
- const code = ref('')
- const loading = ref(false)
-
- const { counting, seconds, sendCode } = useSmsCode(SMS_CODE_SCENE.reset)
-
- const maskedPhone = computed(() => maskPhone(boundPhone.value))
-
- async function loadBoundPhone() {
- try {
- const profile = await fetchProfile()
- boundPhone.value = profile?.phonenumber || profile?.userName || ''
- if (!boundPhone.value) {
- uni.showToast({ title: '未绑定手机号', icon: 'none' })
- }
- } catch (err) {
- uni.showToast({ title: getErrorMessage(err, '加载账号信息失败'), icon: 'none' })
- }
- }
-
- function onSendCode() {
- if (!boundPhone.value) {
- uni.showToast({ title: '未绑定手机号', icon: 'none' })
- return
- }
- sendCode(boundPhone.value)
- }
-
- async function nextStep() {
- if (!boundPhone.value) {
- uni.showToast({ title: '未绑定手机号', icon: 'none' })
- return
- }
- if (!isValidSmsCode(code.value)) {
- uni.showToast({ title: '请输入验证码', icon: 'none' })
- return
- }
- if (loading.value) return
-
- loading.value = true
- try {
- const res = await verifySetPasswordCode({ phone: boundPhone.value, code: code.value })
- if (!res.resetToken) {
- uni.showToast({ title: '验证失败,未获取重置令牌', icon: 'none' })
- return
- }
- uni.navigateTo({
- url: `/pages/mine/set-password/index?resetToken=${encodeURIComponent(res.resetToken)}`,
- })
- } catch (err) {
- uni.showToast({ title: getErrorMessage(err, '验证失败,请重试'), icon: 'none' })
- } finally {
- loading.value = false
- }
- }
-
- onShow(() => {
- void loadBoundPhone()
+ onLoad(() => {
+ uni.redirectTo({ url: '/pages/forgot-password/index?from=privacy' })
})
return {
- code,
- maskedPhone,
- counting,
- seconds,
- onSendCode,
- nextStep,
+ code: ref(''),
+ maskedPhone: ref(''),
+ counting: ref(false),
+ seconds: ref(0),
+ onSendCode: () => {},
+ nextStep: () => {},
}
}
diff --git a/src/pages/mine/set-password/use-set-password.ts b/src/pages/mine/set-password/use-set-password.ts
index 4b65409..0028ab6 100644
--- a/src/pages/mine/set-password/use-set-password.ts
+++ b/src/pages/mine/set-password/use-set-password.ts
@@ -1,63 +1,26 @@
import { onLoad } from '@dcloudio/uni-app'
import { ref } from 'vue'
-import { getErrorMessage } from '@/utils/api-error'
-import { isValidStrongPassword } from '@/utils/validate'
-import { resetPasswordByToken } from './set-password.api'
+/** 兼容旧入口,统一跳转到忘记密码流程 */
export function useSetPassword() {
- const password = ref('')
- const confirmPassword = ref('')
- const resetToken = ref('')
- const loading = ref(false)
-
onLoad((query) => {
const raw = (query?.resetToken as string) || ''
- resetToken.value = raw ? decodeURIComponent(raw) : ''
- if (!resetToken.value) {
- uni.showToast({ title: '请先完成身份验证', icon: 'none' })
- setTimeout(() => uni.navigateBack(), 1500)
+ const resetToken = raw ? decodeURIComponent(raw) : ''
+ if (resetToken) {
+ uni.redirectTo({
+ url: `/pages/change-password/index?resetToken=${encodeURIComponent(resetToken)}&from=privacy`,
+ })
+ return
}
+ uni.redirectTo({ url: '/pages/forgot-password/index?from=privacy' })
})
- function onForgotPassword() {
- uni.navigateTo({ url: '/pages/forgot-password/index' })
+ return {
+ password: ref(''),
+ confirmPassword: ref(''),
+ onForgotPassword: () => {
+ uni.navigateTo({ url: '/pages/forgot-password/index?from=privacy' })
+ },
+ submit: () => {},
}
-
- async function submit() {
- if (!resetToken.value) {
- uni.showToast({ title: '重置令牌无效', icon: 'none' })
- return
- }
- if (!isValidStrongPassword(password.value)) {
- uni.showToast({
- title: '密码需8-20位,且包含字母、数字、符号中至少2种',
- icon: 'none',
- })
- return
- }
- if (password.value !== confirmPassword.value) {
- uni.showToast({ title: '两次密码不一致', icon: 'none' })
- return
- }
- if (loading.value) return
-
- loading.value = true
- try {
- await resetPasswordByToken({
- resetToken: resetToken.value,
- newPassword: password.value,
- confirmPassword: confirmPassword.value,
- })
- uni.showToast({ title: '密码修改成功', icon: 'success' })
- setTimeout(() => {
- uni.navigateBack({ delta: 3 })
- }, 1200)
- } catch (err) {
- uni.showToast({ title: getErrorMessage(err, '修改失败,请重试'), icon: 'none' })
- } finally {
- loading.value = false
- }
- }
-
- return { password, confirmPassword, onForgotPassword, submit }
}
diff --git a/src/pages/mine/set-password/verify/use-set-password-verify.ts b/src/pages/mine/set-password/verify/use-set-password-verify.ts
index a6195e5..b84ee36 100644
--- a/src/pages/mine/set-password/verify/use-set-password-verify.ts
+++ b/src/pages/mine/set-password/verify/use-set-password-verify.ts
@@ -1,6 +1,13 @@
+import { onLoad } from '@dcloudio/uni-app'
+
+/** 兼容旧入口,统一跳转到忘记密码流程 */
export function useSetPasswordVerify() {
+ onLoad(() => {
+ uni.redirectTo({ url: '/pages/forgot-password/index?from=privacy' })
+ })
+
function onPhoneVerify() {
- uni.navigateTo({ url: '/pages/mine/set-password/phone/index' })
+ uni.redirectTo({ url: '/pages/forgot-password/index?from=privacy' })
}
return { onPhoneVerify }
diff --git a/src/pages/mine/support/index.vue b/src/pages/mine/support/index.vue
index badbb89..bce4f1d 100644
--- a/src/pages/mine/support/index.vue
+++ b/src/pages/mine/support/index.vue
@@ -85,9 +85,6 @@
>
{{ item.content }}
-
- {{ item.time }}
-
@@ -205,7 +202,6 @@
>
- {{ item.time }}
我
@@ -215,6 +211,9 @@