fix:最新版本
@@ -1,4 +1,5 @@
|
||||
# 接口根地址(App / 小程序 / H5 直连)
|
||||
# 正式打包读 .env.production;未配置时 src/config/app-env.ts 有兜底地址
|
||||
VITE_API_BASE_URL=http://192.168.0.222:8082
|
||||
|
||||
# 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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-app": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-app-harmony": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-app-plus": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-components": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-h5": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-alipay": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-baidu": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-harmony": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-jd": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-lark": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-qq": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-toutiao": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-mp-xhs": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-quickapp-webview": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-app": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-app-harmony": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-app-plus": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-components": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-h5": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-alipay": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-baidu": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-harmony": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-jd": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-kuaishou": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-lark": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-qq": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-toutiao": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-weixin": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-mp-xhs": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-quickapp-webview": "3.0.0-5020620260917001",
|
||||
"element-china-area-data": "^6.1.0",
|
||||
"vue": "^3.4.21",
|
||||
"vue-i18n": "^9.1.9"
|
||||
"vue": "3.4.21",
|
||||
"vue-i18n": "9.14.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dcloudio/types": "^3.4.8",
|
||||
"@dcloudio/uni-automator": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-5020420260813003",
|
||||
"@dcloudio/uni-stacktracey": "3.0.0-5020420260813003",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-5020420260813003",
|
||||
"@vue/runtime-core": "^3.4.21",
|
||||
"@dcloudio/types": "3.4.31",
|
||||
"@dcloudio/uni-automator": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-cli-shared": "3.0.0-5020620260917001",
|
||||
"@dcloudio/uni-stacktracey": "3.0.0-5020620260917001",
|
||||
"@dcloudio/vite-plugin-uni": "3.0.0-5020620260917001",
|
||||
"@vue/runtime-core": "3.5.44",
|
||||
"@vue/tsconfig": "^0.1.3",
|
||||
"rollup": "4.14.3",
|
||||
"sass": "^1.105.1",
|
||||
"typescript": "^4.9.4",
|
||||
"vite": "5.2.8",
|
||||
|
||||
23
src/App.vue
@@ -1,14 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { onLaunch, onShow } from '@dcloudio/uni-app'
|
||||
import { setupMessageInbox } from '@/hooks/use-message-inbox'
|
||||
import {
|
||||
connectMessageSocket,
|
||||
isMessageSocketConnected,
|
||||
isMessageSocketConnecting,
|
||||
} from '@/utils/message-socket'
|
||||
import { getStoredToken } from '@/utils/auth-token'
|
||||
import { staticAssets } from '@/utils/static-assets'
|
||||
|
||||
const HOME_ROUTE = '/pages/device/index'
|
||||
const LOGIN_ROUTE = '/pages/login/index'
|
||||
|
||||
function applyH5Favicon() {
|
||||
// #ifdef H5
|
||||
if (typeof document === 'undefined') return
|
||||
@@ -25,17 +23,22 @@ function applyH5Favicon() {
|
||||
// #endif
|
||||
}
|
||||
|
||||
onLaunch(() => {
|
||||
applyH5Favicon()
|
||||
function bootstrapAuthRoute() {
|
||||
if (getStoredToken()) {
|
||||
setupMessageInbox()
|
||||
return
|
||||
}
|
||||
uni.reLaunch({ url: LOGIN_ROUTE })
|
||||
}
|
||||
|
||||
onLaunch(() => {
|
||||
applyH5Favicon()
|
||||
bootstrapAuthRoute()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
if (!getStoredToken()) return
|
||||
if (!isMessageSocketConnected() && !isMessageSocketConnecting()) {
|
||||
connectMessageSocket()
|
||||
if (getStoredToken()) {
|
||||
setupMessageInbox()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { getApiBaseUrl } from '@/config/app-env'
|
||||
import { resolveCsAppBaseUrl, UPLOAD_CLIENT_ID } from './request'
|
||||
import {
|
||||
clearStoredCsToken,
|
||||
extractAuthToken,
|
||||
getStoredCsToken,
|
||||
getStoredToken,
|
||||
saveStoredCsToken,
|
||||
} from '@/utils/auth-token'
|
||||
@@ -13,8 +14,7 @@ function resolveCsAuthUrl(path: string): string {
|
||||
const normalized = path.startsWith('/') ? path : `/${path}`
|
||||
const csBase = resolveCsAppBaseUrl()
|
||||
if (csBase) return `${csBase}${normalized}`
|
||||
const main = import.meta.env.VITE_API_BASE_URL?.trim() || ''
|
||||
return `${main.replace(/\/$/, '')}/app${normalized}`
|
||||
return `${getApiBaseUrl()}/app${normalized}`
|
||||
}
|
||||
|
||||
function parseBody(data: unknown): unknown {
|
||||
@@ -62,17 +62,19 @@ async function requestCsLogin(path: string, data: Record<string, unknown>): Prom
|
||||
/** 主站登录后,向 212 用 clientId=app 同步登录,获取上传专用 token */
|
||||
export async function syncCsAuthByPassword(account: string, password: string): Promise<void> {
|
||||
try {
|
||||
clearStoredCsToken()
|
||||
await requestCsLogin('/auth/login/password', {
|
||||
account: account.trim(),
|
||||
password,
|
||||
})
|
||||
} catch {
|
||||
// 212 不可达时不阻断主登录
|
||||
// 212 不可达时不阻断主登录;会话接口仍可用主站 token
|
||||
}
|
||||
}
|
||||
|
||||
export async function syncCsAuthBySms(phone: string, code: string): Promise<void> {
|
||||
try {
|
||||
clearStoredCsToken()
|
||||
await requestCsLogin('/auth/login/sms', {
|
||||
phonenumber: phone.trim(),
|
||||
smsCode: code.trim(),
|
||||
@@ -82,17 +84,10 @@ export async function syncCsAuthBySms(phone: string, code: string): Promise<void
|
||||
}
|
||||
}
|
||||
|
||||
/** 212 无 cs_token 时,用主站 token 兜底(与 upload 请求头逻辑一致) */
|
||||
export function ensureCsUploadReady(): void {
|
||||
if (!getStoredCsToken()) {
|
||||
const main = getStoredToken()
|
||||
if (main) saveStoredCsToken(main)
|
||||
/** 进入客服页前:确认主站已登录(勿把主站 token 写入 cs_token) */
|
||||
export function ensureCsSessionReady(): void {
|
||||
if (!getStoredToken()) {
|
||||
throw new ApiError('请先登录', 401)
|
||||
}
|
||||
}
|
||||
|
||||
export function assertCsUploadToken(): void {
|
||||
ensureCsUploadReady()
|
||||
if (!getStoredCsToken() && !getStoredToken()) {
|
||||
throw new ApiError('请先登录后再发送图片', 401)
|
||||
}
|
||||
}
|
||||
|
||||
185
src/api/home.ts
@@ -1,72 +1,113 @@
|
||||
import { request } from '@/api/request'
|
||||
|
||||
import type { AppHomeVo } from '@/types/location'
|
||||
|
||||
import { parseId, sameId } from '@/utils/device-id'
|
||||
|
||||
|
||||
|
||||
/** GET /app/home/list — 查询当前用户的家庭列表 */
|
||||
|
||||
export function fetchHomeList() {
|
||||
|
||||
return request<AppHomeVo[]>({
|
||||
|
||||
url: '/app/home/list',
|
||||
|
||||
method: 'GET',
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** POST /app/home/create — 创建家庭(返回 RVoid,需再拉列表取 ID) */
|
||||
|
||||
export function createHome(data: { homeName: string }) {
|
||||
|
||||
return request<void>({
|
||||
|
||||
url: '/app/home/create',
|
||||
|
||||
method: 'POST',
|
||||
|
||||
data,
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function isDefaultHome(home: AppHomeVo): boolean {
|
||||
|
||||
const value = home.isDefault
|
||||
|
||||
return value === '1' || value === 1 || value === true
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function pickDefaultHome(homes: AppHomeVo[] | undefined): AppHomeVo | undefined {
|
||||
|
||||
if (!homes?.length) return undefined
|
||||
|
||||
return homes.find(isDefaultHome) ?? homes[0]
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function getHomeId(home?: AppHomeVo): string {
|
||||
|
||||
return parseId(home?.id)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
export function findHomeById(homes: AppHomeVo[] | undefined, homeId: string | number) {
|
||||
|
||||
import { request } from '@/api/request'
|
||||
import type { AppHomeVo, UpdateHomeBody } from '@/types/location'
|
||||
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 — 查询当前用户的家庭列表 */
|
||||
export function fetchHomeList() {
|
||||
return request<AppHomeVo[]>({
|
||||
url: '/app/home/list',
|
||||
method: 'GET',
|
||||
})
|
||||
}
|
||||
|
||||
/** POST /app/home/create — 创建家庭(返回 RVoid,需再拉列表取 ID) */
|
||||
export function createHome(data: { homeName: string }) {
|
||||
return request<void>({
|
||||
url: '/app/home/create',
|
||||
method: 'POST',
|
||||
data,
|
||||
})
|
||||
}
|
||||
|
||||
/** 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 {
|
||||
const value = home.isDefault
|
||||
return value === '1' || value === 1 || value === true
|
||||
}
|
||||
|
||||
export function pickDefaultHome(homes: AppHomeVo[] | undefined): AppHomeVo | undefined {
|
||||
if (!homes?.length) return undefined
|
||||
return homes.find(isDefaultHome) ?? homes[0]
|
||||
}
|
||||
|
||||
export function getHomeId(home?: AppHomeVo): string {
|
||||
return parseId(home?.id)
|
||||
}
|
||||
|
||||
export function findHomeById(homes: AppHomeVo[] | undefined, homeId: string | number) {
|
||||
return homes?.find((item) => sameId(item.id, homeId))
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析当前用户可用的 homeId:
|
||||
* 1. 若 candidate 在用户家庭列表中 → 使用它
|
||||
* 2. 否则使用默认家庭
|
||||
* 3. 若无家庭则自动创建「我的家」
|
||||
*/
|
||||
export async function resolveValidHomeId(candidate?: string | number): Promise<string> {
|
||||
let list = await fetchHomeList()
|
||||
const preferred = parseId(candidate)
|
||||
|
||||
if (preferred && findHomeById(list, preferred)) {
|
||||
return preferred
|
||||
}
|
||||
|
||||
let defaultId = getHomeId(pickDefaultHome(list))
|
||||
if (defaultId) return defaultId
|
||||
|
||||
await createHome({ homeName: '我的家' })
|
||||
list = await fetchHomeList()
|
||||
defaultId = getHomeId(pickDefaultHome(list))
|
||||
return defaultId
|
||||
}
|
||||
|
||||
/** @deprecated 使用 resolveValidHomeId */
|
||||
export async function resolveDefaultHomeId(): Promise<string> {
|
||||
return resolveValidHomeId()
|
||||
}
|
||||
|
||||
/** @deprecated 使用 resolveValidHomeId */
|
||||
export async function ensureDefaultHomeId(): Promise<string> {
|
||||
return resolveValidHomeId()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
import type { ApiResponse } from '@/types/api'
|
||||
import {
|
||||
assertRequestUrl,
|
||||
getApiBaseUrl,
|
||||
getApiClientId,
|
||||
getCsApiBaseUrl,
|
||||
getUploadClientId,
|
||||
} from '@/config/app-env'
|
||||
import {
|
||||
clearStoredCsToken,
|
||||
extractAuthToken,
|
||||
formatBearerAuthorization,
|
||||
getStoredCsToken,
|
||||
@@ -8,22 +16,11 @@ import {
|
||||
} from '@/utils/auth-token'
|
||||
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 接口) */
|
||||
export const API_CLIENT_ID =
|
||||
import.meta.env.VITE_API_CLIENT_ID || '428a8310cd442757ae699df5d894f051'
|
||||
export const API_CLIENT_ID = getApiClientId()
|
||||
|
||||
/** 文件上传 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 精度丢失 */
|
||||
function parseJsonPreserveIdFields(text: string): unknown {
|
||||
@@ -34,19 +31,18 @@ function parseJsonPreserveIdFields(text: string): unknown {
|
||||
return JSON.parse(safe)
|
||||
}
|
||||
|
||||
/** 212 客服服务根路径(含 /app);未配置时返回空字符串 */
|
||||
/** 212 客服服务根路径(含 /app) */
|
||||
export function resolveCsAppBaseUrl(): string {
|
||||
const csBase = import.meta.env.VITE_CS_API_BASE_URL?.trim()
|
||||
// #ifdef H5
|
||||
if (import.meta.env.DEV) return '/cs-app'
|
||||
// #endif
|
||||
if (csBase) return `${csBase.replace(/\/$/, '')}/app`
|
||||
return ''
|
||||
const csBase = getCsApiBaseUrl()
|
||||
return csBase ? `${csBase}/app` : ''
|
||||
}
|
||||
|
||||
function buildCsAppRequestUrl(path: string): string {
|
||||
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)}`
|
||||
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 {
|
||||
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> {
|
||||
const authorization = formatBearerAuthorization(resolveCsAppToken())
|
||||
const csToken = getStoredCsToken()
|
||||
const token = csToken || getStoredToken()
|
||||
const authorization = formatBearerAuthorization(token)
|
||||
return {
|
||||
clientId: UPLOAD_CLIENT_ID,
|
||||
clientId: csToken ? UPLOAD_CLIENT_ID : API_CLIENT_ID,
|
||||
...(authorization ? { Authorization: authorization } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
/** 212 客服 JSON 接口鉴权(与 upload 一致:clientId=app + cs_token) */
|
||||
/** 212 客服 JSON 接口鉴权 */
|
||||
export function buildCsAppAuthHeaders(extra?: Record<string, unknown>): Record<string, string> {
|
||||
const authorization = formatBearerAuthorization(resolveCsAppToken())
|
||||
return {
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
clientId: UPLOAD_CLIENT_ID,
|
||||
clientId: resolveCsAppClientId(),
|
||||
...(authorization ? { Authorization: authorization } : {}),
|
||||
...(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'
|
||||
|
||||
function resolveUploadAuthHeaders(mode: UploadAuthMode): Record<string, string> {
|
||||
@@ -130,7 +140,7 @@ function resolveUploadAuthHeaders(mode: UploadAuthMode): Record<string, string>
|
||||
function resolveUploadUrl(url: string): string {
|
||||
if (/^https?:\/\//i.test(url)) return url
|
||||
const path = url.startsWith('/') ? url : `/${url}`
|
||||
return `${BASE_URL}${path}`
|
||||
return `${getApiBaseUrl()}${path}`
|
||||
}
|
||||
|
||||
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 发出 */
|
||||
export function uploadAppFile<T>(
|
||||
url: string,
|
||||
@@ -220,12 +243,14 @@ export function uploadAppFile<T>(
|
||||
authMode: UploadAuthMode = 'default',
|
||||
): Promise<T> {
|
||||
const targetUrl = resolveUploadUrl(url)
|
||||
const hadCsToken = authMode === 'cs' && !!getStoredCsToken()
|
||||
|
||||
// #ifdef H5
|
||||
return uploadViaFetchH5<T>(targetUrl, filePath, fieldName, authMode)
|
||||
// #endif
|
||||
|
||||
return uploadViaUniMultipart<T>(targetUrl, filePath, fieldName, authMode)
|
||||
return runUpload<T>(targetUrl, filePath, fieldName, authMode).catch((err) => {
|
||||
if (authMode !== 'cs' || !isCsAuthError(err)) throw err
|
||||
if (!hadCsToken) throw err
|
||||
clearStoredCsToken()
|
||||
return runUpload<T>(targetUrl, filePath, fieldName, authMode)
|
||||
})
|
||||
}
|
||||
|
||||
function handleSuccess<T>(
|
||||
@@ -266,6 +291,12 @@ function runRequest<T>(
|
||||
saveTokenFromBody = false,
|
||||
): Promise<T> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
assertRequestUrl(url)
|
||||
} catch (err) {
|
||||
reject(new ApiError(err instanceof Error ? err.message : '接口地址未配置'))
|
||||
return
|
||||
}
|
||||
uni.request({
|
||||
...options,
|
||||
url,
|
||||
@@ -280,7 +311,7 @@ function runRequest<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> {
|
||||
const csBase = resolveCsAppBaseUrl()
|
||||
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 */
|
||||
export function requestLogin<T = unknown>(options: RequestOptions): Promise<T> {
|
||||
const url = `${getApiBaseUrl()}${options.url}`
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
assertRequestUrl(url)
|
||||
} catch (err) {
|
||||
reject(new ApiError(err instanceof Error ? err.message : '接口地址未配置'))
|
||||
return
|
||||
}
|
||||
uni.request({
|
||||
...options,
|
||||
url: `${BASE_URL}${options.url}`,
|
||||
url,
|
||||
header: buildAuthHeaders(options.header),
|
||||
dataType: 'text',
|
||||
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" : "",
|
||||
"appid" : "",
|
||||
"name" : "虫子智家",
|
||||
"appid" : "__UNI__925D0CC",
|
||||
"description" : "",
|
||||
"versionName" : "1.0.0",
|
||||
"versionCode" : "100",
|
||||
@@ -18,6 +18,8 @@
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules" : {
|
||||
"Bluetooth" : {},
|
||||
"Camera" : {},
|
||||
"Maps" : {}
|
||||
},
|
||||
/* 应用发布信息 */
|
||||
@@ -50,9 +52,51 @@
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios" : {},
|
||||
"ios" : {
|
||||
"dSYMs" : false
|
||||
},
|
||||
/* 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
@@ -101,8 +145,8 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
"uniStatistics" : {
|
||||
"enable" : false
|
||||
},
|
||||
"vueVersion" : "3"
|
||||
}
|
||||
|
||||
@@ -6,13 +6,6 @@
|
||||
}
|
||||
},
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/login/index",
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTitleText": "登录"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/device/index",
|
||||
"style": {
|
||||
@@ -20,6 +13,13 @@
|
||||
"navigationBarTitleText": "设备"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/login/index",
|
||||
"style": {
|
||||
"navigationStyle": "custom",
|
||||
"navigationBarTitleText": "登录"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/device/detail/index",
|
||||
"style": {
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
}
|
||||
|
||||
.add-device-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.add-device-page__body {
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
}
|
||||
|
||||
.complete-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.complete-page__body {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="complete-page">
|
||||
<app-navbar title="设备配置" />
|
||||
<scroll-view class="complete-page__scroll" scroll-y>
|
||||
<page-scroll-view class="complete-page__scroll">
|
||||
<view class="complete-page__body">
|
||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||
<complete-success-hero />
|
||||
@@ -107,7 +107,7 @@
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
<view class="complete-page__footer">
|
||||
<view
|
||||
class="complete-page__submit"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="add-device-page">
|
||||
<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">
|
||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||
<bind-bluetooth-hero />
|
||||
@@ -25,7 +25,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="pair-page">
|
||||
<app-navbar title="设备配置" />
|
||||
<scroll-view class="pair-page__scroll" scroll-y>
|
||||
<page-scroll-view class="pair-page__scroll">
|
||||
<view class="pair-page__body">
|
||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||
<pair-hero />
|
||||
@@ -33,7 +33,7 @@
|
||||
<pair-check-list :items="checkItems" />
|
||||
<pair-device-summary :device="device" :connect-status="connectStatus" />
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
<view class="pair-page__footer">
|
||||
<view
|
||||
v-if="connectStatus === 'failed'"
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
}
|
||||
|
||||
.pair-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.pair-page__body {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<view class="scan-page">
|
||||
<app-navbar title="扫描设备" />
|
||||
<scroll-view class="scan-page__scroll" scroll-y>
|
||||
<page-scroll-view class="scan-page__scroll">
|
||||
<view class="scan-page__body">
|
||||
<bind-steps :steps="BIND_STEPS" :current="currentStep" />
|
||||
<scan-hero />
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
<scan-help-tip />
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
}
|
||||
|
||||
.scan-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.scan-page__body {
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<template>
|
||||
<view class="agreement-page">
|
||||
<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 v-if="loading" class="agreement-page__loading">
|
||||
<text>加载中...</text>
|
||||
</view>
|
||||
<text v-else class="agreement-page__text">{{ content }}</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -27,8 +27,7 @@ const { title, content, loading } = useAgreement()
|
||||
}
|
||||
|
||||
.agreement-page__scroll {
|
||||
flex: 1;
|
||||
height: calc(100vh - 88rpx);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.agreement-page__content {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<base-input v-model="password" 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">
|
||||
<primary-button text="确认修改" @click="submit" />
|
||||
@@ -17,8 +17,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { PASSWORD_RULE_HINT } from '@/utils/validate'
|
||||
import { useChangePassword } from './use-change-password'
|
||||
|
||||
const passwordRuleHint = `${PASSWORD_RULE_HINT}。`
|
||||
|
||||
const { password, confirmPassword, submit } = useChangePassword()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { ref } from 'vue'
|
||||
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'
|
||||
|
||||
export function useChangePassword() {
|
||||
@@ -27,10 +27,7 @@ export function useChangePassword() {
|
||||
return
|
||||
}
|
||||
if (!isValidStrongPassword(password.value)) {
|
||||
uni.showToast({
|
||||
title: '密码需8-20位,且包含字母、数字、符号中至少2种',
|
||||
icon: 'none',
|
||||
})
|
||||
uni.showToast({ title: PASSWORD_INVALID_TOAST, icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (password.value !== confirmPassword.value) {
|
||||
|
||||
@@ -163,8 +163,7 @@
|
||||
.device-detail-page__scroll {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
margin-top: -40rpx;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<text class="device-detail-hero__sync">{{ syncText }}</text>
|
||||
</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__dash" aria-hidden="true" />
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
|
||||
<filter-replace-dialog
|
||||
v-model:visible="filterReplaceDialogVisible"
|
||||
@@ -152,12 +152,16 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { usePageScrollHeight } from '@/hooks/use-page-scroll-height'
|
||||
import { staticAssets } from '@/utils/static-assets'
|
||||
import FilterReplaceDialog from './components/filter-replace-dialog/index.vue'
|
||||
import RunModeExplainDialog from './components/run-mode-explain-dialog/index.vue'
|
||||
import { useDeviceDetail } from './use-device-detail'
|
||||
|
||||
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight ?? 0)
|
||||
const { scrollStyle: detailScrollStyle } = usePageScrollHeight({
|
||||
topSelector: '.device-detail-hero',
|
||||
})
|
||||
const runModeExplainVisible = ref(false)
|
||||
|
||||
function onOpenRunModeExplain() {
|
||||
|
||||
@@ -4,3 +4,16 @@
|
||||
padding-bottom: calc(120rpx + env(safe-area-inset-bottom));
|
||||
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">
|
||||
<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">
|
||||
<text class="home-manage-page__summary">{{ summaryText }}</text>
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
|
||||
<home-name-dialog
|
||||
v-model:visible="nameDialogVisible"
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
}
|
||||
|
||||
.home-manage-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.home-manage-page__body {
|
||||
@@ -73,11 +72,18 @@
|
||||
margin-left: 32rpx;
|
||||
}
|
||||
|
||||
.home-manage-page__loading,
|
||||
.home-manage-page__empty {
|
||||
padding: 120rpx 32rpx;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.home-manage-page__loading-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.home-manage-page__empty-text {
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<view class="home-manage-page">
|
||||
<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 v-if="homes.length" class="home-manage-page__list">
|
||||
<view
|
||||
@@ -20,11 +20,14 @@
|
||||
</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>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { ref } from 'vue'
|
||||
import {
|
||||
buildUpdateHomeBody,
|
||||
isValidHomeName,
|
||||
updateHome,
|
||||
} from '@/api/home'
|
||||
import { getErrorMessage } from '@/utils/api-error'
|
||||
import { parseId } from '@/utils/device-id'
|
||||
import { formatCoordinateAddress, reverseGeocode } from '@/utils/map-geocode'
|
||||
import { loadHomeGeo, saveHomeGeo } from '../use-home-manage'
|
||||
@@ -21,6 +27,8 @@ function requestUserLocation(): Promise<UniApp.GetLocationSuccess> {
|
||||
|
||||
export function useHomeLocation() {
|
||||
const homeId = ref('')
|
||||
const homeName = ref('我的家')
|
||||
const saving = ref(false)
|
||||
const latitude = ref(DEFAULT_LATITUDE)
|
||||
const longitude = ref(DEFAULT_LONGITUDE)
|
||||
const searchKeyword = ref('')
|
||||
@@ -136,11 +144,17 @@ export function useHomeLocation() {
|
||||
}
|
||||
}
|
||||
|
||||
function onConfirm() {
|
||||
async function onConfirm() {
|
||||
if (!homeId.value) {
|
||||
uni.navigateBack()
|
||||
return
|
||||
}
|
||||
if (!isValidHomeName(homeName.value)) {
|
||||
uni.showToast({ title: '家庭名称需 2-10 个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (saving.value) return
|
||||
|
||||
const address = addressText.value.trim()
|
||||
|| formatCoordinateAddress(latitude.value, longitude.value)
|
||||
const geo: HomeGeoInfo = {
|
||||
@@ -148,15 +162,30 @@ export function useHomeLocation() {
|
||||
latitude: latitude.value,
|
||||
longitude: longitude.value,
|
||||
}
|
||||
saveHomeGeo(homeId.value, geo)
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 300)
|
||||
|
||||
saving.value = true
|
||||
try {
|
||||
await updateHome(
|
||||
homeId.value,
|
||||
buildUpdateHomeBody(homeName.value, { geo }),
|
||||
)
|
||||
saveHomeGeo(homeId.value, geo)
|
||||
uni.showToast({ title: '保存成功', icon: 'success' })
|
||||
setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 300)
|
||||
} catch (err) {
|
||||
uni.showToast({ title: getErrorMessage(err, '保存家庭位置失败'), icon: 'none' })
|
||||
} finally {
|
||||
saving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onLoad((query?: Record<string, string | undefined>) => {
|
||||
homeId.value = parseId(query?.homeId)
|
||||
if (query?.homeName) {
|
||||
homeName.value = decodeURIComponent(String(query.homeName))
|
||||
}
|
||||
const saved = homeId.value ? loadHomeGeo(homeId.value) : undefined
|
||||
if (query?.address) {
|
||||
addressText.value = decodeURIComponent(String(query.address))
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
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 { getErrorMessage } from '@/utils/api-error'
|
||||
import { fetchHomeManageStats } from './home-manage.api'
|
||||
@@ -31,6 +37,8 @@ export function useHomeManage() {
|
||||
const homeAddress = ref('')
|
||||
const loading = ref(false)
|
||||
const nameDialogVisible = ref(false)
|
||||
const currentHome = ref<AppHomeVo>()
|
||||
const savingName = ref(false)
|
||||
|
||||
const summaryText = computed(
|
||||
() => `共${roomCount.value}个房间,${deviceCount.value}个设备`,
|
||||
@@ -44,11 +52,22 @@ export function useHomeManage() {
|
||||
fetchHomeManageStats(homeId.value),
|
||||
fetchRoomList(homeId.value),
|
||||
])
|
||||
currentHome.value = stats.home
|
||||
if (stats.home?.homeName) homeName.value = stats.home.homeName
|
||||
roomCount.value = rooms.length || stats.roomCount
|
||||
deviceCount.value = stats.deviceCount
|
||||
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) {
|
||||
uni.showToast({ title: getErrorMessage(err, '加载家庭信息失败'), icon: 'none' })
|
||||
} finally {
|
||||
@@ -68,14 +87,31 @@ export function useHomeManage() {
|
||||
nameDialogVisible.value = true
|
||||
}
|
||||
|
||||
function onConfirmHomeName(name: string) {
|
||||
async function onConfirmHomeName(name: string) {
|
||||
const trimmed = name.trim()
|
||||
if (!trimmed) {
|
||||
uni.showToast({ title: '请输入家庭名称', icon: 'none' })
|
||||
if (!isValidHomeName(trimmed)) {
|
||||
uni.showToast({ title: '家庭名称需 2-10 个字符', icon: 'none' })
|
||||
return
|
||||
}
|
||||
homeName.value = trimmed
|
||||
uni.showToast({ title: '家庭名称修改接口待对接', icon: 'none' })
|
||||
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
|
||||
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() {
|
||||
|
||||
@@ -21,7 +21,10 @@
|
||||
@manage="onManageDevices"
|
||||
@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" />
|
||||
<hot-devices :items="hotDevices" @mall="onGoMall" />
|
||||
</template>
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
}
|
||||
|
||||
.device-settings-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.device-settings-page__body {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<view class="device-settings-page">
|
||||
<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-card">
|
||||
<view class="device-settings-card__top">
|
||||
@@ -74,7 +74,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
|
||||
<device-name-dialog
|
||||
v-model:visible="nameDialogVisible"
|
||||
|
||||
@@ -2,6 +2,7 @@ import { onHide, onShow } from '@dcloudio/uni-app'
|
||||
import { computed, ref } from 'vue'
|
||||
import { refreshUnreadMessageCount } from '@/hooks/use-message-inbox'
|
||||
import { fetchHomeList, resolveValidHomeId } from '@/api/home'
|
||||
import { getStoredToken } from '@/utils/auth-token'
|
||||
import { parseId, sameId } from '@/utils/device-id'
|
||||
import { createLocation } from '@/api/location'
|
||||
import { getErrorMessage } from '@/utils/api-error'
|
||||
@@ -131,6 +132,10 @@ export function useDevice() {
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
if (!getStoredToken()) {
|
||||
uni.reLaunch({ url: '/pages/login/index' })
|
||||
return
|
||||
}
|
||||
void loadDevices()
|
||||
void refreshUnreadMessageCount()
|
||||
startPresencePolling()
|
||||
|
||||
@@ -8,7 +8,16 @@
|
||||
</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="code" icon="shield" type="number" placeholder="请输入验证码" :maxlength="6">
|
||||
<template #suffix>
|
||||
@@ -20,15 +29,6 @@
|
||||
</view>
|
||||
</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__agreement">
|
||||
<agreement-checkbox v-model="agreed" />
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { ref } from 'vue'
|
||||
import { useSmsCode } from '@/hooks/use-sms-code'
|
||||
import { isValidPassword, isValidPhone, isValidSmsCode } from '@/utils/validate'
|
||||
@@ -10,8 +11,8 @@ import { loginByPassword, loginBySms } from './login.api'
|
||||
import type { LoginMode } from './login.types'
|
||||
|
||||
export function useLogin() {
|
||||
const mode = ref<LoginMode>('code')
|
||||
const agreed = ref(true)
|
||||
const mode = ref<LoginMode>('password')
|
||||
const agreed = ref(false)
|
||||
const phone = ref('')
|
||||
const code = ref('')
|
||||
const account = ref('')
|
||||
@@ -85,6 +86,12 @@ export function useLogin() {
|
||||
uni.navigateTo({ url: '/pages/forgot-password/index' })
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
if (!getStoredToken()) return
|
||||
setupMessageInbox()
|
||||
uni.reLaunch({ url: '/pages/device/index' })
|
||||
})
|
||||
|
||||
return {
|
||||
mode,
|
||||
agreed,
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
}
|
||||
|
||||
.edit-profile-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.edit-profile-page__body {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<app-navbar title="编辑资料" />
|
||||
</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__avatar-section">
|
||||
<view class="edit-profile-page__avatar-wrap">
|
||||
@@ -118,7 +118,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
|
||||
<view class="edit-profile-page__footer">
|
||||
<view
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { onShow } from '@dcloudio/uni-app'
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import { computed, ref } from 'vue'
|
||||
import { fetchProfile, updateProfile, uploadProfileAvatar } from '@/api/profile'
|
||||
import { getErrorMessage } from '@/utils/api-error'
|
||||
@@ -56,22 +56,25 @@ export function useEditProfile() {
|
||||
const locationText = computed(() =>
|
||||
formatLocation(form.value.province, form.value.city, form.value.district),
|
||||
)
|
||||
function applyProfile(profile: Awaited<ReturnType<typeof fetchProfile>>) {
|
||||
form.value = {
|
||||
nickName: profile.nickName || profile.userName || '',
|
||||
gender: profile.gender || '0',
|
||||
birthday: profile.birthday || '',
|
||||
province: profile.province || '',
|
||||
city: profile.city || '',
|
||||
district: profile.district || '',
|
||||
phonenumber: profile.phonenumber || profile.userName || '',
|
||||
avatarUrl: profile.avatarUrl || '',
|
||||
avatarOssId: profile.avatarOssId ? String(profile.avatarOssId) : '',
|
||||
}
|
||||
}
|
||||
|
||||
async function loadProfile() {
|
||||
if (loading.value) return
|
||||
loading.value = true
|
||||
try {
|
||||
const profile = await fetchProfile()
|
||||
form.value = {
|
||||
nickName: profile.nickName || profile.userName || '',
|
||||
gender: profile.gender || '0',
|
||||
birthday: profile.birthday || '',
|
||||
province: profile.province || '',
|
||||
city: profile.city || '',
|
||||
district: profile.district || '',
|
||||
phonenumber: profile.phonenumber || profile.userName || '',
|
||||
avatarUrl: profile.avatarUrl || '',
|
||||
avatarOssId: profile.avatarOssId ? String(profile.avatarOssId) : '',
|
||||
}
|
||||
applyProfile(await fetchProfile())
|
||||
} catch (err) {
|
||||
uni.showToast({ title: getErrorMessage(err, '加载资料失败'), icon: 'none' })
|
||||
} 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() {
|
||||
avatarSheetVisible.value = true
|
||||
}
|
||||
@@ -105,6 +118,7 @@ export function useEditProfile() {
|
||||
const filePath = res.tempFilePaths[0]
|
||||
if (!filePath) return
|
||||
|
||||
form.value.avatarUrl = filePath
|
||||
uploadingAvatar.value = true
|
||||
uni.showLoading({ title: '上传中...', mask: true })
|
||||
const uploaded = await uploadProfileAvatar(filePath)
|
||||
@@ -200,10 +214,14 @@ export function useEditProfile() {
|
||||
}
|
||||
}
|
||||
|
||||
onShow(() => {
|
||||
onLoad(() => {
|
||||
void loadProfile()
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
void refreshPhoneFromServer()
|
||||
})
|
||||
|
||||
return {
|
||||
loading,
|
||||
saving,
|
||||
|
||||
@@ -8,9 +8,8 @@
|
||||
</template>
|
||||
</app-navbar>
|
||||
|
||||
<scroll-view
|
||||
<page-scroll-view
|
||||
class="notify-page__scroll"
|
||||
scroll-y
|
||||
refresher-enabled
|
||||
:refresher-triggered="loading"
|
||||
@refresherrefresh="onRefresh"
|
||||
@@ -50,7 +49,7 @@
|
||||
</view>
|
||||
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
}
|
||||
|
||||
.notify-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.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">
|
||||
<app-navbar title="账号与安全" />
|
||||
|
||||
<scroll-view class="privacy-page__scroll" scroll-y>
|
||||
<page-scroll-view class="privacy-page__scroll">
|
||||
<view class="privacy-page__body">
|
||||
<view
|
||||
v-for="section in sections"
|
||||
@@ -54,15 +54,27 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
|
||||
<cancel-account-dialog
|
||||
v-model:visible="cancelAccountDialogVisible"
|
||||
@confirm="onConfirmCancelAccount"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { staticAssets } from '@/utils/static-assets'
|
||||
import CancelAccountDialog from './components/cancel-account-dialog/index.vue'
|
||||
import { usePrivacy } from './use-privacy'
|
||||
|
||||
const { sections, onItemTap, onLogout } = usePrivacy()
|
||||
const {
|
||||
sections,
|
||||
cancelAccountDialogVisible,
|
||||
onItemTap,
|
||||
onLogout,
|
||||
onConfirmCancelAccount,
|
||||
} = usePrivacy()
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
}
|
||||
|
||||
.privacy-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.privacy-page__body {
|
||||
|
||||
@@ -15,6 +15,8 @@ function maskPhone(phone?: string): string {
|
||||
|
||||
export function usePrivacy() {
|
||||
const phone = ref('')
|
||||
const cancelAccountDialogVisible = ref(false)
|
||||
const cancelingAccount = ref(false)
|
||||
|
||||
const sections = computed<PrivacySection[]>(() => [
|
||||
{
|
||||
@@ -66,25 +68,23 @@ export function usePrivacy() {
|
||||
return
|
||||
}
|
||||
if (itemId === 'delete-account') {
|
||||
uni.showModal({
|
||||
title: '注销账号',
|
||||
content: '注销后账号及所有数据将被永久删除,且无法恢复。确定继续吗?',
|
||||
confirmColor: '#f04438',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return
|
||||
void (async () => {
|
||||
try {
|
||||
await cancelAccount()
|
||||
teardownMessageInbox()
|
||||
clearStoredToken()
|
||||
uni.showToast({ title: '账号已注销', icon: 'success' })
|
||||
uni.reLaunch({ url: '/pages/login/index' })
|
||||
} catch (err) {
|
||||
uni.showToast({ title: getErrorMessage(err, '注销失败'), icon: 'none' })
|
||||
}
|
||||
})()
|
||||
},
|
||||
})
|
||||
cancelAccountDialogVisible.value = true
|
||||
}
|
||||
}
|
||||
|
||||
async function onConfirmCancelAccount() {
|
||||
if (cancelingAccount.value) return
|
||||
cancelingAccount.value = true
|
||||
try {
|
||||
await cancelAccount()
|
||||
teardownMessageInbox()
|
||||
clearStoredToken()
|
||||
uni.showToast({ title: '账号已注销', icon: 'success' })
|
||||
uni.reLaunch({ url: '/pages/login/index' })
|
||||
} catch (err) {
|
||||
uni.showToast({ title: getErrorMessage(err, '注销失败'), icon: 'none' })
|
||||
} finally {
|
||||
cancelingAccount.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,9 @@ export function usePrivacy() {
|
||||
|
||||
return {
|
||||
sections,
|
||||
cancelAccountDialogVisible,
|
||||
onItemTap,
|
||||
onLogout,
|
||||
onConfirmCancelAccount,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<base-input v-model="confirmPassword" icon="lock" type="password" placeholder="确认密码" />
|
||||
</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">
|
||||
<primary-button text="确认修改" @click="submit" />
|
||||
@@ -23,8 +23,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { PASSWORD_RULE_HINT } from '@/utils/validate'
|
||||
import { useSetPassword } from './use-set-password'
|
||||
|
||||
const passwordRuleHint = `${PASSWORD_RULE_HINT}。`
|
||||
|
||||
const { password, confirmPassword, onForgotPassword, submit } = useSetPassword()
|
||||
</script>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<view class="storage-page">
|
||||
<app-navbar title="储存空间" />
|
||||
|
||||
<scroll-view class="storage-page__scroll" scroll-y>
|
||||
<page-scroll-view class="storage-page__scroll">
|
||||
<view class="storage-page__body">
|
||||
<text class="storage-page__section-label">储存空间</text>
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
</template>
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</page-scroll-view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
}
|
||||
|
||||
.storage-page__scroll {
|
||||
flex: 1;
|
||||
height: 0;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.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'
|
||||
|
||||
/** 断线后首次重连等待(非轮询;连接成功后会保持长连接) */
|
||||
@@ -28,26 +29,18 @@ function resolveCsChatWsBase(): string {
|
||||
|
||||
if (isH5Dev() && !forceDirect) {
|
||||
const proto = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
|
||||
const useCsHost = !!import.meta.env.VITE_CS_API_BASE_URL?.trim()
|
||||
const path = useCsHost ? '/cs-app/cs/chat' : '/app/cs/chat'
|
||||
return `${proto}//${window.location.host}${path}`
|
||||
return `${proto}//${window.location.host}/app/cs/chat`
|
||||
}
|
||||
|
||||
if (configured) {
|
||||
return configured.replace(/[?#].*$/, '').replace(/\/$/, '')
|
||||
}
|
||||
|
||||
const csBase = import.meta.env.VITE_CS_API_BASE_URL?.trim()
|
||||
if (csBase) {
|
||||
const wsBase = csBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws').replace(/\/$/, '')
|
||||
return `${wsBase}/app/cs/chat`
|
||||
}
|
||||
|
||||
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')
|
||||
const httpBase =
|
||||
getApiBaseUrl()
|
||||
|| import.meta.env.VITE_API_PROXY_TARGET?.trim()
|
||||
|| 'http://192.168.0.222:8082'
|
||||
const wsBase = httpBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws').replace(/\/$/, '')
|
||||
return `${wsBase}/app/cs/chat`
|
||||
}
|
||||
|
||||
@@ -79,7 +72,7 @@ function clearReconnectTimer() {
|
||||
}
|
||||
|
||||
function scheduleReconnect() {
|
||||
if (manualClosed || !resolveCsAppToken() || !activeSessionId) return
|
||||
if (manualClosed || !getStoredToken() || !activeSessionId) return
|
||||
clearReconnectTimer()
|
||||
const delay = Math.min(
|
||||
RECONNECT_BASE_MS * Math.pow(1.5, reconnectAttempt),
|
||||
@@ -209,7 +202,7 @@ function bindSocketTask(task: UniApp.SocketTask, seq: number) {
|
||||
}
|
||||
|
||||
export function connectCsChatSocket(sessionId: string) {
|
||||
const token = resolveCsAppToken()
|
||||
const token = getStoredToken()
|
||||
if (!token || !sessionId) return
|
||||
if (connecting) return
|
||||
if (socketOpened && socketTask && activeSessionId === sessionId) return
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { resolveCsAppBaseUrl, request, requestCsApp, uploadAppFile } from '@/api/request'
|
||||
import { assertCsUploadToken, ensureCsUploadReady } from '@/api/cs-auth'
|
||||
import { isCsAuthError, request, uploadAppFile } from '@/api/request'
|
||||
import { getCsApiBaseUrl } from '@/config/app-env'
|
||||
import { ApiError } from '@/utils/api-error'
|
||||
import {
|
||||
isSessionEnded,
|
||||
@@ -27,15 +27,20 @@ function buildSessionPath(sessionId: string, suffix = '') {
|
||||
return `/app/cs/session/${encodeURIComponent(sessionId)}${suffix}`
|
||||
}
|
||||
|
||||
/** 客服会话相关接口统一走 212(与 upload / 图片 message 同服,保证 ossId、url 一致) */
|
||||
function csRequest<T>(options: Parameters<typeof request>[0]): Promise<T> {
|
||||
return resolveCsAppBaseUrl() ? requestCsApp<T>(options) : request<T>(options)
|
||||
/**
|
||||
* 客服会话 / 消息 / 转人工等走主站(222),与设备列表等同套 token + clientId。
|
||||
* 仅图片上传走 212(有 cs_token 用 clientId=app,否则主站 token + 主站 clientId)。
|
||||
*/
|
||||
function csSessionRequest<T>(options: Parameters<typeof request>[0]): Promise<T> {
|
||||
return request<T>(options)
|
||||
}
|
||||
|
||||
function resolveCsUploadUrl(): string {
|
||||
const csBase = resolveCsAppBaseUrl()
|
||||
if (csBase) return `${csBase}/cs/upload`
|
||||
return '/app/cs/upload'
|
||||
// #ifdef H5
|
||||
if (import.meta.env.DEV) return '/cs-app/cs/upload'
|
||||
// #endif
|
||||
const csBase = getCsApiBaseUrl()
|
||||
return csBase ? `${csBase}/app/cs/upload` : '/app/cs/upload'
|
||||
}
|
||||
|
||||
function normalizeCsUploadVo(data: unknown): CzCsUploadVo {
|
||||
@@ -66,7 +71,7 @@ function unwrapRows<T>(data: T[] | CsTableData<T> | undefined): T[] {
|
||||
|
||||
/** POST /app/cs/session — 创建客服会话;已有未结束会话时返回原会话 */
|
||||
export function createCsSession(data: CsCreateSessionBody = {}) {
|
||||
return csRequest<CsAppActionVo | CsSessionVo | string | null>({
|
||||
return csSessionRequest<CsAppActionVo | CsSessionVo | string | null>({
|
||||
url: '/app/cs/session',
|
||||
method: 'POST',
|
||||
data,
|
||||
@@ -113,7 +118,7 @@ export async function resolveCsSession(): Promise<CsResolvedSession> {
|
||||
|
||||
/** GET /app/cs/session/list — 查询自己的会话 */
|
||||
export function fetchCsSessionList(query: CsSessionListQuery = {}) {
|
||||
return csRequest<CsSessionVo[] | CsTableData<CsSessionVo>>({
|
||||
return csSessionRequest<CsSessionVo[] | CsTableData<CsSessionVo>>({
|
||||
url: '/app/cs/session/list',
|
||||
method: 'GET',
|
||||
data: query,
|
||||
@@ -122,7 +127,7 @@ export function fetchCsSessionList(query: CsSessionListQuery = {}) {
|
||||
|
||||
/** GET /app/cs/session/{sessionId} — 查询会话详情 */
|
||||
export function fetchCsSessionDetail(sessionId: string) {
|
||||
return csRequest<CsAppActionVo | CsSessionVo | string | null>({
|
||||
return csSessionRequest<CsAppActionVo | CsSessionVo | string | null>({
|
||||
url: buildSessionPath(sessionId),
|
||||
method: 'GET',
|
||||
}).then((data) => normalizeSessionResponse(unwrapCsActionResponse(data).session))
|
||||
@@ -130,19 +135,23 @@ export function fetchCsSessionDetail(sessionId: string) {
|
||||
|
||||
/** GET /app/cs/session/{sessionId}/messages — 拉取会话消息 */
|
||||
export function fetchCsMessages(sessionId: string, afterSeq = 0) {
|
||||
return csRequest<CsMessageVo[] | CsTableData<CsMessageVo>>({
|
||||
return csSessionRequest<CsMessageVo[] | CsTableData<CsMessageVo>>({
|
||||
url: buildSessionPath(sessionId, '/messages'),
|
||||
method: 'GET',
|
||||
data: { afterSeq },
|
||||
}).then(unwrapRows)
|
||||
}
|
||||
|
||||
/** POST /app/cs/upload — 212 上传(clientId=app + cs_token) */
|
||||
export function uploadCsChatImage(filePath: string): Promise<CzCsUploadVo> {
|
||||
assertCsUploadToken()
|
||||
return uploadAppFile<CzCsUploadVo>(resolveCsUploadUrl(), filePath, 'file', 'cs').then((data) =>
|
||||
normalizeCsUploadVo(data),
|
||||
)
|
||||
/** POST /app/cs/upload — 优先 212;鉴权失败时回退主站 222 */
|
||||
export async function uploadCsChatImage(filePath: string): Promise<CzCsUploadVo> {
|
||||
try {
|
||||
const data = await uploadAppFile<CzCsUploadVo>(resolveCsUploadUrl(), filePath, 'file', 'cs')
|
||||
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 */
|
||||
@@ -161,8 +170,7 @@ export function buildCsImageMessageBody(
|
||||
|
||||
/** POST /app/cs/session/{sessionId}/message — 发送消息 */
|
||||
export function sendCsMessage(sessionId: string, data: CsSendMessageBody) {
|
||||
if (resolveCsAppBaseUrl()) ensureCsUploadReady()
|
||||
return csRequest<CsAppActionVo>({
|
||||
return csSessionRequest<CsAppActionVo>({
|
||||
url: buildSessionPath(sessionId, '/message'),
|
||||
method: 'POST',
|
||||
data,
|
||||
@@ -171,7 +179,7 @@ export function sendCsMessage(sessionId: string, data: CsSendMessageBody) {
|
||||
|
||||
/** POST /app/cs/session/{sessionId}/transfer — 转人工 */
|
||||
export function transferCsSession(sessionId: string) {
|
||||
return csRequest<CsAppActionVo | CsSessionVo | null>({
|
||||
return csSessionRequest<CsAppActionVo | CsSessionVo | null>({
|
||||
url: buildSessionPath(sessionId, '/transfer'),
|
||||
method: 'POST',
|
||||
})
|
||||
@@ -179,7 +187,7 @@ export function transferCsSession(sessionId: string) {
|
||||
|
||||
/** POST /app/cs/session/{sessionId}/end — 结束会话 */
|
||||
export function endCsSession(sessionId: string) {
|
||||
return csRequest<void>({
|
||||
return csSessionRequest<void>({
|
||||
url: buildSessionPath(sessionId, '/end'),
|
||||
method: 'POST',
|
||||
})
|
||||
@@ -187,7 +195,7 @@ export function endCsSession(sessionId: string) {
|
||||
|
||||
/** POST /app/cs/session/{sessionId}/button — 点击机器人按钮 */
|
||||
export function clickCsButton(sessionId: string, data: CsClickButtonBody) {
|
||||
return csRequest<void>({
|
||||
return csSessionRequest<void>({
|
||||
url: buildSessionPath(sessionId, '/button'),
|
||||
method: 'POST',
|
||||
data,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { onBeforeUnmount } from 'vue'
|
||||
import { onHide, onShow, onUnload } from '@dcloudio/uni-app'
|
||||
import { computed, ref } from 'vue'
|
||||
import { ensureCsUploadReady } from '@/api/cs-auth'
|
||||
import { ensureCsSessionReady } from '@/api/cs-auth'
|
||||
import { fetchProfile } from '@/api/profile'
|
||||
import { getErrorMessage } from '@/utils/api-error'
|
||||
import { getStoredToken } from '@/utils/auth-token'
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
uploadCsChatImage,
|
||||
} from './support.api'
|
||||
import {
|
||||
connectCsChatSocket,
|
||||
disconnectCsChatSocket,
|
||||
isCsChatSocketConnected,
|
||||
onCsChatPush,
|
||||
@@ -586,7 +587,12 @@ export function useSupport() {
|
||||
|
||||
function activatePage() {
|
||||
markSupportPageActive(true)
|
||||
ensureCsUploadReady()
|
||||
try {
|
||||
ensureCsSessionReady()
|
||||
} catch {
|
||||
uni.showToast({ title: '请先登录', icon: 'none' })
|
||||
return
|
||||
}
|
||||
void loadUserProfile()
|
||||
if (!sessionId.value) {
|
||||
void ensureSession()
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
<base-input v-model="password" 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">
|
||||
<primary-button text="立即注册" @click="submit" />
|
||||
</view>
|
||||
@@ -25,8 +27,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { PASSWORD_RULE_HINT } from '@/utils/validate'
|
||||
import { useRegister } from './use-register'
|
||||
|
||||
const passwordRuleHint = `${PASSWORD_RULE_HINT}。`
|
||||
|
||||
const {
|
||||
phone,
|
||||
code,
|
||||
@@ -58,6 +63,14 @@ const {
|
||||
margin-bottom: 48rpx;
|
||||
}
|
||||
|
||||
.auth-form-page__hint {
|
||||
display: block;
|
||||
margin-top: 16rpx;
|
||||
font-size: 24rpx;
|
||||
color: $color-text-secondary;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.auth-form-page__btn {
|
||||
margin-top: 16rpx;
|
||||
margin-bottom: 40rpx;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { ref } from 'vue'
|
||||
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 { registerUser } from './register.api'
|
||||
|
||||
@@ -31,8 +36,8 @@ export function useRegister() {
|
||||
uni.showToast({ title: '请输入验证码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!isValidPassword(password.value)) {
|
||||
uni.showToast({ title: '密码至少 6 位', icon: 'none' })
|
||||
if (!isValidStrongPassword(password.value)) {
|
||||
uni.showToast({ title: PASSWORD_INVALID_TOAST, icon: 'none' })
|
||||
return
|
||||
}
|
||||
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 {
|
||||
id?: string | number
|
||||
homeName?: string
|
||||
homeLocationLongitude?: number
|
||||
homeLocationLatitude?: number
|
||||
homeLocationAddress?: string
|
||||
isDefault?: string | number | boolean
|
||||
locationCount?: number
|
||||
createTime?: string
|
||||
}
|
||||
|
||||
/** PUT /app/home/{homeId} 请求体 */
|
||||
export interface UpdateHomeBody {
|
||||
homeName: string
|
||||
homeLocationLongitude: number
|
||||
homeLocationLatitude: number
|
||||
homeLocationAddress: string
|
||||
}
|
||||
|
||||
/** 房间位置(由接口数据映射) */
|
||||
export interface RoomOption {
|
||||
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 {
|
||||
decodeSocketMessageData,
|
||||
@@ -7,82 +9,122 @@ import {
|
||||
import type { MessagePushPayload } from '@/types/message'
|
||||
|
||||
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
|
||||
let heartbeatTimer: ReturnType<typeof setInterval> | null = null
|
||||
let reconnectTimer: ReturnType<typeof setTimeout> | null = null
|
||||
let connecting = false
|
||||
let manualClosed = false
|
||||
let socketOpened = false
|
||||
let disconnectHandled = false
|
||||
interface MessageWsRuntime {
|
||||
socketTask: UniApp.SocketTask | null
|
||||
connecting: boolean
|
||||
socketOpened: boolean
|
||||
manualClosed: boolean
|
||||
connectionSeq: number
|
||||
disconnectHandled: boolean
|
||||
heartbeatTimer: ReturnType<typeof setInterval> | null
|
||||
reconnectTimer: ReturnType<typeof setTimeout> | null
|
||||
reconnectAttempt: number
|
||||
}
|
||||
|
||||
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 {
|
||||
const configured = import.meta.env.VITE_MESSAGE_WS_URL?.trim()
|
||||
const configured = getMessageWsUrl().trim()
|
||||
if (configured) {
|
||||
return configured.replace(/[?#].*$/, '').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 httpBase = getApiBaseUrl() || 'http://192.168.0.222:8082'
|
||||
const wsBase = httpBase.replace(/^https/i, 'wss').replace(/^http/i, 'ws')
|
||||
return `${wsBase}/app/ws/message`
|
||||
}
|
||||
|
||||
function resolveMessageWsUrl(token: string): string {
|
||||
const base = resolveMessageWsBase()
|
||||
return `${base}?token=${encodeURIComponent(token)}`
|
||||
const query = `token=${encodeURIComponent(token)}&clientId=${encodeURIComponent(API_CLIENT_ID)}`
|
||||
return `${base}?${query}`
|
||||
}
|
||||
|
||||
function stopHeartbeat() {
|
||||
if (heartbeatTimer) clearInterval(heartbeatTimer)
|
||||
heartbeatTimer = null
|
||||
function stopHeartbeat(state: MessageWsRuntime) {
|
||||
if (state.heartbeatTimer) clearInterval(state.heartbeatTimer)
|
||||
state.heartbeatTimer = null
|
||||
}
|
||||
|
||||
function sendPing() {
|
||||
if (!socketOpened || !socketTask) return
|
||||
socketTask.send({ data: 'ping' })
|
||||
function sendPing(state: MessageWsRuntime) {
|
||||
if (!state.socketOpened || !state.socketTask) return
|
||||
state.socketTask.send({ data: 'ping' })
|
||||
}
|
||||
|
||||
function startHeartbeat() {
|
||||
stopHeartbeat()
|
||||
sendPing()
|
||||
heartbeatTimer = setInterval(sendPing, HEARTBEAT_INTERVAL_MS)
|
||||
function startHeartbeat(state: MessageWsRuntime) {
|
||||
stopHeartbeat(state)
|
||||
sendPing(state)
|
||||
state.heartbeatTimer = setInterval(() => {
|
||||
sendPing(state)
|
||||
}, HEARTBEAT_INTERVAL_MS)
|
||||
}
|
||||
|
||||
function clearReconnectTimer() {
|
||||
if (reconnectTimer) clearTimeout(reconnectTimer)
|
||||
reconnectTimer = null
|
||||
function clearReconnectTimer(state: MessageWsRuntime) {
|
||||
if (state.reconnectTimer) clearTimeout(state.reconnectTimer)
|
||||
state.reconnectTimer = null
|
||||
}
|
||||
|
||||
function scheduleReconnect() {
|
||||
if (manualClosed || !getStoredToken()) return
|
||||
clearReconnectTimer()
|
||||
reconnectTimer = setTimeout(() => {
|
||||
function resetSocketState(state: MessageWsRuntime) {
|
||||
stopHeartbeat(state)
|
||||
state.socketTask = null
|
||||
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()
|
||||
}, RECONNECT_DELAY_MS)
|
||||
}, delay)
|
||||
}
|
||||
|
||||
function cleanupSocketTask() {
|
||||
stopHeartbeat()
|
||||
socketTask = null
|
||||
socketOpened = false
|
||||
connecting = false
|
||||
disconnectHandled = false
|
||||
}
|
||||
|
||||
function handleDisconnect(reason: string) {
|
||||
if (disconnectHandled) return
|
||||
disconnectHandled = true
|
||||
function handleDisconnect(state: MessageWsRuntime, reason: string) {
|
||||
if (state.disconnectHandled) return
|
||||
state.disconnectHandled = true
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(`[Message WS] ${reason}`)
|
||||
}
|
||||
cleanupSocketTask()
|
||||
if (!manualClosed) {
|
||||
scheduleReconnect()
|
||||
resetSocketState(state)
|
||||
if (!state.manualClosed) {
|
||||
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 {
|
||||
return socketOpened && !!socketTask
|
||||
const state = runtime()
|
||||
return state.socketOpened && !!state.socketTask
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -116,64 +190,78 @@ export function onMessagePush(listener: (payload: MessagePushPayload) => void) {
|
||||
}
|
||||
|
||||
export function connectMessageSocket() {
|
||||
const state = runtime()
|
||||
const token = getStoredToken()
|
||||
if (!token || manualClosed) return
|
||||
if (socketOpened && socketTask) return
|
||||
// 握手进行中:不要 close,否则 DevTools 会报 "closed before connection is established"
|
||||
if (isMessageSocketConnecting()) return
|
||||
if (!token || state.manualClosed) return
|
||||
if (state.socketOpened && state.socketTask) return
|
||||
if (state.connecting) return
|
||||
|
||||
manualClosed = false
|
||||
connecting = true
|
||||
disconnectHandled = false
|
||||
clearReconnectTimer()
|
||||
state.manualClosed = false
|
||||
const seq = ++state.connectionSeq
|
||||
clearReconnectTimer(state)
|
||||
|
||||
const task = uni.connectSocket({
|
||||
url: resolveMessageWsUrl(token),
|
||||
fail: (err) => {
|
||||
if (import.meta.env.DEV) {
|
||||
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) {
|
||||
const previousTask = state.socketTask
|
||||
state.socketTask = null
|
||||
state.socketOpened = false
|
||||
if (previousTask) {
|
||||
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 {
|
||||
// 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 iconCode from '@/static/icon-code@2x.png'
|
||||
import iconChecked from '@/static/icon-checked@2x.png'
|
||||
import iconPassword from '@/static/路径.png'
|
||||
import iconDeviceDetailSettings from '@/static/路径1.png'
|
||||
import deviceDetailHeroBg from '@/static/组 15226@2x.png'
|
||||
import iconRunModeInfo from '@/static/组 15227@2x.png'
|
||||
import iconHomeSelector from '@/static/图标 4.png'
|
||||
import iconHomeArrow from '@/static/组 9.png'
|
||||
import iconHomeSelected from '@/static/完成@2x.png'
|
||||
import iconNotify from '@/static/通知 (1).png'
|
||||
import iconDeviceEmpty from '@/static/图标 8.png'
|
||||
import iconDeviceNameEdit from '@/static/图标 9.png'
|
||||
import iconBindComplete from '@/static/组 41@2x.png'
|
||||
import iconBluetooth from '@/static/蓝牙-F.png'
|
||||
import iconBindDiscover from '@/static/组 281@2x.png'
|
||||
import iconBindPair from '@/static/组 286@2x.png'
|
||||
import iconBindSecure from '@/static/组 291@2x.png'
|
||||
import iconScanDevice from '@/static/组 600@2x.png'
|
||||
import iconScanDeviceAction from '@/static/组 468@2x.png'
|
||||
import iconScanDeviceActionDisabled from '@/static/组 476@2x.png'
|
||||
import iconPassword from '@/static/icon-password.png'
|
||||
import iconDeviceDetailSettings from '@/static/icon-device-settings.png'
|
||||
import deviceDetailHeroBg from '@/static/device-detail-hero-bg@2x.png'
|
||||
import iconRunModeInfo from '@/static/icon-run-mode-info@2x.png'
|
||||
import iconHomeSelector from '@/static/icon-home-selector.png'
|
||||
import iconHomeArrow from '@/static/icon-home-arrow.png'
|
||||
import iconHomeSelected from '@/static/icon-home-selected@2x.png'
|
||||
import iconNotify from '@/static/icon-notify.png'
|
||||
import iconDeviceEmpty from '@/static/icon-device-empty.png'
|
||||
import iconDeviceNameEdit from '@/static/icon-device-name-edit.png'
|
||||
import iconBindComplete from '@/static/icon-bind-complete@2x.png'
|
||||
import iconBluetooth from '@/static/icon-bluetooth.png'
|
||||
import iconBindDiscover from '@/static/icon-bind-discover@2x.png'
|
||||
import iconBindPair from '@/static/icon-bind-pair@2x.png'
|
||||
import iconBindSecure from '@/static/icon-bind-secure@2x.png'
|
||||
import iconScanDevice from '@/static/icon-scan-device@2x.png'
|
||||
import iconScanDeviceAction from '@/static/icon-scan-device-action@2x.png'
|
||||
import iconScanDeviceActionDisabled from '@/static/icon-scan-device-action-disabled@2x.png'
|
||||
import tabDevice from '@/static/tab-device-active.png'
|
||||
import tabDeviceActive from '@/static/tab-device.png'
|
||||
import tabMine from '@/static/tab-mine-active.png'
|
||||
import tabMineActive from '@/static/tab-mine.png'
|
||||
import iconChevronLeft from '@/static/chevron.left.png'
|
||||
import iconSupportMic from '@/static/组 134.png'
|
||||
import iconSupportPhoto from '@/static/图片.png'
|
||||
import iconSupportSend from '@/static/图标 14.png'
|
||||
import iconSupportQueue from '@/static/组 98@2x.png'
|
||||
import iconMineNotify from '@/static/组 14919@2x.png'
|
||||
import iconMineOrder from '@/static/订单@2x.png'
|
||||
import iconMineCoupon from '@/static/优惠券@2x.png'
|
||||
import iconMineAddress from '@/static/组 14923@2x.png'
|
||||
import iconChevronLeft from '@/static/icon-chevron-left.png'
|
||||
import iconSupportMic from '@/static/icon-support-mic.png'
|
||||
import iconSupportPhoto from '@/static/icon-support-photo.png'
|
||||
import iconSupportSend from '@/static/icon-support-send.png'
|
||||
import iconSupportQueue from '@/static/icon-support-queue@2x.png'
|
||||
import iconMineNotify from '@/static/icon-mine-notify@2x.png'
|
||||
import iconMineOrder from '@/static/icon-mine-order@2x.png'
|
||||
import iconMineCoupon from '@/static/icon-mine-coupon@2x.png'
|
||||
import iconMineAddress from '@/static/icon-mine-address@2x.png'
|
||||
|
||||
export const staticAssets = {
|
||||
/** 组 15106@2x.png — 登录区中心大图标 */
|
||||
logo: logoCenter,
|
||||
/** 手机号@2x.png */
|
||||
iconPhone,
|
||||
/** 验证码@2x.png */
|
||||
iconCode,
|
||||
/** 选中@2x.png */
|
||||
iconChecked,
|
||||
/** 路径.png — 密码框 */
|
||||
iconPassword,
|
||||
/** 路径1.png — 设备详情右上角设置 */
|
||||
iconDeviceDetailSettings,
|
||||
/** 组 15226@2x.png — 设备详情页上半部分背景 */
|
||||
deviceDetailHeroBg,
|
||||
/** 组 15227@2x.png — 设备详情「运行模式」旁提示图标 */
|
||||
iconRunModeInfo,
|
||||
/** 图标 4.png — 首页「我的家」 */
|
||||
iconHomeSelector,
|
||||
/** 组 9.png — 「我的家」下拉箭头 */
|
||||
iconHomeArrow,
|
||||
/** 完成@2x.png — 「我的家」下拉选中图标 */
|
||||
iconHomeSelected,
|
||||
/** 通知 (1).png — 设备页右上角通知 */
|
||||
iconNotify,
|
||||
/** 图标 8.png — 设备空状态中心图标 */
|
||||
iconDeviceEmpty,
|
||||
/** 图标 9.png — 完成配置「设备名称」编辑 */
|
||||
iconDeviceNameEdit,
|
||||
/** 组 41@2x.png — 完成配置成功示意图 */
|
||||
iconBindComplete,
|
||||
/** 蓝牙-F.png — 添加设备页蓝牙示意图 */
|
||||
iconBluetooth,
|
||||
/** 组 281@2x.png — 添加设备「发现附近设备」 */
|
||||
iconBindDiscover,
|
||||
/** 组 286@2x.png — 添加设备「快速配对连接」 */
|
||||
iconBindPair,
|
||||
/** 组 291@2x.png — 添加设备「本地安全控制」 */
|
||||
iconBindSecure,
|
||||
/** 组 600@2x.png — 扫描设备页示意图 */
|
||||
iconScanDevice,
|
||||
/** 组 468@2x.png — 发现设备列表「可添加」箭头 */
|
||||
iconScanDeviceAction,
|
||||
/** 组 476@2x.png — 发现设备列表「不可添加」箭头 */
|
||||
iconScanDeviceActionDisabled,
|
||||
tabDevice,
|
||||
tabDeviceActive,
|
||||
tabMine,
|
||||
tabMineActive,
|
||||
/** chevron.left.png — 列表右箭头(旋转 180° 使用) */
|
||||
iconChevronLeft,
|
||||
/** 组 134.png — 在线客服页麦克风 */
|
||||
iconSupportMic,
|
||||
/** 图片.png — 在线客服页发送图片 */
|
||||
iconSupportPhoto,
|
||||
/** 图标 14.png — 在线客服页发送 */
|
||||
iconSupportSend,
|
||||
/** 组 98@2x.png — 在线客服排队卡片标题图标 */
|
||||
iconSupportQueue,
|
||||
/** 组 14919@2x.png — 我的页消息通知 */
|
||||
iconMineNotify,
|
||||
/** 订单@2x.png — 我的页我的订单 */
|
||||
iconMineOrder,
|
||||
/** 优惠券@2x.png — 我的页优惠券 */
|
||||
iconMineCoupon,
|
||||
/** 组 14923@2x.png — 我的页收货地址 */
|
||||
iconMineAddress,
|
||||
} as const
|
||||
|
||||
@@ -6,11 +6,17 @@ export function isValidSmsCode(code: string): boolean {
|
||||
return /^\d{4,6}$/.test(code.trim())
|
||||
}
|
||||
|
||||
/** 登录时输入校验(兼容历史短密码账号) */
|
||||
export function isValidPassword(password: string): boolean {
|
||||
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 {
|
||||
const value = password.trim()
|
||||
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 |