diff --git a/applications/dev/__init__.py b/applications/dev/__init__.py index 4819129..58d9179 100644 --- a/applications/dev/__init__.py +++ b/applications/dev/__init__.py @@ -3,6 +3,7 @@ from applications.dev import role from applications.dev import power from applications.dev import department from applications.dev import console +from applications.dev import setting from flask import Flask # 获取app应用实例,会被初始化插件时重新赋值 diff --git a/applications/dev/setting.py b/applications/dev/setting.py new file mode 100644 index 0000000..84bbd22 --- /dev/null +++ b/applications/dev/setting.py @@ -0,0 +1,43 @@ +from applications.common import curd +from applications.models import pluginSetting +from applications.schemas import pluginSettingOutSchema +from applications.extensions import db + +def get(key): + """ + 获取设置数据库中保存的值。 + + :param key: 查询的键(最长长度 255) + + :return: value + """ + query = pluginSetting.query.filter_by(key=key).all() + data = curd.model_to_dicts(schema=pluginSettingOutSchema, data=query) + if len(data) == 0: + return None + return data[0]['value'] + +def set(key, value): + """ + 设置数据库的值。 + + :param key: 设置的键(最长长度 255) + :param value: 设置的值(最长长度 65525) + + :return: bool + """ + if len(pluginSetting.query.filter_by(key=key).all()) != 0: + d = pluginSetting.query.filter_by(key=key).update({"value": value}) + if d: + db.session.commit() + return True + else: + setting = pluginSetting( + key=key, + value=value + ) + r = db.session.add(setting) + db.session.commit() + return True + return False + \ No newline at end of file diff --git a/applications/models/__init__.py b/applications/models/__init__.py index d94b265..e4b8d98 100644 --- a/applications/models/__init__.py +++ b/applications/models/__init__.py @@ -8,3 +8,4 @@ from .admin_role_power import role_power from .admin_user import User from .admin_user_role import user_role from .admin_mail import Mail +from .plugin_setting import pluginSetting diff --git a/applications/models/plugin_setting.py b/applications/models/plugin_setting.py new file mode 100644 index 0000000..83f56c1 --- /dev/null +++ b/applications/models/plugin_setting.py @@ -0,0 +1,10 @@ +from applications.extensions import db + + +class pluginSetting(db.Model): + __tablename__ = 'plugin_setting' + id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment="设置项ID") + key = db.Column(db.String(255), comment="设置键") + value = db.Column(db.String(65535), comment="设置值") + + \ No newline at end of file diff --git a/applications/schemas/__init__.py b/applications/schemas/__init__.py index 56a8678..cf9daa3 100644 --- a/applications/schemas/__init__.py +++ b/applications/schemas/__init__.py @@ -6,3 +6,4 @@ from .admin_dept import DeptOutSchema from .admin_log import LogOutSchema from .admin_photo import PhotoOutSchema from .admin_mail import MailOutSchema +from .plugin_setting import pluginSettingOutSchema diff --git a/applications/schemas/plugin_setting.py b/applications/schemas/plugin_setting.py new file mode 100644 index 0000000..68f2c3e --- /dev/null +++ b/applications/schemas/plugin_setting.py @@ -0,0 +1,11 @@ +from applications.extensions import ma +from marshmallow import fields, validate + + +class pluginSettingInSchema(ma.Schema): + key = fields.Str(required=True) + value = fields.Str(required=True) + +class pluginSettingOutSchema(ma.Schema): + key = fields.Str(attribute="key") + value = fields.Str(rattribute="value") diff --git a/applications/view/plugin/__init__.py b/applications/view/plugin/__init__.py index 2aa2d47..22ce27a 100644 --- a/applications/view/plugin/__init__.py +++ b/applications/view/plugin/__init__.py @@ -71,10 +71,6 @@ def data(): "plugin_name": info["plugin_name"], "plugin_version": info["plugin_version"], "plugin_description": info["plugin_description"], - "developer_name": info["developer_name"], - "developer_website": info["developer_website"], - "developer_email": info["developer_email"], - "developer_phone": info["developer_phone"], "plugin_folder_name": filename, "enable": "1" if filename in PLUGIN_ENABLE_FOLDERS else "0" } diff --git a/pear.sql b/pear.sql index e33d78a..6a5b12b 100644 --- a/pear.sql +++ b/pear.sql @@ -370,3 +370,14 @@ CREATE TABLE `alembic_version` ( INSERT INTO `alembic_version` VALUES ('7634e028e338'); SET FOREIGN_KEY_CHECKS = 1; + +-- ---------------------------- +-- Table structure for plugin_setting +-- ---------------------------- +DROP TABLE IF EXISTS `admin_user_role`; +CREATE TABLE `admin_user_role` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '标识', + `key` mediumtext COLLATE utf8_unicode_ci COMMENT '键', + `value` mediumtext COLLATE utf8_unicode_ci COMMENT '值', + PRIMARY KEY (`id`) +) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file diff --git a/plugins/helloworld/__init__.json b/plugins/helloworld/__init__.json index 110f9f7..1373e2d 100644 --- a/plugins/helloworld/__init__.json +++ b/plugins/helloworld/__init__.json @@ -1,9 +1,5 @@ { "plugin_name": "Hello World", "plugin_version": "1.0.0.1", - "plugin_description": "一个测试的插件。", - "developer_name": "Yishang", - "developer_website": "https://lovepikachu.top", - "developer_email": "422880152@qq.com", - "developer_phone": "-" + "plugin_description": "一个测试的插件。" } \ No newline at end of file diff --git a/plugins/realip/__init__.json b/plugins/realip/__init__.json index 2f7e77f..659ed4f 100644 --- a/plugins/realip/__init__.json +++ b/plugins/realip/__init__.json @@ -1,9 +1,5 @@ { "plugin_name": "真实IP插件", "plugin_version": "1.0.0.1", - "plugin_description": "在上游更改访客IP地址,并采用自定义日志输出。", - "developer_name": "Yishang", - "developer_website": "https://lovepikachu.top", - "developer_email": "422880152@qq.com", - "developer_phone": "-" + "plugin_description": "在上游更改访客IP地址,并采用自定义日志输出。" } \ No newline at end of file diff --git a/plugins/replacePage/__init__.json b/plugins/replacePage/__init__.json index d555882..143dd0c 100644 --- a/plugins/replacePage/__init__.json +++ b/plugins/replacePage/__init__.json @@ -1,9 +1,5 @@ { "plugin_name": "页面替换插件", "plugin_version": "1.0.0.1", - "plugin_description": "在不更改原有框架视图函数的情况下更改渲染输出页面。", - "developer_name": "Yishang", - "developer_website": "https://lovepikachu.top", - "developer_email": "422880152@qq.com", - "developer_phone": "-" + "plugin_description": "在不更改原有框架视图函数的情况下更改渲染输出页面。" } \ No newline at end of file diff --git a/templates/admin/plugin/main.html b/templates/admin/plugin/main.html index 4ba7465..b0e4f18 100644 --- a/templates/admin/plugin/main.html +++ b/templates/admin/plugin/main.html @@ -133,10 +133,6 @@ {field: 'plugin_name', minWidth: 100, title: '插件名称'}, {field: 'plugin_version', title: '插件版本'}, {field: 'plugin_description', title: '插件描述'}, - {field: 'developer_name', title: '开发者名称'}, - {field: 'developer_website', title: '开发者网站'}, - {field: 'developer_email', title: '开发者邮箱'}, - {field: 'developer_phone', title: '开发者电话'}, {field: 'plugin_folder_name', hide: true}, {field: 'enable', title: '状态', templet: '#plugin-enable', width: 100, align: 'center'}, {title: '操作', templet: '#plugin-bar', width: 120, align: 'center'}