details.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  1. <template>
  2. <div class="details-p">
  3. <div class="tops">
  4. <h3>
  5. <van-icon class="word01" :name="'diy-' + fileType(detailData.docFileType)" />
  6. {{detailData.docName}}
  7. </h3>
  8. </div>
  9. <div class="middles">
  10. <h3>摘要</h3>
  11. <p>{{detailData.docSummary}}</p>
  12. <div class="continue" v-show="buyed == 0">全文共{{detailData.docPageSize}}页,<span @click="continued">继续阅读<van-icon name="arrow-down" size="18" /></span></div>
  13. </div>
  14. <div class="botts" v-show="buyed == 1">
  15. <div class="cont-page" id="pdfPage" style="width: 375px">
  16. <!-- <iframe :src="conts" width="100%" height="100%"></iframe> -->
  17. </div>
  18. </div>
  19. <van-goods-action>
  20. <van-goods-action-icon class="no-icon">
  21. <template #default>
  22. <p class="p1">剑鱼币</p>
  23. <p class="p2">{{detailData.price}}</p>
  24. </template>
  25. </van-goods-action-icon>
  26. <van-goods-action-icon icon="diy-jubao" text="投诉举报" @click="jubaod" />
  27. <van-goods-action-icon :icon="collectd==1?'diy-guanzhu':'diy-weiguanzhu'" text="收藏" @click="canged" />
  28. <van-goods-action-button text="下载文档" @click="uploaded" />
  29. </van-goods-action>
  30. <!-- 充值 -->
  31. <recharge ref="charge" :detailData="detailData" :coins="coins"></recharge>
  32. <!-- 分享 -->
  33. <share-pop ref="shares" :detailData="detailData" :links="links"></share-pop>
  34. </div>
  35. </template>
  36. <script lang="ts">
  37. import { Component, Vue } from 'vue-property-decorator'
  38. import { mapActions } from 'vuex'
  39. import { Icon, Toast, GoodsAction, GoodsActionIcon, GoodsActionButton } from 'vant'
  40. import Recharge from '@/components/Recharge.vue'
  41. import sharePop from '@/components/SharePopup.vue'
  42. import { MixinTop } from '@/utils/mixin-top'
  43. const pdfjsLib = require('pdfjs-dist/build/pdf.js')
  44. const pdfjsViewer = require('pdfjs-dist/web/pdf_viewer.js')
  45. @Component({
  46. name: 'details-p',
  47. mixins: [MixinTop],
  48. components: {
  49. [Icon.name]: Icon,
  50. [GoodsAction.name]: GoodsAction,
  51. [GoodsActionIcon.name]: GoodsActionIcon,
  52. [GoodsActionButton.name]: GoodsActionButton,
  53. Recharge,
  54. sharePop
  55. },
  56. methods: {
  57. ...mapActions({
  58. getDetails: 'main/getDetails',
  59. getShow: 'main/getShow',
  60. getCoin: 'main/getCoin',
  61. getDown: 'main/getDown',
  62. getShare: 'main/getShare',
  63. getAdd: 'main/getAdd',
  64. getRemove: 'main/getRemove'
  65. })
  66. }
  67. })
  68. export default class extends Vue {
  69. getDetails: any
  70. getCoin: any
  71. getDown: any
  72. getShow: any
  73. getShare: any
  74. links: any = []
  75. docIds = ''
  76. coins: any = []
  77. conts: any = []
  78. getAdd: any
  79. getRemove: any
  80. detailData: any = []
  81. collectd = 0
  82. buyed = 0
  83. pdfh5 = null
  84. pdfDocument: any
  85. config: any = {
  86. PAGE_TO_VIEW: 0,
  87. SCALE: 0.9,
  88. CMAP_URL: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.6.347/cmaps/',
  89. CMAP_PACKED: true,
  90. workerSrc: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.6.347/es5/build/pdf.worker.min.js'
  91. }
  92. pData: any = {
  93. heightList: []
  94. }
  95. TopConfig: any = {
  96. actionRightText: '<div style="display:flex;flex-direction: column;align-items: center;"><i class="j-icon icon-iconJianYu"></i><p style="color: #171826;font-size: 10px;line-height: 12px;margin-top:3px;">分享赚积分</p></div>',
  97. actionRightCallback: this.shared,
  98. actionRightStyle: {
  99. color: '#5F5E64',
  100. fontSize: '20px',
  101. paddingLeft: '10px'
  102. }
  103. }
  104. created () {
  105. this.docIds = this.$route.params.id
  106. this.onList()
  107. }
  108. mounted () {
  109. // 监听滚轮
  110. window.addEventListener('scroll', this.watchPage)
  111. }
  112. destroyed () { // 移除监听
  113. window.removeEventListener('scroll', this.watchPage)
  114. }
  115. shared () {
  116. ;(this.$refs.shares as any).show = true
  117. this.getShare({ docId: this.docIds }).then((res: any) => {
  118. console.log(res)
  119. this.links = res.data
  120. })
  121. }
  122. // updateText (type: any, value = '') {
  123. // switch (type) {
  124. // case 'count': {
  125. // document.querySelector('#page_count').textContent = value
  126. // break
  127. // }
  128. // case 'num': {
  129. // document.querySelector('#page_num').textContent = value
  130. // break
  131. // }
  132. // }
  133. // }
  134. renders () {
  135. const container = document.getElementById('pdfPage')
  136. return this.pdfDocument.getPage(this.config.PAGE_TO_VIEW).then((pdfPage: any) => {
  137. const pdfPageView = new pdfjsViewer.PDFPageView({
  138. container: container,
  139. id: this.config.PAGE_TO_VIEW,
  140. scale: this.config.SCALE,
  141. defaultViewport: pdfPage.getViewport({ scale: this.config.SCALE }),
  142. eventBus: new pdfjsViewer.EventBus(),
  143. annotationLayerFactory: new pdfjsViewer.DefaultAnnotationLayerFactory()
  144. })
  145. pdfPageView.setPdfPage(pdfPage)
  146. this.pData.heightList.push(pdfPageView.viewport.height)
  147. return pdfPageView.draw()
  148. })
  149. }
  150. init () {
  151. console.log(this.conts)
  152. pdfjsLib.GlobalWorkerOptions.workerSrc = this.config.workerSrc
  153. const loadingTask = pdfjsLib.getDocument({
  154. url: this.conts,
  155. cMapUrl: this.config.CMAP_URL,
  156. cMapPacked: this.config.CMAP_PACKED
  157. })
  158. loadingTask.promise.then((pdfDocument: any) => {
  159. this.pdfDocument = pdfDocument
  160. console.log(this.pdfDocument.numPages)
  161. // this.updateText({type: 'count', value: this.pdfDocument.numPages})
  162. // this.updateText({type: 'num', value: 1})
  163. for (let i = 0; i < this.pdfDocument.numPages; i++) {
  164. this.config.PAGE_TO_VIEW++
  165. this.renders()
  166. }
  167. })
  168. }
  169. watchPage () {
  170. const top = window.scrollY
  171. let base = 0
  172. for (let i = 0; i < this.pData.heightList.length; i++) {
  173. base += this.pData.heightList[i]
  174. if (top <= base) {
  175. // this.updateText({type: 'num', value: i + 1})
  176. break
  177. }
  178. }
  179. }
  180. buyShow () {
  181. this.getShow({ docId: this.docIds }).then((res: any) => {
  182. console.log(res.data)
  183. this.conts = res.data
  184. this.init()
  185. })
  186. }
  187. onList () {
  188. this.getDetails({ docId: this.docIds, from: this.$route.query.from }).then((res: any) => {
  189. console.log(res.data)
  190. this.detailData = res.data.detail
  191. this.detailData.docSummary = res.data.detail.docSummary.split('').length >= 500 ? res.data.detail.docSummary + '...' : res.data.detail.docSummary
  192. this.buyed = res.data.status
  193. if (res.data.status === 1) {
  194. this.buyShow()
  195. }
  196. this.collectd = res.data.collect
  197. })
  198. this.getCoin({ B: true }).then((res: any) => {
  199. console.log(res.data.data)
  200. this.coins = res.data.data.points
  201. })
  202. }
  203. jubaod () {
  204. Toast({
  205. duration: 3500,
  206. message: '如果您发现此内容有侵权行为,请联系客服400-108-6670进行投诉'
  207. })
  208. }
  209. canged () {
  210. if (this.collectd === 0) {
  211. this.getAdd({ docId: this.docIds }).then((res: any) => {
  212. console.log(res)
  213. if (res.error_code === 0) {
  214. this.collectd = 1
  215. Toast('收藏成功')
  216. }
  217. })
  218. } else {
  219. this.getRemove({ docId: this.docIds }).then((res: any) => {
  220. console.log(res)
  221. if (res.error_code === 0) {
  222. this.collectd = 0
  223. Toast('取消收藏')
  224. }
  225. })
  226. }
  227. }
  228. continued () {
  229. this.uploaded()
  230. }
  231. uploaded () {
  232. if (this.buyed === 1) {
  233. this.getDown({ docId: this.docIds }).then((res: any) => {
  234. if (res.error_code === 0) {
  235. window.location.href = res.data
  236. }
  237. })
  238. } else {
  239. if (this.coins.balance < this.detailData.price) {
  240. ;(this.$refs.charge as any).show = true
  241. } else {
  242. this.$router.push('/purchase/' + this.detailData.docId)
  243. }
  244. }
  245. }
  246. fileType (val: any) {
  247. if (val === 1) {
  248. return 'word'
  249. } else if (val === 2) {
  250. return 'pdf'
  251. } else if (val === 3) {
  252. return 'excel'
  253. } else if (val === 4) {
  254. return 'ppt'
  255. } else if (val === 5) {
  256. return 'txt'
  257. } else {
  258. return ''
  259. }
  260. }
  261. }
  262. </script>
  263. <style lang="scss" scoped>
  264. @include diy-icon('pdf', 24, 24);
  265. @include diy-icon('word', 24, 24);
  266. @include diy-icon('excel', 24, 24);
  267. @include diy-icon('ppt', 24, 24);
  268. @include diy-icon('jubao', 20, 20);
  269. @include diy-icon('weiguanzhu', 20, 20);
  270. @include diy-icon('guanzhu', 20, 20);
  271. @include diy-icon('iconJianYu', 24, 24);
  272. .details-p {
  273. display: flex;
  274. flex-direction: column;
  275. padding-bottom: 80px;
  276. .tops {
  277. display: flex;
  278. background: #fff;
  279. padding: 24px 16px;
  280. h3 {
  281. display: flex;
  282. flex-direction: initial;
  283. width: 100%;
  284. color: #171826;
  285. font-weight: 500;
  286. font-size: 20px;
  287. line-height: 30px;
  288. .word01 {
  289. display: inline-table;
  290. width: 26px;
  291. height: 24px;
  292. margin-right: 8px;
  293. }
  294. }
  295. }
  296. .middles {
  297. padding: 16px;
  298. background: #fff;
  299. margin: 8px 0;
  300. h3 {
  301. font-size: 16px;
  302. line-height: 24px;
  303. font-weight: 500;
  304. color: #171826;
  305. }
  306. p {
  307. color: #5F5E64;
  308. font-size: 14px;
  309. line-height: 20px;
  310. margin-top: 8px;
  311. }
  312. .continue {
  313. color: #5F5E64;
  314. font-size: 14px;
  315. line-height: 20px;
  316. text-align: center;
  317. margin-top: 32px;
  318. span {
  319. display: inline-flex;
  320. align-items: center;
  321. color: #2ABED1;
  322. cursor: pointer;
  323. i {
  324. margin-left: 4px;
  325. }
  326. }
  327. }
  328. }
  329. .botts {
  330. // padding: 16px 24px;
  331. // width: 375px;
  332. background: #fff;
  333. .cont-page {
  334. // width: 375px;
  335. background: #fff;
  336. }
  337. }
  338. .van-goods-action {
  339. // height: 56px;
  340. padding: 8px 16px;
  341. box-shadow: 0px -2px 8px 0px #eee;
  342. display: flex;
  343. justify-content: space-between;
  344. .no-icon {
  345. .p1 {
  346. font-size: 12px;
  347. line-height: 18px;
  348. color: #5F5E64;
  349. }
  350. .p2 {
  351. font-size: 18px;
  352. line-height: 26px;
  353. color: #FB483D;
  354. }
  355. .van-icon {
  356. display: none!important;
  357. }
  358. }
  359. .van-goods-action-icon:not(.no-icon) {
  360. font-size: 10px;
  361. color: #5F5E64;
  362. }
  363. .van-goods-action-button--first {
  364. margin-left: 0;
  365. }
  366. .van-goods-action-button--last {
  367. margin-right: 0;
  368. }
  369. .van-goods-action-button {
  370. flex: none;
  371. }
  372. .van-button--large {
  373. width: 165px;
  374. height: 40px;
  375. }
  376. ::v-deep .van-button--default {
  377. background-color: #2ABED1;
  378. .van-button__content {
  379. .van-button__text {
  380. color: #fff;
  381. font-size: 16px;
  382. }
  383. }
  384. }
  385. }
  386. }
  387. </style>