LoginPage.qml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. import QtQuick
  2. import QtQuick.Controls 2.5
  3. import QtQuick.Layouts 1.3
  4. /*
  5. 登录界面
  6. */
  7. Rectangle {
  8. FontLoader {
  9. id: alibaba
  10. source: "qrc:/components/font/Alibaba-PuHuiTi-Bold.ttf"
  11. }
  12. FontLoader {
  13. id: fontawesome
  14. source: "qrc:/components/font/fontawesome-webfont.ttf"
  15. }
  16. FontLoader {
  17. id: digtalFont
  18. source: "qrc:/components/font/fontawesome-webfont.ttf"
  19. }
  20. id: loginForm
  21. width: parent.width
  22. height: parent.height
  23. color: 'transparent'
  24. //11-15
  25. property StackView stack: null
  26. property int flag: 0
  27. property bool shiftEnabled: false
  28. Component.onCompleted: {
  29. appModel.loadUser()
  30. }
  31. Rectangle {
  32. id: loginFormRect
  33. width: parent.width
  34. height: 500
  35. anchors.top: parent.top
  36. anchors.topMargin: 250
  37. color: 'transparent'
  38. Image {
  39. id: loginBg
  40. width: 960
  41. height: 500
  42. anchors.fill: parent
  43. fillMode: Image.PreserveAspectFit
  44. source: 'qrc:/images/login_bg.png'
  45. }
  46. Rectangle {
  47. id: inputColumn
  48. width: 960
  49. height: 500
  50. anchors.top: parent.top
  51. anchors.topMargin: 150
  52. anchors.fill: parent
  53. color: 'transparent'
  54. TextField {
  55. id: loginUsername
  56. width: 450
  57. height: 50
  58. anchors.horizontalCenter: parent.horizontalCenter
  59. color: mainTextColor
  60. font.pointSize: 22
  61. font.family: fontawesome.name
  62. leftPadding: 50
  63. text: appModel.Account
  64. MouseArea {
  65. anchors.fill: parent
  66. onClicked: {
  67. flag = 2
  68. passwordInputContainer.visible = true
  69. logInText.color = "#00FF33"
  70. passWordText.color = mainAppColor
  71. }
  72. }
  73. background: Rectangle {
  74. implicitWidth: 50
  75. implicitHeight: 50
  76. radius: implicitHeight / 2
  77. color: "transparent"
  78. Text {
  79. id:logInText
  80. text: "\uf007"
  81. font.pointSize: 24
  82. font.family: fontawesome.name
  83. color: mainAppColor
  84. anchors.left: parent.left
  85. anchors.verticalCenter: parent.verticalCenter
  86. leftPadding: 10
  87. //visible:false
  88. }
  89. Rectangle {
  90. width: parent.width - 10
  91. height: 1
  92. anchors.horizontalCenter: parent.horizontalCenter
  93. anchors.bottom: parent.bottom
  94. color: mainTextColor
  95. }
  96. Rectangle {
  97. width: 25
  98. height: 25
  99. anchors.left: parent.right
  100. anchors.verticalCenter: parent.verticalCenter
  101. color: 'transparent'
  102. Text {
  103. anchors.fill: parent
  104. text: "\uf05c"
  105. font.pointSize: 20
  106. font.family: fontawesome.name
  107. color: "#003399"
  108. }
  109. MouseArea {
  110. anchors.fill: parent
  111. onClicked: {
  112. loginUsername.text = ''
  113. }
  114. }
  115. }
  116. Image{
  117. anchors.left: parent.right
  118. anchors.leftMargin:30
  119. anchors.verticalCenter: parent.verticalCenter
  120. source:'qrc:/images/keyboard.png'
  121. visible:false
  122. MouseArea {
  123. anchors.fill: parent
  124. onClicked: {
  125. flag = 2
  126. passwordInputContainer.visible = true
  127. }
  128. }
  129. }
  130. }
  131. }
  132. TextField {
  133. id: loginPassword
  134. anchors.top: loginUsername.bottom
  135. anchors.topMargin: 20
  136. width: 450
  137. height: 50
  138. anchors.horizontalCenter: parent.horizontalCenter
  139. color: mainTextColor
  140. font.pointSize: 22
  141. font.family: fontawesome.name
  142. leftPadding: 50
  143. echoMode: TextField.Password
  144. text: appModel.Password
  145. onAccepted: loginUser(loginUsername.text, loginPassword.text)
  146. Keys.enabled: true
  147. Keys.onEnterPressed: console.log("enter")
  148. //11-15
  149. MouseArea {
  150. anchors.fill: parent
  151. onClicked: {
  152. flag = 1
  153. passwordInputContainer.visible = true
  154. passWordText.color = "#00FF33"
  155. logInText.color = mainAppColor
  156. }
  157. }
  158. background: Rectangle {
  159. implicitWidth: 50
  160. implicitHeight: 50
  161. radius: implicitHeight / 2
  162. color: "transparent"
  163. Text {
  164. //11-15
  165. id:passWordText
  166. text: "\uf023"
  167. font.pointSize: 24
  168. font.family: fontawesome.name
  169. color: mainAppColor
  170. anchors.left: parent.left
  171. anchors.verticalCenter: parent.verticalCenter
  172. leftPadding: 10
  173. }
  174. Rectangle {
  175. width: parent.width - 10
  176. height: 1
  177. anchors.horizontalCenter: parent.horizontalCenter
  178. anchors.bottom: parent.bottom
  179. color: mainTextColor
  180. }
  181. //11-15
  182. Rectangle {
  183. width: 25
  184. height: 25
  185. anchors.left: parent.right
  186. anchors.verticalCenter: parent.verticalCenter
  187. color: 'transparent'
  188. Text {
  189. anchors.fill: parent
  190. text: "\uf05c"
  191. font.pointSize: 20
  192. font.family: fontawesome.name
  193. color: "#003399"
  194. }
  195. MouseArea {
  196. anchors.fill: parent
  197. onClicked: {
  198. loginPassword.text = ''
  199. }
  200. }
  201. }
  202. Image{
  203. anchors.left: parent.right
  204. anchors.leftMargin:30
  205. anchors.verticalCenter: parent.verticalCenter
  206. source:'qrc:/images/keyboard.png'
  207. visible:false
  208. MouseArea {
  209. anchors.fill: parent
  210. onClicked: {
  211. flag = 1
  212. passwordInputContainer.visible = true
  213. }
  214. }
  215. }
  216. }
  217. }
  218. Rectangle {
  219. id: passwordInputContainer
  220. visible:false
  221. anchors.top: loginPassword.bottom
  222. anchors.topMargin: 210
  223. anchors.left: loginPassword.left
  224. anchors.leftMargin: 30
  225. color: "transparent"
  226. property var keysNumberCase: [
  227. "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", "Del"
  228. ]
  229. property var keysFirstLowerCase: [
  230. "q", "w", "e", "r", "t", "y", "u", "i", "o", "p","[","]"
  231. ]
  232. property var keysFirstUpperCase: [
  233. "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P","{","}"
  234. ]
  235. property var keysSecondLowerCase: [
  236. "a", "s", "d", "f", "g", "h", "j", "k", "l",";","Shift"
  237. ]
  238. property var keysSecondUpperCase: [
  239. "A", "S", "D", "F", "G", "H", "J", "K", "L",":","Shift"
  240. ]
  241. property var keysThirdLowerCase: [
  242. "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"
  243. ]
  244. property var keysThirdUpperCase: [
  245. "Z", "X", "C", "V", "B", "N", "M", "<", ">", "?"
  246. ]
  247. GridLayout {
  248. id:gridNumber
  249. anchors.left: passwordInputContainer.left
  250. anchors.leftMargin: 0
  251. columns: 13
  252. Repeater {
  253. model: passwordInputContainer.keysNumberCase
  254. Button {
  255. text: modelData
  256. font{
  257. family:"Cambria"
  258. pointSize:20
  259. }
  260. background: Item {
  261. Rectangle {
  262. radius:3
  263. color: "steelblue" // 设置按钮背景色
  264. width: parent.width
  265. height: parent.height
  266. }
  267. }
  268. onClicked: {
  269. if (modelData === "Del") {
  270. if (flag===1)
  271. loginPassword.text = loginPassword.text.substring(0, loginPassword.text.length - 1);
  272. else if (flag===2)
  273. loginUsername.text = loginUsername.text.substring(0, loginUsername.text.length - 1);
  274. }
  275. else if (modelData === "Shift") {
  276. shiftEnabled = !shiftEnabled;
  277. }
  278. else {
  279. if(flag===1)
  280. loginPassword.text += modelData;
  281. else if(flag===2)
  282. loginUsername.text += modelData;
  283. }
  284. }
  285. }
  286. }
  287. }
  288. GridLayout {
  289. id:gridFirst
  290. visible:ture
  291. anchors.top: gridNumber.bottom
  292. anchors.topMargin: 5
  293. anchors.left: gridNumber.left
  294. anchors.leftMargin: 20
  295. columns: 13
  296. Repeater {
  297. model: shiftEnabled ? passwordInputContainer.keysFirstUpperCase : passwordInputContainer.keysFirstLowerCase
  298. Button {
  299. font{
  300. family:"Cambria"
  301. pointSize:20
  302. }
  303. text: modelData
  304. background: Item {
  305. Rectangle {
  306. radius:3
  307. color: "steelblue" // 设置按钮背景色
  308. width: parent.width
  309. height: parent.height
  310. }
  311. }
  312. onClicked: {
  313. if (modelData === "Del") {
  314. if (flag===1)
  315. loginPassword.text = loginPassword.text.substring(0, loginPassword.text.length - 1);
  316. else if (flag===2)
  317. loginUsername.text = loginUsername.text.substring(0, loginUsername.text.length - 1);
  318. }
  319. else if (modelData === "Shift") {
  320. shiftEnabled = !shiftEnabled;
  321. }
  322. else {
  323. if(flag===1)
  324. loginPassword.text += modelData;
  325. else if(flag===2)
  326. loginUsername.text += modelData;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. GridLayout {
  333. id:gridSecond
  334. visible:true
  335. anchors.top: gridFirst.bottom
  336. anchors.topMargin: 5
  337. anchors.left: gridFirst.left
  338. anchors.leftMargin: 20
  339. columns: 13
  340. Repeater {
  341. model: shiftEnabled ? passwordInputContainer.keysSecondUpperCase : passwordInputContainer.keysSecondLowerCase
  342. Button {
  343. font{
  344. family:"Cambria"
  345. pointSize:20
  346. }
  347. text: modelData
  348. background: Item {
  349. Rectangle {
  350. radius:3
  351. color: "steelblue" // 设置按钮背景色
  352. width: parent.width
  353. height: parent.height
  354. }
  355. }
  356. onClicked: {
  357. if (modelData === "Del") {
  358. if (flag===1)
  359. loginPassword.text = loginPassword.text.substring(0, loginPassword.text.length - 1);
  360. else if (flag===2)
  361. loginUsername.text = loginUsername.text.substring(0, loginUsername.text.length - 1);
  362. }
  363. else if (modelData === "Shift") {
  364. shiftEnabled = !shiftEnabled;
  365. }
  366. else {
  367. if(flag===1)
  368. loginPassword.text += modelData;
  369. else if(flag===2)
  370. loginUsername.text += modelData;
  371. }
  372. }
  373. }
  374. }
  375. }
  376. GridLayout {
  377. id:gridThird
  378. visible:true
  379. anchors.top: gridSecond.bottom
  380. anchors.topMargin: 5
  381. anchors.left: gridSecond.left
  382. anchors.leftMargin: 20
  383. columns: 13
  384. Repeater {
  385. model: shiftEnabled ? passwordInputContainer.keysThirdUpperCase : passwordInputContainer.keysThirdLowerCase
  386. Button {
  387. font{
  388. family:"Cambria"
  389. pointSize:20
  390. }
  391. text: modelData
  392. background: Item {
  393. Rectangle {
  394. radius:3
  395. color: "steelblue" // 设置按钮背景色
  396. width: parent.width
  397. height: parent.height
  398. }
  399. }
  400. onClicked: {
  401. if (modelData === "Del") {
  402. if (flag===1)
  403. loginPassword.text = loginPassword.text.substring(0, loginPassword.text.length - 1);
  404. else if (flag===2)
  405. loginUsername.text = loginUsername.text.substring(0, loginUsername.text.length - 1);
  406. }
  407. else if (modelData === "Shift") {
  408. shiftEnabled = !shiftEnabled;
  409. }
  410. else {
  411. if(flag===1)
  412. loginPassword.text += modelData;
  413. else if(flag===2)
  414. loginUsername.text += modelData;
  415. }
  416. }
  417. }
  418. }
  419. }
  420. }
  421. CButton {
  422. id: resultButton
  423. anchors.top: loginPassword.bottom
  424. anchors.topMargin: 50
  425. anchors.horizontalCenter: parent.horizontalCenter
  426. textHeight: 50
  427. fontHeight: 0.4
  428. width: 450
  429. height: 50
  430. color: pressed ? textClickedColor : mainAppColor
  431. text: "登 录"
  432. onClicked:{
  433. loginUser(loginUsername.text, loginPassword.text)
  434. //readThread.open("desktop")
  435. }
  436. }
  437. }
  438. }
  439. }