index.vue 17.3 KB
Newer Older
1
<template>
李嘉林 committed
2
  <div class="article_container" v-if="article">
柳士祥 committed
3
    
4 5 6
    <div class="richText">
      <div class="title" v-if="article.title">{{article.title}}</div>
      <div class="title_info">
柳士祥 committed
7 8
        <div class="title_user" v-if="article.author">{{article.author}}</div>
        <div class="title_time" v-if="article.createDatetime">{{article.createDatetime}}</div>
9
      </div>
10
      <!-- <wxParse :content="article.content" v-if="!article.msg" /> -->
柳士祥 committed
11 12
      <!-- <div v-html="article.content" v-if="!article.msg"></div>/ -->
      <mp-html :content="article.content" :copy-link="false" @linktap="linktap" v-if="!article.msg" />
柳士祥 committed
13
      <!-- <rich-text :datas="datas" v-if="!article.msg"></rich-text> -->
14 15 16 17 18
      <div class="title" style="min-height: 50vh;color: #999;align-items: center;display: flex;justify-content: center;" v-else>{{article.msg}}</div>
    </div>
    <div style="width:100%;height:10px;background-color:#EEF2F5;"></div>
    <ul>
      <div class="all">全部评论</div>
柳士祥 committed
19
      
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
      <div v-if="list.length == 0" style="text-align: center;color: #969799;font-size:12px">暂无评论</div>
      <li id="pingLun" style="opacity:0;height: 0px;position:absolute;top:-130px;left:0;"></li>
      <li class="van-hairline--bottom" v-for="(item,index) in list" :key="index">
        <div class="left">
          <img :src="(item.userImageUrl || item.handImage) | DFSImg(400,400)" alt="">
        </div>
        <div class="middle">
          <div style="color:#666666;">{{item.reviewName}}</div>
          <div class="time">{{getTime(item.updateDatetime)}}</div>
          <div class="show_info">{{item.content}}</div>
        </div>
      </li>
    </ul>
    <div class="bottom van-hairline--top">
      <input confirm-type="search" placeholder="说两句吧" v-model="commentContent" @confirm="commentsSubmit">
      <div class="icon_box">
        <div class="share" @click="toBottom">
          <div class="num">
            {{total}}
          </div>
          <img src="https://mayi-newshop.oss-cn-shanghai.aliyuncs.com/product/2EWPQRMQwm.png?x-oss-process=image/resize,m_pad,limit_0,w_400,h_400" alt="">
        </div>
        <div class="share" @click="thumbsUp">
          <img src="https://mayi-newshop.oss-cn-shanghai.aliyuncs.com/product/i3HttTMh6f.png?x-oss-process=image/resize,m_pad,limit_0,w_400,h_400" alt="" v-if="!isThumbsUp">
          <img src="https://mayi-newshop.oss-cn-shanghai.aliyuncs.com/product/MkRsXX3QsM.png?x-oss-process=image/resize,m_pad,limit_0,w_400,h_400" alt="" v-else>
        </div>
        <div class="share" @click="poupShow">
          <img src="https://mayi-newshop.oss-cn-shanghai.aliyuncs.com/product/wBYDz3CZkM.png?x-oss-process=image/resize,m_pad,limit_0,w_400,h_400" alt="">
        </div>
      </div>
    </div>

    <shade-guide ref="shadeGuide" />
  </div>
</template>

<script>
import article from '@/api/article'
import shadeGuide from "./shadeGuide.vue";
59 60 61
import { throttle, concatUrl } from "../../../utils/index.js"
// import wxParse from 'mpvue-wxparse'

62
const app = getApp();
柳士祥 committed
63
const { $themeToLink, log } = app;
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
export default {
  data() {
    return {
      article: null,
      commentContent: '',
      articleId: null,
      isThumbsUp: false,

      loading: false,
      finished: false,
      list: [],
      total: 0,
      query: {
        pageNum: 0,
        pageSize: 20,
柳士祥 committed
79
      },
80 81 82
    }
  },
  components: {
柳士祥 committed
83 84
    "shade-guide": shadeGuide,

85 86 87 88 89
  },
  created() {
  },
  onReady() {
  },
90
  onLoad(options) {
91 92 93 94
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline']
    })
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132

    if (options.queryStr) {
      wx.showModal({
        title: "",
        content: options.queryStr,
        showCancel: true,
        cancelText: '取消',
        cancelColor: '#000000',
        confirmText: '确定',
        confirmColor: '#3CC51F',
        success: (result) => {
          if (result.confirm) {

          }
        },
        fail: () => { },
        complete: () => { }
      });
    } else if (options.article_id) {
      this.articleId = options.article_id
      this.query['articleId'] = this.articleId
      this.init()
    }

    //进页面存储需要绑定的信息
    if (options.userId || options.spokesmanRelId) {
      wx.setStorage({
        key: "becomeInfo",
        data: JSON.stringify(options)
      });
    }

    if (wx.getStorageSync("sessionid")) {
      //获取分销信息
      this.getSpokesmanInit(wx.getStorageSync("becomeInfo") ? JSON.parse(wx.getStorageSync("becomeInfo")) : '')
    }


