#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""生成元素映射表 JSON 文件"""

import json
import os

data = {
    "version": "1.0",
    "updated_at": "2026-08-11",
    "source": "前端开发人员提供 - 门户首页+功能中心元素定位键值表",
    "source_files": [
        "web/pc-vue2-platform/src/views/Home/index.vue",
        "web/pc-vue2-platform/src/views/Home/components/NavMenu/index.vue",
        "web/pc-vue2-platform/src/constant/navMenu.js",
    ],
    "description": "覆盖首页导航栏、首页功能块、功能中心置顶/常用/全部功能(13分类)、筛选器、搜索框，共108个元素",
    "tier_order": [
        "首页导航栏", "首页功能块", "功能中心-置顶功能", "功能中心-常用功能",
        "功能中心-全部功能", "功能中心-筛选器", "功能中心-搜索框",
    ],
    "undeveloped_features": [
        {"key": "全部功能-信息发布-播放器发布", "selector": "[data-id=\"publication_list.player\"]", "reason": "getUndevelopedList() 中标记，点击提示'功能开发中'"},
        {"key": "全部功能-数据统计-会议概览", "selector": "[data-id=\"data_list.meeting_summary\"]", "reason": "getUndevelopedList() 中标记，未实现"},
        {"key": "全部功能-数据统计-会议室概览", "selector": "[data-id=\"data_list.room_summary\"]", "reason": "getUndevelopedList() 中标记，未实现"},
    ],
    "notes": [
        "首页常用/置顶功能、功能中心置顶/常用功能随用户个性化配置变化，键值表覆盖默认候选",
        "所有项带 v-permission=\"item.show\"，无权限时元素不渲染",
        "功能中心元素在 el-drawer 内，定位前需先点击 .home_nav_left 打开抽屉",
        "定位优先级: data-key/data-id > id > class",
    ],
    "elements": {},
}

# 首页导航栏 (7)
nav = {
    "导航栏-功能中心抽屉开关": { "selector": ".home_nav_left", "tier": "首页导航栏", "description": "打开/关闭功能中心抽屉" },
    "导航栏-Logo": { "selector": ".home_nav .logo", "tier": "首页导航栏", "description": "顶部 logo 图片" },
    "导航栏-系统名称": { "selector": ".logo_text", "tier": "首页导航栏", "description": "系统名文本，如'统一会议管理平台'" },
    "导航栏-退出登录": { "selector": ".ub-icon-out", "tier": "首页导航栏", "description": "仅 loginAPP==normal 时显示" },
    "导航栏-用户头像": { "selector": ".el-dropdown.themeUl.userInfo", "tier": "首页导航栏", "description": "下拉，hover 展开" },
    "导航栏-个人信息": { "selector": ".el-dropdown-menu__item", "tier": "首页导航栏", "description": "下拉项 command=personInfo" },
    "导航栏-版本信息": { "selector": ".el-dropdown-menu__item", "tier": "首页导航栏", "description": "下拉项 command=version" },
}
for k, v in nav.items():
    v["type"] = "css"
    data["elements"][k] = v

# 首页功能块-常用功能 (8)
home_common = {
    "首页-常用功能-创建会议": "[data-key=\"reserve_list.create\"]",
    "首页-常用功能-会议模板": "[data-key=\"reserve_list.model\"]",
    "首页-常用功能-会议日程": "[data-key=\"reserve_list.schedule\"]",
    "首页-常用功能-会议室": "[data-key=\"reserve_list.room\"]",
    "首页-常用功能-会议列表": "[data-key=\"reserve_list.meeting\"]",
    "首页-常用功能-数据统计": "[data-key=\"data_list.booking\"]",
    "首页-常用功能-使用数据": "[data-key=\"data_list.usage\"]",
    "首页-常用功能-管理看板": "[data-key=\"data_list.dashboard\"]",
}
for k, sel in home_common.items():
    data["elements"][k] = {"selector": sel, "type": "css", "tier": "首页功能块", "description": k.split("-", 2)[2]}

# 首页功能块-置顶功能 (3)
home_top = {
    "首页-置顶功能-会议室列表": "[data-key=\"meetingRoomList\"]",
    "首页-置顶功能-会议运维": "[data-key=\"maintain_list.meeting\"]",
    "首页-置顶功能-设备列表": "[data-key=\"central_list.deviceList\"]",
}
for k, sel in home_top.items():
    data["elements"][k] = {"selector": sel, "type": "css", "tier": "首页功能块", "description": k.split("-", 2)[2]}

