chenjunkai 6 years ago
parent
commit
dbe631fc3d
3 changed files with 102 additions and 13 deletions
  1. 13 5
      controller/LangWord.py
  2. 31 8
      web/index.html
  3. 58 0
      web/js/datachange.js

+ 13 - 5
controller/LangWord.py

@@ -103,7 +103,7 @@ class LangWordView(TemplateView):
         if lk.exists():
             lk_id = lk[0].id
             if old_word_key != word_key:
-                lk.update(word_key=word_key)
+                lk.update(word_key=word_key, updTime=nowTime)
             for w in word_arr:
                 lv_qs = LangValModel.objects.filter(lk__id=lk_id, la__lang=w)
                 if lv_qs.exists():
@@ -133,6 +133,7 @@ class LangWordView(TemplateView):
         line = int(request_dict.get('line', None))
         searchKey = request_dict.get('searchKey', None)
         searchVal = request_dict.get('searchVal', None)
+        orderByupdate = request_dict.get('orderByupdate', 0)
         if page and line:
             lang_set_list = LangSetModel.objects.filter(user__id=userID).values_list('lang__id', flat=True)
             lang_set_list = list(lang_set_list)
@@ -144,12 +145,19 @@ class LangWordView(TemplateView):
                 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,la__id__in=lang_set_list). \
-                values('word_val', 'la__id', 'la__lang', 'lk__word_key', 'lk__id')
+            # lk_qs = lk_qs[(page - 1) * line:page * line].values_list('word_key', flat=True)
+            if orderByupdate == 1:
+                lk_qs = lk_qs.order_by('updTime')
+            else:
+                lk_qs = lk_qs.order_by('-updTime')
+            lk_qs = lk_qs[(page - 1) * line:page * line].values('word_key', 'updTime')
+            k_list = []
             lw_dict = {}
             for lk in lk_qs:
