Browse Source

Item list drag sort
项目列表拖动排序

star7th 6 years ago
parent
commit
db242440d3

BIN
Sqlite/showdoc.db.php


+ 47 - 0
server/Application/Api/Controller/ItemController.class.php

@@ -209,11 +209,41 @@ class ItemController extends BaseController {
             }
         }
 
+        //读取项目顺序
+        $item_sort = D("ItemSort")->where("uid = '$login_user[uid]'")->find();
+        if ($item_sort) {
+            $item_sort_data = json_decode(htmlspecialchars_decode($item_sort['item_sort_data']) , true) ;
+            //var_dump($item_sort_data);
+            foreach ($items as $key => &$value) {
+                //如果item_id有设置了序号,则赋值序号。没有则默认填上0
+                if ($item_sort_data[$value['item_id']]) {
+                    $value['s_number'] = $item_sort_data[$value['item_id']] ;
+                }else{
+                    $value['s_number'] = 0 ;
+                }
+            }
+            $items = $this->_sort_by_key($items , 's_number' ) ;
+        }
+
+
         $items = $items ? array_values($items) : array();
         $this->sendResult($items);
 
     }
 
+    private function _sort_by_key($array , $mykey){
+        for ($i=0; $i < count($array) ; $i++) { 
+            for ($j = $i + 1 ; $j < count($array) ; $j++) {
+                if ($array[$i][$mykey] > $array[$j][$mykey] ) {
+                    $tmp = $array[$i] ;
+                    $array[$i] = $array[$j] ;
+                    $array[$j] = $tmp ;
+                }
+            }
+        }
+        return $array;
+    }
+
     //项目详情
     public function detail(){
         $login_user = $this->checkLogin();
@@ -549,5 +579,22 @@ class ItemController extends BaseController {
         
     }
 
+    //保存项目排序
+    public function sort(){
+        $login_user = $this->checkLogin();
+
+        $data = I("data");
+
+        D("ItemSort")->where(" uid = '$login_user[uid]' ")->delete();
+
+        $ret = D("ItemSort")->add(array("item_sort_data"=>$data,"uid"=>$login_user['uid'],"addtime"=>time()));
+
+        if ($ret) {
+            $this->sendResult(array());
+        }else{
+            $this->sendError(10101);
+        }
+    }
+
 
 }

+ 8 - 0
server/Application/Home/Controller/UpdateController.class.php

@@ -200,6 +200,14 @@ class UpdateController extends BaseController {
         )";
         D("User")->execute($sql);
 
+        //创建item_sort表
+        $sql = "CREATE TABLE IF NOT EXISTS `item_sort` (
+        `id`  INTEGER PRIMARY KEY ,
+        `uid` int(10) NOT NULL DEFAULT '0',
+        `item_sort_data` text NOT NULL DEFAULT '',
+        `addtime` int(11) NOT NULL DEFAULT '0'
+        )";
+        D("UserToken")->execute($sql);
 
 
         echo "OK!\n";

+ 1 - 1
web/index.html

@@ -4,4 +4,4 @@
       "server": window.location.protocol +'//'+ window.location.host + window.location.pathname+ '../server/index.php?s=',
       //"lang" :'en'
       "lang" :'zh-cn'
-  }</script><link href=./static/css/app.7db107f1cbe6b7819bb55457fc29c220.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.83dfe798082afcfc8446.js></script><script type=text/javascript src=./static/js/vendor.ba24f6ccee070864d547.js></script><script type=text/javascript src=./static/js/app.0cdda727c468943488e5.js></script></body></html>
+  }</script><link href=./static/css/app.be99e7bccbff75268e3be3f53334f7f9.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.f34f9c3a63e1e3c7fc52.js></script><script type=text/javascript src=./static/js/vendor.3015ff35497f22398e85.js></script><script type=text/javascript src=./static/js/app.57bb06072a3102577d7e.js></script></body></html>

File diff suppressed because it is too large
+ 0 - 0
web/static/css/app.be99e7bccbff75268e3be3f53334f7f9.css


File diff suppressed because it is too large
+ 0 - 0
web/static/js/app.0cdda727c468943488e5.js


File diff suppressed because it is too large
+ 0 - 0
web/static/js/app.57bb06072a3102577d7e.js


+ 1 - 1
web/static/js/manifest.83dfe798082afcfc8446.js → web/static/js/manifest.f34f9c3a63e1e3c7fc52.js

