tsb_wlan_page.lua 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. --[[
  2. @module tsb_wlan_page
  3. @summary 网络配置页面
  4. @version 1.0
  5. @date 2026.03.17
  6. @author 李一玮
  7. @usage
  8. 本文件是网络配置页面,展示网络配置的各种用法。
  9. ]]
  10. local tsb_wlan_page = {}
  11. -- 页面UI元素
  12. local main_container = nil
  13. local common_ui = require("tsb_common_page")
  14. -- 创建UI
  15. function tsb_wlan_page.create_ui()
  16. main_container = airui.container({
  17. x = 0,
  18. y = 0,
  19. w = 480,
  20. h = 320,
  21. color = 0xFFFFFF,
  22. })
  23. --------------------- 标题栏 ------------------------
  24. local title_bar = airui.container({
  25. parent = main_container,
  26. x = 0,
  27. y = 0,
  28. w = 480,
  29. h = 30,
  30. color = 0xCE93D8,
  31. })
  32. airui.label({
  33. parent = title_bar,
  34. text = "网络设置",
  35. x = 200,
  36. y = 10,
  37. w = 80,
  38. h = 20,
  39. font_size = 16,
  40. color = 0xFFFFFF,
  41. })
  42. -- 标题栏公共信息展示
  43. common_ui.add_battery_display(title_bar)
  44. common_ui.create_back_button(title_bar, tsb_wlan_page.cleanup)
  45. ---------------------------------------------------
  46. -- 滚动容器
  47. local scroll_container = airui.container({
  48. parent = main_container,
  49. x = 0,
  50. y = 30,
  51. w = 480,
  52. h = 260,
  53. color = 0xFFFFFF,
  54. })
  55. local keyboard1 = airui.keyboard({
  56. x = 0,
  57. y = 0,
  58. w = 480,
  59. h = 160, -- x, y, 键盘默认打开ALIGN_BOTTOM_MID,位置从中下方开始计算
  60. mode = "lower", -- 键盘模式,可选 "text"/"upper"/"lower"/"numeric"
  61. auto_hide = true, -- 自动隐藏键盘
  62. bg_color = 0xf1f1f1, -- 键盘背景颜色为灰色,可选,不设置则透明
  63. on_commit = function() -- 确认事件回调,只有在按下确认键时才会触发
  64. log.info("keyboard", "commit")
  65. end
  66. })
  67. --------------------- 4G网络配置 ------------------------
  68. -- 4G网络容器
  69. local network4g_container = airui.container({
  70. parent = scroll_container,
  71. x = 20,
  72. y = 10,
  73. w = 440,
  74. h = 80,
  75. color = 0xF5F5F5,
  76. radius = 8,
  77. })
  78. -- 4G网络标题
  79. airui.label({
  80. parent = network4g_container,
  81. text = "4G网络配置",
  82. x = 10,
  83. y = 10,
  84. w = 120,
  85. h = 30,
  86. font_size = 16,
  87. color = 0xCE93D8,
  88. })
  89. -- 4G开关标签
  90. airui.label({
  91. parent = network4g_container,
  92. text = "4G网络:",
  93. x = 10,
  94. y = 40,
  95. w = 80,
  96. h = 30,
  97. font_size = 14,
  98. })
  99. -- 4G开关状态
  100. local network4g_status = airui.label({
  101. parent = network4g_container,
  102. text = "开启",
  103. x = 80,
  104. y = 40,
  105. w = 60,
  106. h = 30,
  107. font_size = 14,
  108. color = 0x4CAF50,
  109. })
  110. -- 4G开关按钮
  111. local network4g_switch = airui.button({
  112. parent = network4g_container,
  113. x = 350,
  114. y = 40,
  115. w = 80,
  116. h = 30,
  117. text = "关闭",
  118. on_click = function(self)
  119. local current_status = network4g_status:get_text()
  120. if current_status == "开启" then
  121. network4g_status:set_text("关闭")
  122. network4g_status:set_color(0xF44336)
  123. self:set_text("开启")
  124. log.info("set_4g", "关闭4G网络")
  125. -- 这里可以添加关闭4G网络的逻辑
  126. else
  127. network4g_status:set_text("开启")
  128. network4g_status:set_color(0x4CAF50)
  129. self:set_text("关闭")
  130. log.info("set_4g", "开启4G网络")
  131. -- 这里可以添加开启4G网络的逻辑
  132. end
  133. end
  134. })
  135. ---------------------------------------------------
  136. --------------------- WIFI配置 ------------------------
  137. -- WIFI配置容器
  138. local wifi_container = airui.container({
  139. parent = scroll_container,
  140. x = 20,
  141. y = 100,
  142. w = 440,
  143. h = 160,
  144. color = 0xF5F5F5,
  145. radius = 8,
  146. })
  147. -- WIFI配置标题
  148. airui.label({
  149. parent = wifi_container,
  150. text = "WIFI配置",
  151. x = 10,
  152. y = 10,
  153. w = 100,
  154. h = 30,
  155. font_size = 16,
  156. color = 0xCE93D8,
  157. })
  158. -- WIFI开关标签
  159. airui.label({
  160. parent = wifi_container,
  161. text = "WIFI:",
  162. x = 10,
  163. y = 40,
  164. w = 60,
  165. h = 30,
  166. font_size = 14,
  167. })
  168. -- WIFI开关状态
  169. local wifi_status = airui.label({
  170. parent = wifi_container,
  171. text = "开启",
  172. x = 80,
  173. y = 40,
  174. w = 60,
  175. h = 30,
  176. font_size = 14,
  177. color = 0x4CAF50,
  178. })
  179. -- WIFI开关按钮
  180. local wifi_switch = airui.button({
  181. parent = wifi_container,
  182. x = 350,
  183. y = 40,
  184. w = 80,
  185. h = 30,
  186. text = "关闭",
  187. on_click = function(self)
  188. local current_status = wifi_status:get_text()
  189. if current_status == "开启" then
  190. wifi_status:set_text("关闭")
  191. wifi_status:set_color(0xF44336)
  192. self:set_text("开启")
  193. log.info("set_wifi", "关闭WIFI")
  194. -- 这里可以添加关闭WIFI的逻辑
  195. else
  196. wifi_status:set_text("开启")
  197. wifi_status:set_color(0x4CAF50)
  198. self:set_text("关闭")
  199. log.info("set_wifi", "开启WIFI")
  200. -- 这里可以添加开启WIFI的逻辑
  201. end
  202. end
  203. })
  204. -- WIFI名称标签
  205. airui.label({
  206. parent = wifi_container,
  207. text = "WIFI名称:",
  208. x = 10,
  209. y = 80,
  210. w = 100,
  211. h = 30,
  212. font_size = 14,
  213. })
  214. -- WIFI名称输入框
  215. local wifi_name_input = airui.textarea({
  216. parent = wifi_container,
  217. x = 110,
  218. y = 80,
  219. w = 200,
  220. h = 30,
  221. text = "",
  222. keyboard = keyboard1
  223. })
  224. -- WIFI密码标签
  225. airui.label({
  226. parent = wifi_container,
  227. text = "WIFI密码:",
  228. x = 10,
  229. y = 120,
  230. w = 100,
  231. h = 30,
  232. font_size = 14,
  233. })
  234. -- WIFI密码输入框
  235. local wifi_password_input = airui.textarea({
  236. parent = wifi_container,
  237. x = 110,
  238. y = 120,
  239. w = 200,
  240. h = 30,
  241. text = "",
  242. keyboard = keyboard1
  243. })
  244. -- 连接按钮
  245. local connect_wifi_btn = airui.button({
  246. parent = wifi_container,
  247. x = 320,
  248. y = 90,
  249. w = 100,
  250. h = 40,
  251. text = "连接",
  252. on_click = function(self)
  253. local wifi_name = wifi_name_input:get_text()
  254. local wifi_password = wifi_password_input:get_text()
  255. log.info("set_wifi", "连接WIFI:" .. wifi_name)
  256. -- 这里可以添加连接WIFI的逻辑
  257. end
  258. })
  259. ---------------------------------------------------
  260. --------------------- 网络状态 ------------------------
  261. -- 网络状态容器
  262. local network_status_container = airui.container({
  263. parent = scroll_container,
  264. x = 20,
  265. y = 280,
  266. w = 440,
  267. h = 100,
  268. color = 0xF5F5F5,
  269. radius = 8,
  270. })
  271. -- 网络状态标题
  272. airui.label({
  273. parent = network_status_container,
  274. text = "网络状态",
  275. x = 10,
  276. y = 10,
  277. w = 100,
  278. h = 30,
  279. font_size = 16,
  280. color = 0xCE93D8,
  281. })
  282. -- IP地址标签
  283. airui.label({
  284. parent = network_status_container,
  285. text = "IP地址:",
  286. x = 10,
  287. y = 40,
  288. w = 80,
  289. h = 30,
  290. font_size = 14,
  291. })
  292. -- IP地址值
  293. airui.label({
  294. parent = network_status_container,
  295. text = "192.168.1.100",
  296. x = 100,
  297. y = 40,
  298. w = 200,
  299. h = 30,
  300. font_size = 14,
  301. })
  302. -- 信号强度标签
  303. airui.label({
  304. parent = network_status_container,
  305. text = "信号强度:",
  306. x = 10,
  307. y = 70,
  308. w = 80,
  309. h = 30,
  310. font_size = 14,
  311. })
  312. -- 信号强度值
  313. airui.label({
  314. parent = network_status_container,
  315. text = "90%",
  316. x = 100,
  317. y = 70,
  318. w = 50,
  319. h = 30,
  320. font_size = 14,
  321. })
  322. ---------------------------------------------------
  323. -- 底部信息
  324. common_ui.create_status_bar(main_container)
  325. end
  326. -- 初始化页面
  327. function tsb_wlan_page.init(params)
  328. tsb_wlan_page.create_ui()
  329. end
  330. -- 清理页面
  331. function tsb_wlan_page.cleanup()
  332. if main_container then
  333. main_container:destroy()
  334. main_container = nil
  335. end
  336. end
  337. return tsb_wlan_page