133
  },
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
  // onShareAppMessage() {
  //   return {
  //     title: '',
  //     path: `/pages/pages_subpack/article/main?article_id=${this.articleId}`
  //   }
  // },
  async onShareAppMessage(res) {
    console.log('wxshare');
    let newHref = `/pages/pages_subpack/article/main?article_id=${this.articleId}`;
    let title = app.globalData.shopInfo.shopName;
    let hasInvitationStatus = 0;
    if (wx.getStorageSync("sessionid")) {
      await app.fenxiaoModel.getSpokesmanidByShare().then(data => {
        hasInvitationStatus = data.hasInvitationStatus;
      })
      await app.fenxiaoModel.getSpokesmanInfo().then(data => {
        let newData = {}
        if (data != null) {
          if (hasInvitationStatus == 1) {
            newData = {
              spokesmanGroupId: data.groupId,
              spokesmanShopId: data.shopId,
              spokesmanRelId: data.id,
              userId: data.userId
            }
          } else {
            newData = {
              userId: data.userId
            }
          }
        }
        newHref = concatUrl(newHref, newData)
      })
167
    }
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    console.log(newHref, title, 'share');
    return {
      title: title, // 默认是小程序的名称
      path: newHref, // 默认是当前页面
      imageUrl: '',
      success: function (res) {
        // 转发成功之后的回调
        if (res.errMsg == "shareAppMessage:ok") {
          log.info(res, "分享成功");
        }
      },
      fail: function () {
        // 转发失败之后的回调
        if (res.errMsg == "shareAppMessage:fail cancel") {
          // 用户取消转发
          log.info(res, "分享失败");
        } else if (res.errMsg == "shareAppMessage:fail") {
          // 转发失败,其中 detail message 为详细失败信息
        }
      },
      complete: function () {
        // 转发结束之后的回调(转发成不成功都会执行)
      }
    };
192
  },
193 194
  //用户点击右上角分享朋友圈
  onShareTimeline: function () {
195 196
    return {
      title: '',
197 198
      query: `article_id=${this.article_id}`,
      imageUrl: ''
199 200
    }
  },
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
  // async onShareTimeline() {
  //   console.log('Timeline');
  //   // let newHref = `/pages/pages_subpack/article/main?article_id=${this.articleId}`;
  //   let newHref = ''
  //   let title = app.globalData.shopInfo.shopName;
  //   let hasInvitationStatus = 0;
  //   if (wx.getStorageSync("sessionid")) {
  //     await app.fenxiaoModel.getSpokesmanidByShare().then(data => {
  //       hasInvitationStatus = data.hasInvitationStatus;
  //     })
  //     await app.fenxiaoModel.getSpokesmanInfo().then(data => {
  //       let newData = {}
  //       if (data != null) {
  //         if (hasInvitationStatus == 1) {
  //           newData = {
  //             spokesmanGroupId: data.groupId,
  //             spokesmanShopId: data.shopId,
  //             spokesmanRelId: data.id,
  //             userId: data.userId
  //           }
  //         } else {
  //           newData = {
  //             userId: data.userId
  //           }
  //         }
  //       }
  //       newHref = concatUrl(newHref, newData)
  //     })
  //   }
  //   console.log(newHref, title, 'TimelineShare');
  //   // let queryStr = `articleId_${this.articleId}/spokesmanGroupId_${obj.spokesmanGroupId}/spokesmanShopId_${obj.spokesmanShopId}/spokesmanRelId_${obj.spokesmanRelId}/userId_${obj.userId}`
  //   return {
  //     title: title,
  //     query: 'a=1111',
  //     imageUrl: '',
  //     createDatetime: ''
  //   }
  // },
