LoginWidget_display.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from PyQt6 import QtCore
  2. from PyQt6.QtWidgets import QWidget , QMessageBox
  3. from UI.login import Ui_login
  4. from .LogerinTxt import app_logger
  5. from Functions.apiFunction import api_fc
  6. class LoginWidget(Ui_login, QWidget):
  7. login_signal = QtCore.pyqtSignal(bool)
  8. login_user = QtCore.pyqtSignal(list)
  9. def __init__(self, parent=None):
  10. super().__init__(parent)
  11. try:
  12. self.setupUi(self)
  13. # print('login widget')
  14. self.pushButton.clicked.connect(self.btn)
  15. # self.setipinfo()
  16. self.ipinfo = None
  17. except Exception as e:
  18. app_logger.log_error(e)
  19. def severpost_meassge(self, postname, **kwargs):
  20. try:
  21. # ip = "http://" + str(self.ipinfo) + "/static/" + str(postname) + str(postdata) + str(postdata2)
  22. try:
  23. # res = requests.get(url=ip, timeout=30).json()
  24. res = api_fc.request_post('/static/{}'.format(postname), **kwargs)
  25. # print(res)
  26. except Exception as e:
  27. # print('登录服务器失败')
  28. app_logger.log_error('登录服务器失败')
  29. res = ""
  30. QMessageBox.warning(self, "提示", "服务器连接超时,请联系管理员检查服务器!")
  31. app_logger.log_error(e)
  32. return res
  33. except Exception as e:
  34. app_logger.log_error(e)
  35. def btn(self):
  36. try:
  37. username = self.lineEditUser.text()
  38. password = self.lineEditPassword.text()
  39. try:
  40. res = api_fc.get_access_token(username, password)["返回值"]
  41. # print(res)
  42. except Exception as e:
  43. res = ""
  44. app_logger.log_error(e)
  45. # print(res)
  46. if res != "" and int(res[3]) <= 4:
  47. self.login_signal.emit(True)
  48. self.login_user.emit(res)
  49. else:
  50. self.show_message()
  51. except Exception as e:
  52. app_logger.log_error(e)
  53. def show_message(self):
  54. try:
  55. QMessageBox.warning(self, "警告", "无此用户或密码错误或账号无权限访问办公平台")
  56. except Exception as e:
  57. app_logger.log_error(e)