PermissionPage.qml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. import Felgo
  2. import QtQuick
  3. import QtQuick.Controls
  4. import "../controls"
  5. import "../common"
  6. /**
  7. * 权限管理页。
  8. *
  9. * 背景:Android 把权限分两类,平台强制不可绕过——
  10. * 1) 运行时权限(定位/电话/文件与媒体/相机):应用可主动弹窗申请,用户点"允许"即授予;
  11. * 2) 特殊权限(修改系统设置/所有文件访问/悬浮窗):平台禁止静默授予,只能跳系统设置页;
  12. * 若用户已为本应用开启"无障碍服务",可由无障碍服务代为点击开关。
  13. *
  14. * 本页职责:展示各权限状态、提供授权入口、一键补齐全部缺失项。
  15. * 数据源为 C++ 侧 PermissionBridge(上下文属性名 permission)。
  16. */
  17. AppPage {
  18. id: page
  19. title: qsTr("权限管理")
  20. backgroundColor: app.theme_backgroundColor
  21. navigationBarHidden: true
  22. // 权限项数据由 C++ 侧提供;PC 调试时 C++ 侧返回占位数据,页面照常渲染
  23. property var items: permission ? permission.permissionList : []
  24. property int missing: permission ? permission.missingCount : 0
  25. property bool accOn: permission ? permission.accessibilityEnabled : false
  26. Column {
  27. id: rootCol
  28. width: parent.width
  29. anchors.left: parent.left
  30. anchors.right: parent.right
  31. anchors.top: parent.top
  32. anchors.margins: dp(16)
  33. spacing: dp(10)
  34. // ---------- 顶部:无障碍服务状态与说明 ----------
  35. Rectangle {
  36. width: parent.width
  37. height: accTipCol.height + dp(24)
  38. radius: dp(8)
  39. color: page.accOn ? "#e6f4ea" : "#fff4e5"
  40. border.color: page.accOn ? "#34a853" : "#e8a33d"
  41. border.width: 1
  42. Column {
  43. id: accTipCol
  44. anchors.left: parent.left
  45. anchors.right: parent.right
  46. anchors.top: parent.top
  47. anchors.margins: dp(12)
  48. spacing: dp(6)
  49. AppText {
  50. text: page.accOn ? "无障碍服务已开启" : "无障碍服务未开启"
  51. color: page.accOn ? "#1e7e34" : "#a06000"
  52. fontSize: 15
  53. font.bold: true
  54. }
  55. AppText {
  56. width: parent.width
  57. text: page.accOn
  58. ? "“修改系统设置”“所有文件访问”可自动点击开启,无需手动到设置页操作。"
  59. : "开启无障碍服务后,本应用可自动点击系统设置里的权限开关(Android 要求必须由用户手动授权开启一次,程序无法绕过)。未开启也可使用,但特殊权限需手动点击。"
  60. color: "#555555"
  61. fontSize: 12
  62. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  63. }
  64. AppButton {
  65. id: accBtn
  66. text: page.accOn ? "无障碍设置" : "去开启无障碍服务"
  67. textColor: "white"
  68. backgroundColor: page.accOn ? "#5f6368" : "#1a73e8"
  69. flat: false
  70. onClicked: {
  71. permission.openAccessibilitySettings()
  72. }
  73. }
  74. }
  75. }
  76. // ---------- 一键补齐 ----------
  77. Row {
  78. width: parent.width
  79. spacing: dp(10)
  80. AppButton {
  81. id: btnAll
  82. text: page.missing > 0 ? ("一键补齐缺失权限(" + page.missing + ")")
  83. : "全部权限已就绪"
  84. textColor: "white"
  85. backgroundColor: page.missing > 0 ? "#1a73e8" : "#9aa0a6"
  86. flat: false
  87. enabled: page.missing > 0
  88. onClicked: {
  89. permission.requestAll()
  90. }
  91. }
  92. AppButton {
  93. id: btnRefresh
  94. text: "刷新状态"
  95. textColor: "white"
  96. backgroundColor: "#5f6368"
  97. flat: false
  98. onClicked: {
  99. permission.checkAll()
  100. }
  101. }
  102. }
  103. // ---------- 操作结果提示 ----------
  104. Rectangle {
  105. id: msgBox
  106. width: parent.width
  107. height: visible ? msgText.height + dp(16) : 0
  108. visible: permission && permission.lastMessage !== ""
  109. radius: dp(6)
  110. color: "#e8f0fe"
  111. AppText {
  112. id: msgText
  113. anchors.left: parent.left
  114. anchors.right: parent.right
  115. anchors.top: parent.top
  116. anchors.margins: dp(8)
  117. text: permission ? permission.lastMessage : ""
  118. color: "#174ea6"
  119. fontSize: 12
  120. wrapMode: Text.WrapAtWordBoundaryOrAnywhere
  121. }
  122. MouseArea {
  123. anchors.fill: parent
  124. onClicked: permission.clearMessage()
  125. }
  126. }
  127. }
  128. // ---------- 权限列表 ----------
  129. // 放在 Column 之外用锚点定位:避免 Column 依据 ListView 隐式高度、
  130. // ListView 又依赖 Column 高度计算剩余空间的布局循环
  131. ListView {
  132. id: list
  133. anchors.left: parent.left
  134. anchors.right: parent.right
  135. anchors.top: rootCol.bottom
  136. anchors.bottom: parent.bottom
  137. anchors.margins: dp(16)
  138. clip: true
  139. spacing: dp(6)
  140. model: page.items
  141. boundsBehavior: Flickable.StopAtBounds
  142. // 行高复用,减少重复布局开销
  143. delegate: Item {
  144. id: rowItem
  145. width: list.width
  146. height: dp(52)
  147. Rectangle {
  148. anchors.fill: parent
  149. radius: dp(6)
  150. color: modelData.granted ? "#ffffff" : "#fff8f8"
  151. border.color: modelData.granted ? "#d0d0d0" : "#e07a7a"
  152. border.width: 1
  153. Row {
  154. anchors.left: parent.left
  155. anchors.leftMargin: dp(12)
  156. anchors.verticalCenter: parent.verticalCenter
  157. spacing: dp(10)
  158. // 状态圆点
  159. Rectangle {
  160. width: dp(12)
  161. height: dp(12)
  162. radius: width / 2
  163. anchors.verticalCenter: parent.verticalCenter
  164. color: modelData.granted ? "#34a853" : "#d93025"
  165. }
  166. Column {
  167. anchors.verticalCenter: parent.verticalCenter
  168. spacing: dp(2)
  169. AppText {
  170. text: modelData.name
  171. color: app.fontColor
  172. fontSize: 14
  173. font.bold: true
  174. }
  175. AppText {
  176. text: {
  177. if (modelData.granted)
  178. return "已开启"
  179. if (modelData.group === "accessibility")
  180. return "未开启(自动点击的前置条件)"
  181. if (modelData.autoClickSupport && page.accOn)
  182. return "未开启(将自动点击)"
  183. if (modelData.special)
  184. return "未开启(特殊权限,需在系统设置手动开启)"
  185. return "未开启"
  186. }
  187. color: modelData.granted ? "#188038" : "#c5221f"
  188. fontSize: 11
  189. }
  190. }
  191. }
  192. // 右侧操作按钮
  193. Row {
  194. anchors.right: parent.right
  195. anchors.rightMargin: dp(10)
  196. anchors.verticalCenter: parent.verticalCenter
  197. spacing: dp(6)
  198. // 无障碍已开启时,支持自动点击的项提供"自动开启"入口
  199. AppButton {
  200. visible: !modelData.granted
  201. && modelData.autoClickSupport
  202. && page.accOn
  203. text: "自动开启"
  204. textColor: "white"
  205. backgroundColor: "#1a73e8"
  206. flat: false
  207. onClicked: {
  208. permission.request(modelData.group)
  209. }
  210. }
  211. AppButton {
  212. visible: !modelData.granted
  213. && !(modelData.autoClickSupport && page.accOn)
  214. text: modelData.group === "accessibility" ? "去开启" : "去设置"
  215. textColor: "white"
  216. backgroundColor: modelData.special ? "#5f6368" : "#1a73e8"
  217. flat: false
  218. onClicked: {
  219. if (modelData.group === "accessibility")
  220. permission.openAccessibilitySettings()
  221. else
  222. permission.request(modelData.group)
  223. }
  224. }
  225. }
  226. }
  227. }
  228. }
  229. Component.onCompleted: {
  230. if (permission) permission.checkAll()
  231. }
  232. }