index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="page">
  3. <Loading :loading="loading" />
  4. <div v-show="!loading">
  5. <van-image-preview v-model="vshowList" :images="detailData.imageFiles" :start-position='0' @change="onChange"
  6. @scale='onScale' @close='onClose' ref='imagePreview'>
  7. <template v-slot:index>
  8. <div>
  9. 第{{curPage}}页
  10. </div>
  11. </template>
  12. <template v-slot:cover v-if="showBottom">
  13. <div class="pdf-cover-bottom">
  14. <input class="pdf-barinputL" ref='pdfInput' type="number" id="spinner_amount" :value="curPage"
  15. @input="pdfInput" />
  16. <!-- oninput="" -->
  17. <div class="pdf-barinputR">/{{ detailData.imageFiles.length}}</div>
  18. </div>
  19. </template>
  20. </van-image-preview>
  21. <div v-show="!vshowList" class="jurisdiction">
  22. <van-image :src="require('../../../static/images/icon_jurisdiction.png')" />
  23. <div>{{nomessage}}</div>
  24. </div>
  25. </div>
  26. </div>
  27. </template>
  28. <script>
  29. import * as dd from 'dingtalk-jsapi';
  30. import Loading from '@/components/Loading';
  31. import {
  32. ImagePreview
  33. } from 'vant';
  34. export default {
  35. name: 'page',
  36. data() {
  37. return {
  38. nomessage: '',
  39. vshowList: false,
  40. pdfFile: null,
  41. loading: true,
  42. curPage: 1,
  43. curPage2: 1,
  44. totals: 0,
  45. scale: 2,
  46. show: true,
  47. detailData: null,
  48. showBottom: false,
  49. timeCountId: null,
  50. }
  51. },
  52. watch: {
  53. vshowList(nval, oval) {
  54. if (oval && !nval) {
  55. this.vshowList = true;
  56. }
  57. }
  58. },
  59. created() {
  60. if (this.$route.query.path) {
  61. this.loadPdfHandler(this.$route.query.path);
  62. }
  63. if (this.$route.query.title) {
  64. this.ChangePageTitle(this.$route.query.title)
  65. }
  66. if (this.$route.query.id) {
  67. this.loading = true;
  68. this.getDetail();
  69. } else {
  70. // this.loadPdfHandler('http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf');
  71. this.loading = false;
  72. }
  73. if (dd.env.platform != 'notInDingTalk') {
  74. dd.biz.navigation.setRight({
  75. show: false, //控制按钮显示, true 显示, false 隐藏, 默认true
  76. control: false, //是否控制点击事件,true 控制,false 不控制, 默认false
  77. showIcon: false, //是否显示icon,true 显示, false 不显示,默认true; 注:具体UI以客户端为准
  78. onSuccess: () => {},
  79. onFail: function (err) {
  80. alert('dd error: ' + JSON.stringify(err));
  81. }
  82. });
  83. }
  84. },
  85. destroyed() {
  86. this.clearTimeCount();
  87. },
  88. components: {
  89. Loading,
  90. [ImagePreview.Component.name]: ImagePreview.Component,
  91. },
  92. methods: {
  93. // pdf加载时
  94. loadPdfHandler(path) {
  95. this.$nextTick(() => {
  96. this.$refs.canvas.src = path
  97. this.$refs.canvas.start();
  98. });
  99. },
  100. // 获取详情
  101. getDetail() {
  102. let self = this;
  103. this.$api.user.getDetail(this.$route.query.id, localStorage.userId || '').then((response) => {
  104. const res = response.data.data;
  105. this.loading = false;
  106. if (res.code == 0 && res.data) {
  107. this.detailData = res.data;
  108. this.vshowList = true;
  109. this.$nextTick(() => {
  110. this.showBottom = true
  111. })
  112. // let path = res.data.path || ''
  113. // self.loadPdfHandler(path);
  114. // self.loadPdfHandler("http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf");
  115. self.ChangePageTitle(res.data.fileName);
  116. } else if (res.code == 1000) { //没有查看权限
  117. this.vshowList = false;
  118. this.nomessage = res.message
  119. }
  120. }).catch(err => {
  121. console.log(err)
  122. self.loading = false;
  123. });
  124. },
  125. // 修改页面标题
  126. ChangePageTitle(title) {
  127. if (dd.env.platform != 'notInDingTalk') {
  128. dd.ready(function () {
  129. dd.biz.navigation.setTitle({
  130. title: title, //控制标题文本,空字符串表示显示默认文本
  131. onSuccess: function (result) {
  132. console.log(result);
  133. },
  134. onFail: function (err) {
  135. console.log(err);
  136. }
  137. });
  138. });
  139. } else {
  140. document.title = title
  141. }
  142. },
  143. // 缩放
  144. onScale() {
  145. document.getElementById("spinner_amount").blur();
  146. },
  147. // 关闭
  148. onClose() {
  149. document.getElementById("spinner_amount").blur();
  150. },
  151. // 页面切换
  152. onChange(val) {
  153. this.curPage = val + 1;
  154. document.getElementById("spinner_amount").blur();
  155. },
  156. // 开始输入计时
  157. startTimeCount(f) {
  158. this.clearTimeCount();
  159. this.timeCountId = setTimeout(() => {
  160. f();
  161. }, 700)
  162. },
  163. // 清除输入计时
  164. clearTimeCount() {
  165. if (this.timeCountId) {
  166. clearTimeout(this.timeCountId);
  167. this.timeCountId = null;
  168. }
  169. },
  170. // 页码输入
  171. pdfInput(e) {
  172. let value = e.target.value;
  173. if (value) {
  174. value = value.replace(/[^\d]/g, '')
  175. }
  176. this.curPage = value;
  177. this.startTimeCount(() => {
  178. if (!value) {
  179. this.jumpPage(0);
  180. } else if (parseInt(value) > parseInt(this.detailData.imageFiles.length)) {
  181. this.jumpPage(this.detailData.imageFiles.length);
  182. } else {
  183. this.jumpPage(value)
  184. }
  185. })
  186. },
  187. // 输入框失去焦点
  188. pdfInputBlur() {
  189. let spinner = document.getElementById('spinner_amount');
  190. let val = spinner.valueAsNumber
  191. if (val) {
  192. if (this.detailData.imageFiles.length < val) {
  193. val = this.detailData.imageFiles.length;
  194. spinner.valueAsNumber = this.detailData.imageFiles.length;
  195. }
  196. this.jumpPage(val);
  197. } else {
  198. spinner.valueAsNumber = this.curPage
  199. }
  200. },
  201. // 切换页面
  202. jumpPage(val) {
  203. console.log(val)
  204. if (0 < val && val <= this.detailData.imageFiles.length) {
  205. this.curPage = val;
  206. this.$refs.imagePreview.swipeTo(val - 1);
  207. }
  208. },
  209. }
  210. }
  211. </script>
  212. <style scoped>
  213. .jurisdiction {
  214. margin: 10px;
  215. margin-top: 10vh;
  216. text-align: center;
  217. font-size: 17px;
  218. color: #17a8ff;
  219. opacity: 1;
  220. }
  221. .pdf-cover-bottom {
  222. position: fixed;
  223. bottom: 0;
  224. left: 0;
  225. right: 0;
  226. background: #fff;
  227. display: flex;
  228. flex-direction: row;
  229. align-items: center;
  230. justify-content: center;
  231. padding: 20px 10px;
  232. }
  233. .pdf-barinputL {
  234. width: 40px;
  235. height: 20px;
  236. text-align: center;
  237. }
  238. .pdf-barinputR {
  239. margin-left: 5px;
  240. text-align: center;
  241. }
  242. .pdf-jump-button {
  243. position: absolute;
  244. top: 50%;
  245. right: 30px;
  246. transform: translateY(-50%);
  247. border-radius: 5px;
  248. background: #17a8ff;
  249. color: #fff;
  250. }
  251. </style>