239
  methods: {
柳士祥 committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    toPageUrl(backPath, backParams = "") {
      return `../../index/main?from=themeLink&backpath=${encodeURIComponent(
        backPath
      )}&params=${encodeURIComponent(backParams)}`;
    },
    getUrlofLink(data) {
      return data.link.split("?")[0];
    },
    getUrlofQuery(data) {
      let arr = data.link.split("?")
      let params = [];
      arr.forEach((res, index) => {
        if (index >= 1) {
          params.push(res)
        }
      })
      return params.join("?") || "";
    },
    linktap(e) {
      console.log(e.mp.detail);
      let href = e.mp.detail.href
      let articleid = e.mp.detail['data-articleid']
      let productid = e.mp.detail['data-productid']
      let data = {
        link: `/goods/${productid}`,
        type: 1
      }
      let url = this.toPageUrl(this.getUrlofLink(data), this.getUrlofQuery(data));
      console.log(url,'last');
      wx.navigateTo({
        url

      });

      // console.log(href, articleid, productid);
      // let linkVal = `/goods/${productid}`;
      // $themeToLink({
      //   type: 1,
      //   link: linkVal
      // });

    },
282 283 284 285 286 287 288 289 290 291 292
    getSpokesmanInit(extConfig) {
      //绑定上下级关系
      app.fenxiaoModel.becomeRelation(extConfig).then(res => {
        if (res) {
          wx.removeStorage({
            key: "becomeInfo"
          });
        }
      })
    },
    //富文本解析和替换
柳士祥 committed
293
    formatRichText(html) {
柳士祥 committed
294 295 296 297 298
      // let newContent = html.replace(/class="(.*)gobuy(.*)"/gi,function(match){
      //   match = match + ' onclick="gotowebview"'
      //  console.log(match, 'match');
      //  return match;
      // })
柳士祥 committed
299
      let newContent = html.replace(/<img[^>]*>/gi, function (match, capture) {
300
        if (match.startsWith('<img style="object-fit: contain;')) {
柳士祥 committed
301
          // console.log(match, 'match');
302
          match = match.replace(/height:(.*?);/g, 'height: 76px !important;')
柳士祥 committed
303 304
          match = match.replace(/width:(.*?);/g, 'width: 90px !important;')
          // console.log(match, 'match');
305 306 307 308 309
        } else {
          match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
          match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
          match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
        }
柳士祥 committed
310 311
        return match;
      });
柳士祥 committed
312 313 314 315 316 317 318
      // console.log('newContent', newContent);
      // newContent = newContent.replace(/style="[^"]+"/gi, function (match, capture) {
      //   match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
      //   return match;
      // });
      // newContent = newContent.replace(/<br[^>]*\/>/gi, '');
      // newContent = newContent.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;margin:10px 0;"');
319

柳士祥 committed
320 321
      return newContent
    },
322 323 324 325 326
    init() {
      log.info('qq');
      article.getArticleInfo(this.articleId).then(res => {
        if (res.data.data) {
          let article = res.data.data
327 328
          let content = res.data.data.content.replace('<body>', '<div style="overflow-x: hidden;width:100%">').replace("</body>", "</div>")
          let createDatetime = article.createDatetime != '' ? article.createDatetime.slice(0, -9) : ''
柳士祥 committed
329
          article.content = this.formatRichText(content)
330
          article.createDatetime = createDatetime
331 332 333 334 335 336
          this.article = article
          // this.createDatetime = article.createDatetime != '' ? article.createDatetime.slice(0,-3):''
          // log.info(this.createDatetime,'article.createDatetime');
          if (article.fabulousFlag == 'true') {
            this.isThumbsUp = true;
          }
337 338 339 340 341 342
          // 不设置title
          // if (article.title && article.title.length) {
          //   wx.setNavigationBarTitle({
          //     title: article.title
          //   })
          // }
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
        }
      });

    },
    poupShow() {
      this.$refs.shadeGuide.open();
    },
    // 文章评论
    commentsSubmit(e) {
      log.info('submit');
      if (this.articleId == null) return
      if (this.commentContent.trim().length == 0) {
        wx.showToast({
          title: '请输入要评论的内容',
          icon: 'none',
          duration: 1000,
        });
        return
      }
      let query = {
        articleId: this.articleId,
        content: this.commentContent
      }
      log.info(query);
      article.saveReview(query).then(res => {
        if (res.data.code == '200') {
          this.commentContent = '';
          wx.showToast({
            title: '评论成功,正在审核',
            icon: 'none',
            duration: 1000,
          });
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
          });
        }
      })
    },
    //点赞
    thumbsUp() {
      // this.$refs.shadeGuide.open();
      let query = {
        articleId: this.articleId,
        fabulousType: !this.isThumbsUp ? 1 : 2
      }
      // if(!this.isThumbsUp){
      article.addLike(query).then(res => {
        if (res.data.code == "200") {
          this.isThumbsUp = !this.isThumbsUp;
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 1000,
          });
        }
      })
      // }else {
      //   article.cancelLike(query).then(res=>{
      //     if(res.code=="200"){
      //       this.isThumbsUp = !this.isThumbsUp;
      //     }else {
      //       Toast(res.msg)
      //     }
      //   })
      // }
    },
    // 获取评论
    getComments() {
      this.query.pageNum += 1;
      article.getReviews(this.query).then(res => {
        this.loading = false;
        if (res.data.code == '200') {
          res.data.data.forEach(ele => {
            this.list.push(ele)
          })
          this.total = res.data.total;
          if (res.data.data.length < 20) {
            this.finished = true
          }
        } else {
          this.finished = true;
        }
        log.info(res, 777777777)
      })
    },
    getTime(time) {
      time = time.replace(/-/g, "/");
      log.info(time, 888888888)
      let timestamp = (Date.parse(new Date()) - Date.parse(new Date(time))) / 1000;
      if (timestamp < 60) {
        return '刚刚'
      } else if (timestamp < 3600) {
        return parseInt(timestamp / 60) + '分钟前'
      } else if (timestamp < 3600 * 12) {
        return parseInt(parseInt(timestamp / 60) / 60) + '小时前'
      } else if (new Date().getFullYear() == new Date(time).getFullYear()) {
        return time.slice(5).replace(/\//g, "-")
      } else if (new Date().getFullYear() > new Date(time).getFullYear()) {
        return time.replace(/\//g, "-")
      }
    },
    // 划到最底部
    toBottom() {
      wx.createSelectorQuery().select('.article_container').boundingClientRect(function (rect) {
        // 使页面滚动到底部
        log.info(rect.height, 'rect.height');
        wx.pageScrollTo({
          scrollTop: rect.height
        })
      }).exec()
    },
  }
}
</script>

