Browse Source

Create single-page sharing links
创建单页分享链接

star7th 6 years ago
parent
commit
8082c7bcc8

BIN
Sqlite/showdoc.db.php


+ 68 - 0
server/Application/Api/Controller/PageController.class.php

@@ -23,6 +23,14 @@ class PageController extends BaseController {
            $page['addtime'] = date("Y-m-d H:i:s",$page['addtime']);
            //判断是否包含附件信息
            $page['attachment_count'] = D("UploadFile")->where("page_id = '$page_id' ")->count();
+
+           $singlePage = M("SinglePage")->where(" page_id = '%d' ",array($page_id))->limit(1)->find();
+           if ($singlePage) {
+                $page['unique_key'] =  $singlePage['unique_key'] ;
+           }else{
+                $page['unique_key'] = '' ;
+           }
+
         }
         $this->sendResult($page);
     }
@@ -338,4 +346,64 @@ class PageController extends BaseController {
         }
     }
 
+
+    //创建单页
+    public function createSinglePage(){
+        $page_id = I("page_id/d");
+        $isCreateSiglePage = I("isCreateSiglePage");
+        $page = M("Page")->where(" page_id = '$page_id' ")->find();
+        if (!$page || $page['is_del'] == 1) {
+            sleep(1);
+            $this->sendError(10101);
+            return false;
+        }
+        $login_user = $this->checkLogin(false);
+        if (!$this->checkItemPermn($login_user['uid'] , $page['item_id'])) {
+            $this->sendError(10103);
+            return;
+        }
+        D("SinglePage")->where(" page_id = '$page_id' ")->delete();
+        $unique_key = md5(time().rand()."gbgdhbdgtfgfK3@bv45342regdhbdgtfgftghsdg");
+        $add = array(
+            "unique_key" => $unique_key ,
+            "page_id" => $page_id ,
+            );
+        if ($isCreateSiglePage == 'true') { //这里的布尔值被转成字符串了
+           D("SinglePage")->add($add);
+           $this->sendResult($add);
+        }else{
+            $this->sendResult(array());
+        }
+        
+    }
+
+    //页面详情
+    public function infoByKey(){
+        $unique_key = I("unique_key");
+        if (!$unique_key) {
+            return false;
+        }
+        $singlePage = M("SinglePage")->where(" unique_key = '%s' ",array($unique_key))->find();
+        $page_id = $singlePage['page_id'];
+
+        $page = M("Page")->where(" page_id = '$page_id' ")->find();
+        if (!$page || $page['is_del'] == 1) {
+            sleep(1);
+            $this->sendError(10101);
+            return false;
+        }
+        $login_user = $this->checkLogin(false);
+        $page = $page ? $page : array();
+        if ($page) {
+           unset($page['item_id']);
+           unset($page['cat_id']);
+           $page['addtime'] = date("Y-m-d H:i:s",$page['addtime']);
+           //判断是否包含附件信息
+           $page['attachment_count'] = D("UploadFile")->where("page_id = '$page_id' ")->count();
+
+        }
+        $this->sendResult($page);
+    }
+
+
 }

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

@@ -209,6 +209,13 @@ class UpdateController extends BaseController {
         )";
         D("UserToken")->execute($sql);
 
+        //创建single_page表
+        $sql = "CREATE TABLE IF NOT EXISTS `single_page` (
+        `id`  INTEGER PRIMARY KEY ,
+        `unique_key` CHAR(200) NOT NULL DEFAULT '',
+        `page_id` int(11) NOT NULL DEFAULT '0'
+        )";
+        D("UserToken")->execute($sql);
 
         echo "OK!\n";
     }

+ 45 - 12
web_src/src/components/item/show/show_regular_item/PageBar.vue

@@ -32,20 +32,22 @@
     :visible.sync="dialogVisible"
     width="600px"
     :modal="false"
-    class="text-center"
     >
     
     <p>{{$t('item_page_address')}} : <code >{{share_page_link}}</code>
     </p>
-    <p><a href="javascript:;" class="home-phone-butt" v-clipboard:copyhttplist="copyText1" v-clipboard:success="onCopy">{{$t('copy_link')}}</a></p>
-        <p style="border-bottom: 1px solid #eee;"><img  id="qr-page-link" style="width:114px;height:114px;" :src="qr_page_link"> </p>
-        
-      <p >{{$t('single_page_address')}} : <code id="share-single-link">{{share_single_link}}</code>
-      </p>
-        <p><a href="javascript:;" class="home-phone-butt" v-clipboard:copyhttplist="copyText2" v-clipboard:success="onCopy">{{$t('copy_link')}}</a></p>
-        <p style="border-bottom: 1px solid #eee;"><img  id="qr-single-link" style="width:114px;height:114px;" :src="qr_single_link"> </p>
-     <p><a href="https://www.showdoc.cc/page/63882" target="_blank">{{$t('page_diff_tips')}}</a></p><p>
-      </p>
+      <p v-if="false" style="border-bottom: 1px solid #eee;"><img  id="qr-page-link" style="width:114px;height:114px;" :src="qr_page_link"> </p>
+      
+      <div v-show="item_info.ItemPermn">
+        <el-checkbox v-model="isCreateSiglePage" @change="CreateSiglePage">{{$t('create_sigle_page')}}</el-checkbox>
+
+        <p v-if="isCreateSiglePage">{{$t('single_page_address')}} : <code >{{share_single_link}}</code> <p>
+
+        <p>
+          {{$t('create_sigle_page_tips')}}
+        </p>
+      </div>
+
 
 
     <span slot="footer" class="dialog-footer">
