fix:最新版本
@@ -1,4 +1,5 @@
|
|||||||
# 接口根地址(App / 小程序 / H5 直连)
|
# 接口根地址(App / 小程序 / H5 直连)
|
||||||
|
# 正式打包读 .env.production;未配置时 src/config/app-env.ts 有兜底地址
|
||||||
VITE_API_BASE_URL=http://192.168.0.222:8082
|
VITE_API_BASE_URL=http://192.168.0.222:8082
|
||||||
|
|
||||||
# H5 开发:BASE_URL 留空时可走 vite 代理 /app
|
# H5 开发:BASE_URL 留空时可走 vite 代理 /app
|
||||||
|
|||||||
6
.env.production
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# 正式打包(npm run build:* / HBuilderX 发行)读取
|
||||||
|
VITE_API_BASE_URL=http://192.168.0.222:8082
|
||||||
|
VITE_API_PROXY_TARGET=http://192.168.0.222:8082
|
||||||
|
VITE_CS_API_BASE_URL=http://192.168.0.212:8082
|
||||||
|
VITE_MESSAGE_WS_URL=ws://192.168.0.222:8082/app/ws/message
|
||||||
|
VITE_API_CLIENT_ID=428a8310cd442757ae699df5d894f051
|
||||||
871
package-lock.json
generated
49
package.json
@@ -37,34 +37,35 @@
|
|||||||
"type-check": "vue-tsc --noEmit"
|
"type-check": "vue-tsc --noEmit"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dcloudio/uni-app": "3.0.0-5020420260813003",
|
"@dcloudio/uni-app": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-app-harmony": "3.0.0-5020420260813003",
|
"@dcloudio/uni-app-harmony": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-app-plus": "3.0.0-5020420260813003",
|
"@dcloudio/uni-app-plus": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-components": "3.0.0-5020420260813003",
|
"@dcloudio/uni-components": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-h5": "3.0.0-5020420260813003",
|
"@dcloudio/uni-h5": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-alipay": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-alipay": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-baidu": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-baidu": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-harmony": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-harmony": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-jd": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-jd": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-lark": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-lark": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-qq": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-qq": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-toutiao": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-toutiao": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-weixin": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-mp-xhs": "3.0.0-5020420260813003",
|
"@dcloudio/uni-mp-xhs": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-quickapp-webview": "3.0.0-5020420260813003",
|
"@dcloudio/uni-quickapp-webview": "3.0.0-5020620260917001",
|
||||||
"element-china-area-data": "^6.1.0",
|
"element-china-area-data": "^6.1.0",
|
||||||
"vue": "^3.4.21",
|
"vue": "3.4.21",
|
||||||
"vue-i18n": "^9.1.9"
|
"vue-i18n": "9.14.5"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@dcloudio/types": "^3.4.8",
|
"@dcloudio/types": "3.4.31",
|
||||||
"@dcloudio/uni-automator": "3.0.0-5020420260813003",
|
"@dcloudio/uni-automator": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-cli-shared": "3.0.0-5020420260813003",
|
"@dcloudio/uni-cli-shared": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/uni-stacktracey": "3.0.0-5020420260813003",
|
"@dcloudio/uni-stacktracey": "3.0.0-5020620260917001",
|
||||||
"@dcloudio/vite-plugin-uni": "3.0.0-5020420260813003",
|
"@dcloudio/vite-plugin-uni": "3.0.0-5020620260917001",
|
||||||
"@vue/runtime-core": "^3.4.21",
|
"@vue/runtime-core": "3.5.44",
|
||||||
"@vue/tsconfig": "^0.1.3",
|
"@vue/tsconfig": "^0.1.3",
|
||||||
|
"rollup": "4.14.3",
|
||||||
"sass": "^1.105.1",
|
"sass": "^1.105.1",
|
||||||
"typescript": "^4.9.4",
|
"typescript": "^4.9.4",
|
||||||
"vite": "5.2.8",
|
"vite": "5.2.8",
|
||||||
|
|||||||
23
src/App.vue
@@ -1,14 +1,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onLaunch, onShow } from '@dcloudio/uni-app'
|
import { onLaunch, onShow } from '@dcloudio/uni-app'
|
||||||
import { setupMessageInbox } from '@/hooks/use-message-inbox'
|
import { setupMessageInbox } from '@/hooks/use-message-inbox'
|
||||||
import {
|
|
||||||
connectMessageSocket,
|
|
||||||
isMessageSocketConnected,
|
|
||||||
isMessageSocketConnecting,
|
|
||||||
} from '@/utils/message-socket'
|
|
||||||
import { getStoredToken } from '@/utils/auth-token'
|
import { getStoredToken } from '@/utils/auth-token'
|
||||||
import { staticAssets } from '@/utils/static-assets'
|
import { staticAssets } from '@/utils/static-assets'
|
||||||
|
|
||||||
|
const HOME_ROUTE = '/pages/device/index'
|
||||||
|
const LOGIN_ROUTE = '/pages/login/index'
|
||||||
|
|
||||||
function applyH5Favicon() {
|
function applyH5Favicon() {
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
if (typeof document === 'undefined') return
|
if (typeof document === 'undefined') return
|
||||||
@@ -25,17 +23,22 @@ function applyH5Favicon() {
|
|||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
|
|
||||||
onLaunch(() => {
|
function bootstrapAuthRoute() {
|
||||||
applyH5Favicon()
|
|
||||||
if (getStoredToken()) {
|
if (getStoredToken()) {
|
||||||
setupMessageInbox()
|
setupMessageInbox()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
uni.reLaunch({ url: LOGIN_ROUTE })
|
||||||
|
}
|
||||||
|
|
||||||
|
onLaunch(() => {
|
||||||
|
applyH5Favicon()
|
||||||
|
bootstrapAuthRoute()
|
||||||
})
|
})
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
if (!getStoredToken()) return
|
if (getStoredToken()) {
|
||||||
if (!isMessageSocketConnected() && !isMessageSocketConnecting()) {
|
setupMessageInbox()
|
||||||
connectMessageSocket()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
|
import { getApiBaseUrl } from '@/config/app-env'
|
||||||
import { resolveCsAppBaseUrl, UPLOAD_CLIENT_ID } from './request'
|
import { resolveCsAppBaseUrl, UPLOAD_CLIENT_ID } from './request'
|
||||||
import {
|
import {
|
||||||
|
clearStoredCsToken,
|
||||||
extractAuthToken,
|
extractAuthToken,
|
||||||
getStoredCsToken,
|
|
||||||
getStoredToken,
|
getStoredToken,
|
||||||
saveStoredCsToken,
|
saveStoredCsToken,
|
||||||
} from '@/utils/auth-token'
|
} from '@/utils/auth-token'
|
||||||
@@ -13,8 +14,7 @@ function resolveCsAuthUrl(path: string): string {
|
|||||||
const normalized = path.startsWith('/') ? path : `/${path}`
|
const normalized = path.startsWith('/') ? path : `/${path}`
|
||||||
const csBase = resolveCsAppBaseUrl()
|
const csBase = resolveCsAppBaseUrl()
|
||||||
if (csBase) return `${csBase}${normalized}`
|
if (csBase) return `${csBase}${normalized}`
|
||||||
const main = import.meta.env.VITE_API_BASE_URL?.trim() || ''
|
return `${getApiBaseUrl()}/app${normalized}`
|
||||||
return `${main.replace(/\/$/, '')}/app${normalized}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseBody(data: unknown): unknown {
|
function parseBody(data: unknown): unknown {
|
||||||
@@ -62,17 +62,19 @@ async function requestCsLogin(path: string, data: Record<string, unknown>): Prom
|
|||||||
/** 主站登录后,向 212 用 clientId=app 同步登录,获取上传专用 token */
|
/** 主站登录后,向 212 用 clientId=app 同步登录,获取上传专用 token */
|
||||||
export async function syncCsAuthByPassword(account: string, password: string): Promise<void> {
|
export async function syncCsAuthByPassword(account: string, password: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
clearStoredCsToken()
|
||||||
await requestCsLogin('/auth/login/password', {
|
await requestCsLogin('/auth/login/password', {
|
||||||
account: account.trim(),
|
account: account.trim(),
|
||||||
password,
|
password,
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
// 212 不可达时不阻断主登录
|
// 212 不可达时不阻断主登录;会话接口仍可用主站 token
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function syncCsAuthBySms(phone: string, code: string): Promise<void> {
|
export async function syncCsAuthBySms(phone: string, code: string): Promise<void> {
|
||||||
try {
|
try {
|
||||||
|
clearStoredCsToken()
|
||||||
await requestCsLogin('/auth/login/sms', {
|
await requestCsLogin('/auth/login/sms', {
|
||||||
phonenumber: phone.trim(),
|
phonenumber: phone.trim(),
|
||||||
smsCode: code.trim(),
|
smsCode: code.trim(),
|
||||||
@@ -82,17 +84,10 @@ export async function syncCsAuthBySms(phone: string, code: string): Promise<void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 212 无 cs_token 时,用主站 token 兜底(与 upload 请求头逻辑一致) */
|
/** 进入客服页前:确认主站已登录(勿把主站 token 写入 cs_token) */
|
||||||
export function ensureCsUploadReady(): void {
|
export function ensureCsSessionReady(): void {
|
||||||
if (!getStoredCsToken()) {
|
if (!getStoredToken()) {
|
||||||
const main = getStoredToken()
|
throw new ApiError('请先登录', 401)
|
||||||
if (main) saveStoredCsToken(main)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function assertCsUploadToken(): void {
|
|
||||||
ensureCsUploadReady()
|
|
||||||
if (!getStoredCsToken() && !getStoredToken()) {
|
|
||||||
throw new ApiError('请先登录后再发送图片', 401)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
import { request } from '@/api/request'
|
import { request } from '@/api/request'
|
||||||
|
import type { AppHomeVo, UpdateHomeBody } from '@/types/location'
|
||||||
import { parseId, sameId } from '@/utils/device-id'
|
import { parseId, sameId } from '@/utils/device-id'
|
||||||
|
|
||||||
|
const DEFAULT_HOME_LONGITUDE = 116.4074
|
||||||
|
const DEFAULT_HOME_LATITUDE = 39.9042
|
||||||
|
const DEFAULT_HOME_ADDRESS = '未设置'
|
||||||
|
|
||||||
/** GET /app/home/list — 查询当前用户的家庭列表 */
|
/** GET /app/home/list — 查询当前用户的家庭列表 */
|
||||||
export function fetchHomeList() {
|
export function fetchHomeList() {
|
||||||
return request<AppHomeVo[]>({
|
return request<AppHomeVo[]>({
|
||||||
@@ -19,6 +23,43 @@ export function createHome(data: { homeName: string }) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** PUT /app/home/{homeId} — 修改家庭名称与位置 */
|
||||||
|
export function updateHome(homeId: string | number, data: UpdateHomeBody) {
|
||||||
|
return request<void>({
|
||||||
|
url: `/app/home/${encodeURIComponent(String(homeId))}`,
|
||||||
|
method: 'PUT',
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 组装修改家庭接口必填字段(名称 2-10 字,位置四项均必填) */
|
||||||
|
export function buildUpdateHomeBody(
|
||||||
|
homeName: string,
|
||||||
|
options?: {
|
||||||
|
geo?: { address: string; latitude: number; longitude: number }
|
||||||
|
home?: AppHomeVo
|
||||||
|
},
|
||||||
|
): UpdateHomeBody {
|
||||||
|
const geo = options?.geo
|
||||||
|
const home = options?.home
|
||||||
|
return {
|
||||||
|
homeName: homeName.trim(),
|
||||||
|
homeLocationLongitude:
|
||||||
|
geo?.longitude ?? home?.homeLocationLongitude ?? DEFAULT_HOME_LONGITUDE,
|
||||||
|
homeLocationLatitude:
|
||||||
|
geo?.latitude ?? home?.homeLocationLatitude ?? DEFAULT_HOME_LATITUDE,
|
||||||
|
homeLocationAddress:
|
||||||
|
geo?.address?.trim()
|
||||||
|
|| home?.homeLocationAddress?.trim()
|
||||||
|
|| DEFAULT_HOME_ADDRESS,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function isValidHomeName(name: string): boolean {
|
||||||
|
const value = name.trim()
|
||||||
|
return value.length >= 2 && value.length <= 10
|
||||||
|
}
|
||||||
|
|
||||||
function isDefaultHome(home: AppHomeVo): boolean {
|
function isDefaultHome(home: AppHomeVo): boolean {
|
||||||
const value = home.isDefault
|
const value = home.isDefault
|
||||||
return value === '1' || value === 1 || value === true
|
return value === '1' || value === 1 || value === true
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
import type { ApiResponse } from '@/types/api'
|
import type { ApiResponse } from '@/types/api'
|
||||||
import {
|
import {
|
||||||
|
assertRequestUrl,
|
||||||
|
getApiBaseUrl,
|
||||||
|
getApiClientId,
|
||||||
|
getCsApiBaseUrl,
|
||||||
|
getUploadClientId,
|
||||||
|
} from '@/config/app-env'
|
||||||
|
import {
|
||||||
|
clearStoredCsToken,
|
||||||
extractAuthToken,
|
extractAuthToken,
|
||||||
formatBearerAuthorization,
|
formatBearerAuthorization,
|
||||||
getStoredCsToken,
|
getStoredCsToken,
|
||||||
@@ -8,22 +16,11 @@ import {
|
|||||||
} from '@/utils/auth-token'
|
} from '@/utils/auth-token'
|
||||||
import { ApiError, isApiSuccess, unwrapApiData } from '@/utils/api-error'
|
import { ApiError, isApiSuccess, unwrapApiData } from '@/utils/api-error'
|
||||||
|
|
||||||
/** H5 开发走 Vite 代理;App/小程序使用完整后端地址 */
|
|
||||||
function resolveBaseUrl(): string {
|
|
||||||
const envUrl = import.meta.env.VITE_API_BASE_URL ?? ''
|
|
||||||
// #ifdef H5
|
|
||||||
if (import.meta.env.DEV) return ''
|
|
||||||
// #endif
|
|
||||||
return envUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
const BASE_URL = resolveBaseUrl()
|
|
||||||
/** RuoYi-Vue-Plus App 端 clientId(登录等 JSON 接口) */
|
/** RuoYi-Vue-Plus App 端 clientId(登录等 JSON 接口) */
|
||||||
export const API_CLIENT_ID =
|
export const API_CLIENT_ID = getApiClientId()
|
||||||
import.meta.env.VITE_API_CLIENT_ID || '428a8310cd442757ae699df5d894f051'
|
|
||||||
|
|
||||||
/** 文件上传 clientId(与 Postman /app/cs/upload 一致) */
|
/** 文件上传 clientId(与 Postman /app/cs/upload 一致) */
|
||||||
export const UPLOAD_CLIENT_ID = import.meta.env.VITE_UPLOAD_CLIENT_ID || 'app'
|
export const UPLOAD_CLIENT_ID = getUploadClientId()
|
||||||
|
|
||||||
/** 将响应 JSON 中的 int64 主键字段转为字符串,避免 JS 精度丢失 */
|
/** 将响应 JSON 中的 int64 主键字段转为字符串,避免 JS 精度丢失 */
|
||||||
function parseJsonPreserveIdFields(text: string): unknown {
|
function parseJsonPreserveIdFields(text: string): unknown {
|
||||||
@@ -34,19 +31,18 @@ function parseJsonPreserveIdFields(text: string): unknown {
|
|||||||
return JSON.parse(safe)
|
return JSON.parse(safe)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 212 客服服务根路径(含 /app);未配置时返回空字符串 */
|
/** 212 客服服务根路径(含 /app) */
|
||||||
export function resolveCsAppBaseUrl(): string {
|
export function resolveCsAppBaseUrl(): string {
|
||||||
const csBase = import.meta.env.VITE_CS_API_BASE_URL?.trim()
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
if (import.meta.env.DEV) return '/cs-app'
|
if (import.meta.env.DEV) return '/cs-app'
|
||||||
// #endif
|
// #endif
|
||||||
if (csBase) return `${csBase.replace(/\/$/, '')}/app`
|
const csBase = getCsApiBaseUrl()
|
||||||
return ''
|
return csBase ? `${csBase}/app` : ''
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildCsAppRequestUrl(path: string): string {
|
function buildCsAppRequestUrl(path: string): string {
|
||||||
const csBase = resolveCsAppBaseUrl()
|
const csBase = resolveCsAppBaseUrl()
|
||||||
if (!csBase) return `${BASE_URL}${path}`
|
if (!csBase) return `${getApiBaseUrl()}${path}`
|
||||||
if (path.startsWith('/app/')) return `${csBase}${path.slice(4)}`
|
if (path.startsWith('/app/')) return `${csBase}${path.slice(4)}`
|
||||||
if (path.startsWith('/app')) return `${csBase}${path.slice(4)}`
|
if (path.startsWith('/app')) return `${csBase}${path.slice(4)}`
|
||||||
return `${csBase}${path.startsWith('/') ? path : `/${path}`}`
|
return `${csBase}${path.startsWith('/') ? path : `/${path}`}`
|
||||||
@@ -97,30 +93,44 @@ export function buildDownloadAuthHeaders(): Record<string, string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 客服 WebSocket / 会话鉴权用 token(优先 212 cs_token,否则主站 token) */
|
||||||
export function resolveCsAppToken(): string {
|
export function resolveCsAppToken(): string {
|
||||||
return getStoredCsToken() || getStoredToken()
|
return getStoredCsToken() || getStoredToken()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 客服图片上传鉴权头(212,clientId=app,使用 cs_token) */
|
/** 客服 JSON:有 cs_token 用 clientId=app;否则用主站 token + 主站 clientId */
|
||||||
|
export function resolveCsAppClientId(): string {
|
||||||
|
return getStoredCsToken() ? UPLOAD_CLIENT_ID : API_CLIENT_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 客服图片上传:有 cs_token 用 clientId=app;否则与主站一致(主站 token + 主站 clientId) */
|
||||||
export function buildCsUploadAuthHeaders(): Record<string, string> {
|
export function buildCsUploadAuthHeaders(): Record<string, string> {
|
||||||
const authorization = formatBearerAuthorization(resolveCsAppToken())
|
const csToken = getStoredCsToken()
|
||||||
|
const token = csToken || getStoredToken()
|
||||||
|
const authorization = formatBearerAuthorization(token)
|
||||||
return {
|
return {
|
||||||
clientId: UPLOAD_CLIENT_ID,
|
clientId: csToken ? UPLOAD_CLIENT_ID : API_CLIENT_ID,
|
||||||
...(authorization ? { Authorization: authorization } : {}),
|
...(authorization ? { Authorization: authorization } : {}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 212 客服 JSON 接口鉴权(与 upload 一致:clientId=app + cs_token) */
|
/** 212 客服 JSON 接口鉴权 */
|
||||||
export function buildCsAppAuthHeaders(extra?: Record<string, unknown>): Record<string, string> {
|
export function buildCsAppAuthHeaders(extra?: Record<string, unknown>): Record<string, string> {
|
||||||
const authorization = formatBearerAuthorization(resolveCsAppToken())
|
const authorization = formatBearerAuthorization(resolveCsAppToken())
|
||||||
return {
|
return {
|
||||||
'Content-Type': 'application/json;charset=UTF-8',
|
'Content-Type': 'application/json;charset=UTF-8',
|
||||||
clientId: UPLOAD_CLIENT_ID,
|
clientId: resolveCsAppClientId(),
|
||||||
...(authorization ? { Authorization: authorization } : {}),
|
...(authorization ? { Authorization: authorization } : {}),
|
||||||
...(extra as Record<string, string> | undefined),
|
...(extra as Record<string, string> | undefined),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isCsAuthError(err: unknown): boolean {
|
||||||
|
if (!(err instanceof ApiError)) return false
|
||||||
|
if (err.code === 401) return true
|
||||||
|
return /登录状态|未登录|重新登录/i.test(err.message)
|
||||||
|
}
|
||||||
|
|
||||||
export type UploadAuthMode = 'default' | 'cs'
|
export type UploadAuthMode = 'default' | 'cs'
|
||||||
|
|
||||||
function resolveUploadAuthHeaders(mode: UploadAuthMode): Record<string, string> {
|
function resolveUploadAuthHeaders(mode: UploadAuthMode): Record<string, string> {
|
||||||
@@ -130,7 +140,7 @@ function resolveUploadAuthHeaders(mode: UploadAuthMode): Record<string, string>
|
|||||||
function resolveUploadUrl(url: string): string {
|
function resolveUploadUrl(url: string): string {
|
||||||
if (/^https?:\/\//i.test(url)) return url
|
if (/^https?:\/\//i.test(url)) return url
|
||||||
const path = url.startsWith('/') ? url : `/${url}`
|
const path = url.startsWith('/') ? url : `/${url}`
|
||||||
return `${BASE_URL}${path}`
|
return `${getApiBaseUrl()}${path}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUploadSuccess<T>(
|
function handleUploadSuccess<T>(
|
||||||
@@ -212,6 +222,19 @@ async function uploadViaFetchH5<T>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runUpload<T>(
|
||||||
|
targetUrl: string,
|
||||||
|
filePath: string,
|
||||||
|
fieldName: string,
|
||||||
|
authMode: UploadAuthMode,
|
||||||
|
): Promise<T> {
|
||||||
|
// #ifdef H5
|
||||||
|
return uploadViaFetchH5<T>(targetUrl, filePath, fieldName, authMode)
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
return uploadViaUniMultipart<T>(targetUrl, filePath, fieldName, authMode)
|
||||||
|
}
|
||||||
|
|
||||||
/** multipart/form-data 上传;H5 走 fetch 确保 Bearer token 发出 */
|
/** multipart/form-data 上传;H5 走 fetch 确保 Bearer token 发出 */
|
||||||
export function uploadAppFile<T>(
|
export function uploadAppFile<T>(
|
||||||
url: string,
|
url: string,
|
||||||
@@ -220,12 +243,14 @@ export function uploadAppFile<T>(
|
|||||||
authMode: UploadAuthMode = 'default',
|
authMode: UploadAuthMode = 'default',
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
const targetUrl = resolveUploadUrl(url)
|
const targetUrl = resolveUploadUrl(url)
|
||||||
|
const hadCsToken = authMode === 'cs' && !!getStoredCsToken()
|
||||||
|
|
||||||
// #ifdef H5
|
return runUpload<T>(targetUrl, filePath, fieldName, authMode).catch((err) => {
|
||||||
return uploadViaFetchH5<T>(targetUrl, filePath, fieldName, authMode)
|
if (authMode !== 'cs' || !isCsAuthError(err)) throw err
|
||||||
// #endif
|
if (!hadCsToken) throw err
|
||||||
|
clearStoredCsToken()
|
||||||
return uploadViaUniMultipart<T>(targetUrl, filePath, fieldName, authMode)
|
return runUpload<T>(targetUrl, filePath, fieldName, authMode)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSuccess<T>(
|
function handleSuccess<T>(
|
||||||
@@ -266,6 +291,12 @@ function runRequest<T>(
|
|||||||
saveTokenFromBody = false,
|
saveTokenFromBody = false,
|
||||||
): Promise<T> {
|
): Promise<T> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
assertRequestUrl(url)
|
||||||
|
} catch (err) {
|
||||||
|
reject(new ApiError(err instanceof Error ? err.message : '接口地址未配置'))
|
||||||
|
return
|
||||||
|
}
|
||||||
uni.request({
|
uni.request({
|
||||||
...options,
|
...options,
|
||||||
url,
|
url,
|
||||||
@@ -280,7 +311,7 @@ function runRequest<T>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function request<T = unknown>(options: RequestOptions): Promise<T> {
|
export function request<T = unknown>(options: RequestOptions): Promise<T> {
|
||||||
return runRequest<T>(options, `${BASE_URL}${options.url}`, buildAuthHeaders)
|
return runRequest<T>(options, `${getApiBaseUrl()}${options.url}`, buildAuthHeaders)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,15 +321,30 @@ export function request<T = unknown>(options: RequestOptions): Promise<T> {
|
|||||||
export function requestCsApp<T = unknown>(options: RequestOptions): Promise<T> {
|
export function requestCsApp<T = unknown>(options: RequestOptions): Promise<T> {
|
||||||
const csBase = resolveCsAppBaseUrl()
|
const csBase = resolveCsAppBaseUrl()
|
||||||
if (!csBase) return request<T>(options)
|
if (!csBase) return request<T>(options)
|
||||||
return runRequest<T>(options, buildCsAppRequestUrl(options.url), buildCsAppAuthHeaders)
|
|
||||||
|
const url = buildCsAppRequestUrl(options.url)
|
||||||
|
const hadCsToken = !!getStoredCsToken()
|
||||||
|
|
||||||
|
return runRequest<T>(options, url, buildCsAppAuthHeaders).catch((err) => {
|
||||||
|
if (!hadCsToken || !isCsAuthError(err)) throw err
|
||||||
|
clearStoredCsToken()
|
||||||
|
return runRequest<T>(options, url, buildCsAppAuthHeaders)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 登录类接口:从完整响应体提取并保存 token */
|
/** 登录类接口:从完整响应体提取并保存 token */
|
||||||
export function requestLogin<T = unknown>(options: RequestOptions): Promise<T> {
|
export function requestLogin<T = unknown>(options: RequestOptions): Promise<T> {
|
||||||
|
const url = `${getApiBaseUrl()}${options.url}`
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
try {
|
||||||
|
assertRequestUrl(url)
|
||||||
|
} catch (err) {
|
||||||
|
reject(new ApiError(err instanceof Error ? err.message : '接口地址未配置'))
|
||||||
|
return
|
||||||
|
}
|
||||||
uni.request({
|
uni.request({
|
||||||
...options,
|
...options,
|
||||||
url: `${BASE_URL}${options.url}`,
|
url,
|
||||||
header: buildAuthHeaders(options.header),
|
header: buildAuthHeaders(options.header),
|
||||||
dataType: 'text',
|
dataType: 'text',
|
||||||
success: (res) => handleSuccess<T>(res, resolve, reject, true),
|
success: (res) => handleSuccess<T>(res, resolve, reject, true),
|
||||||
|
|||||||
36
src/components/page-scroll-view/index.vue
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<template>
|
||||||
|
<scroll-view
|
||||||
|
class="page-scroll-view"
|
||||||
|
scroll-y
|
||||||
|
:style="mergedStyle"
|
||||||
|
v-bind="$attrs"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</scroll-view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import type { CSSProperties } from 'vue'
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { usePageScrollHeight } from '@/hooks/use-page-scroll-height'
|
||||||
|
|
||||||
|
defineOptions({ inheritAttrs: false })
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
/** 外部传入时覆盖内部计算(如设备详情页自定义顶部区域) */
|
||||||
|
scrollStyle?: CSSProperties
|
||||||
|
extraBottomPx?: number
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const { scrollStyle: defaultScrollStyle } = usePageScrollHeight({
|
||||||
|
extraBottomPx: props.extraBottomPx ?? 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
const mergedStyle = computed<CSSProperties>(() => props.scrollStyle ?? defaultScrollStyle.value)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.page-scroll-view {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
52
src/config/app-env.ts
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
/**
|
||||||
|
* 运行环境配置。
|
||||||
|
* HBuilderX 云打包时 import.meta.env 可能未注入,此处提供源码级兜底地址。
|
||||||
|
* 上线前请修改 APP_ENV_DEFAULTS,或通过 .env.production 覆盖。
|
||||||
|
*/
|
||||||
|
const APP_ENV_DEFAULTS = {
|
||||||
|
apiBaseUrl: 'http://192.168.0.222:8082',
|
||||||
|
csApiBaseUrl: 'http://192.168.0.212:8082',
|
||||||
|
messageWsUrl: 'ws://192.168.0.222:8082/app/ws/message',
|
||||||
|
apiClientId: '428a8310cd442757ae699df5d894f051',
|
||||||
|
uploadClientId: 'app',
|
||||||
|
} as const
|
||||||
|
|
||||||
|
function readViteEnv(key: string): string {
|
||||||
|
const value = (import.meta.env as Record<string, string | undefined>)[key]
|
||||||
|
return typeof value === 'string' ? value.trim() : ''
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 主 API 根地址(App/小程序须为 http(s)://...;H5 开发返回空走代理) */
|
||||||
|
export function getApiBaseUrl(): string {
|
||||||
|
// #ifdef H5
|
||||||
|
if (import.meta.env.DEV) return ''
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
const fromEnv = readViteEnv('VITE_API_BASE_URL') || readViteEnv('VITE_API_PROXY_TARGET')
|
||||||
|
const base = fromEnv || APP_ENV_DEFAULTS.apiBaseUrl
|
||||||
|
return base.replace(/\/$/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 客服服务根地址(不含 /app) */
|
||||||
|
export function getCsApiBaseUrl(): string {
|
||||||
|
const base = readViteEnv('VITE_CS_API_BASE_URL') || APP_ENV_DEFAULTS.csApiBaseUrl
|
||||||
|
return base.replace(/\/$/, '')
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getMessageWsUrl(): string {
|
||||||
|
return readViteEnv('VITE_MESSAGE_WS_URL') || APP_ENV_DEFAULTS.messageWsUrl
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getApiClientId(): string {
|
||||||
|
return readViteEnv('VITE_API_CLIENT_ID') || APP_ENV_DEFAULTS.apiClientId
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUploadClientId(): string {
|
||||||
|
return readViteEnv('VITE_UPLOAD_CLIENT_ID') || APP_ENV_DEFAULTS.uploadClientId
|
||||||
|
}
|
||||||
|
|
||||||
|
/** App 打包后必须是绝对地址;H5 开发允许 /app 相对路径走代理 */
|
||||||
|
export function assertRequestUrl(url: string, hint = '接口地址'): void {
|
||||||
|
if (/^https?:\/\//i.test(url) || url.startsWith('/')) return
|
||||||
|
throw new Error(`${hint}无效:${url || '(空)'},需以 http(s):// 或 / 开头`)
|
||||||
|
}
|
||||||
79
src/hooks/use-page-scroll-height.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import { type CSSProperties, computed, getCurrentInstance, nextTick, onMounted, ref } from 'vue'
|
||||||
|
|
||||||
|
const NAVBAR_BAR_RPX = 88
|
||||||
|
|
||||||
|
export interface PageScrollHeightOptions {
|
||||||
|
/** 从底部额外减去的 px(如底部固定栏) */
|
||||||
|
extraBottomPx?: number
|
||||||
|
/**
|
||||||
|
* 页面顶部已占用区域的选择器(如自定义 hero),测量其高度作为顶部偏移。
|
||||||
|
* 未设置时默认按 statusBar + 导航栏(88rpx) 计算。
|
||||||
|
*/
|
||||||
|
topSelector?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNavbarTopPx() {
|
||||||
|
const sys = uni.getSystemInfoSync()
|
||||||
|
const statusBar = sys.statusBarHeight ?? 0
|
||||||
|
const navbarBar = uni.upx2px(NAVBAR_BAR_RPX)
|
||||||
|
return statusBar + navbarBar
|
||||||
|
}
|
||||||
|
|
||||||
|
export function usePageScrollHeight(options: PageScrollHeightOptions = {}) {
|
||||||
|
const { extraBottomPx = 0, topSelector } = options
|
||||||
|
const heightPx = ref(0)
|
||||||
|
|
||||||
|
function applyHeight(topPx: number) {
|
||||||
|
const sys = uni.getSystemInfoSync()
|
||||||
|
const windowHeight = sys.windowHeight ?? sys.screenHeight ?? 667
|
||||||
|
heightPx.value = Math.max(0, windowHeight - topPx - extraBottomPx)
|
||||||
|
}
|
||||||
|
|
||||||
|
function measureNavbarHeight() {
|
||||||
|
applyHeight(getNavbarTopPx())
|
||||||
|
}
|
||||||
|
|
||||||
|
function measureCustomTop() {
|
||||||
|
if (!topSelector) {
|
||||||
|
measureNavbarHeight()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = getCurrentInstance()
|
||||||
|
const query = instance
|
||||||
|
? uni.createSelectorQuery().in(instance.proxy!)
|
||||||
|
: uni.createSelectorQuery()
|
||||||
|
|
||||||
|
query
|
||||||
|
.select(topSelector)
|
||||||
|
.boundingClientRect((rect) => {
|
||||||
|
const top =
|
||||||
|
rect && !Array.isArray(rect) && rect.height
|
||||||
|
? rect.height
|
||||||
|
: getNavbarTopPx()
|
||||||
|
applyHeight(top)
|
||||||
|
})
|
||||||
|
.exec()
|
||||||
|
}
|
||||||
|
|
||||||
|
function remeasureScrollHeight() {
|
||||||
|
if (topSelector) {
|
||||||
|
nextTick(measureCustomTop)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
measureNavbarHeight()
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
nextTick(remeasureScrollHeight)
|
||||||
|
})
|
||||||
|
|
||||||
|
remeasureScrollHeight()
|
||||||
|
|
||||||
|
const scrollStyle = computed<CSSProperties>(() => ({
|
||||||
|
height: `${heightPx.value}px`,
|
||||||
|
width: '100%',
|
||||||
|
}))
|
||||||
|
|
||||||
|
return { scrollHeight: heightPx, scrollStyle, remeasureScrollHeight }
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name" : "",
|
"name" : "虫子智家",
|
||||||
"appid" : "",
|
"appid" : "__UNI__925D0CC",
|
||||||
"description" : "",
|
"description" : "",
|
||||||
"versionName" : "1.0.0",
|
"versionName" : "1.0.0",
|
||||||
"versionCode" : "100",
|
"versionCode" : "100",
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
},
|
},
|
||||||
/* 模块配置 */
|
/* 模块配置 */
|
||||||
"modules" : {
|
"modules" : {
|
||||||
|
"Bluetooth" : {},
|
||||||
|
"Camera" : {},
|
||||||
"Maps" : {}
|
"Maps" : {}
|
||||||
},
|
},
|
||||||
/* 应用发布信息 */
|
/* 应用发布信息 */
|
||||||
@@ -50,9 +52,51 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
/* ios打包配置 */
|
/* ios打包配置 */
|
||||||
"ios" : {},
|
"ios" : {
|
||||||
|
"dSYMs" : false
|
||||||
|
},
|
||||||
/* SDK配置 */
|
/* SDK配置 */
|
||||||
"sdkConfigs" : {}
|
"sdkConfigs" : {
|
||||||
|
"maps" : {},
|
||||||
|
"push" : {
|
||||||
|
"unipush" : {
|
||||||
|
"version" : "2",
|
||||||
|
"offline" : false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"icons" : {
|
||||||
|
"android" : {
|
||||||
|
"hdpi" : "unpackage/res/icons/72x72.png",
|
||||||
|
"xhdpi" : "unpackage/res/icons/96x96.png",
|
||||||
|
"xxhdpi" : "unpackage/res/icons/144x144.png",
|
||||||
|
"xxxhdpi" : "unpackage/res/icons/192x192.png"
|
||||||
|
},
|
||||||
|
"ios" : {
|
||||||
|
"appstore" : "unpackage/res/icons/1024x1024.png",
|
||||||
|
"ipad" : {
|
||||||
|
"app" : "unpackage/res/icons/76x76.png",
|
||||||
|
"app@2x" : "unpackage/res/icons/152x152.png",
|
||||||
|
"notification" : "unpackage/res/icons/20x20.png",
|
||||||
|
"notification@2x" : "unpackage/res/icons/40x40.png",
|
||||||
|
"proapp@2x" : "unpackage/res/icons/167x167.png",
|
||||||
|
"settings" : "unpackage/res/icons/29x29.png",
|
||||||
|
"settings@2x" : "unpackage/res/icons/58x58.png",
|
||||||
|
"spotlight" : "unpackage/res/icons/40x40.png",
|
||||||
|
"spotlight@2x" : "unpackage/res/icons/80x80.png"
|
||||||
|
},
|
||||||
|
"iphone" : {
|
||||||
|
"app@2x" : "unpackage/res/icons/120x120.png",
|
||||||
|
"app@3x" : "unpackage/res/icons/180x180.png",
|
||||||
|
"notification@2x" : "unpackage/res/icons/40x40.png",
|
||||||
|
"notification@3x" : "unpackage/res/icons/60x60.png",
|
||||||
|
"settings@2x" : "unpackage/res/icons/58x58.png",
|
||||||
|
"settings@3x" : "unpackage/res/icons/87x87.png",
|
||||||
|
"spotlight@2x" : "unpackage/res/icons/80x80.png",
|
||||||
|
"spotlight@3x" : "unpackage/res/icons/120x120.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/* 快应用特有相关 */
|
/* 快应用特有相关 */
|
||||||
|
|||||||
@@ -6,13 +6,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pages": [
|
"pages": [
|
||||||
{
|
|
||||||
"path": "pages/login/index",
|
|
||||||
"style": {
|
|
||||||
"navigationStyle": "custom",
|
|
||||||
"navigationBarTitleText": "登录"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"path": "pages/device/index",
|
"path": "pages/device/index",
|
||||||
"style": {
|
"style": {
|
||||||
@@ -20,6 +13,13 @@
|
|||||||
"navigationBarTitleText": "设备"
|
"navigationBarTitleText": "设备"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"path": "pages/login/index",
|
||||||
|
"style": {
|
||||||
|
"navigationStyle": "custom",
|
||||||
|
"navigationBarTitleText": "登录"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"path": "pages/device/detail/index",
|
"path": "pages/device/detail/index",
|
||||||
"style": {
|
"style": {
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.add-device-page__scroll {
|
.add-device-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-device-page__body {
|
.add-device-page__body {
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.complete-page__scroll {
|
.complete-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.complete-page__body {
|
.complete-page__body {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="complete-page">
|
<view class="complete-page">
|
||||||
<app-navbar title="设备配置" />
|
<app-navbar title="设备配置" />
|
||||||
<scroll-view class="complete-page__scroll" scroll-y>
|
<page-scroll-view class="complete-page__scroll">
|
||||||
<view class="complete-page__body">
|
<view class="complete-page__body">
|
||||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||||
<complete-success-hero />
|
<complete-success-hero />
|
||||||
@@ -107,7 +107,7 @@
|
|||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
<view class="complete-page__footer">
|
<view class="complete-page__footer">
|
||||||
<view
|
<view
|
||||||
class="complete-page__submit"
|
class="complete-page__submit"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="add-device-page">
|
<view class="add-device-page">
|
||||||
<app-navbar title="添加设备" />
|
<app-navbar title="添加设备" />
|
||||||
<scroll-view class="add-device-page__scroll" scroll-y>
|
<page-scroll-view class="add-device-page__scroll">
|
||||||
<view class="add-device-page__body">
|
<view class="add-device-page__body">
|
||||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||||
<bind-bluetooth-hero />
|
<bind-bluetooth-hero />
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="pair-page">
|
<view class="pair-page">
|
||||||
<app-navbar title="设备配置" />
|
<app-navbar title="设备配置" />
|
||||||
<scroll-view class="pair-page__scroll" scroll-y>
|
<page-scroll-view class="pair-page__scroll">
|
||||||
<view class="pair-page__body">
|
<view class="pair-page__body">
|
||||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||||
<pair-hero />
|
<pair-hero />
|
||||||
@@ -33,7 +33,7 @@
|
|||||||
<pair-check-list :items="checkItems" />
|
<pair-check-list :items="checkItems" />
|
||||||
<pair-device-summary :device="device" :connect-status="connectStatus" />
|
<pair-device-summary :device="device" :connect-status="connectStatus" />
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
<view class="pair-page__footer">
|
<view class="pair-page__footer">
|
||||||
<view
|
<view
|
||||||
v-if="connectStatus === 'failed'"
|
v-if="connectStatus === 'failed'"
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.pair-page__scroll {
|
.pair-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.pair-page__body {
|
.pair-page__body {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="scan-page">
|
<view class="scan-page">
|
||||||
<app-navbar title="扫描设备" />
|
<app-navbar title="扫描设备" />
|
||||||
<scroll-view class="scan-page__scroll" scroll-y>
|
<page-scroll-view class="scan-page__scroll">
|
||||||
<view class="scan-page__body">
|
<view class="scan-page__body">
|
||||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||||
<scan-hero />
|
<scan-hero />
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
|
|
||||||
<scan-help-tip />
|
<scan-help-tip />
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -7,8 +7,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.scan-page__scroll {
|
.scan-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.scan-page__body {
|
.scan-page__body {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="agreement-page">
|
<view class="agreement-page">
|
||||||
<app-navbar :title="title" />
|
<app-navbar :title="title" />
|
||||||
<scroll-view class="agreement-page__scroll" scroll-y>
|
<page-scroll-view class="agreement-page__scroll">
|
||||||
<view class="agreement-page__content">
|
<view class="agreement-page__content">
|
||||||
<view v-if="loading" class="agreement-page__loading">
|
<view v-if="loading" class="agreement-page__loading">
|
||||||
<text>加载中...</text>
|
<text>加载中...</text>
|
||||||
</view>
|
</view>
|
||||||
<text v-else class="agreement-page__text">{{ content }}</text>
|
<text v-else class="agreement-page__text">{{ content }}</text>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -27,8 +27,7 @@ const { title, content, loading } = useAgreement()
|
|||||||
}
|
}
|
||||||
|
|
||||||
.agreement-page__scroll {
|
.agreement-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: calc(100vh - 88rpx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.agreement-page__content {
|
.agreement-page__content {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<base-input v-model="password" icon="lock" type="password" placeholder="请输入密码" />
|
<base-input v-model="password" icon="lock" type="password" placeholder="请输入密码" />
|
||||||
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="确认密码" />
|
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="确认密码" />
|
||||||
|
|
||||||
<text class="auth-form-page__hint">8-20位字符,须包含字母、数字、符号中的至少2种。</text>
|
<text class="auth-form-page__hint">{{ passwordRuleHint }}</text>
|
||||||
|
|
||||||
<view class="auth-form-page__btn">
|
<view class="auth-form-page__btn">
|
||||||
<primary-button text="确认修改" @click="submit" />
|
<primary-button text="确认修改" @click="submit" />
|
||||||
@@ -17,8 +17,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { PASSWORD_RULE_HINT } from '@/utils/validate'
|
||||||
import { useChangePassword } from './use-change-password'
|
import { useChangePassword } from './use-change-password'
|
||||||
|
|
||||||
|
const passwordRuleHint = `${PASSWORD_RULE_HINT}。`
|
||||||
|
|
||||||
const { password, confirmPassword, submit } = useChangePassword()
|
const { password, confirmPassword, submit } = useChangePassword()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { getErrorMessage } from '@/utils/api-error'
|
import { getErrorMessage } from '@/utils/api-error'
|
||||||
import { isValidStrongPassword } from '@/utils/validate'
|
import { isValidStrongPassword, PASSWORD_INVALID_TOAST } from '@/utils/validate'
|
||||||
import { resetPasswordByToken } from './change-password.api'
|
import { resetPasswordByToken } from './change-password.api'
|
||||||
|
|
||||||
export function useChangePassword() {
|
export function useChangePassword() {
|
||||||
@@ -27,10 +27,7 @@ export function useChangePassword() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!isValidStrongPassword(password.value)) {
|
if (!isValidStrongPassword(password.value)) {
|
||||||
uni.showToast({
|
uni.showToast({ title: PASSWORD_INVALID_TOAST, icon: 'none' })
|
||||||
title: '密码需8-20位,且包含字母、数字、符号中至少2种',
|
|
||||||
icon: 'none',
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (password.value !== confirmPassword.value) {
|
if (password.value !== confirmPassword.value) {
|
||||||
|
|||||||
@@ -163,8 +163,7 @@
|
|||||||
.device-detail-page__scroll {
|
.device-detail-page__scroll {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
margin-top: -40rpx;
|
margin-top: -40rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
<text class="device-detail-hero__sync">{{ syncText }}</text>
|
<text class="device-detail-hero__sync">{{ syncText }}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<scroll-view class="device-detail-page__scroll" scroll-y>
|
<page-scroll-view class="device-detail-page__scroll" :scroll-style="detailScrollStyle">
|
||||||
<view class="device-detail-panel">
|
<view class="device-detail-panel">
|
||||||
<view class="device-detail-panel__dash" aria-hidden="true" />
|
<view class="device-detail-panel__dash" aria-hidden="true" />
|
||||||
|
|
||||||
@@ -140,7 +140,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
|
|
||||||
<filter-replace-dialog
|
<filter-replace-dialog
|
||||||
v-model:visible="filterReplaceDialogVisible"
|
v-model:visible="filterReplaceDialogVisible"
|
||||||
@@ -152,12 +152,16 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import { usePageScrollHeight } from '@/hooks/use-page-scroll-height'
|
||||||
import { staticAssets } from '@/utils/static-assets'
|
import { staticAssets } from '@/utils/static-assets'
|
||||||
import FilterReplaceDialog from './components/filter-replace-dialog/index.vue'
|
import FilterReplaceDialog from './components/filter-replace-dialog/index.vue'
|
||||||
import RunModeExplainDialog from './components/run-mode-explain-dialog/index.vue'
|
import RunModeExplainDialog from './components/run-mode-explain-dialog/index.vue'
|
||||||
import { useDeviceDetail } from './use-device-detail'
|
import { useDeviceDetail } from './use-device-detail'
|
||||||
|
|
||||||
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight ?? 0)
|
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight ?? 0)
|
||||||
|
const { scrollStyle: detailScrollStyle } = usePageScrollHeight({
|
||||||
|
topSelector: '.device-detail-hero',
|
||||||
|
})
|
||||||
const runModeExplainVisible = ref(false)
|
const runModeExplainVisible = ref(false)
|
||||||
|
|
||||||
function onOpenRunModeExplain() {
|
function onOpenRunModeExplain() {
|
||||||
|
|||||||
@@ -4,3 +4,16 @@
|
|||||||
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
|
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.device-page__loading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
min-height: 360rpx;
|
||||||
|
padding: 48rpx 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.device-page__loading-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<view class="home-manage-page">
|
<view class="home-manage-page">
|
||||||
<app-navbar title="家庭管理" />
|
<app-navbar title="家庭管理" />
|
||||||
|
|
||||||
<scroll-view class="home-manage-page__scroll" scroll-y>
|
<page-scroll-view class="home-manage-page__scroll">
|
||||||
<view class="home-manage-page__body">
|
<view class="home-manage-page__body">
|
||||||
<text class="home-manage-page__summary">{{ summaryText }}</text>
|
<text class="home-manage-page__summary">{{ summaryText }}</text>
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
|
|
||||||
<home-name-dialog
|
<home-name-dialog
|
||||||
v-model:visible="nameDialogVisible"
|
v-model:visible="nameDialogVisible"
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.home-manage-page__scroll {
|
.home-manage-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.home-manage-page__body {
|
.home-manage-page__body {
|
||||||
@@ -73,11 +72,18 @@
|
|||||||
margin-left: 32rpx;
|
margin-left: 32rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.home-manage-page__loading,
|
||||||
.home-manage-page__empty {
|
.home-manage-page__empty {
|
||||||
padding: 120rpx 32rpx;
|
padding: 120rpx 32rpx;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.home-manage-page__loading-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
line-height: 1.5;
|
||||||
|
}
|
||||||
|
|
||||||
.home-manage-page__empty-text {
|
.home-manage-page__empty-text {
|
||||||
font-size: 28rpx;
|
font-size: 28rpx;
|
||||||
color: #999;
|
color: #999;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<view class="home-manage-page">
|
<view class="home-manage-page">
|
||||||
<app-navbar title="家庭管理" />
|
<app-navbar title="家庭管理" />
|
||||||
|
|
||||||
<scroll-view class="home-manage-page__scroll" scroll-y>
|
<page-scroll-view class="home-manage-page__scroll">
|
||||||
<view class="home-manage-page__body">
|
<view class="home-manage-page__body">
|
||||||
<view v-if="homes.length" class="home-manage-page__list">
|
<view v-if="homes.length" class="home-manage-page__list">
|
||||||
<view
|
<view
|
||||||
@@ -20,11 +20,14 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view v-else-if="!loading" class="home-manage-page__empty">
|
<view v-else-if="loading" class="home-manage-page__loading">
|
||||||
|
<text class="home-manage-page__loading-text">加载中...</text>
|
||||||
|
</view>
|
||||||
|
<view v-else class="home-manage-page__empty">
|
||||||
<text class="home-manage-page__empty-text">暂无家庭</text>
|
<text class="home-manage-page__empty-text">暂无家庭</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import {
|
||||||
|
buildUpdateHomeBody,
|
||||||
|
isValidHomeName,
|
||||||
|
updateHome,
|
||||||
|
} from '@/api/home'
|
||||||
|
import { getErrorMessage } from '@/utils/api-error'
|
||||||
import { parseId } from '@/utils/device-id'
|
import { parseId } from '@/utils/device-id'
|
||||||
import { formatCoordinateAddress, reverseGeocode } from '@/utils/map-geocode'
|
import { formatCoordinateAddress, reverseGeocode } from '@/utils/map-geocode'
|
||||||
import { loadHomeGeo, saveHomeGeo } from '../use-home-manage'
|
import { loadHomeGeo, saveHomeGeo } from '../use-home-manage'
|
||||||
@@ -21,6 +27,8 @@ function requestUserLocation(): Promise<UniApp.GetLocationSuccess> {
|
|||||||
|
|
||||||
export function useHomeLocation() {
|
export function useHomeLocation() {
|
||||||
const homeId = ref('')
|
const homeId = ref('')
|
||||||
|
const homeName = ref('我的家')
|
||||||
|
const saving = ref(false)
|
||||||
const latitude = ref(DEFAULT_LATITUDE)
|
const latitude = ref(DEFAULT_LATITUDE)
|
||||||
const longitude = ref(DEFAULT_LONGITUDE)
|
const longitude = ref(DEFAULT_LONGITUDE)
|
||||||
const searchKeyword = ref('')
|
const searchKeyword = ref('')
|
||||||
@@ -136,11 +144,17 @@ export function useHomeLocation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onConfirm() {
|
async function onConfirm() {
|
||||||
if (!homeId.value) {
|
if (!homeId.value) {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!isValidHomeName(homeName.value)) {
|
||||||
|
uni.showToast({ title: '家庭名称需 2-10 个字符', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (saving.value) return
|
||||||
|
|
||||||
const address = addressText.value.trim()
|
const address = addressText.value.trim()
|
||||||
|| formatCoordinateAddress(latitude.value, longitude.value)
|
|| formatCoordinateAddress(latitude.value, longitude.value)
|
||||||
const geo: HomeGeoInfo = {
|
const geo: HomeGeoInfo = {
|
||||||
@@ -148,15 +162,30 @@ export function useHomeLocation() {
|
|||||||
latitude: latitude.value,
|
latitude: latitude.value,
|
||||||
longitude: longitude.value,
|
longitude: longitude.value,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saving.value = true
|
||||||
|
try {
|
||||||
|
await updateHome(
|
||||||
|
homeId.value,
|
||||||
|
buildUpdateHomeBody(homeName.value, { geo }),
|
||||||
|
)
|
||||||
saveHomeGeo(homeId.value, geo)
|
saveHomeGeo(homeId.value, geo)
|
||||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}, 300)
|
}, 300)
|
||||||
|
} catch (err) {
|
||||||
|
uni.showToast({ title: getErrorMessage(err, '保存家庭位置失败'), icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
saving.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onLoad((query?: Record<string, string | undefined>) => {
|
onLoad((query?: Record<string, string | undefined>) => {
|
||||||
homeId.value = parseId(query?.homeId)
|
homeId.value = parseId(query?.homeId)
|
||||||
|
if (query?.homeName) {
|
||||||
|
homeName.value = decodeURIComponent(String(query.homeName))
|
||||||
|
}
|
||||||
const saved = homeId.value ? loadHomeGeo(homeId.value) : undefined
|
const saved = homeId.value ? loadHomeGeo(homeId.value) : undefined
|
||||||
if (query?.address) {
|
if (query?.address) {
|
||||||
addressText.value = decodeURIComponent(String(query.address))
|
addressText.value = decodeURIComponent(String(query.address))
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { resolveValidHomeId } from '@/api/home'
|
import {
|
||||||
|
buildUpdateHomeBody,
|
||||||
|
isValidHomeName,
|
||||||
|
resolveValidHomeId,
|
||||||
|
updateHome,
|
||||||
|
} from '@/api/home'
|
||||||
|
import type { AppHomeVo } from '@/types/location'
|
||||||
import { fetchRoomList } from '@/api/location'
|
import { fetchRoomList } from '@/api/location'
|
||||||
import { getErrorMessage } from '@/utils/api-error'
|
import { getErrorMessage } from '@/utils/api-error'
|
||||||
import { fetchHomeManageStats } from './home-manage.api'
|
import { fetchHomeManageStats } from './home-manage.api'
|
||||||
@@ -31,6 +37,8 @@ export function useHomeManage() {
|
|||||||
const homeAddress = ref('')
|
const homeAddress = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const nameDialogVisible = ref(false)
|
const nameDialogVisible = ref(false)
|
||||||
|
const currentHome = ref<AppHomeVo>()
|
||||||
|
const savingName = ref(false)
|
||||||
|
|
||||||
const summaryText = computed(
|
const summaryText = computed(
|
||||||
() => `共${roomCount.value}个房间,${deviceCount.value}个设备`,
|
() => `共${roomCount.value}个房间,${deviceCount.value}个设备`,
|
||||||
@@ -44,11 +52,22 @@ export function useHomeManage() {
|
|||||||
fetchHomeManageStats(homeId.value),
|
fetchHomeManageStats(homeId.value),
|
||||||
fetchRoomList(homeId.value),
|
fetchRoomList(homeId.value),
|
||||||
])
|
])
|
||||||
|
currentHome.value = stats.home
|
||||||
if (stats.home?.homeName) homeName.value = stats.home.homeName
|
if (stats.home?.homeName) homeName.value = stats.home.homeName
|
||||||
roomCount.value = rooms.length || stats.roomCount
|
roomCount.value = rooms.length || stats.roomCount
|
||||||
deviceCount.value = stats.deviceCount
|
deviceCount.value = stats.deviceCount
|
||||||
const geo = loadHomeGeo(homeId.value)
|
const geo = loadHomeGeo(homeId.value)
|
||||||
homeAddress.value = geo?.address ?? ''
|
homeAddress.value =
|
||||||
|
stats.home?.homeLocationAddress?.trim()
|
||||||
|
|| geo?.address
|
||||||
|
|| ''
|
||||||
|
if (stats.home?.homeLocationAddress && stats.home.homeLocationLatitude != null) {
|
||||||
|
saveHomeGeo(homeId.value, {
|
||||||
|
address: stats.home.homeLocationAddress,
|
||||||
|
latitude: stats.home.homeLocationLatitude,
|
||||||
|
longitude: stats.home.homeLocationLongitude ?? 116.4074,
|
||||||
|
})
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
uni.showToast({ title: getErrorMessage(err, '加载家庭信息失败'), icon: 'none' })
|
uni.showToast({ title: getErrorMessage(err, '加载家庭信息失败'), icon: 'none' })
|
||||||
} finally {
|
} finally {
|
||||||
@@ -68,14 +87,31 @@ export function useHomeManage() {
|
|||||||
nameDialogVisible.value = true
|
nameDialogVisible.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function onConfirmHomeName(name: string) {
|
async function onConfirmHomeName(name: string) {
|
||||||
const trimmed = name.trim()
|
const trimmed = name.trim()
|
||||||
if (!trimmed) {
|
if (!isValidHomeName(trimmed)) {
|
||||||
uni.showToast({ title: '请输入家庭名称', icon: 'none' })
|
uni.showToast({ title: '家庭名称需 2-10 个字符', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!homeId.value || savingName.value) return
|
||||||
|
|
||||||
|
savingName.value = true
|
||||||
|
try {
|
||||||
|
const geo = loadHomeGeo(homeId.value)
|
||||||
|
await updateHome(
|
||||||
|
homeId.value,
|
||||||
|
buildUpdateHomeBody(trimmed, { geo, home: currentHome.value }),
|
||||||
|
)
|
||||||
homeName.value = trimmed
|
homeName.value = trimmed
|
||||||
uni.showToast({ title: '家庭名称修改接口待对接', icon: 'none' })
|
if (currentHome.value) {
|
||||||
|
currentHome.value = { ...currentHome.value, homeName: trimmed }
|
||||||
|
}
|
||||||
|
uni.showToast({ title: '修改成功', icon: 'success' })
|
||||||
|
} catch (err) {
|
||||||
|
uni.showToast({ title: getErrorMessage(err, '修改家庭名称失败'), icon: 'none' })
|
||||||
|
} finally {
|
||||||
|
savingName.value = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onOpenLocation() {
|
function onOpenLocation() {
|
||||||
|
|||||||
@@ -21,7 +21,10 @@
|
|||||||
@manage="onManageDevices"
|
@manage="onManageDevices"
|
||||||
@select="onSelectDevice"
|
@select="onSelectDevice"
|
||||||
/>
|
/>
|
||||||
<template v-else-if="!loading">
|
<view v-else-if="loading" class="device-page__loading">
|
||||||
|
<text class="device-page__loading-text">加载中...</text>
|
||||||
|
</view>
|
||||||
|
<template v-else>
|
||||||
<device-empty :step-hint="bindStepHint" @bind="onStartBind" />
|
<device-empty :step-hint="bindStepHint" @bind="onStartBind" />
|
||||||
<hot-devices :items="hotDevices" @mall="onGoMall" />
|
<hot-devices :items="hotDevices" @mall="onGoMall" />
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.device-settings-page__scroll {
|
.device-settings-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.device-settings-page__body {
|
.device-settings-page__body {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<view class="device-settings-page">
|
<view class="device-settings-page">
|
||||||
<app-navbar title="设备设置" />
|
<app-navbar title="设备设置" />
|
||||||
|
|
||||||
<scroll-view class="device-settings-page__scroll" scroll-y>
|
<page-scroll-view class="device-settings-page__scroll">
|
||||||
<view class="device-settings-page__body">
|
<view class="device-settings-page__body">
|
||||||
<view class="device-settings-card">
|
<view class="device-settings-card">
|
||||||
<view class="device-settings-card__top">
|
<view class="device-settings-card__top">
|
||||||
@@ -74,7 +74,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
|
|
||||||
<device-name-dialog
|
<device-name-dialog
|
||||||
v-model:visible="nameDialogVisible"
|
v-model:visible="nameDialogVisible"
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { onHide, onShow } from '@dcloudio/uni-app'
|
|||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { refreshUnreadMessageCount } from '@/hooks/use-message-inbox'
|
import { refreshUnreadMessageCount } from '@/hooks/use-message-inbox'
|
||||||
import { fetchHomeList, resolveValidHomeId } from '@/api/home'
|
import { fetchHomeList, resolveValidHomeId } from '@/api/home'
|
||||||
|
import { getStoredToken } from '@/utils/auth-token'
|
||||||
import { parseId, sameId } from '@/utils/device-id'
|
import { parseId, sameId } from '@/utils/device-id'
|
||||||
import { createLocation } from '@/api/location'
|
import { createLocation } from '@/api/location'
|
||||||
import { getErrorMessage } from '@/utils/api-error'
|
import { getErrorMessage } from '@/utils/api-error'
|
||||||
@@ -131,6 +132,10 @@ export function useDevice() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onShow(() => {
|
onShow(() => {
|
||||||
|
if (!getStoredToken()) {
|
||||||
|
uni.reLaunch({ url: '/pages/login/index' })
|
||||||
|
return
|
||||||
|
}
|
||||||
void loadDevices()
|
void loadDevices()
|
||||||
void refreshUnreadMessageCount()
|
void refreshUnreadMessageCount()
|
||||||
startPresencePolling()
|
startPresencePolling()
|
||||||
|
|||||||
@@ -8,7 +8,16 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<template v-if="mode === 'code'">
|
<template v-if="mode === 'password'">
|
||||||
|
<base-input v-model="account" icon="phone" placeholder="请输入账号" />
|
||||||
|
<base-input v-model="password" icon="lock" type="password" placeholder="请输入密码" />
|
||||||
|
<view class="login-page__links">
|
||||||
|
<text class="login-page__link" @tap="switchMode('code')">验证码登录</text>
|
||||||
|
<text class="login-page__link" @tap="goForgotPassword">忘记密码?</text>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template v-else>
|
||||||
<base-input v-model="phone" icon="phone" type="number" placeholder="请输入手机号" :maxlength="11" />
|
<base-input v-model="phone" icon="phone" type="number" placeholder="请输入手机号" :maxlength="11" />
|
||||||
<base-input v-model="code" icon="shield" type="number" placeholder="请输入验证码" :maxlength="6">
|
<base-input v-model="code" icon="shield" type="number" placeholder="请输入验证码" :maxlength="6">
|
||||||
<template #suffix>
|
<template #suffix>
|
||||||
@@ -20,15 +29,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<base-input v-model="account" icon="phone" placeholder="请输入账号" />
|
|
||||||
<base-input v-model="password" icon="lock" type="password" placeholder="请输入密码" />
|
|
||||||
<view class="login-page__links">
|
|
||||||
<text class="login-page__link" @tap="switchMode('code')">验证码登录</text>
|
|
||||||
<text class="login-page__link" @tap="goForgotPassword">忘记密码?</text>
|
|
||||||
</view>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<view class="login-page__footer">
|
<view class="login-page__footer">
|
||||||
<view class="login-page__agreement">
|
<view class="login-page__agreement">
|
||||||
<agreement-checkbox v-model="agreed" />
|
<agreement-checkbox v-model="agreed" />
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { onShow } from '@dcloudio/uni-app'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useSmsCode } from '@/hooks/use-sms-code'
|
import { useSmsCode } from '@/hooks/use-sms-code'
|
||||||
import { isValidPassword, isValidPhone, isValidSmsCode } from '@/utils/validate'
|
import { isValidPassword, isValidPhone, isValidSmsCode } from '@/utils/validate'
|
||||||
@@ -10,8 +11,8 @@ import { loginByPassword, loginBySms } from './login.api'
|
|||||||
import type { LoginMode } from './login.types'
|
import type { LoginMode } from './login.types'
|
||||||
|
|
||||||
export function useLogin() {
|
export function useLogin() {
|
||||||
const mode = ref<LoginMode>('code')
|
const mode = ref<LoginMode>('password')
|
||||||
const agreed = ref(true)
|
const agreed = ref(false)
|
||||||
const phone = ref('')
|
const phone = ref('')
|
||||||
const code = ref('')
|
const code = ref('')
|
||||||
const account = ref('')
|
const account = ref('')
|
||||||
@@ -85,6 +86,12 @@ export function useLogin() {
|
|||||||
uni.navigateTo({ url: '/pages/forgot-password/index' })
|
uni.navigateTo({ url: '/pages/forgot-password/index' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
if (!getStoredToken()) return
|
||||||
|
setupMessageInbox()
|
||||||
|
uni.reLaunch({ url: '/pages/device/index' })
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode,
|
mode,
|
||||||
agreed,
|
agreed,
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.edit-profile-page__scroll {
|
.edit-profile-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.edit-profile-page__body {
|
.edit-profile-page__body {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<app-navbar title="编辑资料" />
|
<app-navbar title="编辑资料" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<scroll-view class="edit-profile-page__scroll" scroll-y>
|
<page-scroll-view class="edit-profile-page__scroll">
|
||||||
<view class="edit-profile-page__body">
|
<view class="edit-profile-page__body">
|
||||||
<view class="edit-profile-page__avatar-section">
|
<view class="edit-profile-page__avatar-section">
|
||||||
<view class="edit-profile-page__avatar-wrap">
|
<view class="edit-profile-page__avatar-wrap">
|
||||||
@@ -118,7 +118,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
|
|
||||||
<view class="edit-profile-page__footer">
|
<view class="edit-profile-page__footer">
|
||||||
<view
|
<view
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { onShow } from '@dcloudio/uni-app'
|
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { fetchProfile, updateProfile, uploadProfileAvatar } from '@/api/profile'
|
import { fetchProfile, updateProfile, uploadProfileAvatar } from '@/api/profile'
|
||||||
import { getErrorMessage } from '@/utils/api-error'
|
import { getErrorMessage } from '@/utils/api-error'
|
||||||
@@ -56,11 +56,7 @@ export function useEditProfile() {
|
|||||||
const locationText = computed(() =>
|
const locationText = computed(() =>
|
||||||
formatLocation(form.value.province, form.value.city, form.value.district),
|
formatLocation(form.value.province, form.value.city, form.value.district),
|
||||||
)
|
)
|
||||||
async function loadProfile() {
|
function applyProfile(profile: Awaited<ReturnType<typeof fetchProfile>>) {
|
||||||
if (loading.value) return
|
|
||||||
loading.value = true
|
|
||||||
try {
|
|
||||||
const profile = await fetchProfile()
|
|
||||||
form.value = {
|
form.value = {
|
||||||
nickName: profile.nickName || profile.userName || '',
|
nickName: profile.nickName || profile.userName || '',
|
||||||
gender: profile.gender || '0',
|
gender: profile.gender || '0',
|
||||||
@@ -72,6 +68,13 @@ export function useEditProfile() {
|
|||||||
avatarUrl: profile.avatarUrl || '',
|
avatarUrl: profile.avatarUrl || '',
|
||||||
avatarOssId: profile.avatarOssId ? String(profile.avatarOssId) : '',
|
avatarOssId: profile.avatarOssId ? String(profile.avatarOssId) : '',
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadProfile() {
|
||||||
|
if (loading.value) return
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
applyProfile(await fetchProfile())
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
uni.showToast({ title: getErrorMessage(err, '加载资料失败'), icon: 'none' })
|
uni.showToast({ title: getErrorMessage(err, '加载资料失败'), icon: 'none' })
|
||||||
} finally {
|
} finally {
|
||||||
@@ -79,6 +82,16 @@ export function useEditProfile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 从换绑手机号等子页返回时只刷新手机号,避免覆盖未保存的头像等编辑 */
|
||||||
|
async function refreshPhoneFromServer() {
|
||||||
|
try {
|
||||||
|
const profile = await fetchProfile()
|
||||||
|
form.value.phonenumber = profile.phonenumber || profile.userName || ''
|
||||||
|
} catch {
|
||||||
|
// 静默失败,保留当前表单
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function onOpenAvatarSheet() {
|
function onOpenAvatarSheet() {
|
||||||
avatarSheetVisible.value = true
|
avatarSheetVisible.value = true
|
||||||
}
|
}
|
||||||
@@ -105,6 +118,7 @@ export function useEditProfile() {
|
|||||||
const filePath = res.tempFilePaths[0]
|
const filePath = res.tempFilePaths[0]
|
||||||
if (!filePath) return
|
if (!filePath) return
|
||||||
|
|
||||||
|
form.value.avatarUrl = filePath
|
||||||
uploadingAvatar.value = true
|
uploadingAvatar.value = true
|
||||||
uni.showLoading({ title: '上传中...', mask: true })
|
uni.showLoading({ title: '上传中...', mask: true })
|
||||||
const uploaded = await uploadProfileAvatar(filePath)
|
const uploaded = await uploadProfileAvatar(filePath)
|
||||||
@@ -200,10 +214,14 @@ export function useEditProfile() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onShow(() => {
|
onLoad(() => {
|
||||||
void loadProfile()
|
void loadProfile()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
onShow(() => {
|
||||||
|
void refreshPhoneFromServer()
|
||||||
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
loading,
|
loading,
|
||||||
saving,
|
saving,
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
</template>
|
</template>
|
||||||
</app-navbar>
|
</app-navbar>
|
||||||
|
|
||||||
<scroll-view
|
<page-scroll-view
|
||||||
class="notify-page__scroll"
|
class="notify-page__scroll"
|
||||||
scroll-y
|
|
||||||
refresher-enabled
|
refresher-enabled
|
||||||
:refresher-triggered="loading"
|
:refresher-triggered="loading"
|
||||||
@refresherrefresh="onRefresh"
|
@refresherrefresh="onRefresh"
|
||||||
@@ -50,7 +49,7 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.notify-page__scroll {
|
.notify-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.notify-page__body {
|
.notify-page__body {
|
||||||
|
|||||||
@@ -0,0 +1,197 @@
|
|||||||
|
<template>
|
||||||
|
<view v-if="visible" class="cancel-account-dialog">
|
||||||
|
<view class="cancel-account-dialog__mask" @tap="onCancel" />
|
||||||
|
<view class="cancel-account-dialog__panel" @tap.stop>
|
||||||
|
<text class="cancel-account-dialog__title">注销账号</text>
|
||||||
|
<view class="cancel-account-dialog__body">
|
||||||
|
<text class="cancel-account-dialog__warn">
|
||||||
|
注销后账号及所有数据将被永久删除,且无法恢复,请谨慎操作。
|
||||||
|
</text>
|
||||||
|
<text class="cancel-account-dialog__item">· 已绑定的智能设备将全部解绑</text>
|
||||||
|
<text class="cancel-account-dialog__item">· 家庭、订单及客服记录将无法找回</text>
|
||||||
|
<text class="cancel-account-dialog__item">· 注销完成后需重新注册才能使用</text>
|
||||||
|
</view>
|
||||||
|
<view class="cancel-account-dialog__footer">
|
||||||
|
<view class="cancel-account-dialog__btn" @tap.stop="onCancel">
|
||||||
|
<text class="cancel-account-dialog__btn-text">我再想想</text>
|
||||||
|
</view>
|
||||||
|
<view class="cancel-account-dialog__divider-v" />
|
||||||
|
<view
|
||||||
|
class="cancel-account-dialog__btn"
|
||||||
|
:class="{ 'cancel-account-dialog__btn--disabled': !canConfirm }"
|
||||||
|
@tap.stop="onConfirm"
|
||||||
|
>
|
||||||
|
<text
|
||||||
|
class="cancel-account-dialog__btn-text cancel-account-dialog__btn-text--danger"
|
||||||
|
:class="{ 'cancel-account-dialog__btn-text--disabled': !canConfirm }"
|
||||||
|
>
|
||||||
|
{{ confirmText }}
|
||||||
|
</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, onUnmounted, ref, watch } from 'vue'
|
||||||
|
|
||||||
|
const COUNTDOWN_SECONDS = 10
|
||||||
|
|
||||||
|
const props = defineProps<{
|
||||||
|
visible: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const emit = defineEmits<{
|
||||||
|
'update:visible': [value: boolean]
|
||||||
|
confirm: []
|
||||||
|
}>()
|
||||||
|
|
||||||
|
const countdown = ref(COUNTDOWN_SECONDS)
|
||||||
|
let timer: ReturnType<typeof setInterval> | undefined
|
||||||
|
|
||||||
|
const canConfirm = computed(() => countdown.value <= 0)
|
||||||
|
|
||||||
|
const confirmText = computed(() =>
|
||||||
|
canConfirm.value ? '确认注销' : `确认注销(${countdown.value}s)`,
|
||||||
|
)
|
||||||
|
|
||||||
|
function clearTimer() {
|
||||||
|
if (timer) clearInterval(timer)
|
||||||
|
timer = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCountdown() {
|
||||||
|
clearTimer()
|
||||||
|
countdown.value = COUNTDOWN_SECONDS
|
||||||
|
timer = setInterval(() => {
|
||||||
|
if (countdown.value <= 1) {
|
||||||
|
countdown.value = 0
|
||||||
|
clearTimer()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
countdown.value -= 1
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.visible,
|
||||||
|
(visible) => {
|
||||||
|
if (visible) startCountdown()
|
||||||
|
else clearTimer()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
onUnmounted(clearTimer)
|
||||||
|
|
||||||
|
function onCancel() {
|
||||||
|
emit('update:visible', false)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onConfirm() {
|
||||||
|
if (!canConfirm.value) return
|
||||||
|
emit('confirm')
|
||||||
|
emit('update:visible', false)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.cancel-account-dialog {
|
||||||
|
position: fixed;
|
||||||
|
inset: 0;
|
||||||
|
z-index: 500;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__mask {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: rgba(0, 0, 0, 0.55);
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__panel {
|
||||||
|
position: relative;
|
||||||
|
width: 600rpx;
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 24rpx;
|
||||||
|
overflow: hidden;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__title {
|
||||||
|
display: block;
|
||||||
|
padding: 48rpx 40rpx 24rpx;
|
||||||
|
font-size: 34rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: $color-text;
|
||||||
|
text-align: center;
|
||||||
|
line-height: 1.3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__body {
|
||||||
|
padding: 0 40rpx 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__warn {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #f04438;
|
||||||
|
line-height: 1.6;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__item {
|
||||||
|
display: block;
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: $color-text-secondary;
|
||||||
|
line-height: 1.65;
|
||||||
|
text-align: left;
|
||||||
|
margin-bottom: 10rpx;
|
||||||
|
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__footer {
|
||||||
|
display: flex;
|
||||||
|
align-items: stretch;
|
||||||
|
border-top: 1rpx solid #ebedf0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__btn {
|
||||||
|
flex: 1;
|
||||||
|
height: 96rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
&--disabled {
|
||||||
|
opacity: 0.45;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__divider-v {
|
||||||
|
width: 1rpx;
|
||||||
|
background: #ebedf0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cancel-account-dialog__btn-text {
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: $color-text;
|
||||||
|
line-height: 1;
|
||||||
|
|
||||||
|
&--danger {
|
||||||
|
color: #f04438;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&--disabled {
|
||||||
|
color: #98a2b3;
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<view class="privacy-page">
|
<view class="privacy-page">
|
||||||
<app-navbar title="账号与安全" />
|
<app-navbar title="账号与安全" />
|
||||||
|
|
||||||
<scroll-view class="privacy-page__scroll" scroll-y>
|
<page-scroll-view class="privacy-page__scroll">
|
||||||
<view class="privacy-page__body">
|
<view class="privacy-page__body">
|
||||||
<view
|
<view
|
||||||
v-for="section in sections"
|
v-for="section in sections"
|
||||||
@@ -54,15 +54,27 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
|
|
||||||
|
<cancel-account-dialog
|
||||||
|
v-model:visible="cancelAccountDialogVisible"
|
||||||
|
@confirm="onConfirmCancelAccount"
|
||||||
|
/>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { staticAssets } from '@/utils/static-assets'
|
import { staticAssets } from '@/utils/static-assets'
|
||||||
|
import CancelAccountDialog from './components/cancel-account-dialog/index.vue'
|
||||||
import { usePrivacy } from './use-privacy'
|
import { usePrivacy } from './use-privacy'
|
||||||
|
|
||||||
const { sections, onItemTap, onLogout } = usePrivacy()
|
const {
|
||||||
|
sections,
|
||||||
|
cancelAccountDialogVisible,
|
||||||
|
onItemTap,
|
||||||
|
onLogout,
|
||||||
|
onConfirmCancelAccount,
|
||||||
|
} = usePrivacy()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.privacy-page__scroll {
|
.privacy-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.privacy-page__body {
|
.privacy-page__body {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ function maskPhone(phone?: string): string {
|
|||||||
|
|
||||||
export function usePrivacy() {
|
export function usePrivacy() {
|
||||||
const phone = ref('')
|
const phone = ref('')
|
||||||
|
const cancelAccountDialogVisible = ref(false)
|
||||||
|
const cancelingAccount = ref(false)
|
||||||
|
|
||||||
const sections = computed<PrivacySection[]>(() => [
|
const sections = computed<PrivacySection[]>(() => [
|
||||||
{
|
{
|
||||||
@@ -66,13 +68,13 @@ export function usePrivacy() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (itemId === 'delete-account') {
|
if (itemId === 'delete-account') {
|
||||||
uni.showModal({
|
cancelAccountDialogVisible.value = true
|
||||||
title: '注销账号',
|
}
|
||||||
content: '注销后账号及所有数据将被永久删除,且无法恢复。确定继续吗?',
|
}
|
||||||
confirmColor: '#f04438',
|
|
||||||
success: (res) => {
|
async function onConfirmCancelAccount() {
|
||||||
if (!res.confirm) return
|
if (cancelingAccount.value) return
|
||||||
void (async () => {
|
cancelingAccount.value = true
|
||||||
try {
|
try {
|
||||||
await cancelAccount()
|
await cancelAccount()
|
||||||
teardownMessageInbox()
|
teardownMessageInbox()
|
||||||
@@ -81,10 +83,8 @@ export function usePrivacy() {
|
|||||||
uni.reLaunch({ url: '/pages/login/index' })
|
uni.reLaunch({ url: '/pages/login/index' })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
uni.showToast({ title: getErrorMessage(err, '注销失败'), icon: 'none' })
|
uni.showToast({ title: getErrorMessage(err, '注销失败'), icon: 'none' })
|
||||||
}
|
} finally {
|
||||||
})()
|
cancelingAccount.value = false
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,7 +118,9 @@ export function usePrivacy() {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
sections,
|
sections,
|
||||||
|
cancelAccountDialogVisible,
|
||||||
onItemTap,
|
onItemTap,
|
||||||
onLogout,
|
onLogout,
|
||||||
|
onConfirmCancelAccount,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="确认密码" />
|
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="确认密码" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<text class="set-password-page__hint">8-20位字符,须包含字母、数字、符号中的至少2种。</text>
|
<text class="set-password-page__hint">{{ passwordRuleHint }}</text>
|
||||||
|
|
||||||
<view class="set-password-page__btn">
|
<view class="set-password-page__btn">
|
||||||
<primary-button text="确认修改" @click="submit" />
|
<primary-button text="确认修改" @click="submit" />
|
||||||
@@ -23,8 +23,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { PASSWORD_RULE_HINT } from '@/utils/validate'
|
||||||
import { useSetPassword } from './use-set-password'
|
import { useSetPassword } from './use-set-password'
|
||||||
|
|
||||||
|
const passwordRuleHint = `${PASSWORD_RULE_HINT}。`
|
||||||
|
|
||||||
const { password, confirmPassword, onForgotPassword, submit } = useSetPassword()
|
const { password, confirmPassword, onForgotPassword, submit } = useSetPassword()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<view class="storage-page">
|
<view class="storage-page">
|
||||||
<app-navbar title="储存空间" />
|
<app-navbar title="储存空间" />
|
||||||
|
|
||||||
<scroll-view class="storage-page__scroll" scroll-y>
|
<page-scroll-view class="storage-page__scroll">
|
||||||
<view class="storage-page__body">
|
<view class="storage-page__body">
|
||||||
<text class="storage-page__section-label">储存空间</text>
|
<text class="storage-page__section-label">储存空间</text>
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</page-scroll-view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.storage-page__scroll {
|
.storage-page__scroll {
|
||||||
flex: 1;
|
width: 100%;
|
||||||
height: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.storage-page__body {
|
.storage-page__body {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { resolveCsAppToken } from '@/api/request'
|
import { getApiBaseUrl } from '@/config/app-env'
|
||||||
|
import { getStoredToken } from '@/utils/auth-token'
|
||||||
import type { CsChatWsPayload, CsMessageVo, CsSessionVo } from './support.types'
|
import type { CsChatWsPayload, CsMessageVo, CsSessionVo } from './support.types'
|
||||||
|
|
||||||
/** 断线后首次重连等待(非轮询;连接成功后会保持长连接) */
|
/** 断线后首次重连等待(非轮询;连接成功后会保持长连接) */
|
||||||
@@ -28,26 +29,18 @@ function resolveCsChatWsBase(): string {
|
|||||||
|
|
||||||
if (isH5Dev() && !forceDirect) {
|
if (isH5Dev() && !forceDirect) {
|
||||||
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||||
const useCsHost = !!import.meta.env.VITE_CS_API_BASE_URL?.trim()
|
return `${proto}//${window.location.host}/app/cs/chat`
|
||||||
const path = useCsHost ? '/cs-app/cs/chat' : '/app/cs/chat'
|
|
||||||
return `${proto}//${window.location.host}${path}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configured) {
|
if (configured) {
|
||||||
return configured.replace(/[?#].*$/, '').replace(/\/$/, '')
|
return configured.replace(/[?#].*$/, '').replace(/\/$/, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
const csBase = import.meta.env.VITE_CS_API_BASE_URL?.trim()
|
const httpBase =
|
||||||
if (csBase) {
|
getApiBaseUrl()
|
||||||
const wsBase = csBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws').replace(/\/$/, '')
|
|| import.meta.env.VITE_API_PROXY_TARGET?.trim()
|
||||||
return `${wsBase}/app/cs/chat`
|
|| 'http://192.168.0.222:8082'
|
||||||
}
|
const wsBase = httpBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws').replace(/\/$/, '')
|
||||||
|
|
||||||
const envBase = import.meta.env.VITE_API_BASE_URL?.trim() || ''
|
|
||||||
const fallback =
|
|
||||||
import.meta.env.VITE_API_PROXY_TARGET?.trim() || 'http://192.168.0.222:8082'
|
|
||||||
const httpBase = envBase || fallback
|
|
||||||
const wsBase = httpBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws')
|
|
||||||
return `${wsBase}/app/cs/chat`
|
return `${wsBase}/app/cs/chat`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +72,7 @@ function clearReconnectTimer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function scheduleReconnect() {
|
function scheduleReconnect() {
|
||||||
if (manualClosed || !resolveCsAppToken() || !activeSessionId) return
|
if (manualClosed || !getStoredToken() || !activeSessionId) return
|
||||||
clearReconnectTimer()
|
clearReconnectTimer()
|
||||||
const delay = Math.min(
|
const delay = Math.min(
|
||||||
RECONNECT_BASE_MS * Math.pow(1.5, reconnectAttempt),
|
RECONNECT_BASE_MS * Math.pow(1.5, reconnectAttempt),
|
||||||
@@ -209,7 +202,7 @@ function bindSocketTask(task: UniApp.SocketTask, seq: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function connectCsChatSocket(sessionId: string) {
|
export function connectCsChatSocket(sessionId: string) {
|
||||||
const token = resolveCsAppToken()
|
const token = getStoredToken()
|
||||||
if (!token || !sessionId) return
|
if (!token || !sessionId) return
|
||||||
if (connecting) return
|
if (connecting) return
|
||||||
if (socketOpened && socketTask && activeSessionId === sessionId) return
|
if (socketOpened && socketTask && activeSessionId === sessionId) return
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { resolveCsAppBaseUrl, request, requestCsApp, uploadAppFile } from '@/api/request'
|
import { isCsAuthError, request, uploadAppFile } from '@/api/request'
|
||||||
import { assertCsUploadToken, ensureCsUploadReady } from '@/api/cs-auth'
|
import { getCsApiBaseUrl } from '@/config/app-env'
|
||||||
import { ApiError } from '@/utils/api-error'
|
import { ApiError } from '@/utils/api-error'
|
||||||
import {
|
import {
|
||||||
isSessionEnded,
|
isSessionEnded,
|
||||||
@@ -27,15 +27,20 @@ function buildSessionPath(sessionId: string, suffix = '') {
|
|||||||
return `/app/cs/session/${encodeURIComponent(sessionId)}${suffix}`
|
return `/app/cs/session/${encodeURIComponent(sessionId)}${suffix}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 客服会话相关接口统一走 212(与 upload / 图片 message 同服,保证 ossId、url 一致) */
|
/**
|
||||||
function csRequest<T>(options: Parameters<typeof request>[0]): Promise<T> {
|
* 客服会话 / 消息 / 转人工等走主站(222),与设备列表等同套 token + clientId。
|
||||||
return resolveCsAppBaseUrl() ? requestCsApp<T>(options) : request<T>(options)
|
* 仅图片上传走 212(有 cs_token 用 clientId=app,否则主站 token + 主站 clientId)。
|
||||||
|
*/
|
||||||
|
function csSessionRequest<T>(options: Parameters<typeof request>[0]): Promise<T> {
|
||||||
|
return request<T>(options)
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveCsUploadUrl(): string {
|
function resolveCsUploadUrl(): string {
|
||||||
const csBase = resolveCsAppBaseUrl()
|
// #ifdef H5
|
||||||
if (csBase) return `${csBase}/cs/upload`
|
if (import.meta.env.DEV) return '/cs-app/cs/upload'
|
||||||
return '/app/cs/upload'
|
// #endif
|
||||||
|
const csBase = getCsApiBaseUrl()
|
||||||
|
return csBase ? `${csBase}/app/cs/upload` : '/app/cs/upload'
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeCsUploadVo(data: unknown): CzCsUploadVo {
|
function normalizeCsUploadVo(data: unknown): CzCsUploadVo {
|
||||||
@@ -66,7 +71,7 @@ function unwrapRows<T>(data: T[] | CsTableData<T> | undefined): T[] {
|
|||||||
|
|
||||||
/** POST /app/cs/session — 创建客服会话;已有未结束会话时返回原会话 */
|
/** POST /app/cs/session — 创建客服会话;已有未结束会话时返回原会话 */
|
||||||
export function createCsSession(data: CsCreateSessionBody = {}) {
|
export function createCsSession(data: CsCreateSessionBody = {}) {
|
||||||
return csRequest<CsAppActionVo | CsSessionVo | string | null>({
|
return csSessionRequest<CsAppActionVo | CsSessionVo | string | null>({
|
||||||
url: '/app/cs/session',
|
url: '/app/cs/session',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
@@ -113,7 +118,7 @@ export async function resolveCsSession(): Promise<CsResolvedSession> {
|
|||||||
|
|
||||||
/** GET /app/cs/session/list — 查询自己的会话 */
|
/** GET /app/cs/session/list — 查询自己的会话 */
|
||||||
export function fetchCsSessionList(query: CsSessionListQuery = {}) {
|
export function fetchCsSessionList(query: CsSessionListQuery = {}) {
|
||||||
return csRequest<CsSessionVo[] | CsTableData<CsSessionVo>>({
|
return csSessionRequest<CsSessionVo[] | CsTableData<CsSessionVo>>({
|
||||||
url: '/app/cs/session/list',
|
url: '/app/cs/session/list',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
data: query,
|
data: query,
|
||||||
@@ -122,7 +127,7 @@ export function fetchCsSessionList(query: CsSessionListQuery = {}) {
|
|||||||
|
|
||||||
/** GET /app/cs/session/{sessionId} — 查询会话详情 */
|
/** GET /app/cs/session/{sessionId} — 查询会话详情 */
|
||||||
export function fetchCsSessionDetail(sessionId: string) {
|
export function fetchCsSessionDetail(sessionId: string) {
|
||||||
return csRequest<CsAppActionVo | CsSessionVo | string | null>({
|
return csSessionRequest<CsAppActionVo | CsSessionVo | string | null>({
|
||||||
url: buildSessionPath(sessionId),
|
url: buildSessionPath(sessionId),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
}).then((data) => normalizeSessionResponse(unwrapCsActionResponse(data).session))
|
}).then((data) => normalizeSessionResponse(unwrapCsActionResponse(data).session))
|
||||||
@@ -130,19 +135,23 @@ export function fetchCsSessionDetail(sessionId: string) {
|
|||||||
|
|
||||||
/** GET /app/cs/session/{sessionId}/messages — 拉取会话消息 */
|
/** GET /app/cs/session/{sessionId}/messages — 拉取会话消息 */
|
||||||
export function fetchCsMessages(sessionId: string, afterSeq = 0) {
|
export function fetchCsMessages(sessionId: string, afterSeq = 0) {
|
||||||
return csRequest<CsMessageVo[] | CsTableData<CsMessageVo>>({
|
return csSessionRequest<CsMessageVo[] | CsTableData<CsMessageVo>>({
|
||||||
url: buildSessionPath(sessionId, '/messages'),
|
url: buildSessionPath(sessionId, '/messages'),
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
data: { afterSeq },
|
data: { afterSeq },
|
||||||
}).then(unwrapRows)
|
}).then(unwrapRows)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** POST /app/cs/upload — 212 上传(clientId=app + cs_token) */
|
/** POST /app/cs/upload — 优先 212;鉴权失败时回退主站 222 */
|
||||||
export function uploadCsChatImage(filePath: string): Promise<CzCsUploadVo> {
|
export async function uploadCsChatImage(filePath: string): Promise<CzCsUploadVo> {
|
||||||
assertCsUploadToken()
|
try {
|
||||||
return uploadAppFile<CzCsUploadVo>(resolveCsUploadUrl(), filePath, 'file', 'cs').then((data) =>
|
const data = await uploadAppFile<CzCsUploadVo>(resolveCsUploadUrl(), filePath, 'file', 'cs')
|
||||||
normalizeCsUploadVo(data),
|
return normalizeCsUploadVo(data)
|
||||||
)
|
} catch (err) {
|
||||||
|
if (!isCsAuthError(err)) throw err
|
||||||
|
const data = await uploadAppFile<CzCsUploadVo>('/app/cs/upload', filePath, 'file', 'default')
|
||||||
|
return normalizeCsUploadVo(data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 图片消息体:msgType + ossId + clientMsgId */
|
/** 图片消息体:msgType + ossId + clientMsgId */
|
||||||
@@ -161,8 +170,7 @@ export function buildCsImageMessageBody(
|
|||||||
|
|
||||||
/** POST /app/cs/session/{sessionId}/message — 发送消息 */
|
/** POST /app/cs/session/{sessionId}/message — 发送消息 */
|
||||||
export function sendCsMessage(sessionId: string, data: CsSendMessageBody) {
|
export function sendCsMessage(sessionId: string, data: CsSendMessageBody) {
|
||||||
if (resolveCsAppBaseUrl()) ensureCsUploadReady()
|
return csSessionRequest<CsAppActionVo>({
|
||||||
return csRequest<CsAppActionVo>({
|
|
||||||
url: buildSessionPath(sessionId, '/message'),
|
url: buildSessionPath(sessionId, '/message'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
@@ -171,7 +179,7 @@ export function sendCsMessage(sessionId: string, data: CsSendMessageBody) {
|
|||||||
|
|
||||||
/** POST /app/cs/session/{sessionId}/transfer — 转人工 */
|
/** POST /app/cs/session/{sessionId}/transfer — 转人工 */
|
||||||
export function transferCsSession(sessionId: string) {
|
export function transferCsSession(sessionId: string) {
|
||||||
return csRequest<CsAppActionVo | CsSessionVo | null>({
|
return csSessionRequest<CsAppActionVo | CsSessionVo | null>({
|
||||||
url: buildSessionPath(sessionId, '/transfer'),
|
url: buildSessionPath(sessionId, '/transfer'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
})
|
})
|
||||||
@@ -179,7 +187,7 @@ export function transferCsSession(sessionId: string) {
|
|||||||
|
|
||||||
/** POST /app/cs/session/{sessionId}/end — 结束会话 */
|
/** POST /app/cs/session/{sessionId}/end — 结束会话 */
|
||||||
export function endCsSession(sessionId: string) {
|
export function endCsSession(sessionId: string) {
|
||||||
return csRequest<void>({
|
return csSessionRequest<void>({
|
||||||
url: buildSessionPath(sessionId, '/end'),
|
url: buildSessionPath(sessionId, '/end'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
})
|
})
|
||||||
@@ -187,7 +195,7 @@ export function endCsSession(sessionId: string) {
|
|||||||
|
|
||||||
/** POST /app/cs/session/{sessionId}/button — 点击机器人按钮 */
|
/** POST /app/cs/session/{sessionId}/button — 点击机器人按钮 */
|
||||||
export function clickCsButton(sessionId: string, data: CsClickButtonBody) {
|
export function clickCsButton(sessionId: string, data: CsClickButtonBody) {
|
||||||
return csRequest<void>({
|
return csSessionRequest<void>({
|
||||||
url: buildSessionPath(sessionId, '/button'),
|
url: buildSessionPath(sessionId, '/button'),
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data,
|
data,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { onBeforeUnmount } from 'vue'
|
import { onBeforeUnmount } from 'vue'
|
||||||
import { onHide, onShow, onUnload } from '@dcloudio/uni-app'
|
import { onHide, onShow, onUnload } from '@dcloudio/uni-app'
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { ensureCsUploadReady } from '@/api/cs-auth'
|
import { ensureCsSessionReady } from '@/api/cs-auth'
|
||||||
import { fetchProfile } from '@/api/profile'
|
import { fetchProfile } from '@/api/profile'
|
||||||
import { getErrorMessage } from '@/utils/api-error'
|
import { getErrorMessage } from '@/utils/api-error'
|
||||||
import { getStoredToken } from '@/utils/auth-token'
|
import { getStoredToken } from '@/utils/auth-token'
|
||||||
@@ -17,6 +17,7 @@ import {
|
|||||||
uploadCsChatImage,
|
uploadCsChatImage,
|
||||||
} from './support.api'
|
} from './support.api'
|
||||||
import {
|
import {
|
||||||
|
connectCsChatSocket,
|
||||||
disconnectCsChatSocket,
|
disconnectCsChatSocket,
|
||||||
isCsChatSocketConnected,
|
isCsChatSocketConnected,
|
||||||
onCsChatPush,
|
onCsChatPush,
|
||||||
@@ -586,7 +587,12 @@ export function useSupport() {
|
|||||||
|
|
||||||
function activatePage() {
|
function activatePage() {
|
||||||
markSupportPageActive(true)
|
markSupportPageActive(true)
|
||||||
ensureCsUploadReady()
|
try {
|
||||||
|
ensureCsSessionReady()
|
||||||
|
} catch {
|
||||||
|
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||||
|
return
|
||||||
|
}
|
||||||
void loadUserProfile()
|
void loadUserProfile()
|
||||||
if (!sessionId.value) {
|
if (!sessionId.value) {
|
||||||
void ensureSession()
|
void ensureSession()
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
<base-input v-model="password" icon="lock" type="password" placeholder="请输入密码" />
|
<base-input v-model="password" icon="lock" type="password" placeholder="请输入密码" />
|
||||||
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="请确认密码" />
|
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="请确认密码" />
|
||||||
|
|
||||||
|
<text class="auth-form-page__hint">{{ passwordRuleHint }}</text>
|
||||||
|
|
||||||
<view class="auth-form-page__btn">
|
<view class="auth-form-page__btn">
|
||||||
<primary-button text="立即注册" @click="submit" />
|
<primary-button text="立即注册" @click="submit" />
|
||||||
</view>
|
</view>
|
||||||
@@ -25,8 +27,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { PASSWORD_RULE_HINT } from '@/utils/validate'
|
||||||
import { useRegister } from './use-register'
|
import { useRegister } from './use-register'
|
||||||
|
|
||||||
|
const passwordRuleHint = `${PASSWORD_RULE_HINT}。`
|
||||||
|
|
||||||
const {
|
const {
|
||||||
phone,
|
phone,
|
||||||
code,
|
code,
|
||||||
@@ -58,6 +63,14 @@ const {
|
|||||||
margin-bottom: 48rpx;
|
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 {
|
.auth-form-page__btn {
|
||||||
margin-top: 16rpx;
|
margin-top: 16rpx;
|
||||||
margin-bottom: 40rpx;
|
margin-bottom: 40rpx;
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { useSmsCode } from '@/hooks/use-sms-code'
|
import { useSmsCode } from '@/hooks/use-sms-code'
|
||||||
import { isValidPassword, isValidPhone, isValidSmsCode } from '@/utils/validate'
|
import {
|
||||||
|
isValidPhone,
|
||||||
|
isValidSmsCode,
|
||||||
|
isValidStrongPassword,
|
||||||
|
PASSWORD_INVALID_TOAST,
|
||||||
|
} from '@/utils/validate'
|
||||||
import { SMS_CODE_SCENE } from '@/types/api'
|
import { SMS_CODE_SCENE } from '@/types/api'
|
||||||
import { registerUser } from './register.api'
|
import { registerUser } from './register.api'
|
||||||
|
|
||||||
@@ -31,8 +36,8 @@ export function useRegister() {
|
|||||||
uni.showToast({ title: '请输入验证码', icon: 'none' })
|
uni.showToast({ title: '请输入验证码', icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!isValidPassword(password.value)) {
|
if (!isValidStrongPassword(password.value)) {
|
||||||
uni.showToast({ title: '密码至少 6 位', icon: 'none' })
|
uni.showToast({ title: PASSWORD_INVALID_TOAST, icon: 'none' })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (password.value !== confirmPassword.value) {
|
if (password.value !== confirmPassword.value) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 90 KiB After Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 5.5 KiB After Width: | Height: | Size: 5.5 KiB |
|
Before Width: | Height: | Size: 509 B After Width: | Height: | Size: 509 B |
|
Before Width: | Height: | Size: 629 B After Width: | Height: | Size: 629 B |
|
Before Width: | Height: | Size: 302 B After Width: | Height: | Size: 302 B |
|
Before Width: | Height: | Size: 702 B After Width: | Height: | Size: 702 B |
|
Before Width: | Height: | Size: 642 B After Width: | Height: | Size: 642 B |
|
Before Width: | Height: | Size: 695 B After Width: | Height: | Size: 695 B |
|
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 538 B After Width: | Height: | Size: 538 B |
|
Before Width: | Height: | Size: 352 B After Width: | Height: | Size: 352 B |
|
Before Width: | Height: | Size: 865 B After Width: | Height: | Size: 865 B |
|
Before Width: | Height: | Size: 821 B After Width: | Height: | Size: 821 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 445 B After Width: | Height: | Size: 445 B |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 358 B After Width: | Height: | Size: 358 B |
|
Before Width: | Height: | Size: 1016 B After Width: | Height: | Size: 1016 B |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 617 B After Width: | Height: | Size: 617 B |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 3.9 KiB |
|
Before Width: | Height: | Size: 681 B After Width: | Height: | Size: 681 B |
|
Before Width: | Height: | Size: 395 B After Width: | Height: | Size: 395 B |
@@ -15,11 +15,22 @@ export interface AppLocationVo {
|
|||||||
export interface AppHomeVo {
|
export interface AppHomeVo {
|
||||||
id?: string | number
|
id?: string | number
|
||||||
homeName?: string
|
homeName?: string
|
||||||
|
homeLocationLongitude?: number
|
||||||
|
homeLocationLatitude?: number
|
||||||
|
homeLocationAddress?: string
|
||||||
isDefault?: string | number | boolean
|
isDefault?: string | number | boolean
|
||||||
locationCount?: number
|
locationCount?: number
|
||||||
createTime?: string
|
createTime?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** PUT /app/home/{homeId} 请求体 */
|
||||||
|
export interface UpdateHomeBody {
|
||||||
|
homeName: string
|
||||||
|
homeLocationLongitude: number
|
||||||
|
homeLocationLatitude: number
|
||||||
|
homeLocationAddress: string
|
||||||
|
}
|
||||||
|
|
||||||
/** 房间位置(由接口数据映射) */
|
/** 房间位置(由接口数据映射) */
|
||||||
export interface RoomOption {
|
export interface RoomOption {
|
||||||
locationId: string | number
|
locationId: string | number
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { API_CLIENT_ID } from '@/api/request'
|
||||||
|
import { getApiBaseUrl, getMessageWsUrl } from '@/config/app-env'
|
||||||
import { getStoredToken } from '@/utils/auth-token'
|
import { getStoredToken } from '@/utils/auth-token'
|
||||||
import {
|
import {
|
||||||
decodeSocketMessageData,
|
decodeSocketMessageData,
|
||||||
@@ -7,82 +9,122 @@ import {
|
|||||||
import type { MessagePushPayload } from '@/types/message'
|
import type { MessagePushPayload } from '@/types/message'
|
||||||
|
|
||||||
const HEARTBEAT_INTERVAL_MS = 25000
|
const HEARTBEAT_INTERVAL_MS = 25000
|
||||||
const RECONNECT_DELAY_MS = 25000
|
const RECONNECT_BASE_MS = 10000
|
||||||
|
const RECONNECT_MAX_MS = 30000
|
||||||
|
const RUNTIME_KEY = '__CZZJ_MESSAGE_WS_RUNTIME__'
|
||||||
|
|
||||||
let socketTask: UniApp.SocketTask | null = null
|
interface MessageWsRuntime {
|
||||||
let heartbeatTimer: ReturnType<typeof setInterval> | null = null
|
socketTask: UniApp.SocketTask | null
|
||||||
let reconnectTimer: ReturnType<typeof setTimeout> | null = null
|
connecting: boolean
|
||||||
let connecting = false
|
socketOpened: boolean
|
||||||
let manualClosed = false
|
manualClosed: boolean
|
||||||
let socketOpened = false
|
connectionSeq: number
|
||||||
let disconnectHandled = false
|
disconnectHandled: boolean
|
||||||
|
heartbeatTimer: ReturnType<typeof setInterval> | null
|
||||||
|
reconnectTimer: ReturnType<typeof setTimeout> | null
|
||||||
|
reconnectAttempt: number
|
||||||
|
}
|
||||||
|
|
||||||
const listeners = new Set<(payload: MessagePushPayload) => void>()
|
const listeners = new Set<(payload: MessagePushPayload) => void>()
|
||||||
|
|
||||||
|
function createRuntime(): MessageWsRuntime {
|
||||||
|
return {
|
||||||
|
socketTask: null,
|
||||||
|
connecting: false,
|
||||||
|
socketOpened: false,
|
||||||
|
manualClosed: false,
|
||||||
|
connectionSeq: 0,
|
||||||
|
disconnectHandled: false,
|
||||||
|
heartbeatTimer: null,
|
||||||
|
reconnectTimer: null,
|
||||||
|
reconnectAttempt: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 全局单例,避免 HMR / 重复 import 后丢失连接状态又新建多条 WS */
|
||||||
|
function runtime(): MessageWsRuntime {
|
||||||
|
if (typeof globalThis !== 'undefined') {
|
||||||
|
const holder = globalThis as typeof globalThis & {
|
||||||
|
[RUNTIME_KEY]?: MessageWsRuntime
|
||||||
|
}
|
||||||
|
if (!holder[RUNTIME_KEY]) {
|
||||||
|
holder[RUNTIME_KEY] = createRuntime()
|
||||||
|
}
|
||||||
|
return holder[RUNTIME_KEY]
|
||||||
|
}
|
||||||
|
return createRuntime()
|
||||||
|
}
|
||||||
|
|
||||||
function resolveMessageWsBase(): string {
|
function resolveMessageWsBase(): string {
|
||||||
const configured = import.meta.env.VITE_MESSAGE_WS_URL?.trim()
|
const configured = getMessageWsUrl().trim()
|
||||||
if (configured) {
|
if (configured) {
|
||||||
return configured.replace(/[?#].*$/, '').replace(/\/$/, '')
|
return configured.replace(/[?#].*$/, '').replace(/\/$/, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
const envBase = import.meta.env.VITE_API_BASE_URL?.trim() || ''
|
const httpBase = getApiBaseUrl() || 'http://192.168.0.222:8082'
|
||||||
const fallback = import.meta.env.VITE_API_PROXY_TARGET?.trim() || 'http://192.168.0.222:8082'
|
|
||||||
const httpBase = envBase || fallback
|
|
||||||
const wsBase = httpBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws')
|
const wsBase = httpBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws')
|
||||||
return `${wsBase}/app/ws/message`
|
return `${wsBase}/app/ws/message`
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveMessageWsUrl(token: string): string {
|
function resolveMessageWsUrl(token: string): string {
|
||||||
const base = resolveMessageWsBase()
|
const base = resolveMessageWsBase()
|
||||||
return `${base}?token=${encodeURIComponent(token)}`
|
const query = `token=${encodeURIComponent(token)}&clientId=${encodeURIComponent(API_CLIENT_ID)}`
|
||||||
|
return `${base}?${query}`
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopHeartbeat() {
|
function stopHeartbeat(state: MessageWsRuntime) {
|
||||||
if (heartbeatTimer) clearInterval(heartbeatTimer)
|
if (state.heartbeatTimer) clearInterval(state.heartbeatTimer)
|
||||||
heartbeatTimer = null
|
state.heartbeatTimer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendPing() {
|
function sendPing(state: MessageWsRuntime) {
|
||||||
if (!socketOpened || !socketTask) return
|
if (!state.socketOpened || !state.socketTask) return
|
||||||
socketTask.send({ data: 'ping' })
|
state.socketTask.send({ data: 'ping' })
|
||||||
}
|
}
|
||||||
|
|
||||||
function startHeartbeat() {
|
function startHeartbeat(state: MessageWsRuntime) {
|
||||||
stopHeartbeat()
|
stopHeartbeat(state)
|
||||||
sendPing()
|
sendPing(state)
|
||||||
heartbeatTimer = setInterval(sendPing, HEARTBEAT_INTERVAL_MS)
|
state.heartbeatTimer = setInterval(() => {
|
||||||
|
sendPing(state)
|
||||||
|
}, HEARTBEAT_INTERVAL_MS)
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearReconnectTimer() {
|
function clearReconnectTimer(state: MessageWsRuntime) {
|
||||||
if (reconnectTimer) clearTimeout(reconnectTimer)
|
if (state.reconnectTimer) clearTimeout(state.reconnectTimer)
|
||||||
reconnectTimer = null
|
state.reconnectTimer = null
|
||||||
}
|
}
|
||||||
|
|
||||||
function scheduleReconnect() {
|
function resetSocketState(state: MessageWsRuntime) {
|
||||||
if (manualClosed || !getStoredToken()) return
|
stopHeartbeat(state)
|
||||||
clearReconnectTimer()
|
state.socketTask = null
|
||||||
reconnectTimer = setTimeout(() => {
|
state.socketOpened = false
|
||||||
|
state.connecting = false
|
||||||
|
state.disconnectHandled = false
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleReconnect(state: MessageWsRuntime) {
|
||||||
|
if (state.manualClosed || !getStoredToken()) return
|
||||||
|
clearReconnectTimer(state)
|
||||||
|
const delay = Math.min(
|
||||||
|
RECONNECT_BASE_MS * Math.pow(1.5, state.reconnectAttempt),
|
||||||
|
RECONNECT_MAX_MS,
|
||||||
|
)
|
||||||
|
state.reconnectAttempt += 1
|
||||||
|
state.reconnectTimer = setTimeout(() => {
|
||||||
connectMessageSocket()
|
connectMessageSocket()
|
||||||
}, RECONNECT_DELAY_MS)
|
}, delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanupSocketTask() {
|
function handleDisconnect(state: MessageWsRuntime, reason: string) {
|
||||||
stopHeartbeat()
|
if (state.disconnectHandled) return
|
||||||
socketTask = null
|
state.disconnectHandled = true
|
||||||
socketOpened = false
|
|
||||||
connecting = false
|
|
||||||
disconnectHandled = false
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleDisconnect(reason: string) {
|
|
||||||
if (disconnectHandled) return
|
|
||||||
disconnectHandled = true
|
|
||||||
if (import.meta.env.DEV) {
|
if (import.meta.env.DEV) {
|
||||||
console.log(`[Message WS] ${reason}`)
|
console.log(`[Message WS] ${reason}`)
|
||||||
}
|
}
|
||||||
cleanupSocketTask()
|
resetSocketState(state)
|
||||||
if (!manualClosed) {
|
if (!state.manualClosed) {
|
||||||
scheduleReconnect()
|
scheduleReconnect(state)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,12 +144,44 @@ function handleSocketMessage(raw: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bindSocketTask(task: UniApp.SocketTask, seq: number, state: MessageWsRuntime) {
|
||||||
|
state.socketTask = task
|
||||||
|
|
||||||
|
task.onOpen(() => {
|
||||||
|
if (seq !== state.connectionSeq) return
|
||||||
|
state.socketOpened = true
|
||||||
|
state.connecting = false
|
||||||
|
state.reconnectAttempt = 0
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('[Message WS] connected')
|
||||||
|
}
|
||||||
|
startHeartbeat(state)
|
||||||
|
})
|
||||||
|
|
||||||
|
task.onMessage((res) => {
|
||||||
|
if (seq !== state.connectionSeq) return
|
||||||
|
handleSocketMessage(decodeSocketMessageData(res.data))
|
||||||
|
})
|
||||||
|
|
||||||
|
task.onClose(() => {
|
||||||
|
if (seq !== state.connectionSeq) return
|
||||||
|
handleDisconnect(state, 'closed')
|
||||||
|
})
|
||||||
|
|
||||||
|
task.onError(() => {
|
||||||
|
if (seq !== state.connectionSeq) return
|
||||||
|
handleDisconnect(state, 'error')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function isMessageSocketConnected(): boolean {
|
export function isMessageSocketConnected(): boolean {
|
||||||
return socketOpened && !!socketTask
|
const state = runtime()
|
||||||
|
return state.socketOpened && !!state.socketTask
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isMessageSocketConnecting(): boolean {
|
export function isMessageSocketConnecting(): boolean {
|
||||||
return connecting || (!!socketTask && !socketOpened)
|
const state = runtime()
|
||||||
|
return state.connecting || (!!state.socketTask && !state.socketOpened)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function onMessagePush(listener: (payload: MessagePushPayload) => void) {
|
export function onMessagePush(listener: (payload: MessagePushPayload) => void) {
|
||||||
@@ -116,64 +190,78 @@ export function onMessagePush(listener: (payload: MessagePushPayload) => void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function connectMessageSocket() {
|
export function connectMessageSocket() {
|
||||||
|
const state = runtime()
|
||||||
const token = getStoredToken()
|
const token = getStoredToken()
|
||||||
if (!token || manualClosed) return
|
if (!token || state.manualClosed) return
|
||||||
if (socketOpened && socketTask) return
|
if (state.socketOpened && state.socketTask) return
|
||||||
// 握手进行中:不要 close,否则 DevTools 会报 "closed before connection is established"
|
if (state.connecting) return
|
||||||
if (isMessageSocketConnecting()) return
|
|
||||||
|
|
||||||
manualClosed = false
|
state.manualClosed = false
|
||||||
connecting = true
|
const seq = ++state.connectionSeq
|
||||||
disconnectHandled = false
|
clearReconnectTimer(state)
|
||||||
clearReconnectTimer()
|
|
||||||
|
|
||||||
const task = uni.connectSocket({
|
const previousTask = state.socketTask
|
||||||
url: resolveMessageWsUrl(token),
|
state.socketTask = null
|
||||||
fail: (err) => {
|
state.socketOpened = false
|
||||||
if (import.meta.env.DEV) {
|
if (previousTask) {
|
||||||
console.log('[Message WS] connect fail', err)
|
|
||||||
}
|
|
||||||
handleDisconnect('connect fail')
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
socketTask = task
|
|
||||||
|
|
||||||
task.onOpen(() => {
|
|
||||||
socketOpened = true
|
|
||||||
connecting = false
|
|
||||||
if (import.meta.env.DEV) {
|
|
||||||
console.log('[Message WS] connected')
|
|
||||||
}
|
|
||||||
startHeartbeat()
|
|
||||||
})
|
|
||||||
|
|
||||||
task.onMessage((res) => {
|
|
||||||
handleSocketMessage(decodeSocketMessageData(res.data))
|
|
||||||
})
|
|
||||||
|
|
||||||
task.onClose(() => {
|
|
||||||
handleDisconnect('closed')
|
|
||||||
})
|
|
||||||
|
|
||||||
task.onError(() => {
|
|
||||||
handleDisconnect('error')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export function disconnectMessageSocket() {
|
|
||||||
manualClosed = true
|
|
||||||
clearReconnectTimer()
|
|
||||||
stopHeartbeat()
|
|
||||||
disconnectHandled = true
|
|
||||||
if (socketTask) {
|
|
||||||
try {
|
try {
|
||||||
socketTask.close({})
|
previousTask.close({})
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
state.connecting = true
|
||||||
|
state.disconnectHandled = false
|
||||||
|
|
||||||
|
const url = resolveMessageWsUrl(token)
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('[Message WS] connect', url.replace(/token=[^&]+/, 'token=***'))
|
||||||
|
}
|
||||||
|
|
||||||
|
const task = uni.connectSocket({
|
||||||
|
url,
|
||||||
|
fail: (err) => {
|
||||||
|
if (seq !== state.connectionSeq) return
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.log('[Message WS] connect fail', err)
|
||||||
|
}
|
||||||
|
resetSocketState(state)
|
||||||
|
scheduleReconnect(state)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!task || typeof task.onOpen !== 'function') {
|
||||||
|
state.connecting = false
|
||||||
|
if (import.meta.env.DEV) {
|
||||||
|
console.warn('[Message WS] invalid SocketTask')
|
||||||
|
}
|
||||||
|
scheduleReconnect(state)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bindSocketTask(task, seq, state)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function disconnectMessageSocket() {
|
||||||
|
const state = runtime()
|
||||||
|
state.manualClosed = true
|
||||||
|
state.connectionSeq += 1
|
||||||
|
state.reconnectAttempt = 0
|
||||||
|
clearReconnectTimer(state)
|
||||||
|
stopHeartbeat(state)
|
||||||
|
state.disconnectHandled = true
|
||||||
|
|
||||||
|
const task = state.socketTask
|
||||||
|
state.socketTask = null
|
||||||
|
state.socketOpened = false
|
||||||
|
state.connecting = false
|
||||||
|
|
||||||
|
if (task) {
|
||||||
|
try {
|
||||||
|
task.close({})
|
||||||
} catch {
|
} catch {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
socketTask = null
|
|
||||||
socketOpened = false
|
|
||||||
connecting = false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,103 +3,72 @@ import logoCenter from '@/static/logo-center@2x.png'
|
|||||||
import iconPhone from '@/static/icon-phone@2x.png'
|
import iconPhone from '@/static/icon-phone@2x.png'
|
||||||
import iconCode from '@/static/icon-code@2x.png'
|
import iconCode from '@/static/icon-code@2x.png'
|
||||||
import iconChecked from '@/static/icon-checked@2x.png'
|
import iconChecked from '@/static/icon-checked@2x.png'
|
||||||
import iconPassword from '@/static/路径.png'
|
import iconPassword from '@/static/icon-password.png'
|
||||||
import iconDeviceDetailSettings from '@/static/路径1.png'
|
import iconDeviceDetailSettings from '@/static/icon-device-settings.png'
|
||||||
import deviceDetailHeroBg from '@/static/组 15226@2x.png'
|
import deviceDetailHeroBg from '@/static/device-detail-hero-bg@2x.png'
|
||||||
import iconRunModeInfo from '@/static/组 15227@2x.png'
|
import iconRunModeInfo from '@/static/icon-run-mode-info@2x.png'
|
||||||
import iconHomeSelector from '@/static/图标 4.png'
|
import iconHomeSelector from '@/static/icon-home-selector.png'
|
||||||
import iconHomeArrow from '@/static/组 9.png'
|
import iconHomeArrow from '@/static/icon-home-arrow.png'
|
||||||
import iconHomeSelected from '@/static/完成@2x.png'
|
import iconHomeSelected from '@/static/icon-home-selected@2x.png'
|
||||||
import iconNotify from '@/static/通知 (1).png'
|
import iconNotify from '@/static/icon-notify.png'
|
||||||
import iconDeviceEmpty from '@/static/图标 8.png'
|
import iconDeviceEmpty from '@/static/icon-device-empty.png'
|
||||||
import iconDeviceNameEdit from '@/static/图标 9.png'
|
import iconDeviceNameEdit from '@/static/icon-device-name-edit.png'
|
||||||
import iconBindComplete from '@/static/组 41@2x.png'
|
import iconBindComplete from '@/static/icon-bind-complete@2x.png'
|
||||||
import iconBluetooth from '@/static/蓝牙-F.png'
|
import iconBluetooth from '@/static/icon-bluetooth.png'
|
||||||
import iconBindDiscover from '@/static/组 281@2x.png'
|
import iconBindDiscover from '@/static/icon-bind-discover@2x.png'
|
||||||
import iconBindPair from '@/static/组 286@2x.png'
|
import iconBindPair from '@/static/icon-bind-pair@2x.png'
|
||||||
import iconBindSecure from '@/static/组 291@2x.png'
|
import iconBindSecure from '@/static/icon-bind-secure@2x.png'
|
||||||
import iconScanDevice from '@/static/组 600@2x.png'
|
import iconScanDevice from '@/static/icon-scan-device@2x.png'
|
||||||
import iconScanDeviceAction from '@/static/组 468@2x.png'
|
import iconScanDeviceAction from '@/static/icon-scan-device-action@2x.png'
|
||||||
import iconScanDeviceActionDisabled from '@/static/组 476@2x.png'
|
import iconScanDeviceActionDisabled from '@/static/icon-scan-device-action-disabled@2x.png'
|
||||||
import tabDevice from '@/static/tab-device-active.png'
|
import tabDevice from '@/static/tab-device-active.png'
|
||||||
import tabDeviceActive from '@/static/tab-device.png'
|
import tabDeviceActive from '@/static/tab-device.png'
|
||||||
import tabMine from '@/static/tab-mine-active.png'
|
import tabMine from '@/static/tab-mine-active.png'
|
||||||
import tabMineActive from '@/static/tab-mine.png'
|
import tabMineActive from '@/static/tab-mine.png'
|
||||||
import iconChevronLeft from '@/static/chevron.left.png'
|
import iconChevronLeft from '@/static/icon-chevron-left.png'
|
||||||
import iconSupportMic from '@/static/组 134.png'
|
import iconSupportMic from '@/static/icon-support-mic.png'
|
||||||
import iconSupportPhoto from '@/static/图片.png'
|
import iconSupportPhoto from '@/static/icon-support-photo.png'
|
||||||
import iconSupportSend from '@/static/图标 14.png'
|
import iconSupportSend from '@/static/icon-support-send.png'
|
||||||
import iconSupportQueue from '@/static/组 98@2x.png'
|
import iconSupportQueue from '@/static/icon-support-queue@2x.png'
|
||||||
import iconMineNotify from '@/static/组 14919@2x.png'
|
import iconMineNotify from '@/static/icon-mine-notify@2x.png'
|
||||||
import iconMineOrder from '@/static/订单@2x.png'
|
import iconMineOrder from '@/static/icon-mine-order@2x.png'
|
||||||
import iconMineCoupon from '@/static/优惠券@2x.png'
|
import iconMineCoupon from '@/static/icon-mine-coupon@2x.png'
|
||||||
import iconMineAddress from '@/static/组 14923@2x.png'
|
import iconMineAddress from '@/static/icon-mine-address@2x.png'
|
||||||
|
|
||||||
export const staticAssets = {
|
export const staticAssets = {
|
||||||
/** 组 15106@2x.png — 登录区中心大图标 */
|
|
||||||
logo: logoCenter,
|
logo: logoCenter,
|
||||||
/** 手机号@2x.png */
|
|
||||||
iconPhone,
|
iconPhone,
|
||||||
/** 验证码@2x.png */
|
|
||||||
iconCode,
|
iconCode,
|
||||||
/** 选中@2x.png */
|
|
||||||
iconChecked,
|
iconChecked,
|
||||||
/** 路径.png — 密码框 */
|
|
||||||
iconPassword,
|
iconPassword,
|
||||||
/** 路径1.png — 设备详情右上角设置 */
|
|
||||||
iconDeviceDetailSettings,
|
iconDeviceDetailSettings,
|
||||||
/** 组 15226@2x.png — 设备详情页上半部分背景 */
|
|
||||||
deviceDetailHeroBg,
|
deviceDetailHeroBg,
|
||||||
/** 组 15227@2x.png — 设备详情「运行模式」旁提示图标 */
|
|
||||||
iconRunModeInfo,
|
iconRunModeInfo,
|
||||||
/** 图标 4.png — 首页「我的家」 */
|
|
||||||
iconHomeSelector,
|
iconHomeSelector,
|
||||||
/** 组 9.png — 「我的家」下拉箭头 */
|
|
||||||
iconHomeArrow,
|
iconHomeArrow,
|
||||||
/** 完成@2x.png — 「我的家」下拉选中图标 */
|
|
||||||
iconHomeSelected,
|
iconHomeSelected,
|
||||||
/** 通知 (1).png — 设备页右上角通知 */
|
|
||||||
iconNotify,
|
iconNotify,
|
||||||
/** 图标 8.png — 设备空状态中心图标 */
|
|
||||||
iconDeviceEmpty,
|
iconDeviceEmpty,
|
||||||
/** 图标 9.png — 完成配置「设备名称」编辑 */
|
|
||||||
iconDeviceNameEdit,
|
iconDeviceNameEdit,
|
||||||
/** 组 41@2x.png — 完成配置成功示意图 */
|
|
||||||
iconBindComplete,
|
iconBindComplete,
|
||||||
/** 蓝牙-F.png — 添加设备页蓝牙示意图 */
|
|
||||||
iconBluetooth,
|
iconBluetooth,
|
||||||
/** 组 281@2x.png — 添加设备「发现附近设备」 */
|
|
||||||
iconBindDiscover,
|
iconBindDiscover,
|
||||||
/** 组 286@2x.png — 添加设备「快速配对连接」 */
|
|
||||||
iconBindPair,
|
iconBindPair,
|
||||||
/** 组 291@2x.png — 添加设备「本地安全控制」 */
|
|
||||||
iconBindSecure,
|
iconBindSecure,
|
||||||
/** 组 600@2x.png — 扫描设备页示意图 */
|
|
||||||
iconScanDevice,
|
iconScanDevice,
|
||||||
/** 组 468@2x.png — 发现设备列表「可添加」箭头 */
|
|
||||||
iconScanDeviceAction,
|
iconScanDeviceAction,
|
||||||
/** 组 476@2x.png — 发现设备列表「不可添加」箭头 */
|
|
||||||
iconScanDeviceActionDisabled,
|
iconScanDeviceActionDisabled,
|
||||||
tabDevice,
|
tabDevice,
|
||||||
tabDeviceActive,
|
tabDeviceActive,
|
||||||
tabMine,
|
tabMine,
|
||||||
tabMineActive,
|
tabMineActive,
|
||||||
/** chevron.left.png — 列表右箭头(旋转 180° 使用) */
|
|
||||||
iconChevronLeft,
|
iconChevronLeft,
|
||||||
/** 组 134.png — 在线客服页麦克风 */
|
|
||||||
iconSupportMic,
|
iconSupportMic,
|
||||||
/** 图片.png — 在线客服页发送图片 */
|
|
||||||
iconSupportPhoto,
|
iconSupportPhoto,
|
||||||
/** 图标 14.png — 在线客服页发送 */
|
|
||||||
iconSupportSend,
|
iconSupportSend,
|
||||||
/** 组 98@2x.png — 在线客服排队卡片标题图标 */
|
|
||||||
iconSupportQueue,
|
iconSupportQueue,
|
||||||
/** 组 14919@2x.png — 我的页消息通知 */
|
|
||||||
iconMineNotify,
|
iconMineNotify,
|
||||||
/** 订单@2x.png — 我的页我的订单 */
|
|
||||||
iconMineOrder,
|
iconMineOrder,
|
||||||
/** 优惠券@2x.png — 我的页优惠券 */
|
|
||||||
iconMineCoupon,
|
iconMineCoupon,
|
||||||
/** 组 14923@2x.png — 我的页收货地址 */
|
|
||||||
iconMineAddress,
|
iconMineAddress,
|
||||||
} as const
|
} as const
|
||||||
|
|||||||
@@ -6,11 +6,17 @@ export function isValidSmsCode(code: string): boolean {
|
|||||||
return /^\d{4,6}$/.test(code.trim())
|
return /^\d{4,6}$/.test(code.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 登录时输入校验(兼容历史短密码账号) */
|
||||||
export function isValidPassword(password: string): boolean {
|
export function isValidPassword(password: string): boolean {
|
||||||
return password.length >= 6 && password.length <= 32
|
return password.length >= 6 && password.length <= 32
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 设置/修改登录密码:8-20 位,且字母、数字、符号至少包含 2 种 */
|
/** 注册 / 修改密码统一规则说明 */
|
||||||
|
export const PASSWORD_RULE_HINT = '8-20位字符,须包含字母、数字、符号中的至少2种'
|
||||||
|
|
||||||
|
export const PASSWORD_INVALID_TOAST = `密码需${PASSWORD_RULE_HINT.replace('。', '')}`
|
||||||
|
|
||||||
|
/** 注册 / 修改密码:8-20 位,且字母、数字、符号至少包含 2 种 */
|
||||||
export function isValidStrongPassword(password: string): boolean {
|
export function isValidStrongPassword(password: string): boolean {
|
||||||
const value = password.trim()
|
const value = password.trim()
|
||||||
if (value.length < 8 || value.length > 20) return false
|
if (value.length < 8 || value.length > 20) return false
|
||||||
|
|||||||
BIN
unpackage/res/icons/1024x1024.png
Normal file
|
After Width: | Height: | Size: 103 KiB |
BIN
unpackage/res/icons/120x120.png
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
BIN
unpackage/res/icons/144x144.png
Normal file
|
After Width: | Height: | Size: 5.9 KiB |
BIN
unpackage/res/icons/152x152.png
Normal file
|
After Width: | Height: | Size: 6.4 KiB |
BIN
unpackage/res/icons/167x167.png
Normal file
|
After Width: | Height: | Size: 7.5 KiB |
BIN
unpackage/res/icons/180x180.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
unpackage/res/icons/192x192.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
unpackage/res/icons/20x20.png
Normal file
|
After Width: | Height: | Size: 577 B |
BIN
unpackage/res/icons/29x29.png
Normal file
|
After Width: | Height: | Size: 879 B |
BIN
unpackage/res/icons/40x40.png
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
unpackage/res/icons/58x58.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
unpackage/res/icons/60x60.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |