index.vue 7.4 KB

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