@@ -86,6 +88,7 @@
         share_single_link:"",
         copyText1:'',
         copyText2:'',
+        isCreateSiglePage:false
       }
     },
   components:{
@@ -100,9 +103,9 @@
     share_page(){
       var page_id = this.page_id > 0 ? this.page_id : 0 ;
       this.share_page_link = this.getRootPath()+"#/"+this.item_id +'?page_id='+page_id ;
-      this.share_single_link= this.getRootPath()+"#/page/"+page_id ;
+      //this.share_single_link= this.getRootPath()+"#/page/"+page_id ;
       this.qr_page_link = DocConfig.server +'/api/common/qrcode&size=3&url='+encodeURIComponent(this.share_page_link);
-      this.qr_single_link = DocConfig.server +'/api/common/qrcode&size=3&url='+encodeURIComponent(this.share_single_link);
+      //this.qr_single_link = DocConfig.server +'/api/common/qrcode&size=3&url='+encodeURIComponent(this.share_single_link);
       this.dialogVisible = true;
       this.copyText1 = this.item_info.item_name+' - '+this.page_info.page_title+"\r\n"+ this.share_page_link;
       this.copyText2 = this.page_info.page_title+"\r\n"+ this.share_single_link;
@@ -148,9 +151,39 @@
     onCopy(){
       this.$message(this.$t("copy_success"));
     },
+    CreateSiglePage(){
+        var page_id = this.page_id > 0 ? this.page_id : 0 ;
+        var that = this ;
+        var url = DocConfig.server+'/api/page/createSinglePage';
+        var params = new URLSearchParams();
+        params.append('page_id',  page_id);
+        params.append('isCreateSiglePage',  this.isCreateSiglePage);
+
+        that.axios.post(url, params)
+        .then(function (response) {
+          if (response.data.error_code === 0 ) {
+            var unique_key = response.data.data.unique_key ;
+            if (unique_key) {
+              that.share_single_link = that.getRootPath()+"#/p/"+unique_key ;
+            }else{
+              that.share_single_link = '';
+            }
+            
+
+          }else{
+            that.$alert(response.data.error_message);
+          }
+        });
+
+    }
+
   },
   mounted () {
     var that = this ;
+    if (this.page_info.unique_key) {
+      this.isCreateSiglePage = true ;
+      this.share_single_link = this.getRootPath()+"#/p/"+this.page_info.unique_key ;
+    };
     document.onkeydown=function(e){  //对整个页面文档监听 其键盘快捷键
       var keyNum=window.event ? e.keyCode :e.which;  //获取被按下的键值 
       if (keyNum == 69 && e.ctrlKey) {  //Ctrl +e 为编辑

+ 8 - 2
web_src/src/components/page/Index.vue

@@ -119,10 +119,16 @@ export default {
     get_page_content(){
         var that = this ;
         var page_id = that.$route.params.page_id ;
-        var url = DocConfig.server+'/api/page/info';
-
+        var unique_key = that.$route.params.unique_key ;
+        if (unique_key) {
+          var url = DocConfig.server+'/api/page/infoByKey';
+        }else{
+          var url = DocConfig.server+'/api/page/info';
+        }
+        
         var params = new URLSearchParams();
         params.append('page_id', page_id );
+        params.append('unique_key', unique_key );
         that.axios.post(url, params)
           .then(function (response) {
             if (response.data.error_code === 0 ) {

+ 5 - 0
web_src/src/router/index.js

@@ -91,6 +91,11 @@ export default new Router({
       name: 'PageIndex',
       component: PageIndex
     },
+    {
+      path: '/p/:unique_key',
+      name: 'PageIndex',
+      component: PageIndex
+    },
     {
       path: '/page/edit/:item_id/:page_id',
       name: 'PageEdit',

+ 3 - 1
web_src/static/lang/en.js

@@ -283,5 +283,7 @@ exports.default = {
     "private_item":"private item",
     "private_item_passwrod":"Please set a password for private item",
 
-       
+    "create_sigle_page":"I want to create a single page address",
+    "create_sigle_page_tips":"When you just want to share a page and not the whole project, you can choose to share a single page address. After sharing, your friends will only see a single page, can not browse the catalog menu, and can not switch to other pages to view.",
+
 };

+ 5 - 0
web_src/static/lang/zh-CN.js

@@ -289,4 +289,9 @@ exports.default = {
     "Open_item":"公开项目",
     "private_item":"私密项目",
     "private_item_passwrod":"私密项目请设置访问密码",
+
+    "create_sigle_page":"我要创建单页面地址",
+    "create_sigle_page_tips":"当仅仅想分享某个页面、而不想分享整个项目的时候,你可以选择分享单页面地址。分享出去后,你的好友将仅仅只看到单个页面,无法浏览目录菜单,也无法切换到其他页面查看。",
+
+
 };