Blame view

pages/fileLook/fileLook.vue 2.82 KB
290144e9   易尊强   第一次
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
  <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>