# 功能中心-置顶功能 (5)
center_top = {
    "功能中心-置顶功能-创建会议": "[data-key=\"reserve_list.create\"]",
    "功能中心-置顶功能-会议模板": "[data-key=\"reserve_list.model\"]",
    "功能中心-置顶功能-会议日程": "[data-key=\"reserve_list.schedule\"]",
    "功能中心-置顶功能-会议室": "[data-key=\"reserve_list.room\"]",
    "功能中心-置顶功能-会议列表": "[data-key=\"reserve_list.meeting\"]",
}
for k, sel in center_top.items():
    data["elements"][k] = {"selector": sel, "type": "css", "tier": "功能中心-置顶功能", "description": k.split("-", 2)[2]}

# 功能中心-常用功能 (6)
center_common = {
    "功能中心-常用功能-创建会议": "[data-key=\"reserve_list.create\"]",
    "功能中心-常用功能-会议模板": "[data-key=\"reserve_list.model\"]",
    "功能中心-常用功能-会议日程": "[data-key=\"reserve_list.schedule\"]",
    "功能中心-常用功能-会议室": "[data-key=\"reserve_list.room\"]",
    "功能中心-常用功能-会议列表": "[data-key=\"reserve_list.meeting\"]",
    "功能中心-常用功能-数据统计": "[data-key=\"data_list.booking\"]",
}
for k, sel in center_common.items():
    data["elements"][k] = {"selector": sel, "type": "css", "tier": "功能中心-常用功能", "description": k.split("-", 2)[2]}

# 功能中心-全部功能 (13 categories)
all_func = {
    # 会议预约 (5)
    "全部功能-会议预约-创建会议": "[data-id=\"reserve_list.create\"]",
    "全部功能-会议预约-会议模板": "[data-id=\"reserve_list.model\"]",
    "全部功能-会议预约-会议日程": "[data-id=\"reserve_list.schedule\"]",
    "全部功能-会议预约-会议室": "[data-id=\"reserve_list.room\"]",
    "全部功能-会议预约-会议列表": "[data-id=\"reserve_list.meeting\"]",
    # 运维维护 (7)
    "全部功能-运维维护-会议运维": "[data-id=\"maintain_list.meeting\"]",
    "全部功能-运维维护-视频设备": "[data-id=\"maintain_list.video_dev\"]",
    "全部功能-运维维护-维护区域": "[data-id=\"maintain_list.room_list\"]",
    "全部功能-运维维护-维护设备": "[data-id=\"maintain_list.dev_list\"]",
    "全部功能-运维维护-告警列表": "[data-id=\"maintain_list.alarm_list\"]",
    "全部功能-运维维护-会议巡检": "[data-id=\"maintain_list.meeting_inspect\"]",
    "全部功能-运维维护-待办巡检": "[data-id=\"maintain_list.inspect_list\"]",
    # 维护工单 (3)
    "全部功能-维护工单-待办工单": "[data-id=\"workorder_list.order_list\"]",
    "全部功能-维护工单-我的工单": "[data-id=\"workorder_list.order_my\"]",
    "全部功能-维护工单-告警工单": "[data-id=\"workorder_list.alarm_order\"]",
    # 集控控制 (10)
    "全部功能-集控控制-设备列表": "[data-id=\"central_list.deviceList\"]",
    "全部功能-集控控制-远程控制": "[data-id=\"central_list.remoteControl\"]",
    "全部功能-集控控制-文件下发": "[data-id=\"central_list.fileList\"]",
    "全部功能-集控控制-消息下发": "[data-id=\"central_list.infoList\"]",
    "全部功能-集控控制-壁纸下发": "[data-id=\"central_list.wallPaper\"]",
    "全部功能-集控控制-脚本命令": "[data-id=\"central_list.shellList\"]",
    "全部功能-集控控制-应用管理": "[data-id=\"central_list.appList\"]",
    "全部功能-集控控制-屏幕管理": "[data-id=\"central_list.screenControl\"]",
    "全部功能-集控控制-软件卸载": "[data-id=\"central_list.installList\"]",
    "全部功能-集控控制-设备网络": "[data-id=\"central_list.devicenet\"]",
    # 会议转录 (1)
    "全部功能-会议转录-转录列表": "[data-id=\"trans_list.table\"]",
    # 信息发布 (2, 1 undeveloped excluded)
    "全部功能-信息发布-信息发布": "[data-id=\"publication_list.info\"]",
    "全部功能-信息发布-门牌发布": "[data-id=\"publication_list.doorScreen\"]",
    # 数据统计 (17, 2 undeveloped excluded)
    "全部功能-数据统计-数据统计": "[data-id=\"data_list.booking\"]",
    "全部功能-数据统计-使用数据": "[data-id=\"data_list.usage\"]",
    "全部功能-数据统计-管理看板": "[data-id=\"data_list.dashboard\"]",
    "全部功能-数据统计-故障数据": "[data-id=\"data_list.fault\"]",
    "全部功能-数据统计-运维数据": "[data-id=\"data_list.devops_data\"]",
    "全部功能-数据统计-运维统计": "[data-id=\"data_list.devops_total\"]",
    "全部功能-数据统计-巡检报告": "[data-id=\"data_list.inspect_report\"]",
    "全部功能-数据统计-会议统计": "[data-id=\"data_list.meeting_total\"]",
    "全部功能-数据统计-通知统计": "[data-id=\"data_list.notice_total\"]",
    "全部功能-数据统计-会议服务统计": "[data-id=\"data_list.meeting_service\"]",
    "全部功能-数据统计-会议室统计": "[data-id=\"data_list.room_total\"]",
    "全部功能-数据统计-WeLink会议统计": "[data-id=\"data_list.welink_total\"]",
    "全部功能-数据统计-WeLink历史记录": "[data-id=\"data_list.welink_history\"]",
    "全部功能-数据统计-SMC3会议统计": "[data-id=\"data_list.smc3_total\"]",
    "全部功能-数据统计-SMC3历史记录": "[data-id=\"data_list.smc3_history\"]",
    "全部功能-数据统计-RSE会议统计": "[data-id=\"data_list.res_total\"]",
    "全部功能-数据统计-RSE历史记录": "[data-id=\"data_list.res_history\"]",
    # 资产管理 (3)
    "全部功能-资产管理-资产信息": "[data-id=\"asset_list.asset_info\"]",
    "全部功能-资产管理-资产故障": "[data-id=\"asset_list.asset_repair\"]",
    "全部功能-资产管理-资产设备": "[data-id=\"asset_list.asset_device\"]",
    # 会务管理 (2)
    "全部功能-会务管理-会务统筹": "[data-id=\"conference_list.coord\"]",
    "全部功能-会务管理-会务工单": "[data-id=\"conference_list.order\"]",
    # 信息管理 (3)
    "全部功能-信息管理-信息窗管理": "[data-id=\"info_list.message_window\"]",
    "全部功能-信息管理-消息通知": "[data-id=\"info_list.notification\"]",
    "全部功能-信息管理-待办事项": "[data-id=\"info_list.todo_list\"]",
    # 其他 (3)
    "全部功能-其他-文件列表": "[data-id=\"other_list.file_list\"]",
    "全部功能-其他-下载列表": "[data-id=\"other_list.down_list\"]",
    "全部功能-其他-通讯录": "[data-id=\"other_list.contact_list\"]",
    # 预定2.0 (6)
    "全部功能-预定2.0-会议室列表": "[data-id=\"meetingRoomList\"]",
    "全部功能-预定2.0-已预定会议": "[data-id=\"bookedMeeting\"]",
    "全部功能-预定2.0-历史记录": "[data-id=\"historyRecord\"]",
    "全部功能-预定2.0-会议模板": "[data-id=\"meetingTemplate\"]",
    "全部功能-预定2.0-会议审批": "[data-id=\"meetingApproval\"]",
    "全部功能-预定2.0-参会人模板": "[data-id=\"participantTemplate\"]",
}
for k, sel in all_func.items():
    parts = k.split("-", 2)
    category = parts[1] if len(parts) >= 3 else ""
    data["elements"][k] = {"selector": sel, "type": "css", "tier": "功能中心-全部功能", "description": f"{category} - {parts[2]}"}

