fileLook.vue 2.82 KB
<template>
	<view class="page">
		<view class="" style="width: 96%;margin: 0 auto;overflow: hidden;" v-show="!isNull">
			<view class="" style="width: 140rpx; margin: 0 auto;margin-top: 300rpx;font-size: 30rpx;">
				暂无信息
			</view>
		</view>
		<view class="" style="width: 96%;margin: 0 auto;overflow: hidden;" v-show="isNull">
			<view class="item" v-for="(it,index) in fileList" :key="index">
				<view class="fileName" style="margin-left: 30rpx; ">
					{{it.docmentName}}
				</view>
				<button @click="download(it.docmentUrl)">下载</button>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				// 用户公司ID
				companyId: '',
				// 公文列表
				fileList: [],
				isNull: false,
				baseUrl: 'http://deyanggaoxin.fengshiyun.com'
			}
		},
		onShow() {
			this.getFileList()
		},
		methods: {
			// 获取当前用户的公文
			getFileList() {
				let userInfo = uni.getStorageSync('user')
				request({
					url: '/api/Extend/basedocumenthandle/GetListByCurrentUser',
					method: 'get',
					data: {}
				}).then(res => {
					console.log(res)
					if (res.code === 200) {
						this.fileList = res.data.list
						if (this.fileList.length > 0) {
							this.isNull = true
						}
					}
				})
			},
			download(it) {
				uni.downloadFile({
						url: this.baseUrl + it,//下载地址接口返回
						success: (data) => {
							if (data.statusCode === 200) {
								//文件保存到本地
								uni.saveFile({
									tempFilePath: data.tempFilePath, //临时路径
									success: function(res) {
										uni.showToast({
											icon: 'none',
											mask: true,
											title: '文件已保存:' + res.savedFilePath, //保存路径
											duration: 3000,
										});
										setTimeout(() => {
											//打开文档查看
											uni.openDocument({
												filePath: res.savedFilePath,
												success: function(res) {
													// console.log('打开文档成功');
												}
											});
										}, 3000)
									}
								});
							}
						},
						fail: (err) => {
							that.loadelshow = false
							console.log(err);
							uni.showToast({
								icon: 'none',
								mask: true,
								title: '失败请重新下载',
							});
						},
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		width: 100%;
		height: 100vh;
		background-color: #f4f4f4;
	}
	.fileName{
		width: 400rpx;
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}
	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #ffffff;
		border-radius: 20rpx;
		height: 80rpx;
		margin-top: 30rpx;

		button {
			height: 60rpx;
			text-align: center;
			line-height: 60rpx;
			margin: 0;
			font-size: 20rpx;
			margin-right: 30rpx;
		}
	}
</style>