-                lw_dict[lk] = {}
+                k_list.append(lk['word_key'])
+                lw_dict[lk['word_key']] = {'updTime': lk['updTime']}
+            lv_qs = LangValModel.objects.filter(lk__word_key__in=k_list, la__id__in=lang_set_list). \
+                values('word_val', 'la__id', 'la__lang', 'lk__word_key', 'lk__id')
             for lv in lv_qs:
                 lw_dict[lv['lk__word_key']][lv['la__lang']] = lv['word_val']
             res = {

+ 31 - 8
web/index.html

@@ -18,6 +18,7 @@
     <script src="js/jqhttpsdk.js"></script>
     <script src="js/jkcor.js"></script>
     <script src="js/pages.js"></script>
+    <script src="js/datachange.js"></script>
     <style>
         td {
             white-space: nowrap;
@@ -101,8 +102,10 @@
                 <div class="row">
                     <div id="searchCheckBox" class="col-md-12"></div>
                     <div class="col-md-12">
-                        <input type="text" class="form-group form-control" id="searchInput" style="width: 300px;display: inline"/>
-                        <button class="btn btn-danger form-inline" style="margin-bottom: 5px" onclick="searchKeyAction()">搜索</button>
+                        <input type="text" class="form-group form-control" id="searchInput"
+                               style="width: 300px;display: inline"/>
+                        <button class="btn btn-danger form-inline" style="margin-bottom: 5px"
+                                onclick="searchKeyAction()">搜索</button>
                     </div>
                 </div>
             </div>
@@ -179,11 +182,13 @@
 </div>
 
 <script type="text/javascript">
+    var orderByupdate = 0
     $(function () {
         let post_data = {
             'token': $.cookie('access_token'),
             'page': 1,
             'line': 5,
+            'orderByupdate': orderByupdate
         };
         InitIndex(post_data)
         // $('#pagination').pagination({
@@ -202,6 +207,21 @@
         // });
     });
 
+    function orderByUpdateTimeFunc(status) {
+        if (status === 1) {
+            orderByupdate = 0
+        } else {
+            orderByupdate = 1
+        }
+        let post_data = {
+            'token': $.cookie('access_token'),
+            'page': 1,
+            'line': 5,
+            'orderByupdate': orderByupdate
+        };
+        InitIndex(post_data)
+    }
+
     function InitIndex(post_data) {
 
         $.postJSON(
@@ -275,20 +295,22 @@
             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>';
+        // head_html += '<th>udpateTime &nbsp;<i class="fa fa-arrow-down" aria-hidden="true"></i></td><th width="180px"><a href="#" onclick="addRow()">add</a></th></tr>';
+        head_html += ('<th><a href="#" onclick="orderByUpdateTimeFunc(' + orderByupdate + ')">udpateTime &nbsp;<i class="fa ' + (orderByupdate == 1 ? 'fa-arrow-up' : 'fa-arrow-down') + '" aria-hidden="true"></i></a></td><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 = '';
 
-
+        console.log('--------');
         $.each(body_data, function (idx, obj) {
             // console.log(idx)
-            // console.log(obj)
+            console.log(obj)
             let edit_btn = '<a href="#" title="Edit" onclick="editFunc(\'' + idx + '\')"><i class="fa fa-edit"></i></a>';
-            let del_btn = '<a href="#" title="Delete" onclick="deleteFunc(\'' + idx + '\')"><i class="fa fa-ban"></i></a>';
+            // let del_btn = '<a href="#" title="Delete" onclick="deleteFunc(\'' + idx + '\')"><i class="fa fa-ban"></i></a>';
+            let del_btn = '';
             body_html += '<tr>';
             body_html += ('<td>' + idx + '</td>');
-            console.log('--------');
+
             $.each(la_list, function (x, y) {
                 if (obj[y['lang']]) {
                     body_html += ('<td>' + obj[y['lang']] + '</td>')
@@ -296,7 +318,8 @@
                     body_html += ('<td></td>')
                 }
             });
-            body_html += '<td>' + edit_btn + '&nbsp;&nbsp;&nbsp;' + del_btn + '</td></tr>';
+            let updTime = $.DateChange.UnixToDate(obj['updTime'], true, 8);
+            body_html += ('<td>' + updTime + '<span class="arrow dsc"></td><td>' + edit_btn + '&nbsp;&nbsp;&nbsp;' + del_btn + '</td></tr>');
         });
 
         $('#langTableHead').html(head_html);

+ 58 - 0
web/js/datachange.js

@@ -0,0 +1,58 @@
+(function($) {
+    $.extend({
+        // console.log($.DateChange.DateToUnix('2014-5-15 20:20:20'));
+        // console.log($.DateChange.UnixToDate(1325347200));
+        DateChange: {
+            /**
+             * 当前时间戳
+             * @return <int>        unix时间戳(秒)
+             * @author chanjunkai
+             */
+            CurTime: function(){
+                return Date.parse(new Date())/1000;
+            },
+            /**
+             * 日期 转换为 Unix时间戳
+             * @param <string> 2014-01-01 20:20:20  日期格式
+             * @return <int>        unix时间戳(秒)
+             */
+            DateToUnix: function(string) {
+                var f = string.split(' ', 2);
+                var d = (f[0] ? f[0] : '').split('-', 3);
+                var t = (f[1] ? f[1] : '').split(':', 3);
+                return (new Date(
+                    parseInt(d[0], 10) || null,
+                    (parseInt(d[1], 10) || 1) - 1,
+                    parseInt(d[2], 10) || null,
+                    parseInt(t[0], 10) || null,
+                    parseInt(t[1], 10) || null,
+                    parseInt(t[2], 10) || null
+                )).getTime() / 1000;
+            },
+            /**
+             * 时间戳转换日期
+             * @param <int> unixTime    待时间戳(秒)
+             * @param <bool> isFull    返回完整时间(Y-m-d 或者 Y-m-d H:i:s)
+             * @param <int>  timeZone   时区
+             */
+            UnixToDate: function(unixTime, isFull, timeZone) {
+                if (typeof (timeZone) == 'number')
+                {
+                    unixTime = parseInt(unixTime) + parseInt(timeZone) * 60 * 60;
+                }
+                var time = new Date(unixTime * 1000);
+                var ymdhis = "";
+                ymdhis += time.getUTCFullYear() + "-";
+                ymdhis += (time.getUTCMonth()+1) + "-";
+                ymdhis += time.getUTCDate();
+                if (isFull === true)
+                {
+                    ymdhis += " " + time.getUTCHours() + ":";
+                    ymdhis += time.getUTCMinutes() + ":";
+                    ymdhis += time.getUTCSeconds();
+                }
+                return ymdhis;
+            }
+        }
+    });
+})(jQuery);