<template>
|
<view class="file-list">
|
<view v-if="loading" class="loading-text">加载中...</view>
|
<view v-else>
|
<view v-for="(item, index) in fileList" :key="index" class="file-item" @click="openFile(item)">
|
<text class="file-name">{{ item.name }}</text>
|
<text class="file-type">{{ item.type.toUpperCase() }}</text>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import { type } from 'os'
|
export default {
|
data() {
|
return {
|
fileList: [{
|
name:this.parseFileName("http://yida-vpc-imm-online.oss-cn-shanghai.aliyuncs.com/3797b875-e59e-4fce-aab8-1dc96ddb7371.xls?Expires=1742470114&OSSAccessKeyId=LTAI4Fd2B26zpQ9s9zu6zd7C&Signature=QYlEZnF71noA%2BWNCHeLCf%2Fm0bjc%3D"),
|
url:"http://yida-vpc-imm-online.oss-cn-shanghai.aliyuncs.com/3797b875-e59e-4fce-aab8-1dc96ddb7371.xls?Expires=1742470114&OSSAccessKeyId=LTAI4Fd2B26zpQ9s9zu6zd7C&Signature=QYlEZnF71noA%2BWNCHeLCf%2Fm0bjc%3D",
|
type:this.getFileType("http://yida-vpc-imm-online.oss-cn-shanghai.aliyuncs.com/3797b875-e59e-4fce-aab8-1dc96ddb7371.xls?Expires=1742470114&OSSAccessKeyId=LTAI4Fd2B26zpQ9s9zu6zd7C&Signature=QYlEZnF71noA%2BWNCHeLCf%2Fm0bjc%3D")
|
}],
|
loading: false
|
}
|
},
|
created() {
|
// this.fetchFileList()
|
},
|
methods: {
|
// async fetchFileList() {
|
// try {
|
// this.loading = true
|
// this.$post({
|
// url: "/LLJ/GetFileUrlByU9List",
|
// data: {
|
// u9No: this.u9No,
|
// type: this.type
|
// }
|
// }).then(res => {
|
// this.fileList = res.data.map(url => ({
|
// name: this.parseFileName(url),
|
// url: url,
|
// type: this.getFileType(url)
|
// }))
|
// })
|
// } catch (e) {
|
// uni.showToast({
|
// title: '加载失败',
|
// icon: 'none'
|
// })
|
// } finally {
|
// this.loading = false
|
// }
|
// },
|
|
parseFileName(url) {
|
const filename = url.split('/').pop()
|
return filename.split('.')[0]
|
},
|
|
getFileType(url) {
|
const ext = url.split('.').pop().toLowerCase()
|
return ext === 'pdf' ? 'pdf' : ['jpg', 'jpeg', 'png'].includes(ext) ? 'image' : 'other'
|
},
|
|
async openFile(file) {
|
try {
|
uni.showLoading({
|
title: '打开中...'
|
})
|
|
if (file.type === 'pdf') {
|
const {
|
tempFilePath
|
} = await uni.downloadFile({
|
url: file.url
|
})
|
uni.openDocument({
|
filePath: tempFilePath
|
})
|
} else if (file.type === 'image') {
|
uni.previewImage({
|
urls: [file.url]
|
})
|
}
|
|
} catch (e) {
|
uni.showToast({
|
title: '打开失败',
|
icon: 'none'
|
})
|
} finally {
|
uni.hideLoading()
|
}
|
}
|
},
|
onLoad(options) {
|
//options中包含了url附带的参数
|
let params = options;
|
|
this.u9No = params["itemID"];
|
this.type = params["type"];
|
|
}
|
}
|
</script>
|
|
<style scoped>
|
.file-list {
|
padding: 20rpx;
|
}
|
|
.file-item {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 24rpx;
|
margin: 16rpx 0;
|
background: #fff;
|
border-radius: 12rpx;
|
box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
|
}
|
|
.file-name {
|
font-size: 28rpx;
|
color: #333;
|
flex: 1;
|
}
|
|
.file-type {
|
font-size: 24rpx;
|
color: #666;
|
padding: 8rpx 16rpx;
|
background: #f0f2f5;
|
border-radius: 8rpx;
|
margin-left: 20rpx;
|
}
|
|
.loading-text {
|
text-align: center;
|
padding: 20rpx;
|
color: #666;
|
}
|
</style>
|