From 388350ea5bd25106ea4503e0df261ea7a7d54446 Mon Sep 17 00:00:00 2001 From: honue Date: Fri, 21 Jun 2024 23:23:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AE=E6=92=AD=E5=9B=BE=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E5=B1=8F=E5=B9=95=E5=A4=A7=E5=B0=8F=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=88=86=E5=BC=80=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 7 ++- plugins/trendingshow/__init__.py | 89 +++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 33 deletions(-) diff --git a/package.json b/package.json index e8cb4b7..5f83122 100644 --- a/package.json +++ b/package.json @@ -734,10 +734,13 @@ "name": "流行趋势轮播", "description": "在仪表板中显示流行趋势海报轮播图。", "labels": "仪表板", - "version": "1.1", + "version": "1.2", "icon": "TrendingShow.jpg", "author": "jxxghp", - "level": 1 + "level": 1, + "history": { + "v1.2": "不同屏幕大小,支持分开设置" + } }, "DailyWord": { "name": "每日一言", diff --git a/plugins/trendingshow/__init__.py b/plugins/trendingshow/__init__.py index a4221e9..542a619 100644 --- a/plugins/trendingshow/__init__.py +++ b/plugins/trendingshow/__init__.py @@ -1,3 +1,4 @@ +import re from typing import List, Tuple, Dict, Any, Optional from app.chain.tmdb import TmdbChain @@ -12,7 +13,7 @@ class TrendingShow(_PluginBase): # 插件图标 plugin_icon = "TrendingShow.jpg" # 插件版本 - plugin_version = "1.1" + plugin_version = "1.2" # 插件作者 plugin_author = "jxxghp" # 作者主页 @@ -25,11 +26,13 @@ class TrendingShow(_PluginBase): auth_level = 1 _enable: bool = False - _size: str = "mini" + _small_dev_size: str = "small" + _big_dev_size: str = "large" def init_plugin(self, config: dict = None): self._enable = config.get("enable") - self._size = config.get("size") + self._small_dev_size = config.get("small_dev_size") or "small" + self._big_dev_size = config.get("big_dev_size") or "large" @staticmethod def get_command() -> List[Dict[str, Any]]: @@ -77,8 +80,29 @@ class TrendingShow(_PluginBase): { 'component': 'VSelect', 'props': { - 'model': 'size', - 'label': '组件规格', + 'model': 'small_dev_size', + 'label': '小屏幕组件规格', + 'items': [ + {"title": "迷你", "value": "mini"}, + {"title": "小型", "value": "small"}, + {"title": "中型", "value": "medium"}, + {"title": "大型", "value": "large"} + ] + } + } + ] + }, { + 'component': 'VCol', + 'props': { + 'cols': 12, + 'md': 4 + }, + 'content': [ + { + 'component': 'VSelect', + 'props': { + 'model': 'big_dev_size', + 'label': '大屏幕组件规格', 'items': [ {"title": "迷你", "value": "mini"}, {"title": "小型", "value": "small"}, @@ -95,13 +119,14 @@ class TrendingShow(_PluginBase): } ], { "enable": self._enable, - "size": self._size + "small_dev_size": self._small_dev_size, + "big_dev_size": self._big_dev_size } def get_page(self) -> List[dict]: pass - def get_dashboard(self) -> Optional[Tuple[Dict[str, Any], Dict[str, Any], List[dict]]]: + def get_dashboard(self, **kwargs) -> Optional[Tuple[Dict[str, Any], Dict[str, Any], List[dict]]]: """ 获取插件仪表盘页面,需要返回:1、仪表板col配置字典;2、全局配置(自动刷新等);3、仪表板页面元素配置json(含数据) 1、col配置参考: @@ -115,30 +140,20 @@ class TrendingShow(_PluginBase): 3、页面配置使用Vuetify组件拼装,参考:https://vuetifyjs.com/ """ # 列配置 - if self._size == "mini": - cols = { - "cols": 12, - "md": 4 - } - height = 160 - elif self._size == "small": - cols = { - "cols": 12, - "md": 6 - } - height = 262 - elif self._size == "medium": - cols = { - "cols": 12, - "md": 8 - } - height = 335 + size_config = { + "mini": {"cols": {"cols": 12, "md": 4}, "height": 150}, + "small": {"cols": {"cols": 12, "md": 6}, "height": 225}, + "medium": {"cols": {"cols": 12, "md": 8}, "height": 450}, + "large": {"cols": {"cols": 12, "md": 12}, "height": 550} + } + + if self.is_mobile(kwargs.get('user_agent')): + config = size_config.get(self._small_dev_size, size_config["large"]) else: - cols = { - "cols": 12, - "md": 12 - } - height = 500 + config = size_config.get(self._big_dev_size, size_config["small"]) + + cols = config["cols"] + height = config["height"] # 全局配置 attrs = { "border": False @@ -190,7 +205,9 @@ class TrendingShow(_PluginBase): { 'component': 'VCarouselItem', 'props': { - 'src': media.get_backdrop_image() if self._size == "mini" else media.backdrop_path, + 'src': media.get_backdrop_image() if ( + self.is_mobile(kwargs.get('user_agent')) and + self._small_dev_size == "mini") else media.backdrop_path, 'cover': True, 'position': 'top' }, @@ -231,3 +248,13 @@ class TrendingShow(_PluginBase): def stop_service(self): pass + + @staticmethod + def is_mobile(user_agent): + mobile_keywords = [ + 'Mobile', 'iPhone', 'Android', 'Kindle', 'Opera Mini', 'Opera Mobi' + ] + for keyword in mobile_keywords: + if re.search(keyword, user_agent, re.IGNORECASE): + return True + return False