| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- import Felgo
- import QtQuick
- import QtQuick.Controls
- import "../controls"
- import "../common"
- /**
- * 权限管理页。
- *
- * 背景:Android 把权限分两类,平台强制不可绕过——
- * 1) 运行时权限(定位/电话/文件与媒体/相机):应用可主动弹窗申请,用户点"允许"即授予;
- * 2) 特殊权限(修改系统设置/所有文件访问/悬浮窗):平台禁止静默授予,只能跳系统设置页;
- * 若用户已为本应用开启"无障碍服务",可由无障碍服务代为点击开关。
- *
- * 本页职责:展示各权限状态、提供授权入口、一键补齐全部缺失项。
- * 数据源为 C++ 侧 PermissionBridge(上下文属性名 permission)。
- */
- AppPage {
- id: page
- title: qsTr("权限管理")
- backgroundColor: app.theme_backgroundColor
- navigationBarHidden: true
- // 权限项数据由 C++ 侧提供;PC 调试时 C++ 侧返回占位数据,页面照常渲染
- property var items: permission ? permission.permissionList : []
- property int missing: permission ? permission.missingCount : 0
- property bool accOn: permission ? permission.accessibilityEnabled : false
- Column {
- id: rootCol
- width: parent.width
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.margins: dp(16)
- spacing: dp(10)
- // ---------- 顶部:无障碍服务状态与说明 ----------
- Rectangle {
- width: parent.width
- height: accTipCol.height + dp(24)
- radius: dp(8)
- color: page.accOn ? "#e6f4ea" : "#fff4e5"
- border.color: page.accOn ? "#34a853" : "#e8a33d"
- border.width: 1
- Column {
- id: accTipCol
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.margins: dp(12)
- spacing: dp(6)
- AppText {
- text: page.accOn ? "无障碍服务已开启" : "无障碍服务未开启"
- color: page.accOn ? "#1e7e34" : "#a06000"
- fontSize: 15
- font.bold: true
- }
- AppText {
- width: parent.width
- text: page.accOn
- ? "“修改系统设置”“所有文件访问”可自动点击开启,无需手动到设置页操作。"
- : "开启无障碍服务后,本应用可自动点击系统设置里的权限开关(Android 要求必须由用户手动授权开启一次,程序无法绕过)。未开启也可使用,但特殊权限需手动点击。"
- color: "#555555"
- fontSize: 12
- wrapMode: Text.WrapAtWordBoundaryOrAnywhere
- }
- AppButton {
- id: accBtn
- text: page.accOn ? "无障碍设置" : "去开启无障碍服务"
- textColor: "white"
- backgroundColor: page.accOn ? "#5f6368" : "#1a73e8"
- flat: false
- onClicked: {
- permission.openAccessibilitySettings()
- }
- }
- }
- }
- // ---------- 一键补齐 ----------
- Row {
- width: parent.width
- spacing: dp(10)
- AppButton {
- id: btnAll
- text: page.missing > 0 ? ("一键补齐缺失权限(" + page.missing + ")")
- : "全部权限已就绪"
- textColor: "white"
- backgroundColor: page.missing > 0 ? "#1a73e8" : "#9aa0a6"
- flat: false
- enabled: page.missing > 0
- onClicked: {
- permission.requestAll()
- }
- }
- AppButton {
- id: btnRefresh
- text: "刷新状态"
- textColor: "white"
- backgroundColor: "#5f6368"
- flat: false
- onClicked: {
- permission.checkAll()
- }
- }
- }
- // ---------- 操作结果提示 ----------
- Rectangle {
- id: msgBox
- width: parent.width
- height: visible ? msgText.height + dp(16) : 0
- visible: permission && permission.lastMessage !== ""
- radius: dp(6)
- color: "#e8f0fe"
- AppText {
- id: msgText
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.margins: dp(8)
- text: permission ? permission.lastMessage : ""
- color: "#174ea6"
- fontSize: 12
- wrapMode: Text.WrapAtWordBoundaryOrAnywhere
- }
- MouseArea {
- anchors.fill: parent
- onClicked: permission.clearMessage()
- }
- }
- }
- // ---------- 权限列表 ----------
- // 放在 Column 之外用锚点定位:避免 Column 依据 ListView 隐式高度、
- // ListView 又依赖 Column 高度计算剩余空间的布局循环
- ListView {
- id: list
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: rootCol.bottom
- anchors.bottom: parent.bottom
- anchors.margins: dp(16)
- clip: true
- spacing: dp(6)
- model: page.items
- boundsBehavior: Flickable.StopAtBounds
- // 行高复用,减少重复布局开销
- delegate: Item {
- id: rowItem
- width: list.width
- height: dp(52)
- Rectangle {
- anchors.fill: parent
- radius: dp(6)
- color: modelData.granted ? "#ffffff" : "#fff8f8"
- border.color: modelData.granted ? "#d0d0d0" : "#e07a7a"
- border.width: 1
- Row {
- anchors.left: parent.left
- anchors.leftMargin: dp(12)
- anchors.verticalCenter: parent.verticalCenter
- spacing: dp(10)
- // 状态圆点
- Rectangle {
- width: dp(12)
- height: dp(12)
- radius: width / 2
- anchors.verticalCenter: parent.verticalCenter
- color: modelData.granted ? "#34a853" : "#d93025"
- }
- Column {
- anchors.verticalCenter: parent.verticalCenter
- spacing: dp(2)
- AppText {
- text: modelData.name
- color: app.fontColor
- fontSize: 14
- font.bold: true
- }
- AppText {
- text: {
- if (modelData.granted)
- return "已开启"
- if (modelData.group === "accessibility")
- return "未开启(自动点击的前置条件)"
- if (modelData.autoClickSupport && page.accOn)
- return "未开启(将自动点击)"
- if (modelData.special)
- return "未开启(特殊权限,需在系统设置手动开启)"
- return "未开启"
- }
- color: modelData.granted ? "#188038" : "#c5221f"
- fontSize: 11
- }
- }
- }
- // 右侧操作按钮
- Row {
- anchors.right: parent.right
- anchors.rightMargin: dp(10)
- anchors.verticalCenter: parent.verticalCenter
- spacing: dp(6)
- // 无障碍已开启时,支持自动点击的项提供"自动开启"入口
- AppButton {
- visible: !modelData.granted
- && modelData.autoClickSupport
- && page.accOn
- text: "自动开启"
- textColor: "white"
- backgroundColor: "#1a73e8"
- flat: false
- onClicked: {
- permission.request(modelData.group)
- }
- }
- AppButton {
- visible: !modelData.granted
- && !(modelData.autoClickSupport && page.accOn)
- text: modelData.group === "accessibility" ? "去开启" : "去设置"
- textColor: "white"
- backgroundColor: modelData.special ? "#5f6368" : "#1a73e8"
- flat: false
- onClicked: {
- if (modelData.group === "accessibility")
- permission.openAccessibilitySettings()
- else
- permission.request(modelData.group)
- }
- }
- }
- }
- }
- }
- Component.onCompleted: {
- if (permission) permission.checkAll()
- }
- }
|