66 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Python
		
	
	
	
<template>
 | 
						||
	<uni-list>
 | 
						||
		<uni-list-item :title="item.name" :note="item.description" :thumb="getThumb(item.file_.mime)" thumb-size="lg"
 | 
						||
			rightText="点击下载" v-for="item in dataList" :key="item.id" @click="down(item.file_.file)" link></uni-list-item>
 | 
						||
	</uni-list>
 | 
						||
</template>
 | 
						||
 | 
						||
<script>
 | 
						||
	export default {
 | 
						||
		data() {
 | 
						||
			return {
 | 
						||
				dataList: []
 | 
						||
			}
 | 
						||
		},
 | 
						||
		onLoad() {
 | 
						||
			this.$u.api.getDocument({
 | 
						||
				pageoff: true
 | 
						||
			}).then(res => {
 | 
						||
				this.dataList = res.data
 | 
						||
			})
 | 
						||
 | 
						||
		},
 | 
						||
		methods: {
 | 
						||
			getThumb(name) {
 | 
						||
				if (name.indexOf('word') != -1) {
 | 
						||
					return '/static/common/word.svg'
 | 
						||
				} else if (name.indexOf('pdf') != -1) {
 | 
						||
					return '/static/common/pdf.svg'
 | 
						||
				} else if (name.indexOf('sheet') != -1) {
 | 
						||
					return '/static/common/excel.svg'
 | 
						||
				} else if (name.indexOf('ppt') != -1) {
 | 
						||
					return '/static/common/ppt.svg'
 | 
						||
				}
 | 
						||
 | 
						||
			},
 | 
						||
			down(file) {
 | 
						||
				// console.log(file)
 | 
						||
				uni.showLoading({
 | 
						||
					title: '下载中'
 | 
						||
				})
 | 
						||
				uni.downloadFile({
 | 
						||
					url: file + '?token=' + this.vuex_token, //仅为示例,并非真实的资源
 | 
						||
					success: (res) => {
 | 
						||
						uni.showLoading({
 | 
						||
							title:'正在打开'
 | 
						||
						})
 | 
						||
						var filePath = res.tempFilePath;
 | 
						||
						    uni.openDocument({
 | 
						||
						      filePath: filePath,
 | 
						||
						      success: function (res) {
 | 
						||
						        uni.hideLoading()
 | 
						||
						      },
 | 
						||
							  fail() {
 | 
						||
							  	uni.hideLoading()
 | 
						||
							  }
 | 
						||
						    });
 | 
						||
					},
 | 
						||
					fail() {
 | 
						||
						uni.hideLoading()
 | 
						||
					}
 | 
						||
				});
 | 
						||
			}
 | 
						||
		}
 | 
						||
	}
 | 
						||
</script>
 |