class MoreNewsPage(QWidget): def __init__(self, *args, **kwargs): super(MoreNewsPage, self).__init__(*args, **kwargs) layout = QVBoxLayout() self.news_scroll = QScrollArea(parent=self, objectName='newsScroll') self.news_scroll.setWidgetResizable(True) layout.addWidget(self.news_scroll) self.paginator = Paginator(parent=self) self.paginator.clicked.connect(self.getCurrentNews) layout.addWidget(self.paginator, alignment=Qt.AlignBottom | Qt.AlignCenter) # layout.addWidget(QLabel('暂无更多新闻,关注其他资讯...', styleSheet='font-size:18px;color:rgb(200,120,130)') # , alignment=Qt.AlignCenter) self.setLayout(layout) self.setStyleSheet(""" #newsScroll{ border:none; } """) # 获取新闻公告内容 def getCurrentNews(self): current_page = self.paginator.current_page try: r = requests.get(url=settings.SERVER_ADDR + 'bulletin/?page=' + str(current_page)) response = json.loads(r.content.decode('utf-8')) if r.status_code != 200: raise ValueError(response['message']) except Exception: pass else: self.resetNewsBox() news_data = response['bulletins'] for news_obj in news_data: news_item = NewsItem(title=news_obj['title'], create_time=news_obj['create_time'], item_id=news_obj['id'], file_url=news_obj['file_url'], parent=self.news_box) news_item.item_clicked.connect(self.read_detail_news) self.news_box.layout().addWidget(news_item) self.news_box.layout().addStretch() self.paginator.setTotalPages(response['total_page']) # 清除控件内的条目 def resetNewsBox(self): if hasattr(self, 'news_box'): self.news_box.deleteLater() self.news_box = QWidget(parent=self.news_scroll) news_layout = QVBoxLayout(margin=0) self.news_box.setLayout(news_layout) self.news_scroll.setWidget(self.news_box) # 阅读新闻 def read_detail_news(self, title, file_url): file_addr = settings.STATIC_PREFIX + file_url popup = PDFContentPopup(title=title, file=file_addr) popup.exec_()
class TransactionNoticePage(QWidget): def __init__(self, category_id, *args, **kwargs): super(TransactionNoticePage, self).__init__(*args, **kwargs) self.category_id = category_id layout = QVBoxLayout(margin=0, spacing=1) # 页码器 contro_widget = QWidget(parent=self, objectName='controlWidget') contro_widget.setFixedHeight(22) controller_layout = QHBoxLayout(margin=0) self.paginator = Paginator(parent=contro_widget) self.paginator.clicked.connect(self.getCurrentNotices) controller_layout.addWidget(self.paginator, alignment=Qt.AlignRight) contro_widget.setLayout(controller_layout) layout.addWidget(contro_widget) self.notice_table = TransactionNoticeTable() layout.addWidget(self.notice_table) # 无数据的显示 self.no_data_label = QLabel('暂无相关数据...', styleSheet='color:rgb(200,100,50)', alignment=Qt.AlignCenter) self.no_data_label.hide() layout.addWidget(self.no_data_label) self.setLayout(layout) self.setStyleSheet(""" #controlWidget{ background-color: rgb(178,200,187); min-height: 20px; } """) # 获取当前通知 def getCurrentNotices(self): current_page = self.paginator.current_page try: # 发起请求当前数据 r = requests.get(url=settings.SERVER_ADDR + 'exnotice/?page=' + str(current_page) + '&page_size=50&category=' + str(self.category_id), ) response = json.loads(r.content.decode('utf-8')) if r.status_code != 200: raise ValueError(response['message']) except Exception: pass else: if response['exnotices']: self.notice_table.showRowContents(response['exnotices']) self.paginator.setTotalPages(response['total_page']) self.notice_table.show() self.no_data_label.hide() else: self.no_data_label.show() self.notice_table.hide()
class HedgePlanPage(QWidget): def __init__(self, *args, **kwargs): super(HedgePlanPage, self).__init__(*args, **kwargs) layout = QVBoxLayout() layout.setContentsMargins(QMargins(0, 0, 0, 5)) layout.setSpacing(5) self.table = InvestPlanTable() layout.addWidget(self.table) # 无数据的显示 self.no_data_label = QLabel('暂无套保方案数据...', styleSheet='color:rgb(200,100,50)', alignment=Qt.AlignCenter) self.no_data_label.hide() layout.addWidget(self.no_data_label) # 页码控制布局 self.paginator = Paginator() self.paginator.setMargins(0, 10, 3, 0) self.paginator.clicked.connect(self.getCurrentPlanContents) layout.addWidget(self.paginator, alignment=Qt.AlignCenter) self.setLayout(layout) # 请求数据 def getCurrentPlanContents(self): current_page = self.paginator.current_page try: url = settings.SERVER_ADDR + 'strategy/hedgeplan/?page=' + str( current_page) r = requests.get(url=url) response = json.loads(r.content.decode('utf-8')) if r.status_code != 200: raise ValueError(response['message']) except Exception as e: self.network_message_label.setText(str(e)) else: if response['records']: self.paginator.setTotalPages(response['total_page']) self.table.showRowContents(response['records']) self.table.show() self.paginator.show() self.no_data_label.hide() else: self.no_data_label.show() self.table.hide() self.paginator.hide()
class MarketAnalysisMaintain(QWidget): def __init__(self, *args, **kwargs): super(MarketAnalysisMaintain, self).__init__(*args, **kwargs) layout = QVBoxLayout(margin=0) message_button_layout = QHBoxLayout() self.paginator = Paginator() self.paginator.clicked.connect(self.getFileContents) message_button_layout.addWidget(self.paginator) message_button_layout.addStretch() self.network_message_label = QLabel() message_button_layout.addWidget(self.network_message_label) message_button_layout.addWidget(QPushButton( '新增', clicked=self.create_analysis_file), alignment=Qt.AlignRight) layout.addLayout(message_button_layout) # 显示的表格 self.table = MarketAnalysisMaintainTable() layout.addWidget(self.table) self.setLayout(layout) # 获取内容 def getFileContents(self): current_page = self.paginator.current_page try: user_id = pickle.loads(settings.app_dawn.value('UKEY')) url = settings.SERVER_ADDR + 'user/' + str( user_id) + '/marketanalysis/?page=' + str(current_page) r = requests.get(url=url) response = json.loads(r.content.decode('utf-8')) if r.status_code != 200: raise ValueError(response['message']) except Exception as e: self.network_message_label.setText(str(e)) else: print(response) self.paginator.setTotalPages(response['total_page']) self.table.showRowContents(response['records']) self.network_message_label.setText(response['message']) # 新增一个文件 def create_analysis_file(self): popup = CreateNewMarketAnalysisPopup(parent=self) popup.exec_()
class MessageServiceMaintain(QWidget): def __init__(self, *args, **kwargs): super(MessageServiceMaintain, self).__init__(*args, **kwargs) layout = QVBoxLayout(margin=0) combo_message_layout = QHBoxLayout() self.date_combo = QComboBox(activated=self.getCurrentSMS) combo_message_layout.addWidget(self.date_combo, alignment=Qt.AlignLeft) # 页码控制器 self.paginator = Paginator() self.paginator.clicked.connect(self.getCurrentSMS) combo_message_layout.addWidget(self.paginator) self.network_message_label = QLabel() combo_message_layout.addWidget(self.network_message_label) combo_message_layout.addStretch() combo_message_layout.addWidget(QPushButton( '新增', clicked=self.create_new_sms), alignment=Qt.AlignRight) layout.addLayout(combo_message_layout) # 展示短信通的表格 self.sms_table = SMSTable() layout.addWidget(self.sms_table) self.setLayout(layout) self._addCombo() # 添加时间选择 def _addCombo(self): for date_item in [ { 'name': '今日', 'days': 0 }, { 'name': '最近3天', 'days': -3 }, { 'name': '最近7天', 'days': -7 }, { 'name': '全部', 'days': 'all' }, ]: self.date_combo.addItem(date_item['name'], date_item['days']) # 获取当前短信通信息 def getCurrentSMS(self): current_page = self.paginator.current_page try: user_id = pickle.loads(settings.app_dawn.value('UKEY')) r = requests.get(url=settings.SERVER_ADDR + 'user/' + str(user_id) + '/shortmessage/') response = json.loads(r.content.decode('utf8')) if r.status_code != 200: raise ValueError(response['message']) except Exception as e: self.network_message_label.setText(str(e)) else: self.sms_table.showRowContents(response['records']) self.paginator.setTotalPages(response['total_page']) return current_data = self.date_combo.currentData() current_date = QDate.currentDate() if current_data != 'all': min_date = current_date.addDays(current_data) url = settings.SERVER_ADDR + 'info/sms/?current_page=' + str( current_page) + '&mc=' + settings.app_dawn.value( 'machine') + '&min_date=' + min_date.toString('yyyy-MM-dd') else: url = settings.SERVER_ADDR + 'info/sms/?current_page=' + str( current_page) + '&mc=' + settings.app_dawn.value('machine') try: r = requests.get(url=url) response = json.loads(r.content.decode('utf-8')) except Exception as e: self.network_message_label.setText(str(e)) else: sms_data = response['data']['contacts'] self.sms_table.showRowContents(sms_data) self.paginator.setTotalPages(response['data']['total_page']) # 新增一条短信通 def create_new_sms(self): popup = CreateNewSMSLink(parent=self) popup.exec_()
class NormalReportPage(QWidget): def __init__(self, category_id, *args, **kwargs): super(NormalReportPage, self).__init__(*args, **kwargs) self.category_id = category_id layout = QVBoxLayout(margin=0, spacing=1) # 相关品种选框 variety_widget = QWidget(parent=self, objectName='varietyCombo') variety_widget.setFixedHeight(22) relate_variety_layout = QHBoxLayout(margin=0, spacing=2) relate_variety_layout.addWidget(QLabel('相关品种:')) self.variety_combo = QComboBox(activated=self.varietyChanged, objectName='combo') self.variety_combo.setCursor(Qt.PointingHandCursor) self.variety_combo.setMinimumWidth(80) relate_variety_layout.addWidget(self.variety_combo) relate_variety_layout.addStretch() # 页码控制 self.paginator = Paginator(parent=self) self.paginator.clicked.connect(self.getCurrentReports) relate_variety_layout.addWidget(self.paginator) variety_widget.setLayout(relate_variety_layout) layout.addWidget(variety_widget) self.report_table = NormalReportTable(self) self.report_table.setObjectName('reportTable') layout.addWidget(self.report_table) # 无数据的显示 self.no_data_label = QLabel('暂无相关数据...', styleSheet='color:rgb(200,100,50)', alignment=Qt.AlignCenter) self.no_data_label.hide() layout.addWidget(self.no_data_label) self.setLayout(layout) self.setStyleSheet(""" #reportTable{ border: none; background-color:rgb(240, 240, 240); } #varietyCombo{ background-color: rgb(178,200,187) } #varietyCombo #combo{ background-color: rgb(178,200,187); border: 1px solid rgb(200, 200, 200); color: rgb(7,99,109); font-weight: bold; } #varietyCombo #combo QAbstractItemView::item{ height:20px; } #varietyCombo #combo::drop-down{ border: 0px; } #varietyCombo #combo::down-arrow{ image:url("media/more.png"); width: 15px; height:15px; } """) self.variety_combo.setView(QListView()) # 获取品种选框内容 def getVarietyCombo(self): try: r = requests.get(url=settings.SERVER_ADDR + 'variety/?way=group') response = json.loads(r.content.decode('utf-8')) if r.status_code != 200: raise ValueError(response['message']) except Exception as e: pass else: self.variety_combo.clear() # 加入全部 self.variety_combo.addItem('全部', 0) for variety_group in response['variety']: for variety_item in variety_group['subs']: self.variety_combo.addItem(variety_item['name'], variety_item['id']) # 选择了品种 def varietyChanged(self): self.paginator.clearPages() self.getCurrentReports() # 获取当前显示的报告 def getCurrentReports(self): current_page = self.paginator.current_page current_variety_id = self.variety_combo.currentData() try: r = requests.get(url=settings.SERVER_ADDR + 'report/?page=' + str(current_page) + '&page_size=50&variety=' + str(current_variety_id) + '&category=' + str(self.category_id)) response = json.loads(r.content.decode('utf8')) if r.status_code != 200: raise ValueError(response['message']) except Exception: pass else: if response['reports']: self.report_table.showRowContents(response['reports']) self.paginator.setTotalPages(response['total_page']) self.no_data_label.hide() self.report_table.show() else: self.no_data_label.show() self.report_table.hide()