当前位置:   article > 正文

uni-app如何在小程序上预览pdf文件。_uniapp的在微信小程序中怎么打开pdf文件并监听是否浏览到底

uniapp的在微信小程序中怎么打开pdf文件并监听是否浏览到底
<script>
import sureItem from '../../components/contractItem/sureItem.vue'
import agreementItem from '../../components/contractItem/agreementItem.vue'

import { generatePfm2PerContractInfo, myContractPageInfo, taskConfirmPage, queryDrawTaskAuth } from '../../api/api.js'
import mixin from '@/mixin/index.js';
import noData from '../../components/noData'

export default {
	components: {
		sureItem,
		agreementItem,
		noData
	},
	mixins: [mixin],
	data() {
		return {
			activeTab: 1,
			platformAutoSignAuthStatus: '',
			personalId: uni.getStorageSync('personalId'),
			status: 'loadmore',
			item: {},
			list1: [{
				name: '任务确认单',
			}, {
				name: '合同协议',
			}],
			activeStyle: {
				// 'width': '58rpx',
				'height': '46rpx',
				'font-size': '30rpx',
				'font-family': 'PingFang SC',
				'font-weight': 600,
				'color': '#222222',
				'line-height': '46rpx'

			},
			isLogin: false,
			params: {
				current: 1,
				size: 10
			},
			total: 0,
			taskList: [],
			agreementList: [],
		}
	},
	onShow() {
		this.isLogin = uni.getStorageSync('isLogin')
		this.getUserInfo()
		this.getData()
	},
	computed: {
		count() {
			return this.activeTab == 0 ? this.taskList.length : this.agreementList.length
		}
	},
	methods: {
		getData() {
			this.activeTab == 0 ? this.getTaskList() : this.personalContractWay()
		},
		click(item) {
			this.activeTab = item.index
			this.getData()
		},
		async startSignWay(item) {
			if (!this.isLogin) return
			this.item = item
			if (!this.userInfo.isRealName) {
				//已登录没有实名的时候先去实名认证。
				this.goRenzhengWay('wx://pages/myContract/myContract')
			} else {
				this.getIsSign()
			}

		},
		async getIsSign() {
			let platformAutoSignAuthStatus = this.item.platformAutoSignAuthStatus
			if (platformAutoSignAuthStatus == 1) {
				this.goSignWay()
			}
			if (platformAutoSignAuthStatus == 0) {
				uni.showModal({
					content: '暂时无法进行签署,请联系客服' + '\r\n' + '电话:0731-84120935' + '\r\n' + '微信:19911531016',
					cancelText: "取消",
					confirmText: "预览合同",
					success: async (res) => {
						if (res.confirm) {
							let contractPath = encodeURIComponent(this.item.contractPath)
							uni.navigateTo({ url: '/pages/contractPre/contractPre?url=' + contractPath })
						}
					},
				})
			}
		},
		async goSignWay() {
			let params = {
				"personId": this.personalId,
				"platformId": this.item.platformId,
				"returnUrl": "/pages/myContract/myContract",
			}
			let res = await generatePfm2PerContractInfo(params, { custom: { auth: true } })
			let url = encodeURIComponent(res.contractSignUrl)
			uni.navigateTo({ url: '/pages/contractPre/contractPre?url=' + url })
		},
		async seeWay(item) {
			if (item.contractPath) {
				let url = encodeURIComponent(item.contractPath)
				uni.navigateTo({ url: '/pages/contractPre/contractPre?url=' + url })
			}

		},
		async getTaskList() {
			let params = {
				personalId: this.personalId,
				current: this.params.current,
				size: this.params.size,
				name: '',
			}
			let res = await taskConfirmPage({ params, custom: { auth: true } })
			this.total = res.total
			if (this.params.current == 1) {
				this.taskList = res.records
			} else {
				this.taskList = this.taskList.concat(res.records)
			}
			if (this.count >= this.total) {
				this.status = 'nomore'
			} else {
				this.status = 'loadmore'
			}
		},
		async personalContractWay() {
			let params = {
				personalId: this.personalId,
				current: this.params.current,
				size: this.params.size,
			}
			let res = await myContractPageInfo({ params, custom: { auth: true } })
			this.total = res.total
			if (this.params.current == 1) {
				this.agreementList = res.records
			} else {
				this.agreementList = this.agreementList.concat(res.records)
			}
			if (this.count >= this.total) {
				this.status = 'nomore'
			} else {
				this.status = 'loadmore'
			}
		},
		goPrePage(item) {
			if (item.taskContractPath) {
				let fileLink = item.taskContractPath
				wx.downloadFile({
					url: fileLink,
					success: function (res) {
						if (res.statusCode != 200) {
						}
						var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
						wx.openDocument({
							filePath: Path,
							showMenu: true,
							success: function (res) {
								console.log('打开成功');
							}
						})
					},
					fail: function (err) {
						console.log(err, "wx.downloadFile fail err");
					}
				})
			}
		},
		onPullDownRefresh() {
			this.params.current = 1
			this.activeTab == 0 ? this.getTaskList() : this.personalContractWay()
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			if (this.count >= this.total || this.status === 'loading') return
			this.params.current++
			this.activeTab == 0 ? this.getTaskList() : this.personalContractWay()
		},
	}
}
</script>

<template>
	<view class="col-center contract-page">
		<view class="tab-box">
			<u-tabs :list="list1" :current="activeTab" :lineColor="`url(${lineBg}) 100% 100%`"
				itemStyle="width:230rpx;  height: 34px;" :activeStyle="activeStyle" @click="click"></u-tabs>
		</view>
		<view class="list-content" v-if="activeTab == 0">
			<view v-for="(item, index) in taskList" :key="index">
				<sureItem :item="item" @goDetail="goPrePage"></sureItem>
			</view>
			<u-loadmore v-if="taskList.length > 0" :status="status" />
			<noData v-if="taskList.length == 0"></noData>
		</view>
		<view class="list-content col-center" v-if="activeTab == 1">
			<view v-for="item in agreementList" :key="item.id">
				<agreementItem :item="item" @goSeeDetail="seeWay" @goDetail.stop="startSignWay()"></agreementItem>
			</view>
			<u-loadmore v-if="agreementList.length > 0" :status="status" />
			<noData v-if="agreementList.length == 0"></noData>

		</view>


	</view>
</template>

<style lang="scss" scoped>
.contract-page {
	.tab-box {
		box-sizing: border-box;
		width: 750rpx;
		height: 80rpx;
		// border: solid 1px red;
		background-color: #fff;


	}

	.list-content {
		box-sizing: border-box;
		width: 750rpx;
		margin-top: 10rpx;
		// border: pink solid 1px;
	}
}
</style>



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235
  • 236
  • 237

只兼容小程序的时候,只需要用wx自带的下载文件,然后打开文件即可。不用使用pdf.js工具
那个工具有兼容问题,还有跨越问题,可能还要后端配置文件流输出的问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/997633
推荐阅读