Browse Source

langkeysearch

chenjunkai 6 năm trước cách đây
mục cha
commit
f327e1290d
3 tập tin đã thay đổi với 84 bổ sung24 xóa
  1. 7 0
      controller/LangWord.py
  2. 62 24
      web/index.html
  3. 15 0
      web/userTab.html

+ 7 - 0
controller/LangWord.py

@@ -131,9 +131,16 @@ class LangWordView(TemplateView):
     def do_query(self, request_dict, response, userID):
         page = int(request_dict.get('page', None))
         line = int(request_dict.get('line', None))
+        searchKey = request_dict.get('searchKey', None)
+        searchVal = request_dict.get('searchVal', None)
         if page and line:
             la_qs = LangAreaModel.objects.filter().values('lang', 'id')
             lk_qs = LangKeyModel.objects.filter()
+            if searchKey and searchVal:
+                if searchKey == 'key':
+                    lk_qs = lk_qs.filter(word_key__contains=searchVal)
+                else:
+                    lk_qs = lk_qs.filter(langvalmodel__word_val__contains=searchVal, langvalmodel__la__lang=searchKey)
             count = lk_qs.count()
             lk_qs = lk_qs[(page - 1) * line:page * line].values_list('word_key', flat=True)
             lv_qs = LangValModel.objects.filter(lk__word_key__in=lk_qs). \

+ 62 - 24
web/index.html

@@ -87,14 +87,16 @@
         <section class="tab-item-1">
             <div class="container-fluid">
                 <div class="row">
+                    <div id="searchCheckBox"></div>
                     <div class="col-md-12">
-                        <div class="input-group">
-                            <div class="input-group-prepend">
-                                <div class="input-group-text">
-                                </div>
-                            </div>
-                        </div>
+                        <input type="text" class="form-control" id="searchInput"/>
+                        <button class="btn btn-danger form-inline" onclick="searchKeyAction()">搜索</button>
                     </div>
+                </div>
+            </div>
+            <hr>
+            <div class="container-fluid">
+                <div class="row">
                     <!--add-->
                     <div class="col-md-12">
                         <table class="table table-bordered table-hover">
@@ -106,6 +108,7 @@
                 <div id="pagination"></div>
             </div>
 
+            <hr>
 
             <!---->
             <div class="container-fluid">
@@ -168,8 +171,27 @@
         let post_data = {
             'token': $.cookie('access_token'),
             'page': 1,
-            'line': 10
+            'line': 10,
         };
+        InitIndex(post_data)
+        // $('#pagination').pagination({
+        //     pages: 50, //总页数
+        //     edges: 2,
+        //     cssStyle: 'pagination-sm', //按纽大小pagination-lg或写入自定义css
+        //     displayedPages: 5, //显示几个
+        //     onPageClick: function(pageNumber, event) {
+        //         //点击时调用
+        //         // alert(pageNumber);
+        //     },
+        //     onInit: function(getid) {
+        //         //刷新时或初始化调用
+        //         // alert(getid);
+        //     }
+        // });
+    });
+
+    function InitIndex(post_data) {
+
         $.postJSON(
             http_ip_prot + 'langWord/query', JSON.stringify(post_data),
             function (data) {
@@ -199,23 +221,9 @@
                 }
             }
         );
-        // $('#pagination').pagination({
-        //     pages: 50, //总页数
-        //     edges: 2,
-        //     cssStyle: 'pagination-sm', //按纽大小pagination-lg或写入自定义css
-        //     displayedPages: 5, //显示几个
-        //     onPageClick: function(pageNumber, event) {
-        //         //点击时调用
-        //         // alert(pageNumber);
-        //     },
-        //     onInit: function(getid) {
-        //         //刷新时或初始化调用
-        //         // alert(getid);
-        //     }
-        // });
-    });
+    }
+
     let la_list
-    let checkboxInput = '<input type="checkbox" aria-label="Checkbox for following text input">'
     let lw_data
 
     function queryData(page) {
@@ -246,13 +254,18 @@
         let body_data = data['lw_dict'];
         lw_data = body_data
         let head_html = '<tr><th>key</th>';
+        let search_tab = '<label><input type="radio" name="optionsRadios" value="key" checked>key</label>'
+
         //头部标签添加
+
         $.each(head_data, function (idx, obj) {
             // console.log(idx)
             head_html += ('<th>' + obj['lang'] + '</th>')
+            search_tab += '&nbsp;&nbsp;&nbsp;<label><input type="radio" name="optionsRadios" value="' + obj['lang'] + '">' + obj['lang'] + '</label>'
         });
         head_html += '<th width="180px"><a href="#" onclick="addRow()">add</a></th></tr>';
-
+        // search_tab += '<td width="180px"><button class="btn-primary btn">搜索</button></td></tr>';
+        $('#searchCheckBox').html(search_tab)
         let body_html = '';
 
 
@@ -423,6 +436,31 @@
         // })
     }
 
+    function searchKeyAction() {
+        let searchKey = $('input[name="optionsRadios"]:checked').val();
+        let searchVal = $('#searchInput').val()
+        console.log('-------------------------------')
+        console.log(searchKey)
+        console.log(searchVal)
+        console.log('-------------------------------')
+        let post_data = {}
+        if (searchVal && searchKey) {
+            post_data = {
+                'token': $.cookie('access_token'),
+                'page': 1,
+                'line': 10,
+                'searchKey': searchKey,
+                'searchVal': searchVal
+            };
+        } else {
+            post_data = {
+                'token': $.cookie('access_token'),
+                'page': 1,
+                'line': 10,
+            };
+        }
+        InitIndex(post_data)
+    }
 </script>
 </body>
 </html>

+ 15 - 0
web/userTab.html

@@ -139,12 +139,15 @@
                 </div>
             </div>
             <!--模态框end-->
+            <!--<input type="checkbox" aria-label="Checkbox for following text input">-->
+
         </section>
     </div>
 </div>
 
 <script type="text/javascript">
     let index_data
+    let user_data
     $(function () {
         let post_data = {
             'token': $.cookie('access_token'),
@@ -161,6 +164,18 @@
                 }
             }
         );
+        $.postJSON(
+            http_ip_prot + 'langArea/query', JSON.stringify(post_data),
+            function (data) {
+                if (data['code'] == 0) {
+                    user_data = data['res']
+                    console.log(user_data)
+                } else {
+                    alert(data['msg'])
+                }
+            }
+        );
+
     });
 
     function addTable(data) {