#
Junjie
2024-01-03 068b15a5d507d691679ff55749dc6f3a920ea1c1
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>API开放平台</title>
    <link rel="stylesheet" href="../static/css/element.css">
    <script type="text/javascript" src="../static/js/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="../static/js/vue.min.js"></script>
    <script type="text/javascript" src="../static/js/showdown.min.js"></script>
    <script type="text/javascript" src="../static/js/common.js"></script>
    <script type="text/javascript" src="../static/js/element.js"></script>
    <style>
        #content {
            width: 80%;
            margin-left: 10%;
        }
 
        #content table {
            background: #fff;
            border: solid 1px #ddd;
            margin-bottom: 1.25rem;
            table-layout: auto
        }
 
        #content table caption {
            background: transparent;
            color: #222;
            font-size: 1rem;
            font-weight: bold
        }
 
        #content table thead {
            background: #F5F5F5
        }
 
        #content table thead tr th,#content table thead tr td {
            color: #222;
            font-size: 0.875rem;
            font-weight: bold;
            padding: 0.5rem 0.625rem 0.625rem
        }
 
        #content table tfoot {
            background: #F5F5F5
        }
 
        #content table tfoot tr th,#content table tfoot tr td {
            color: #222;
            font-size: 0.875rem;
            font-weight: bold;
            padding: 0.5rem 0.625rem 0.625rem
        }
 
        #content table tr th,#content table tr td {
            color: #222;
            font-size: 0.875rem;
            padding: 0.5625rem 0.625rem;
            text-align: left
        }
 
        #content table tr.even,#content table tr.alt,#content table tr:nth-of-type(even) {
            background: #F9F9F9
        }
 
        #content table thead tr th,#content table tfoot tr th,#content table tfoot tr td,#content table tbody tr th,#content table tbody tr td,#content table tr td {
            display: table-cell;
            line-height: 1.125rem
        }
 
        #content pre {
            white-space: pre-wrap;       /* css-3 */
            white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
            white-space: -o-pre-wrap;    /* Opera 7 */
            word-wrap: break-word;       /* Internet Explorer 5.5+ */
            background-color: #f8f8f8;
            border: 1px solid #dfdfdf;
            margin-top: 1.5em;
            margin-bottom: 1.5em;
            padding: 0.125rem 0.3125rem 0.0625rem;
        }
 
        #content pre code {
            background-color: transparent;
            border: 0;
            padding: 0;
        }
 
        .el-dropdown-link {
            cursor: pointer;
            color: #409EFF;
        }
        .el-icon-arrow-down {
            font-size: 12px;
        }
    </style>