@@ -1 +1 @@
-!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,a){for(var i,u,f,s=0,l=[];s<t.length;s++)u=t[s],o[u]&&l.push(o[u][0]),o[u]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,a);l.length;)l.shift()();if(a)for(s=0;s<a.length;s++)f=n(n.s=a[s]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(u);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var a=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+"static/js/"+e+"."+{0:"ba24f6ccee070864d547",1:"0cdda727c468943488e5"}[e]+".js";var u=setTimeout(r,12e4);return i.onerror=i.onload=r,a.appendChild(i),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="./",n.oe=function(e){throw console.error(e),e}}([]);
+!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,a){for(var i,u,f,s=0,l=[];s<t.length;s++)u=t[s],o[u]&&l.push(o[u][0]),o[u]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,a);l.length;)l.shift()();if(a)for(s=0;s<a.length;s++)f=n(n.s=a[s]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(u);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var a=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+"static/js/"+e+"."+{0:"3015ff35497f22398e85",1:"57bb06072a3102577d7e"}[e]+".js";var u=setTimeout(r,12e4);return i.onerror=i.onload=r,a.appendChild(i),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="./",n.oe=function(e){throw console.error(e),e}}([]);

File diff suppressed because it is too large
+ 0 - 0
web/static/js/vendor.3015ff35497f22398e85.js


File diff suppressed because it is too large
+ 0 - 0
web/static/js/vendor.ba24f6ccee070864d547.js


+ 43 - 20
web_src/package-lock.json

@@ -206,9 +206,9 @@
       "dev": true
     },
     "argparse": {
-      "version": "1.0.9",
-      "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.9.tgz",
-      "integrity": "sha1-c9g7wmP4bpf4zE9rrhsOkKfSLIY=",
+      "version": "1.0.10",
+      "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
+      "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
       "dev": true,
       "requires": {
         "sprintf-js": "~1.0.2"
@@ -404,6 +404,11 @@
         "postcss-value-parser": "^3.2.3"
       }
     },
