TextbookDetailPdf.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <!-- 预览 -->
  3. <div class="tarcer-dev-Preview" v-loading="loading" v-if="isData">
  4. <Header />
  5. <HeaderOne title="教材详情" name="试读PDF" />
  6. <div class="main" v-if="data">
  7. <div class="flassify">
  8. <div class="text">
  9. <p class="p1">{{ data.name }}</p>
  10. <p class="p2">
  11. <span>
  12. {{ data.author }}
  13. </span>
  14. </p>
  15. </div>
  16. <div class="pay_collect">
  17. <div class="download">
  18. <img
  19. @click="download"
  20. src="../../assets/common/download.png"
  21. alt=""
  22. />
  23. <!-- <span>DOWNLOAD</span> -->
  24. </div>
  25. </div>
  26. </div>
  27. <div v-if="attachment" class="pdf-box">
  28. <pdf
  29. ref="pdf"
  30. :src="attachment"
  31. v-for="i in numPages"
  32. :key="i"
  33. :page="i"
  34. >
  35. {{ i / numPages }}
  36. </pdf>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import Header from "@/components/inputModules/common/Header";
  43. import HeaderOne from "@/components/inputModules/common/HeaderOne";
  44. import pdf from "vue-pdf";
  45. import { updateWordPack } from "@/utils/i18n";
  46. import { getToken } from "@/utils/auth";
  47. import { Base64 } from "js-base64";
  48. import { TextbookAPI, LearnWebSI } from "@/api/ajax";
  49. export default {
  50. name: "TextbookDetailPdf",
  51. components: {
  52. Header,
  53. HeaderOne,
  54. pdf,
  55. },
  56. data() {
  57. return {
  58. numPages: null,
  59. isCollect: false,
  60. materialId: null,
  61. data: null,
  62. attachment: null,
  63. loading: false,
  64. Ispreview: "", // 是不是预览
  65. NopymentShow: false, //添加订单弹窗
  66. PymentShow: false, //支付订单弹窗
  67. orderNumber: null, //订单号
  68. IsDownload: false, //是否可以下载
  69. allList: null,
  70. isData: false,
  71. };
  72. },
  73. computed: {},
  74. methods: {
  75. // 下载
  76. download() {
  77. let userInfor = JSON.parse(getToken());
  78. let UserCode = "",
  79. UserType = "",
  80. SessionID = "";
  81. if (userInfor) {
  82. UserCode = userInfor.user_code;
  83. UserType = userInfor.user_type;
  84. SessionID = userInfor.session_id;
  85. }
  86. let FileID = Base64.decode(this.$route.query.fileId);
  87. let data = {
  88. SessionID,
  89. UserCode,
  90. UserType,
  91. FileID,
  92. };
  93. location.href =
  94. process.env.VUE_APP_BASE_API +
  95. `/GCLSFileServer/WebFileDownload?UserCode=${data.UserCode}&UserType=${data.UserType}&SessionID=${data.SessionID}&FileID=${data.FileID}`;
  96. },
  97. // 获取pdf的页数
  98. getNumPages() {
  99. this.loading = true;
  100. let _this = this;
  101. let loadingTask = pdf.createLoadingTask(_this.attachment);
  102. loadingTask.promise
  103. .then((pdf) => {
  104. if (_this.data.isPurchased) {
  105. _this.numPages = pdf.numPages;
  106. } else {
  107. _this.numPages = 2;
  108. }
  109. _this.loading = false;
  110. })
  111. .catch((err) => {
  112. console.error("Pdf Loading failed", err);
  113. });
  114. },
  115. // 获取学习资料详情
  116. getdetail() {
  117. this.loading = true;
  118. let Mname = "book-book_manager-GetBook";
  119. // 获取课程详情
  120. TextbookAPI(Mname, {
  121. id: this.materialId,
  122. })
  123. .then((res) => {
  124. this.data = res;
  125. this.loading = false;
  126. this.attachment =
  127. process.env.VUE_APP_PDF_API +
  128. Base64.decode(this.$route.query.relativePath);
  129. this.getNumPages();
  130. console.log(this.attachment);
  131. })
  132. .catch((res) => {
  133. this.loading = false;
  134. });
  135. },
  136. },
  137. async created() {
  138. await updateWordPack({
  139. word_key_list: [
  140. "Key5",
  141. "Key8",
  142. "Key9",
  143. "Key39",
  144. "Key43",
  145. "Key52",
  146. "Key53",
  147. "Key54",
  148. "Key55",
  149. "Key58",
  150. "Key72",
  151. "Key94",
  152. "Key107",
  153. "Key109",
  154. "Key214",
  155. "Key232",
  156. "Key108",
  157. "Key396",
  158. "Key472",
  159. "Key473",
  160. "Key474",
  161. "Key572",
  162. "Key574",
  163. "Key575",
  164. "Key576",
  165. ],
  166. });
  167. this.isData = true;
  168. },
  169. mounted() {
  170. this.materialId = this.$route.query.id;
  171. if (this.materialId) {
  172. this.getdetail();
  173. }
  174. },
  175. };
  176. </script>
  177. <style lang="scss" scoped>
  178. .tarcer-dev-Preview {
  179. height: 100%;
  180. .main {
  181. min-height: 543px;
  182. background: #f6f6f6;
  183. padding-bottom: 20px;
  184. padding-top: 30px;
  185. position: relative;
  186. }
  187. .flassify {
  188. position: relative;
  189. width: 1140px;
  190. height: 154px;
  191. margin: 0 auto;
  192. background-color: #fff;
  193. border-radius: 8px;
  194. display: flex;
  195. justify-content: space-between;
  196. // align-items: center;
  197. padding: 0 30px;
  198. .text {
  199. height: 100%;
  200. padding-top: 24px;
  201. .p1 {
  202. font-weight: bold;
  203. font-size: 30px;
  204. color: #1f2127;
  205. }
  206. .p2 {
  207. margin-top: 8px;
  208. margin-bottom: 8px;
  209. font-size: 16px;
  210. color: #1f2127;
  211. }
  212. }
  213. .pay_collect {
  214. // position: absolute;
  215. // right: 30px;
  216. // bottom: 24px;
  217. height: 100%;
  218. padding-top: 90px;
  219. display: flex;
  220. align-content: center;
  221. .price {
  222. font-weight: bold;
  223. font-size: 24px;
  224. margin-right: 20px;
  225. .price_2 {
  226. font-size: 16px;
  227. }
  228. }
  229. .pay {
  230. width: 120px;
  231. height: 40px;
  232. background: #ff9900;
  233. border-radius: 4px;
  234. color: white;
  235. font-weight: 600;
  236. font-size: 20px;
  237. text-align: center;
  238. line-height: 40px;
  239. cursor: pointer;
  240. margin-right: 20px;
  241. }
  242. .collect {
  243. display: flex;
  244. align-items: center;
  245. height: 40px;
  246. font-weight: bold;
  247. font-size: 24px;
  248. color: #1f2127;
  249. img {
  250. width: 24px;
  251. margin-right: 10px;
  252. cursor: pointer;
  253. }
  254. }
  255. .download {
  256. height: 40px;
  257. margin-right: 20px;
  258. display: flex;
  259. align-items: center;
  260. font-weight: bold;
  261. font-size: 24px;
  262. color: #1f2127;
  263. img {
  264. width: 24px;
  265. margin-right: 10px;
  266. cursor: pointer;
  267. }
  268. }
  269. }
  270. }
  271. .pdf-box {
  272. width: 1140px;
  273. margin: 24px auto;
  274. }
  275. .NObuy {
  276. width: 1200px;
  277. margin: 24px auto;
  278. min-height: 1000px;
  279. filter: blur(8px);
  280. }
  281. .buyBtn {
  282. width: 284px;
  283. height: 67px;
  284. background: #ff9900;
  285. border-radius: 8px;
  286. text-align: center;
  287. line-height: 67px;
  288. color: white;
  289. font-weight: bold;
  290. font-size: 22px;
  291. margin: 0 auto;
  292. cursor: pointer;
  293. position: relative;
  294. top: -150px;
  295. }
  296. .dialogTitle {
  297. }
  298. }
  299. </style>
  300. <style lang="scss">
  301. .tarcer-dev-Preview {
  302. .el-dialog__body {
  303. padding: 30px 32px;
  304. }
  305. }
  306. .cui-ribbonTopBars {
  307. display: none !important;
  308. }
  309. </style>