</head>
<body>
    <div id="app">
        <div id="content"></div>
        <div style="position: fixed;top: 20px;right: 20px;width: 100px;">
            <el-menu default-active="1">
                <el-menu-item index="1">
                    <span slot="title" @click="introduceClick()">规范说明</span>
                </el-menu-item>
                <el-menu-item index="2">
                    <span slot="title" @click="keyList()">密钥管理</span>
                </el-menu-item>
            </el-menu>
        </div>
 
        <el-dialog title="密钥管理" :visible.sync="keyTableVisible">
            <el-table :data="keyTableData" v-loading="loading">
                <el-table-column property="hostId$" label="仓库"></el-table-column>
                <el-table-column property="signKey" label="签名密钥" width="150"></el-table-column>
                <el-table-column property="appKey" label="接口请求密钥" width="250"></el-table-column>
                <el-table-column property="createTime$" label="时间" width="200"></el-table-column>
                <el-table-column label="操作" width="400">
                    <template slot-scope="scope">
                        <el-button size="mini" @click="generateSignKey(scope.row.hostId)">签名密钥</el-button>
                        <el-button size="mini" @click="generateAppKey(scope.row.hostId)">接口密钥</el-button>
                        <el-switch
                                v-model="scope.row.signStatus"
                                @change="switchChange(scope.row.hostId,scope.row.signStatus)"
                                active-text="开启签名"
                                inactive-text="关闭签名">
                        </el-switch>
                    </template>
                </el-table-column>
            </el-table>
        </el-dialog>
    </div>
 
    <script>
        showdown.setOption('tables', true);
        var converter = new showdown.Converter()
 
        var app = new Vue({
            el: '#app',
            data: {
                keyTableVisible: false,
                keyTableData: [],
                loading: true
            },
            created() {
                this.init()
            },
            methods: {
                init() {
                    this.introduceClick()
                },
                introduceClick() {
                    $.ajax({
                        url: "md/introduce.md",
                        headers: {'token': localStorage.getItem('token')},
                        method: 'GET',
                        success: function (res) {
                            // $("#content").html(marked.parse(res))
                            // console.log(converter.makeHtml(res))
                            $("#content").html(converter.makeHtml(res))
                        }
                    });
                },
                keyList() {
                    let that = this
                    this.keyTableVisible = true
                    $.ajax({
                        url: baseUrl + "/hostKey/list/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: {},
                        dataType:'json',
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            let tmp = []
                            res.data.forEach((item, index) => {
                                item.signStatus = item.signStatus == 1 ? true : false;
                                tmp.push(item)
                            });
                            that.keyTableData = tmp
                            that.loading = false
                        }
                    });
                },
                generateSignKey(hostId) {
                    let that = this
                    this.$confirm('此操作将覆盖原签名密钥, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        $.ajax({
                            url: baseUrl + "/hostKey/generateSignKey/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: {
                                hostId: hostId
                            },
                            dataType: 'json',
                            contentType: 'application/json;charset=UTF-8',
                            method: 'GET',
                            success: function (res) {
                                if (res.code === 200) {
                                    that.$message({
                                        type: 'success',
                                        message: '生成成功'
                                    });
 
                                    that.keyTableData.forEach((item, index) => {
                                        if (item.hostId == hostId) {
                                            item.signKey = res.data.signKey
                                        }
                                    });
                                } else {
                                    that.$message({
                                        type: 'error',
                                        message: res.msg
                                    });
                                }
                            }
                        });
                    }).catch(() => {
                        //取消
                    });
                },
                generateAppKey(hostId) {
                    let that = this
                    this.$confirm('此操作将覆盖原接口密钥, 是否继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        $.ajax({
                            url: baseUrl + "/hostKey/generateAppKey/auth",
                            headers: {'token': localStorage.getItem('token')},
                            data: {
                                hostId: hostId
                            },
                            dataType: 'json',
                            contentType: 'application/json;charset=UTF-8',
                            method: 'GET',
                            success: function (res) {
                                if (res.code === 200) {
                                    that.$message({
                                        type: 'success',
                                        message: '生成成功'
                                    });
 
                                    that.keyTableData.forEach((item, index) => {
                                        if (item.hostId == hostId) {
                                            item.appKey = res.data.appKey
                                        }
                                    });
                                } else {
                                    that.$message({
                                        type: 'error',
                                        message: res.msg
                                    });
                                }
                            }
                        });
                    }).catch(() => {
                        //取消
                    });
                },
                switchChange(hostId, signStatus) {
                    let that = this
                    //签名校验开关
                    $.ajax({
                        url: baseUrl + "/hostKey/switchSign/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: {
                            hostId: hostId,
                            signStatus: signStatus ? 1 : 0,
                        },
                        dataType: 'json',
                        contentType: 'application/json;charset=UTF-8',
                        method: 'GET',
                        success: function (res) {
                            if (res.code === 200) {
                                that.$message({
                                    type: 'success',
                                    message: '切换成功'
                                });
                            } else {
                                that.$message({
                                    type: 'error',
                                    message: res.msg
                                });
                            }
                        }
                    });
                }
            }
        })
    </script>
</body>
</html>