diff --git a/utils/common.py b/utils/common.py index 68c3f130..a60a236c 100644 --- a/utils/common.py +++ b/utils/common.py @@ -1,7 +1,7 @@ # 导入所需的库 import re, random, requests, json import time -import os +import os, glob import logging from datetime import datetime from datetime import timedelta @@ -718,6 +718,25 @@ def get_all_file_paths(self, folder_path): return file_paths + # 获取指定路径下指定拓展名的文件名列表 + def get_specify_extension_names_in_folder(self, path: str, extension: str): + """ + 获取指定路径下指定拓展名的文件名列表 + + Parameters: + path (str): 指定的路径 + extension (str): 指定的拓展名(例如:.json、.txt、.jpg等) + + Returns: + list: 文件名列表 + """ + if not os.path.exists(path): + logging.error(f"路径 '{path}' 不存在") + return [] + + file_names = glob.glob(os.path.join(path, f"*{extension}")) + return [os.path.basename(file_name) for file_name in file_names] + def remove_extension_from_list(self, file_name_list): """ 将包含多个带有拓展名的文件名的列表中的拓展名去掉,只返回文件名部分组成的新列表 @@ -795,6 +814,7 @@ def get_live2d_model_name(self, path): return None + """ .]]@@ .@]] @@@@ O@@` ,]]]]]]]]]]]]. /]] /@]` diff --git a/webui.py b/webui.py index 69713153..7078f366 100644 --- a/webui.py +++ b/webui.py @@ -5448,10 +5448,22 @@ def update_echart_gift(): with ui.card().style(card_css): ui.label("配置模板") with ui.row(): - input_config_template_path = ui.input(label='配置模板路径', value="", placeholder='输入你需要加载或保存的配置文件路径,例如:直播带货.json') - - button_config_template_save = ui.button('保存webui配置到文件', on_click=lambda: config_template_save(input_config_template_path.value), color=button_internal_color).style(button_internal_css) - button_config_template_load = ui.button('读取模板到本地(慎点)', on_click=lambda: config_template_load(input_config_template_path.value), color=button_internal_color).style(button_internal_css) + # 获取指定路径下指定拓展名的文件名列表 + config_template_paths = common.get_specify_extension_names_in_folder("./", "*.json") + data_json = {} + for line in config_template_paths: + data_json[line] = line + select_config_template_path = ui.select( + label='配置模板路径', + options=data_json, + value="", + with_input=True, + new_value_mode='add-unique', + clearable=True + ) + + button_config_template_save = ui.button('保存webui配置到文件', on_click=lambda: config_template_save(select_config_template_path.value), color=button_internal_color).style(button_internal_css) + button_config_template_load = ui.button('读取模板到本地(慎点)', on_click=lambda: config_template_load(select_config_template_path.value), color=button_internal_color).style(button_internal_css)