Browse Source

解决游客不登录可看帖

Waller8 11 months ago
parent
commit
a37748327c

+ 52 - 48
src/components/Home.vue

@@ -80,7 +80,7 @@
                     </el-popover>
                   </div>
                   <div style="float: left;margin: 0px 10px" @click="collect(item)">
-                    <img v-if="!item.isFavorite" src="@/assets/like/favorite.png" style="height:12px">
+                    <img v-if="!item.isFavorited" src="@/assets/like/favorite.png" style="height:12px">
                     <img v-else src="@/assets/like/favorited.png" style="height:12px">
                     <el-button type="text" style="padding:0px;color:#666666" slot="reference">收藏</el-button>
                   </div>
@@ -347,7 +347,6 @@ export default {
       secCommList: [],
       isLike: false,     //是否点赞
       favoriteImg: require('../assets/like/favorite.png'),
-      appKey: '',
       radio: '1',
       postOwner: 'other',  //发帖子的人
       replyShareText: '',    //回复帖子的文本
@@ -396,8 +395,8 @@ export default {
      * 确认删除帖子
      */
     async confirmDelShare() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
-        appKey: localStorage.getItem('appKey'),
+      let res = await http.fetchPost(this.localHref + '/rest', {
+        appKey: this.appKey,     // localStorage.getItem('appKey'),
         v: 2,
         method: 'deleteShareBG',
         shareID: this.editItem.id
@@ -411,8 +410,8 @@ export default {
      * 获取初始页面数据
      */
     async getShareContent() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
-        appKey: localStorage.getItem('appKey'),
+      let res = await http.fetchPost(this.localHref + '/rest', {
+        appKey: this.appKey,     // localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
         opItem: 2,
@@ -435,13 +434,11 @@ export default {
           item.commentTotal = 0;   //一级评论总条数
           item.commentList = [];  //评论列表
           item.likeList = [];   //点赞列表
-          item.isFavorite = false
+          item.isFavorited = false
         })
         this.shareList = res.data.data
       } else {
-        this.$refs.head.getAppKey()
-        // window.location.reload()
-        // this.getAppKey()
+        // this.$refs.head.getAppKey()
       }
       console.log(res.data);
     },
@@ -450,7 +447,7 @@ export default {
      */
     async getSharePagintion() {
       let param = {
-        appKey: localStorage.getItem('appKey'),
+        appKey: this.appKey,   // localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
         opItem: 2,
@@ -461,7 +458,7 @@ export default {
         lastID: this.shareList[this.shareList.length - 1].id
       }
       console.log(param);
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref + '/rest', param)
       console.log(res.data);
       if (res.data.retCode == 1) {
         if (res.data.data.length == 0) {
@@ -489,8 +486,8 @@ export default {
         })
         // this.shareList = res.data.data
       } else {
-        console.log('dsagggag');
-        this.getAppKey()
+        // console.log('dsagggag');
+        // this.getAppKey()
       }
     },
     /**
@@ -525,8 +522,8 @@ export default {
       if (item.reply_count == item.commentList.length) {
         return
       } else {
-        let res = await http.fetchPost('https://https.ttq.so/rest', {
-          appKey: localStorage.getItem('appKey'),
+        let res = await http.fetchPost(this.localHref + '/rest', {
+          appKey: this.appKey,     // localStorage.getItem('appKey'),
           v: 2,
           method: "getShareReply",
           page: val || 1,
@@ -553,7 +550,7 @@ export default {
           item.commentTotal = res.data.total
           item.commentList = res.data.data
         } else {
-          this.getAppKey()
+          this.$refs.head.getAppKey()
         }
       }
 
@@ -562,7 +559,7 @@ export default {
      * 获取二级评论
      */
     async getMinorComment(val, comItem) {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref + '/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: "getShareReply",
@@ -584,7 +581,6 @@ export default {
         comItem.secCommList = res.data.data
         comItem.secCommTotal = res.data.total
       } else {
-        this.getAppKey()
       }
     },
     /**
@@ -594,8 +590,8 @@ export default {
       if (item.commend_count == item.likeList.length) {
         return
       } else {
-        let res = await http.fetchPost('https://https.ttq.so/rest', {
-          appKey: localStorage.getItem('appKey'),
+        let res = await http.fetchPost(this.localHref + '/rest', {
+          appKey: this.appKey,     // localStorage.getItem('appKey'),
           v: 2,
           method: "commendList",
           shareID: item.id,
@@ -610,7 +606,7 @@ export default {
           })
           item.likeList = res.data.data
         } else {
-          this.getAppKey()
+
         }
       }
     },
@@ -619,10 +615,10 @@ export default {
      */
     async like(item) {
       if (item.is_commend != 1) {
-        const res = await http.fetchPost('https://https.ttq.so/rest', {
+        const res = await http.fetchPost(this.localHref + '/rest', {
           method: 'setShareCommend',
           shareID: item.id,
-          appKey: localStorage.getItem('appKey'),
+          appKey: this.appKey,     // localStorage.getItem('appKey'),
           v: 2,
           status: 1,
         })
@@ -630,6 +626,8 @@ export default {
           item.is_commend = 1
           item.commend_count = parseInt(item.commend_count) + 1
           this.getLikeList(item)
+        } else {
+          this.$refs.head.getAppKey()
         }
       } else {
         this.getLikeList(item)
@@ -640,7 +638,7 @@ export default {
      */
     async replyShare(content, item) {
       let param = {
-        appKey: localStorage.getItem('appKey'),
+        appKey: this.appKey,     // localStorage.getItem('appKey'),
         method: 'shareReply',
         v: 2,
         pictures: '',
@@ -649,7 +647,7 @@ export default {
         shareID: item.id,
         replyID: '',
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref + '/rest', param)
       if (res.data.retCode == 1) {
         this.getPrimaryComment(1, item)
         this.$message('评论成功');
@@ -662,7 +660,7 @@ export default {
      */
     async replyFirstCom(content, item) {
       let param = {
-        appKey: localStorage.getItem('appKey'),
+        appKey: this.appKey,     // localStorage.getItem('appKey'),
         method: 'shareReply',
         v: 2,
         pictures: this.uploadImgList.join(','),
@@ -671,7 +669,7 @@ export default {
         replyID: item.id,
         receiveMemberID: item.member_id
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref + '/rest', param)
       if (res.data.retCode == 1) {
         this.getMinorComment(1, item)
       } else {
@@ -683,7 +681,7 @@ export default {
      */
     async replySecComment(content, item) {
       let param = {
-        appKey: localStorage.getItem('appKey'),
+        appKey: this.appKey,     // localStorage.getItem('appKey'),
         method: 'shareReply',
         v: 2,
         pictures: this.uploadImgList.join(','),
@@ -692,7 +690,7 @@ export default {
         replyID: item.id,
         receiveMemberID: item.member_id
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref + '/rest', param)
       if (res.data.retCode == 1) {
         this.$message({ message: '评论成功', type: 'success' });
       } else {
@@ -736,8 +734,8 @@ export default {
      * 举报
      */
     async informSuc() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
-        appKey: localStorage.getItem('appKey'),
+      let res = await http.fetchPost(this.localHref + '/rest', {
+        appKey: this.appKey,     // localStorage.getItem('appKey'),
         v: 2,
         method: 'feedback',
         type: this.radio,
@@ -752,10 +750,7 @@ export default {
           type: 'success'
         })
       } else {
-        this.$message({
-          message: res.data.msg,
-          type: 'error'
-        })
+        this.$refs.head.getAppKey()
       }
     },
     /**
@@ -763,36 +758,45 @@ export default {
      */
     async collect(item) {
       let param
-      if (item.isFavorite) {
+      if (item.isFavorited) {
         //取消收藏
         return
       } else {
         param = {
-          appKey: localStorage.getItem('appKey'),
+          appKey: this.appKey,     // localStorage.getItem('appKey'),
           v: 2,
           method: 'setFavorite',
           id: item.id,
           opType: 4,
           isFavorite: 1
         }
-        let res = await http.fetchPost('https://https.ttq.so/rest', param)
+        let res = await http.fetchPost(this.localHref + '/rest', param)
+        // console.log(res);
         if (res.data.retCode == 1) {
-          item.isFavorite = true
+          item.isFavorited = true
         } else {
-          this.$message({
-            message: res.data.msg,
-            type: 'error'
-          })
+          this.$refs.head.getAppKey()
         }
       }
     },
     /**获取分享二维码 */
     async getQR(item) {
-      let res = await http.fetchGet('https://https.ttq.so/web/Init/shareLink.html?id=' + item.id)
-      console.log(res);
-      if (res.data.retCode == 1) {
-        this.qrSrc = res.data.data[0].qrcode
+      if (this.appKey != '45dd2c1249bf047037ed4af0e78730') {
+        let res = await http.fetchGet(this.localHref + '/web/Init/shareLink.html?id=' + item.id)
+        // console.log(res);
+        if (res.data.retCode == 1) {
+          this.qrSrc = res.data.data[0].qrcode
+        }
+      }else{
+        this.$refs.head.getAppKey()
       }
+      // let res = await http.fetchGet(this.localHref + '/web/Init/shareLink.html?id=' + item.id)
+      // // console.log(res);
+      // if (res.data.retCode == 1) {
+      //   this.qrSrc = res.data.data[0].qrcode
+      // } else {
+      //   this.$refs.head.getAppKey()
+      // }
     },
     jumpReply(content, item) {
       let idItem

+ 4 - 4
src/components/common/Aside.vue

@@ -85,9 +85,9 @@ export default {
 * 获取菜单列表
 */
     async getMenuList() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         method: 'getShareTag',
-        appKey: localStorage.getItem('appKey') || "45dd2c1249bf047037ed4af0e78730",
+        appKey: this.appKey,     // localStorage.getItem('appKey') || "45dd2c1249bf047037ed4af0e78730",
         v: 2
       })
       console.log(res.data);
@@ -106,8 +106,8 @@ export default {
       this.shareList = []
       this.tagParam.parentId = secTagItem.parent_id
       this.tagParam.cateId = secTagItem.cate_id
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
-        appKey: localStorage.getItem('appKey') || "45dd2c1249bf047037ed4af0e78730",
+      let res = await http.fetchPost(this.localHref+'/rest', {
+        appKey: this.appKey, // localStorage.getItem('appKey') || "45dd2c1249bf047037ed4af0e78730",
         v: 3.9,
         method: "getShareBG",
         opItem: 2,

+ 29 - 22
src/components/common/Head.vue

@@ -12,11 +12,11 @@
       </div>
       <!-- 顶部右边登录注册按钮 -->
       <div class="topBtn">
-        <div v-if="!localStorageAppKey">
+        <div v-if="localStorageAppKey == '45dd2c1249bf047037ed4af0e78730'">
           <el-button type="text" @click="loginDialog = true">登录</el-button>
         </div>
         <!-- 登陆后显示头像信息 -->
-        <div v-if="localStorageAppKey" style="position: relative;">
+        <div v-if="localStorageAppKey != '45dd2c1249bf047037ed4af0e78730'" style="position: relative;">
           <el-dropdown trigger="click" placement="bottom">
             <div style="height:45px">
               <img :src="userInfo.avatar" style="height:40px;margin-top:9px;border-radius: 50%;" @click="tipVisible = !tipVisible">
@@ -131,7 +131,7 @@ import http from '@/http.js'
 export default {
   data() {
     return {
-      localStorageAppKey: localStorage.getItem('appKey'),
+      localStorageAppKey: this.appKey,
       loginDialog: false,
       tipVisible: false,
       username: '',
@@ -140,12 +140,12 @@ export default {
       loginType: 'inputLogin',
       loginWay: 'pwd',
       msgCount: 0,
-      userInfo:{}
+      userInfo: {}
     };
   },
   created() {
     this.getMsgCount()
-    this.getAppKey()
+    // this.getAppKey()
   },
   mounted() {
 
@@ -155,11 +155,12 @@ export default {
 * 获取appKey
 */
     async getAppKey() {
-      let res = await http.fetchGet('https://https.ttq.so/web/Init/getAppKey.html')
+      let res = await http.fetchGet(this.localHref + '/web/Init/getAppKey.html')
       if (res.data.retCode === 1) {
+        this.appKey = res.data.app_key
         localStorage.setItem('appKey', res.data.app_key)
         this.userInfo = res.data.member_info
-        return 
+        return
       } else {
         //拿不到appKey重新去登录
         this.loginDialog = true
@@ -169,11 +170,12 @@ export default {
      * 登录
      */
     login() {
-      http.fetchPost("https://https.ttq.so/web/Init/login.html", { account: this.username, pwd: this.password })
+      http.fetchPost(this.localHref + "/web/Init/login.html", { account: this.username, pwd: this.password })
         .then(res => {
           console.log(res.data.app_key)
           if (res.data.retCode == 1) {
             //登录成功,保存appkey
+            this.appKey = res.data.app_key
             localStorage.setItem('appKey', res.data.app_key)
             localStorage.setItem('userId', res.data.member_id)
             this.loginDialog = false
@@ -191,6 +193,16 @@ export default {
     * 发帖子,跳转页面
     */
     jumpSend() {
+      if (this.appKey == localStorage.getItem('appKey')) {
+        return this.$router.push({
+          name: 'send',
+          params: {
+            list: this.shareList,
+          }
+        })
+      }else{
+        this.getAppKey()
+      }
       // let routeUrl = this.$router.resolve({
       //   name: 'send',
       //   params: {
@@ -198,12 +210,7 @@ export default {
       //   }
       // })
       // window.open(routeUrl.href, '_blank');
-      return this.$router.push({
-        name: 'send',
-        params: {
-          list: this.shareList,
-        }
-      })
+
     },
     /**
     * 跳转到消息页面
@@ -216,8 +223,7 @@ export default {
       //     list: this.shareList,
       //   }
       // })
-
-       let routeUrl = this.$router.resolve({
+      let routeUrl = this.$router.resolve({
         name: 'user',
         params: {
           // userInfo: this.userInfo,
@@ -240,16 +246,17 @@ export default {
         this.loginType = 'inputLogin'
       }
     },
+    //获取消息个数
     async getMsgCount() {
-      const appKey = localStorage.getItem('appKey')
-      let res = await http.fetchGet('https://https.ttq.so/web/Init/getNotice.html?appKey=' + appKey)
+      const appKey = this.appKey       // localStorage.getItem('appKey')
+      let res = await http.fetchGet(this.localHref + '/web/Init/getNotice.html?appKey=' + appKey)
       console.log(res.data);
-      if(res.data.retCode ==1){
+      if (res.data.retCode == 1) {
         this.msgCount = res.data.count
-      }else{
-        this.getAppKey()
+      } else {
+        // this.getAppKey()
       }
-      
+
     }
   }
 };

+ 5 - 5
src/components/page/Reply.vue

@@ -256,7 +256,7 @@ export default {
         replyID: idItem.replyID ,
       }
       console.log(param);
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref+'/rest', param)
       if (res.data.retCode == 1) {
         this.$router.push('/')
         // this.getPrimaryComment(1, item)
@@ -332,7 +332,7 @@ export default {
         pageSize: 10,
         type: this.atType || 0
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', params)
+      let res = await http.fetchPost(this.localHref+'/rest', params)
       if (res.data.retCode == 1) {
         if (this.atType == 0) {
           res.data.data.map(atItem => {
@@ -401,7 +401,7 @@ export default {
     },
     /**获取话题分类标签 */
     async getTopicTag() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: 'topicCategory',
@@ -428,7 +428,7 @@ export default {
     },
     /**获取话题列表*/
     async getTopicList(id, page) {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: 'getTopicList',
@@ -564,7 +564,7 @@ export default {
      * 输入框搜索
      */
     async getLinkList(type, page) {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: 'searchII',

+ 9 - 9
src/components/page/UserCenter.vue

@@ -263,7 +263,7 @@ export default {
      * 获取用户信息
      */
     async getUserInfo() {
-      let res = await http.fetchGet('https://https.ttq.so/web/Init/getAppKey.html')
+      let res = await http.fetchGet(this.localHref+'/web/Init/getAppKey.html')
       console.log(res.data);
       if (res.data.retCode == 1) {
         res.data.member_info.insulin_plan = insulinMapping(res.data.member_info.insulin_plan)
@@ -319,7 +319,7 @@ export default {
      */
     async atMyself() {
       this.isactive = 1
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
@@ -347,7 +347,7 @@ export default {
     async commentMyself() {
       this.isactive = 2
       this.aboutMyList = []
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
@@ -385,7 +385,7 @@ export default {
     async likeMyself() {
       this.isactive = 3
       this.aboutMyList = []
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
@@ -410,7 +410,7 @@ export default {
      * @分页
      */
     async atPagin() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
@@ -437,7 +437,7 @@ export default {
     * 评论分页
     */
     async commentPagin() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
@@ -464,7 +464,7 @@ export default {
      * 点赞分页
      */
     async likePagin() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 3.9,
         method: "getShareBG",
@@ -511,7 +511,7 @@ export default {
         replyID: item.id,
         receiveMemberID: item.member_id
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref+'/rest', param)
       if (res.data.retCode == 1) {
         this.$message({ message: res.data.msg, type: 'success' });
       } else {
@@ -545,7 +545,7 @@ export default {
           receiveMemberID: item.member_id
         }
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', param)
+      let res = await http.fetchPost(this.localHref+'/rest', param)
       if (res.data.retCode == 1) {
         this.$message({ message: res.data.msg, type: 'success' });
       } else {

+ 5 - 5
src/components/page/send.vue

@@ -282,7 +282,7 @@ export default {
         shareIcon: this.isQuest ? 1 : 0,
         codeID: '',
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', params)
+      let res = await http.fetchPost(this.localHref+'/rest', params)
       if (res.data.retCode == 1) {
         this.$message('发帖成功');
         setTimeout(() => {
@@ -357,7 +357,7 @@ export default {
         pageSize: 10,
         type: this.type || 0
       }
-      let res = await http.fetchPost('https://https.ttq.so/rest', params)
+      let res = await http.fetchPost(this.localHref+'/rest', params)
       if (res.data.retCode == 1) {
         res.data.data.map(atItem => {
           atItem.age = convertAge(parseInt(atItem.birthday))   //获取年龄
@@ -404,7 +404,7 @@ export default {
     },
     /**获取话题分类标签 */
     async getTopicTag() {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: 'topicCategory',
@@ -431,7 +431,7 @@ export default {
     },
     /**获取话题列表*/
     async getTopicList(id, page) {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: 'getTopicList',
@@ -568,7 +568,7 @@ export default {
      * 输入框搜索
      */
     async getLinkList(type, page) {
-      let res = await http.fetchPost('https://https.ttq.so/rest', {
+      let res = await http.fetchPost(this.localHref+'/rest', {
         appKey: localStorage.getItem('appKey'),
         v: 2,
         method: 'searchII',

+ 3 - 1
src/main.js

@@ -8,7 +8,9 @@ import router from './router'
 Vue.use(ElementUI);
 
 Vue.config.productionTip = false
-
+Vue.prototype.appKey = '45dd2c1249bf047037ed4af0e78730';
+// Vue.prototype.localUrl = 'https://https.ttq.so'    //本地编程使用
+Vue.prototype.localHref=location.protocol+'//'+document.domain;   //线上使用
 /* eslint-disable no-new */
 new Vue({
   el: '#app',