From 5ab82d4571740c4582cd5f0a7ebd2575ea67c446 Mon Sep 17 00:00:00 2001
From: Ironsp <1522278303@qq.com>
Date: Thu, 24 Sep 2026 11:17:39 +0800
Subject: [PATCH] =?UTF-8?q?feat=20=E6=8E=88=E6=9D=83=E6=BF=80=E6=B4=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/components.d.ts | 2 +
src/components/home/activateNotice.vue | 155 +++++++++++++++++++++++++
src/components/home/construction.vue | 5 +-
src/components/home/progress.vue | 7 +-
src/components/home/projectList.vue | 21 ++--
src/components/home/status.vue | 5 +-
src/components/home/warning.vue | 21 ++--
src/components/unauthorized.vue | 113 ++++++++++++++++++
src/composables/useDeviceAuth.ts | 83 +++++++++++++
src/pages.json | 4 +-
src/pages/Ahome/index.vue | 10 ++
src/utils/device.ts | 3 +-
12 files changed, 406 insertions(+), 23 deletions(-)
create mode 100644 src/components/home/activateNotice.vue
create mode 100644 src/components/unauthorized.vue
create mode 100644 src/composables/useDeviceAuth.ts
diff --git a/src/components.d.ts b/src/components.d.ts
index f648498..99f6fba 100644
--- a/src/components.d.ts
+++ b/src/components.d.ts
@@ -16,6 +16,7 @@ declare module 'vue' {
HeatmapLayerPanel: typeof import('./components/heatmap/layerPanel.vue')['default']
HeatmapLegend: typeof import('./components/heatmap/legend.vue')['default']
HeatmapPointDetail: typeof import('./components/heatmap/pointDetail.vue')['default']
+ HomeActivateNotice: typeof import('./components/home/activateNotice.vue')['default']
HomeConstruction: typeof import('./components/home/construction.vue')['default']
HomeHomeNav: typeof import('./components/home/homeNav.vue')['default']
HomeList: typeof import('./components/home/list.vue')['default']
@@ -39,6 +40,7 @@ declare module 'vue' {
SettingsSensorConfig: typeof import('./components/settings/sensorConfig.vue')['default']
SettingsWifiNetwork: typeof import('./components/settings/wifiNetwork.vue')['default']
SettingsWifiSettings: typeof import('./components/settings/wifiSettings.vue')['default']
+ Unauthorized: typeof import('./components/unauthorized.vue')['default']
WarningFilter: typeof import('./components/warning/filter.vue')['default']
WarningItem: typeof import('./components/warning/item.vue')['default']
WorkDashboard: typeof import('./components/work/dashboard.vue')['default']
diff --git a/src/components/home/activateNotice.vue b/src/components/home/activateNotice.vue
new file mode 100644
index 0000000..594a041
--- /dev/null
+++ b/src/components/home/activateNotice.vue
@@ -0,0 +1,155 @@
+
+
+
+
+
+ 设备未授权激活
+
+
+
+ 检测到 1 台新设备待激活
+
+
+ 请输入设备ID完成授权激活后,方可获取该设备ID获取压实数据及位置信息
+
+
+
+
+
+
+
+ 设备ID
+
+
+
+ {{ deviceId }}
+
+
+
+
+
+
+
+
+
+
diff --git a/src/components/home/construction.vue b/src/components/home/construction.vue
index e9d2c53..9730414 100644
--- a/src/components/home/construction.vue
+++ b/src/components/home/construction.vue
@@ -1,7 +1,9 @@
@@ -12,7 +14,8 @@ const { hasCurrentProject, currentProject } = useCurrentProject()
-
+
+
diff --git a/src/components/home/progress.vue b/src/components/home/progress.vue
index 4b4dcc9..b2f8af6 100644
--- a/src/components/home/progress.vue
+++ b/src/components/home/progress.vue
@@ -1,11 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ title }}
+
+
+ {{ tipLine1 }}
+
+
+ {{ tipLine2 }}
+
+
+
+
+
diff --git a/src/composables/useDeviceAuth.ts b/src/composables/useDeviceAuth.ts
new file mode 100644
index 0000000..cd909da
--- /dev/null
+++ b/src/composables/useDeviceAuth.ts
@@ -0,0 +1,83 @@
+import type { AuthStatus } from '@/api/types'
+import { onShow } from '@dcloudio/uni-app'
+import { computed, ref } from 'vue'
+import { activateDevice, getDeviceStatus } from '@/api/device'
+import { getDeviceId } from '@/utils/device'
+import storage from '@/utils/storage'
+
+const AUTH_STATUS_KEY = 'device_auth_status'
+
+/** 模块级共享,保证各页面读到同一授权状态 */
+const authStatus = ref(storage.get(AUTH_STATUS_KEY, '0') ?? '0')
+const loading = ref(false)
+
+/**
+ * 设备授权状态:仅 authStatus === '1' 视为已激活
+ * 未激活时首页相关模块保留标题,内容展示未授权提示
+ *
+ * 注意:onShow 仅在页面级调用时注册,避免子组件重复监听
+ */
+export function useDeviceAuth(options?: { watchShow?: boolean }) {
+ const isActivated = computed(() => authStatus.value === '1')
+ const deviceId = computed(() => getDeviceId())
+
+ function setAuthStatus(status: AuthStatus) {
+ authStatus.value = status
+ storage.set(AUTH_STATUS_KEY, status)
+ }
+
+ async function fetchAuthStatus() {
+ loading.value = true
+ try {
+ const res = await getDeviceStatus(deviceId.value)
+ const status = res.data?.authStatus
+ if (status != null && status !== '')
+ setAuthStatus(String(status) as AuthStatus)
+ }
+ catch {
+ // 接口失败时沿用本地缓存状态
+ }
+ finally {
+ loading.value = false
+ }
+ }
+
+ /** 提交授权码激活设备,成功后更新本地状态 */
+ async function activate(activationCode: string) {
+ const code = activationCode.trim()
+ if (!code)
+ throw new Error('请输入授权码')
+
+ const res = await activateDevice({
+ activationCode: code,
+ deviceId: deviceId.value,
+ })
+ const ok = res.code === 200 || res.code === 0
+ if (!ok)
+ throw new Error(res.msg || '激活失败')
+
+ setAuthStatus('1')
+ return res
+ }
+
+ function refreshAuthStatus() {
+ authStatus.value = storage.get(AUTH_STATUS_KEY, '0') ?? '0'
+ }
+
+ if (options?.watchShow) {
+ onShow(() => {
+ refreshAuthStatus()
+ })
+ }
+
+ return {
+ authStatus,
+ isActivated,
+ deviceId,
+ loading,
+ setAuthStatus,
+ fetchAuthStatus,
+ activate,
+ refreshAuthStatus,
+ }
+}
diff --git a/src/pages.json b/src/pages.json
index 659f0ca..0c23132 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -16,7 +16,7 @@
"navigationBarTitleText": "Road-Roller"
},
"pages": [
- // GENERATED BY UNI-PAGES, PLATFORM: H5 || APP
+ // GENERATED BY UNI-PAGES, PLATFORM: APP || H5
{
"path": "pages/Ahome/index",
"type": "home",
@@ -121,7 +121,7 @@
"color": "@tabFontColor",
"selectedColor": "@tabSelectedColor",
"list": [
- // GENERATED BY UNI-PAGES, PLATFORM: H5 || APP
+ // GENERATED BY UNI-PAGES, PLATFORM: APP || H5
{
"pagePath": "pages/Ahome/index",
"text": "首页",
diff --git a/src/pages/Ahome/index.vue b/src/pages/Ahome/index.vue
index 36925ae..1863c2a 100644
--- a/src/pages/Ahome/index.vue
+++ b/src/pages/Ahome/index.vue
@@ -1,4 +1,7 @@
@@ -21,6 +30,7 @@ definePage({
+
diff --git a/src/utils/device.ts b/src/utils/device.ts
index f36b40a..d4a7df4 100644
--- a/src/utils/device.ts
+++ b/src/utils/device.ts
@@ -83,7 +83,7 @@ function generateUUID(): string {
/**
* 获取设备唯一标识
*/
-function getDeviceId(): string {
+export function getDeviceId(): string {
// 从存储获取
const storedId = storage.get(DEVICE_ID_KEY)
if (storedId) {
@@ -195,6 +195,7 @@ export function getOrInitDeviceInfo(): SystemInfo {
export default {
getSystemInfo,
+ getDeviceId,
getDeviceTypeName,
getOsTypeName,
saveDeviceInfo,