+    "awe-dnd": {
+      "version": "0.3.4",
+      "resolved": "https://registry.npmjs.org/awe-dnd/-/awe-dnd-0.3.4.tgz",
+      "integrity": "sha512-ZvwlnaUn1RFwYXQUxLZKtyKH2R+z+8an1B0cTVfDA6UP7i2JxDnxXNwecR56qhwQha39XDQDpgmqz9kQghhksQ=="
+    },
     "aws-sign2": {
       "version": "0.7.0",
       "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
@@ -4224,9 +4229,9 @@
       }
     },
     "esprima": {
-      "version": "2.7.3",
-      "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz",
-      "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=",
+      "version": "4.0.1",
+      "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
+      "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==",
       "dev": true
     },
     "esquery": {
@@ -6540,9 +6545,9 @@
       }
     },
     "istanbul-lib-instrument": {
-      "version": "1.10.1",
-      "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-1.10.1.tgz",
-      "integrity": "sha512-1dYuzkOCbuR5GRJqySuZdsmsNKPL3PTuyPevQfoCXJePT9C8y1ga75neU+Tuy9+yS3G/dgx8wgOmp2KLpgdoeQ==",
+      "version": "1.10.2",
+      "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-1.10.2.tgz",
+      "integrity": "sha512-aWHxfxDqvh/ZlxR8BBaEPVSWDPUkGD63VjGQn3jcw8jCp7sHEMKcrj4xfJn/ABzdMEHiQNyvDQhqm5o8+SQg7A==",
       "dev": true,
       "requires": {
         "babel-generator": "^6.18.0",
@@ -6550,14 +6555,14 @@
         "babel-traverse": "^6.18.0",
         "babel-types": "^6.18.0",
         "babylon": "^6.18.0",
-        "istanbul-lib-coverage": "^1.2.0",
+        "istanbul-lib-coverage": "^1.2.1",
         "semver": "^5.3.0"
       },
       "dependencies": {
         "istanbul-lib-coverage": {
-          "version": "1.2.0",
-          "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-1.2.0.tgz",
-          "integrity": "sha512-GvgM/uXRwm+gLlvkWHTjDAvwynZkL9ns15calTrmhGgowlwJBbWMYzWbKqE2DT6JDP1AFXKa+Zi0EkqNCUqY0A==",
+          "version": "1.2.1",
+          "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-1.2.1.tgz",
+          "integrity": "sha512-PzITeunAgyGbtY1ibVIUiV679EFChHjoMNRibEIobvmrCRaIgwLxNucOSimtNWUhEib/oO7QY2imD75JVgCJWQ==",
           "dev": true
         }
       }
@@ -7019,13 +7024,13 @@
       "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls="
     },
     "js-yaml": {
-      "version": "3.7.0",
-      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.7.0.tgz",
-      "integrity": "sha1-XJZ93YN6m/3KXy3oQlOr6KHAO4A=",
+      "version": "3.13.1",
+      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
+      "integrity": "sha512-YfbcO7jXDdyj0DGxYVSlSeQNHbD7XPWvrVWeVUujrQEoZzWJIRrCPoyk6kL6IAjAG2IolMK4T0hNUe0HOUs5Jw==",
       "dev": true,
       "requires": {
         "argparse": "^1.0.7",
-        "esprima": "^2.6.0"
+        "esprima": "^4.0.0"
       }
     },
     "jsbn": {
@@ -7292,9 +7297,9 @@
       }
     },
     "lodash": {
-      "version": "4.17.10",
-      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
-      "integrity": "sha512-UejweD1pDoXu+AD825lWwp4ZGtSwgnpZxb3JDViD7StjQz+Nb/6l093lx4OQ0foGWNRoc19mWy7BzL+UAK2iVg=="
+      "version": "4.17.11",
+      "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
+      "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
     },
     "lodash._arraycopy": {
       "version": "3.0.0",
@@ -12768,6 +12773,24 @@
         "mkdirp": "~0.5.1",
         "sax": "~1.2.1",
         "whet.extend": "~0.9.9"
+      },
+      "dependencies": {
+        "esprima": {
+          "version": "2.7.3",
+          "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz",
+          "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=",
+          "dev": true
+        },
+        "js-yaml": {
+          "version": "3.7.0",
+          "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.7.0.tgz",
+          "integrity": "sha1-XJZ93YN6m/3KXy3oQlOr6KHAO4A=",
+          "dev": true,
+          "requires": {
+            "argparse": "^1.0.7",
+            "esprima": "^2.6.0"
+          }
+        }
       }
     },
     "symbol-tree": {

+ 1 - 0
web_src/package.json

@@ -14,6 +14,7 @@
     "build": "node build/build.js"
   },
   "dependencies": {
+    "awe-dnd": "^0.3.4",
     "axios": "^0.17.1",
     "babel-polyfill": "^6.26.0",
     "babel-preset-es2015": "^6.24.1",

+ 45 - 4
web_src/src/components/item/Index.vue

@@ -35,7 +35,9 @@
         <div class="container-thumbnails">
           <ul class="thumbnails" id="item-list" v-if="itemList">
 
-              <li class=" text-center"  v-for="item in itemList">
+              <li class=" text-center"  v-for="item in itemList"
+                 v-dragging="{ item: item, list: itemList, group: 'item' }"
+              >
                 <router-link class="thumbnail item-thumbnail"  :to="'/' +  (item.item_domain ? item.item_domain:item.item_id )" title="">
                   <span class="item-setting " @click.prevent="click_item_setting(item.item_id)" :title="$t('item_setting')" >
                     <i class="el-icon-setting"></i>
@@ -215,8 +217,8 @@ export default {
           //当鼠标放在项目上时将浮现设置和置顶图标
           $(".item-thumbnail").mouseover(function(){
             $(this).find(".item-setting").show();
-            $(this).find(".item-top").show();
-            $(this).find(".item-down").show();
+            //$(this).find(".item-top").show();
+            //$(this).find(".item-down").show();
           });
 
           //当鼠标离开项目上时将隐藏设置和置顶图标
@@ -288,11 +290,50 @@ export default {
         data();
       };
     },
+
+
+    sort_item(data){
+      var that = this ;
+      var url = DocConfig.server+'/api/item/sort';
+      var params = new URLSearchParams();
+      params.append('data', JSON.stringify(data));
+      that.axios.post(url, params)
+        .then(function (response) {
+          if (response.data.error_code === 0 ) {
+            //that.get_item_list();
+            //window.location.reload();
+
+          }else{
+            that.$alert(response.data.error_message,'',{
+              callback:function(){
+                window.location.reload();
+              }
+            });
+            
+          }
+          
+        });
+    },
+    dragging(){
+      this.$dragging.$off('dragged',true);
+      this.$dragging.$on('dragged', ({ value }) => {
+        //console.log(value);
+        let data = {};
+        for (var i = 0; i < value['list'].length; i++) {
+          let key = value['list'][i]['item_id'] ;
+          data[key] = i + 1  ;
+        };
+        this.sort_item(data);
+      })
+    }
+
   },
   mounted () {
     this.get_item_list();
     this.user_info();
-    
+    this.dragging();
+
+
   },
   beforeDestroy(){
     this.$message.closeAll();

+ 3 - 0
web_src/src/main.js

@@ -17,6 +17,7 @@ import myEnLocale from '../static/lang/en'
 import 'url-search-params-polyfill'
 import "babel-polyfill";
 import VueClipboard from 'vue-clipboard2';
+import VueDND from 'awe-dnd'
 
 
 Vue.use(util);
@@ -26,6 +27,8 @@ Vue.component('Footer', Footer);
 Vue.use(ElementUI)
 Vue.use(VueI18n)
 Vue.use(VueClipboard)
+Vue.use(VueDND)
+
 
 //多语言相关
 var allZhLocale = Object.assign(zhLocale,myZhLocale);

Some files were not shown because too many files changed in this diff