更新插件功能
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"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": "-"
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
初始化插件
|
||||
"""
|
||||
import os
|
||||
import logging
|
||||
from flask import Flask, render_template_string
|
||||
from applications.dev import console
|
||||
|
||||
# 获取插件所在的目录(结尾没有分割符号)
|
||||
dir_path = os.path.dirname(__file__).replace("\\", "/")
|
||||
folder_name = dir_path[dir_path.rfind("/") + 1:] # 插件文件夹名称
|
||||
|
||||
def event_enable():
|
||||
"""当此插件被启用时会调用此处"""
|
||||
print(f"启用插件,dir_path: {dir_path} ; folder_name: {folder_name}")
|
||||
|
||||
|
||||
def event_disable():
|
||||
"""当此插件被禁用时会调用此处"""
|
||||
print(f"禁用插件,dir_path: {dir_path} ; folder_name: {folder_name}")
|
||||
|
||||
def event_init(app: Flask):
|
||||
"""初始化完成时会调用这里"""
|
||||
# 使用下面的代码 查看所有注册的视图函数。对于 Flask app.route 函数的实现,请参考 https://www.jianshu.com/p/dff3bc2f4836
|
||||
# print(app.view_functions)
|
||||
|
||||
# 定义新视图函数
|
||||
def new_index():
|
||||
# 规避 render_template 的做法
|
||||
with open(dir_path + "/templates/replacePage_index.html", "r", encoding='utf-8') as f:
|
||||
return render_template_string(f.read())
|
||||
|
||||
# Index.index 是主页的视图函数对应的名称,原视图函数位于 applications/view/index/index.py
|
||||
del app.view_functions['Index.index'] # 释放原视图函数
|
||||
app.view_functions['Index.index'] = new_index # 替换原视图函数
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>pear-admin-flask</title>
|
||||
<meta name="description" content="pear-admin-flask">
|
||||
{% include 'admin/common/header.html' %}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='index/layui/css/layui.css') }}"/>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='index/css/main.css') }}"/>
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='index/css/load.css') }}"/>
|
||||
<style>
|
||||
.layui-nav .layui-this:after {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.layui-nav .layui-nav-bar {
|
||||
display: none;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<!-- header -->
|
||||
<div class="ew-header">
|
||||
<img class="layui-logo" src="{{ url_for('static', filename='index/images/un28.svg') }}"
|
||||
style="height:50px;padding: 10px;"/>
|
||||
<div class="ew-nav-group">
|
||||
<div class="nav-toggle"><i class="layui-icon layui-icon-more-vertical"></i></div>
|
||||
<ul class="layui-nav" lay-filter="ew-header-nav">
|
||||
<li class="layui-nav-item">
|
||||
<a lay-href="/">首页</a>
|
||||
</li>
|
||||
<li class="layui-nav-item">
|
||||
<a href="/admin" target="_blank">后台</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<!-- banner -->
|
||||
<div class="ew-banner" style="box-shadow: 0 0 8px rgba(0,0,0,.101562);">
|
||||
<div class="layui-container">
|
||||
<div class="layui-row layui-col-space25" style="margin-top: 10px;">
|
||||
<h1>主页被我替换了哈哈哈!</h1>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<br/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<!-- js部分 -->
|
||||
<script src="{{ url_for('static', filename='admin/component/layui/layui.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='admin/component/pear/pear.js') }}"></script>
|
||||
|
||||
<script>
|
||||
layui.use(['layer', 'form', 'jquery'], function () {
|
||||
var $ = layui.jquery
|
||||
var layer = layui.layer
|
||||
var form = layui.form
|
||||
var jquery = layui.jquery
|
||||
})
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user