Przeglądaj źródła

新增项目置顶功能

star7th 8 lat temu
rodzic
commit
8dbac74624

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+Application/Runtime/
+server/Application/Runtime/
+

+ 19 - 0
Application/Home/Controller/ItemController.class.php

@@ -6,6 +6,25 @@ class ItemController extends BaseController {
     public function index(){
         $login_user = $this->checkLogin();        
         $items  = D("Item")->where("uid = '$login_user[uid]' or item_id in ( select item_id from ".C('DB_PREFIX')."item_member where uid = '$login_user[uid]' ) ")->select();
+        //读取需要置顶的项目
+        $top_items = D("ItemTop")->where("uid = '$login_user[uid]'")->select();
+        if ($top_items) {
+            $top_item_ids = array() ;
+            foreach ($top_items as $key => $value) {
+                $top_item_ids[] = $value['item_id'];
+            }
+            foreach ($items as $key => $value) {
+                $items[$key]['top'] = 0 ;
+                if (in_array($value['item_id'], $top_item_ids) ) {
+                    $items[$key]['top'] = 1 ;
+                    $tmp = $items[$key] ;
+                    unset($items[$key]);
+                    array_unshift($items,$tmp) ;
+                }
+            }
+
+            $items = array_values($items);
+        }
         
         $share_url = get_domain().__APP__.'/uid/'.$login_user['uid'];
 

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

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

+ 13 - 7
Application/Home/View/Item/index.html

@@ -1,5 +1,5 @@
 <include file="Common/header" />
-<link rel="stylesheet" href="__PUBLIC__/css/item/index.css?v=1.2" />
+<link rel="stylesheet" href="__PUBLIC__/css/item/index.css?v=1.234" />
     <div class="container-narrow">
 
       <div class="masthead">
@@ -30,14 +30,23 @@
 
         <foreach name="items" item="item">
           <li class="span3 text-center">
-            <a class="thumbnail" href="{:U('Home/Item/show',array('item_id'=>$item['item_id']))}" title="{$item.item_description}">
+            <a class="thumbnail item-thumbnail" href="{:U('Home/Item/show',array('item_id'=>$item['item_id']))}" title="{$item.item_description}">
+              <span class="item-setting" data-src="{:U('/home/item/setting',array('item_id'=>$item[item_id]))}"  title="项目设置">
+                <i class="icon-wrench" ></i>
+              </span>
+
+              <if condition="$item['top']">
+                  <span class="item-top" data-action="cancel" data-item_id="{$item.item_id}" title="取消置顶"><i class="icon-arrow-down" ></i></span>
+              <else />
+                  <span class="item-top" data-action="top" data-item_id="{$item.item_id}" title="置顶项目"><i class="icon-arrow-up"  ></i></span>
+              </if>
               <p class="my-item">{$item.item_name}</p>
             </a>
           </li>     
         </foreach>
 
         <li class="span3 text-center">
-          <a class="thumbnail" href="{:U('Home/Item/add')}" title="{$Think.Lang.add_an_item}添加一个新项目">
+          <a class="thumbnail " href="{:U('Home/Item/add')}" title="{$Think.Lang.add_an_item}添加一个新项目">
             <p class="my-item ">{$Think.Lang.new_item}&nbsp;<i class="icon-plus"></i></p>
           </a>
         </li>
@@ -61,7 +70,4 @@
 
 
  <include file="Common/footer" />
- <script type="text/javascript">
-
-
- </script>
+ <script src="__PUBLIC__/js/item/index.js?v=1"></script>

+ 14 - 0
Public/css/item/index.css

@@ -34,4 +34,18 @@ margin-top: 60px;
 
 .masthead h3{
   color: #333;
+}
+
+.item-setting{
+  float:right;
+  margin-right:15px;
+  margin-top:5px;
+  display: none;
+}
+
+.item-top{
+  float:right;
+  margin-right:5px;
+  margin-top:5px;
+  display: none;
 }

+ 53 - 0
Public/js/item/index.js

@@ -0,0 +1,53 @@
+
+//当鼠标放在项目上时将浮现设置和置顶图标
+$(".item-thumbnail").mouseover(function(){
+  $(this).find(".item-setting").show();
+  $(this).find(".item-top").show();
+  $(this).find(".item-down").show();
+});
+
+//当鼠标离开项目上时将隐藏设置和置顶图标
+$(".item-thumbnail").mouseout(function(){
+  $(this).find(".item-setting").hide();
+  $(this).find(".item-top").hide();
+  $(this).find(".item-down").hide();
+});
+
+//点击项目设置图标时
+$(".item-setting").click(function(){
+  var url = $(this).data("src");
+  window.location.href = url ;
+  return false;
+});
+
+//点击项目置顶图标时
+$(".item-top").click(function(){
+
+  var action = $(this).data("action");
+  var item_id = $(this).data("item_id");
+  $.post(
+    DocConfig.server+"/api/item/top",
+    {"action":action,"item_id":item_id},
+    function(data){
+      window.location.reload();
+    },
+    "json"
+    );
+  return false;
+});
+
+//点击取消置顶图标时
+$(".item-down").click(function(){
+
+  var action = 'cancel';
+  var item_id = $(this).data("item_id");
+  $.post(
+    DocConfig.server+"/api/item/top",
+    {"action":action,"item_id":item_id},
+    function(data){
+      window.location.reload();
+    },
+    "json"
+    );
+  return false;
+});

BIN
Sqlite/showdoc.db.php


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

@@ -270,7 +270,26 @@ class ItemController extends BaseController {
         }else{
             $this->sendError(10101);
         }
+    }
 
+    //置顶项目
+    public function top(){
+        $login_user = $this->checkLogin();
 
+        $item_id = I("item_id/d");
+        $action = I("action");
+
+        if ($action == 'top') {
+            $ret = D("ItemTop")->add(array("item_id"=>$item_id,"uid"=>$login_user['uid'],"addtime"=>time()));
+        }
+        elseif ($action == 'cancel') {
+            $ret = D("ItemTop")->where(" uid = '$login_user[uid]' and item_id = '$item_id' ")->delete();
+        }
+        if ($ret) {
+            $this->sendResult(array());
+        }else{
+            $this->sendError(10101);
+        }
     }
+    
 }