交互优化
This commit is contained in:
parent
2f40fe95a6
commit
63efc96eac
2
main.py
2
main.py
|
@ -273,6 +273,8 @@ def filter_group_mode1(parameter, group, hits):
|
|||
def predict():
|
||||
mode = request.args.get('mode')
|
||||
parameter = request.args.get('parameter')
|
||||
if len(trim_space(parameter)) == 0:
|
||||
return jsonify({'status': 1, 'message': '请输入参数', 'result': []})
|
||||
all_idiom, group = filter_logic(mode, parameter)
|
||||
result = get_max_group(all_idiom, group, 6)
|
||||
return jsonify({'status': 0, 'message': 'success', 'result': result})
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
|
||||
<!-- Bootstrap CSS -->
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
|
||||
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
</head>
|
||||
|
||||
|
@ -19,27 +20,27 @@
|
|||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="mode" id="mode0" value="0" checked>
|
||||
<label class="form-check-label" for="mode0">拼音1</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="mode" id="mode1" value="1">
|
||||
<label class="form-check-label" for="mode1">拼音2</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="mode" id="mode2" value="2">
|
||||
<label class="form-check-label" for="mode2">汉兜1</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="mode" id="mode3" value="3">
|
||||
<label class="form-check-label" for="mode3">汉兜2</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="mode" id="mode4" value="4">
|
||||
<label class="form-check-label" for="mode4">文字正则</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input class="form-check-input" type="radio" name="mode" id="mode5" value="5">
|
||||
<label class="form-check-label" for="mode5">拼音正则</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
|
@ -63,8 +64,12 @@
|
|||
<!-- Optional JavaScript -->
|
||||
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.6.0.min.js" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
|
||||
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"
|
||||
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
|
||||
crossorigin="anonymous"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('input[name=mode]').on('click', function (e) {
|
||||
|
@ -91,22 +96,29 @@
|
|||
$("#parameter").val('')
|
||||
})
|
||||
$('#submit').on('click', function () {
|
||||
$.get('/predict', { mode: $("input[name='mode']:checked").val(), parameter: $('#parameter').val() }, function (result) {
|
||||
if(result && result.status === 0){
|
||||
text = result.result.map(function(item){
|
||||
return item.word + '\t' + item.pinyin
|
||||
}).join('\n')
|
||||
if(!text){
|
||||
$('#result').val('无匹配结果')
|
||||
$.ajax({
|
||||
url: '/predict',
|
||||
data: { mode: $("input[name='mode']:checked").val(), parameter: $('#parameter').val() },
|
||||
success: function (result,) {
|
||||
if (result && result.status === 0) {
|
||||
text = result.result.map(function (item) {
|
||||
return item.word + '\t' + item.pinyin
|
||||
}).join('\n')
|
||||
if (!text) {
|
||||
$('#result').val('无匹配结果')
|
||||
}
|
||||
else {
|
||||
$('#result').val(text)
|
||||
}
|
||||
}
|
||||
else{
|
||||
$('#result').val(text)
|
||||
else {
|
||||
$('#result').val(result.message)
|
||||
}
|
||||
},
|
||||
error: function(){
|
||||
$('#result').val('出错了,请检查参数')
|
||||
}
|
||||
else {
|
||||
$('#result').val(result)
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
|
Loading…
Reference in New Issue