forked from lazzyfu/goInsight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql_dict.html
More file actions
270 lines (255 loc) · 13.1 KB
/
mysql_dict.html
File metadata and controls
270 lines (255 loc) · 13.1 KB
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
{% extends 'base.html' %}
{% load staticfiles %}
{% block right_content %}
<div class="row">
<div class="col-md-12">
<div class="box box-info">
<div class="box-header box-border">
<div class="mailbox-read-info">
<h3 class="box-title"><span class="fa fa-cog"></span> 查看数据字典
</h3>
</div>
</div>
<div class="box-body">
<form class="form-horizontal" id="DbDictQueryForm" action="{% url 'p_dbdict' %}"
method="post">
<div class="form-group">
<div class="col-md-4">
<label class="control-label col-sm-2">环境</label>
<div class="col-sm-10">
<select id="s_envi" name="envi_id" style="width: 100%" required
class="form-control selectpicker" title="选择环境..."
onchange="getTargetSchema()">
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-4">
<label class="control-label col-sm-2">库名</label>
<div class="col-sm-10">
<select id="s_schema" name="database" required
class="form-control selectpicker" title="选择库名..." data-size='8'
data-live-search="true">
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-4">
<label class="control-label col-sm-2"></label>
<div class="col-sm-10 pull-left">
<button type="submit" class="btn bg-info btn-sm">查询</button>
</div>
</div>
</div>
{% csrf_token %}
</form>
</div>
</div>
<div class="box" id="typediv1" style="visibility: hidden">
<div class="box-header box-border">
<div class="mailbox-read-info">
<h3 class="box-title"><span class="fa fa-file-code-o"></span>
</h3>
<button id="generate_pdf">点击生成单个HTML文件(在新页面保存即可)</button>
</div>
</div>
<div class="box-body" id="pdf_content">
<div style="text-align: center;line-height: 60px;" id="xtop">
<span style="font-size: 24px;font-weight: bold" id="dbtitle">
</span>
</div>
<div>
<h3>一、表名索引</h3>
<div style="margin-top: 10px;" id="href_table">
</div>
</div>
<div>
<h3>二、表结构详情</h3>
<div id="html_table"></div>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block link_javascripts %}
<script>
let curDate = new Date();
let dbtime = curDate.toLocaleDateString().split('/').join('-');
function repeatStringNumTimes(string, times) {
return times > 0 ? string.repeat(times) : "";
}
// 获取用户设置的环境
$(function () {
$.ajax({
url: '{% url 'p_get_sql_orders_envi' %}',
type: 'GET',
dataType: 'json',
timeout: 10000,
cache: false,
success: function (data) {
$("#s_envi").empty();
$.each(data, function (index, row) {
$("#s_envi").append(
"<option data-icon='glyphicon-record' value=" + row.envi_id + ">" + row.envi_name + "</option>"
);
});
$('.selectpicker').selectpicker('refresh')
}
});
});
/**
* 获取指定环境的schema
*/
function getTargetSchema() {
let s_schema = $('#s_schema');
let envi_id = $('#s_envi').val();
let csrftoken = $.cookie('csrftoken');
$.ajax({
url: '{% url 'p_get_target_schemas' %}',
type: 'POST',
dataType: 'json',
data: {'envi_id': envi_id, 'purpose': 'dbdict', 'csrfmiddlewaretoken': csrftoken},
timeout: 5000,
cache: false,
success: function (data) {
s_schema.empty();
let html = '';
$.each(data, function (index, row) {
let result = [row.host, row.port, row.schema].join(',');
let show_result = [row.comment, row.port, row.schema].join('_');
html += "<option data-icon='fa fa-database' value=" + result + ">" + show_result + "</option>"
});
s_schema.append(html);
$('.selectpicker').selectpicker('refresh')
}
})
}
/**
* 查询
*/
$('#DbDictQueryForm').on('submit', function (e) {
$(this).ajaxSubmit({
dataType: 'json',
beforeSubmit: showLoadingScreen($('body'), '数据处理中,请稍后...'),
success: function (result) {
hideLoadingScreen($('body'));
if (result.status === 0) {
document.getElementById('typediv1').style.visibility = "visible";
let db = $('#s_schema').val().split(',')[2];
let dbtitle = $('#dbtitle');
dbtitle.empty();
dbtitle.append("数据库: " + db + " 数据字典文档[" + dbtime + "]");
let data = result.data;
let html_table = $('#html_table');
let href_table = $('#href_table');
href_table.empty();
html_table.empty();
let html_t = '';
let href_t = '';
let num = 0;
data.forEach(function (row) {
num += 1;
let table_name = row[0];
let table_comment = row[1];
let create_time = row[2];
let table_value = row[3].split('<a>');
let index_value = row[4].split('<a>');
href_t += "<div style=\"margin-top: 10px;padding-left: 20px;\">\n" +
"<a href='#" + table_name + "'>" + num + '、' + table_name + ' ' + repeatStringNumTimes('.', 50) + ' ' + table_comment + "</a><br>\n" +
"</div>";
let row_html = "<div style=\"height: auto;overflow: scroll;border:1px solid #ccc;padding:10px;margin:10px\">";
row_html += "<a style='color: black;font-size:16px;font-weight: bold' name='" + table_name + "'>" + num + "、表名: " + table_name + " 备注: "
+ table_comment + " 创建时间: " + create_time + "</a><a href='#xtop'> 返回顶部</a>";
let table_tr_html = '', index_tr_html = '';
let table_row_num = 0, index_row_num = 0;
table_value.forEach(function (i) {
let tmp_data = i.split('<b>');
table_tr_html += "<tr>";
table_row_num += 1;
table_tr_html += "<td>" + table_row_num + "</td>";
tmp_data.forEach(function (j) {
table_tr_html += "<td>" + j + "</td>"
});
table_tr_html += "</tr>"
});
index_value.forEach(function (i) {
let tmp_data = i.split('<b>');
index_tr_html += "<tr>";
index_row_num += 1;
index_tr_html += "<td>" + index_row_num + "</td>";
tmp_data.forEach(function (j) {
index_tr_html += "<td>" + j + "</td>"
});
index_tr_html += "</tr>"
});
row_html += "<table class=\"table table-bordered\" style='margin-top: 20px;padding-top: 5px;margin-bottom: 5px;'>\n" +
" <thead>\n" +
" <tr style='background: #e4dede;'>\n" +
" <th>序列</th>\n" +
" <th>列名</th>\n" +
" <th>数据类型</th>\n" +
" <th>可空</th>\n" +
" <th>默认值</th>\n" +
" <th>字符集</th>\n" +
" <th>校对规则</th>\n" +
" <th>备注</th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" + table_tr_html +
" </tbody>\n" +
" </table>";
row_html += "<table class=\"table table-bordered\" style='margin-top: 20px;padding-top: 5px'>\n" +
" <thead>\n" +
" <tr style='background: #e4dede;'>\n" +
" <th>序列</th>\n" +
" <th>索引名</th>\n" +
" <th>唯一</th>\n" +
" <th>基数</th>\n" +
" <th>类型</th>\n" +
" <th>包含字段</th>\n" +
" </tr>\n" +
" </thead>\n" +
" <tbody>\n" + index_tr_html +
" </tbody>\n" +
" </table>";
row_html += "</div>";
html_t += row_html;
});
html_table.append(html_t);
href_table.append(href_t);
} else if (result.status === 2) {
displayPNotify(result.status, result.msg)
}
},
error: function (jqXHR) {
if (jqXHR.status === 403) {
displayPNotify(jqXHR.status)
}
}
});
return false;
});
$('#generate_pdf').click(function () {
let csrftoken = $.cookie('csrftoken');
let data = $('#pdf_content').html();
$.ajax({
url: '{% url 'p_generate_html' %}',
type: 'POST',
dataType: 'json',
data: {'data': data, 'csrfmiddlewaretoken': csrftoken},
beforeSubmit: showLoadingScreen($('body'), '数据处理中,请稍后...'),
timeout: 600000,
cache: false,
success: function (result) {
hideLoadingScreen($('body'));
if (result.status === 0) {
window.location.href = result.jump_url
}
}
})
})
</script>
{% endblock %}