forked from php-danfu.shenzhenbenwo.com

lefengyang
2025-09-10 3c9dcaf742cfa3e3c2b0843c8752cf7713aaf1fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<head>
    <title>{$title|default=''} - {$powered|default=''}</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="../statics/css/layui.css" rel="stylesheet">
    <script src="../statics/js/layui.js"></script>
    <script src="../statics/js/jquery.js"></script>
    <script src="../statics/js/vue.js"></script>
    <script src="../statics/js/axios.js"></script>
    <style>
        body {
            background-color: #f3f3f4;
            margin-top: 10px;
        }
        .centered {
            text-align: center;
        }
        .centered button {
            width: 200px;
            height: 60px;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15" id="app" v-cloak="">
        <div class="layui-card">
            <div class="centered">
                <div class="layui-progress">
                    <div class="layui-progress-bar layui-bg-blue" lay-percent="100%"></div>
                </div>
            </div>
            <div class="layui-card-header">升级系统</div>
            <div class="layui-card-body">
                <div class="layui-row">
                    <p style="font-size: 18px;">版本更迭: <span style="color: red">{$version_now} - {$version_new}</span></p>
                    <div class="layui-form-item" style="margin-top: 10px">
                        <label class="layui-form-label" style="font-size: 18px;padding-left: 0;">表前缀</label>
                        <div class="layui-input-block">
                            <input type="text" style="width: 10%" v-model="prefix" name="title" lay-verify="title"
                                   autocomplete="off" placeholder="请输入表前缀" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="centered">
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" v-if="isUpgrade && executeIng">
                        正在升级中
                    </button>
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" v-if="isUpgrade && !executeIng"
                            @click="startUpgrade">立即升级
                    </button>
                    <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" v-else-if="isUpgrade == false">无需升级</button>
                </div>
            </div>
            <div class="layui-card-body">
                <div class="layui-form">
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th>表名</th>
                            <th>执行状态</th>
                            <th width="40%">错误原因</th>
                            <th>执行时间</th>
                            <th width="12%">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr v-for="(item,index) in upgradeData">
                            <td>{{item.table}}</td>
                            <td>{{item.status ? '执行成功':'执行失败'}}</td>
                            <td>{{item.error}}</td>
                            <td>{{item.add_time}}</td>
                            <td>无操作</td>
                        </tr>
                        </tbody>
                    </table>
                </div>
                <div class="layui-form">
 
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" charset="utf-8">
    var isUpgrade = <?=$isUpgrade ? 'true' : 'false'?>;
    new Vue({
        el: '#app',
        data: {
            sleep: 0,
            prefix: 'eb_',
            upgradeData: [],
            isUpgrade: isUpgrade,
            executeIng: false,
            page: 1,
        },
        methods: {
            startUpgrade: function () {
                var that = this;
                if (!that.prefix) {
                    return that.showMsg('请填写表前缀');
                }
                this.requestGet('upgrade/run', {
                    sleep: this.sleep,
                    prefix: this.prefix,
                    page: this.page
                }).then(function (res) {
                    if (res.data.sleep !== -1) {
                        if (res.data.page) {
                            that.page = res.data.page;
                        }
                        that.sleep = res.data.sleep;
                        that.upgradeData.push(res.data);
                        that.executeIng = true;
                        setTimeout(function () {
                            that.startUpgrade();
                        }, 100);
                    } else {
                        that.isUpgrade = false;
                        that.nextAction = true;
                        that.executeIng = false;
                        return that.showMsg('执行完毕');
                    }
                }).catch(function (res) {
                    return that.showMsg(res.msg);
                });
            },
            requestGet: function (url, data) {
                var params = Object.keys(data).map(function (key) {
                    return key + '=' + data[key];
                }).join('&');
                return new Promise(function (resolve, reject) {
                    axios.get(url + (params ? '?' + params : '')).then(function (res) {
                        if (res.status == 200) {
                            resolve(res.data)
                        } else {
                            reject(res.data);
                        }
                    }).catch(function (err) {
                        reject({msg: err})
                    });
                })
            },
            showMsg: function (msg, success) {
                alert(msg);
            },
        }
    })
</script>
</body>
</html>