# 功能中心-筛选器 (13)
filters = {
    "全部功能-筛选器-全部": "#filter_all",
    "全部功能-筛选器-会议预约": "#reserve_enable",
    "全部功能-筛选器-运维维护": "#maintain_enable",
    "全部功能-筛选器-维护工单": "#workorder_enable",
    "全部功能-筛选器-集控控制": "#central_enable",
    "全部功能-筛选器-会议转录": "#trans_enable",
    "全部功能-筛选器-信息发布": "#publication_enable",
    "全部功能-筛选器-数据统计": "#data_enable",
    "全部功能-筛选器-资产管理": "#asset_enable",
    "全部功能-筛选器-会务管理": "#conference_enable",
    "全部功能-筛选器-信息管理": "#info_enable",
    "全部功能-筛选器-其他": "#other_enable",
    "全部功能-筛选器-预定2.0": "#filter_meetingV2",
}
for k, sel in filters.items():
    data["elements"][k] = {"selector": sel, "type": "css", "tier": "功能中心-筛选器", "description": k.split("-", 2)[2]}

# 功能中心-搜索框 (1)
data["elements"]["功能中心-搜索输入框"] = {
    "selector": ".menu_header .search input",
    "type": "css",
    "tier": "功能中心-搜索框",
    "description": "功能中心搜索输入框",
}

# Write JSON
os.makedirs("backend/app/data", exist_ok=True)
with open("backend/app/data/elements_mapping.json", "w", encoding="utf-8") as f:
    json.dump(data, f, ensure_ascii=False, indent=2)

print(f"Total elements: {len(data['elements'])}")
print("JSON file written: backend/app/data/elements_mapping.json")