<style lang="scss" scoped>
463
// @import url("~mpvue-wxparse/src/wxParse.css");
柳士祥 committed
464 465 466
.mceNonEditable{
  box-sizing: border-box;
}
467 468 469
.imgbox .img {
  height: 96px !important;
}
470 471 472 473 474 475 476 477 478
.article_container {
  position: relative;
}
.richText {
  width: 100%;
  height: auto;
  padding: 0 10px;
  padding-bottom: 100px;
  box-sizing: border-box;
479
  overflow-x: hidden;
480 481 482
}

.title {
柳士祥 committed
483
  font-size: 20px;
484 485 486 487
  color: #333;
  width: 100%;
  padding: 12px 0;
  text-align: left;
488
  font-weight: 700;
489 490 491
}
.title_info {
  display: flex;
492
  justify-content: flex-start;
柳士祥 committed
493
  // padding: 0 12px;
494
  font-size: 13px;
495
  margin-bottom: 24px;
496 497 498 499 500 501 502
}
.title_user {
  width: 100%;
  color: #999;
}
.title_time {
  width: 100%;
柳士祥 committed
503
  // padding-right: 13px;
504
  text-align: left;
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
  color: #999;
}

.bottom {
  width: 100%;
  height: 49px;
  position: fixed;
  background-color: #fff;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  padding-right: 22px;
  box-sizing: border-box;
}
input {
  border: none;
  width: 150px;
  height: 20px;
  line-height: 20px;
  background-color: #eeeeed;
  border-radius: 16px;
  padding: 5px 13px;
  font-size: 16px;
}

.icon_box {
  flex-grow: 1;
  display: flex;
  padding-left: 9px;
  align-items: center;
  justify-content: space-between;
}
.share,
.zan {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  position: relative;
}
.num {
  position: absolute;
  top: -9px;
  left: calc(100% - 9px);
  border-radius: 10px;
  min-width: 18px;
  height: 18px;
  background-color: #ff4848;
  color: #fff;
  text-align: center;
  line-height: 18px;
  padding: 0 6px;
  /* transform: translateX(100%); */
}
img {
  max-width: 100%;
  height: 100%;
  /* margin-right: 30px; */
}

ul {
  width: 100%;
  // padding-bottom: 22px;
  position: relative;
  padding: 0 10px;
  margin-bottom: 100px;
  box-sizing: border-box;
  li {
    width: 100%;
    padding-right: 7px;
    display: flex;
    padding: 0 12px;
    margin-bottom: 10px;
    padding-bottom: 12px;
    .left {
      width: 36px;
      height: 36px;
      height: 100%;
      margin-right: 14px;
      border-radius: 20px;
      overflow: hidden;
      img {
        width: 100%;
        // height: 36px;
      }
    }
    .middle {
      width: 100%;
      font-size: 13px;
      .show_info {
        font-size: 14px;
        color: #333333;
      }
      .time {
        padding: 5px 0 8px;
        color: #666666;
      }
    }
  }
  .all {
    width: 100%;
    font-size: 14px;
    color: #333;
    padding: 10px 12px 12px;
  }
}
柳士祥 committed
615
</style>