cnf
2025-05-15 5f0b94e9c252e507b4c09badf923796151be0d03
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
<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>