| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <template>
- <view class="box">
- <ss-preview :fileUrl="fileUrl" :fileType="fileType"></ss-preview>
- </view>
- </template>
- <script>
- export default {
- components:{},
- data() {
- return {
- fileUrl: '',
- fileType: '2',
- fileMap: {
- '1': '/static/pdf/2.pdf', //银通汽车4s管理系统
- '2': '/static/pdf/3.pdf', //银通汽车租赁管理系统
- '3': '/static/pdf/1.pdf', // 银通云越管理系统
- }
- };
- },
- onLoad(options) {
- console.log(options)
- const fileIndex = options.file || '1';
- const baseUrl = this.fileMap[fileIndex] || this.fileMap['1'];
- this.fileUrl = baseUrl + '?t=' + Date.now();
- console.log(this.fileUrl)
- this.handlePreview();
- },
- methods: {
- handlePreview() {
- //#ifdef MP-WEIXIN
- this.previewWechat(this.fileUrl);
- return;
- //#endif
-
- //#ifdef H5
- if (this.isWechat()) {
- this.clearWechatCache();
- }
- //#endif
- },
- isWechat() {
- var ua = navigator.userAgent.toLowerCase();
- return ua.indexOf('micromessenger') !== -1;
- },
- previewWechat(urlPdf) {
- uni.showLoading({ title: '加载中...' });
- uni.downloadFile({
- url: urlPdf,
- header: {
- 'Cache-Control': 'no-cache',
- 'Pragma': 'no-cache'
- },
- success: (res) => {
- if (res.statusCode === 200) {
- uni.openDocument({
- filePath: res.tempFilePath,
- fileType: 'pdf',
- showMenu: true,
- success: () => {
- console.log('打开成功');
- },
- fail: (err) => {
- console.error('打开失败:', err);
- uni.showToast({ title: '打开失败', icon: 'none' });
- }
- });
- } else {
- uni.showToast({ title: '下载失败', icon: 'none' });
- }
- },
- fail: (err) => {
- console.error('下载失败:', err);
- uni.showToast({ title: '下载失败', icon: 'none' });
- },
- complete: () => {
- uni.hideLoading();
- }
- });
- },
- clearWechatCache() {
- try {
- if (window.location.reload) {
- window.location.reload(true);
- }
- } catch (e) {
- console.log('刷新失败:', e);
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .box {
- padding: 0;
- }
- </style>
|