| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta content="width=device-width, initial-scale=1.0" name="viewport">
- <title>{% block title %}{{ app_name }}{% endblock %}</title>
- <!-- Tailwind CSS -->
- <script src="{{ url_for('static', filename='js/tailwindcss.js') }}"></script>
- <!-- Font Awesome -->
- <link href="{{ url_for('static', filename='fontawesome/css/all.min.css') }}" rel="stylesheet">
- <!-- ECharts -->
- <script src="{{ url_for('static', filename='echarts/dist/echarts.min.js') }}"></script>
- <!-- jQuery -->
- <script src="{{ url_for('static', filename='js/jquery.min.js') }}"></script>
- <!-- Custom CSS -->
- <link href="{{ url_for('static', filename='css/style.css') }}" rel="stylesheet">
- {% block head %}{% endblock %}
- </head>
- <body class="min-h-screen flex flex-col">
- {% block content %}{% endblock %}
- {% block scripts %}{% endblock %}
- <!-- 全局 Token 自动刷新 -->
- <script>
- (function () {
- var refreshing = false;
- var pendingRequests = [];
- $.ajaxSetup({
- beforeSend: function (xhr) {
- var token = localStorage.getItem('token') || localStorage.getItem('jwt_token');
- if (token) {
- xhr.setRequestHeader('Authorization', 'Bearer ' + token);
- }
- }
- });
- $(document).ajaxError(function (event, jqXHR, settings) {
- if (jqXHR.status === 401 && !refreshing) {
- var rt = localStorage.getItem('refresh_token');
- if (!rt) {
- window.location.href = '/login';
- return;
- }
- refreshing = true;
- // 暂停后续请求重试队列
- pendingRequests.push({ settings: settings });
- $.ajax({
- url: '/api/v1/auth/refresh',
- method: 'POST',
- contentType: 'application/json',
- data: JSON.stringify({ refresh_token: rt }),
- success: function (resp) {
- if (resp.code === '000000') {
- localStorage.setItem('token', resp.data.access_token);
- localStorage.setItem('refresh_token', resp.data.refresh_token);
- // 重试所有挂起的请求
- pendingRequests.forEach(function (p) {
- $.ajax(p.settings);
- });
- } else {
- window.location.href = '/login';
- }
- },
- error: function () {
- window.location.href = '/login';
- },
- complete: function () {
- refreshing = false;
- pendingRequests = [];
- }
- });
- return false;
- }
- });
- })();
- </script>
- </body>
- </html>
|