1
jhzh
2026-01-14 fa821ce7a7755dd0e13897cefc57071d4596431b
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>
  <div class="wrapper">
    <div class="header">
      <mt-header :title="$t('jy220')">
        <router-link to="" slot="left">
          <mt-button @click="goBack" icon="back"></mt-button>
        </router-link>
      </mt-header>
    </div>
    <div class="agreement-content">
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner"></div>
        <p>加载中...</p>
      </div>
      <div v-else-if="error" class="error-container">
        <p>{{ error }}</p>
        <button @click="loadPdf" class="retry-btn">重试</button>
      </div>
      <div v-else class="pdf-wrapper">
        <ImageViewer :imageUrls="imageUrls" v-if="imageUrls && imageUrls.length > 0" />
      </div>
    </div>
  </div>
</template>
<script>
import * as api from '@/axios/api'
import ImageViewer from '@/components/ImageViewer.vue'
 
export default {
  components: {
    ImageViewer
  },
  data () {
    return {
      loading: true,
      error: null,
      imageUrls: []
    }
  },
  mounted () {
    this.loadPdf()
  },
  methods: {
    goBack () {
      this.$router.back(-1)
    },
    async loadPdf () {
      this.loading = true
      this.error = null
      try {
        const result = await api.viewAgreementPdf()
        if (result.status === 0) {
          // result.data 现在是图片数组
          if (Array.isArray(result.data) && result.data.length > 0) {
            const APIUrl = require('@/axios/api.url').default
            this.imageUrls = result.data.map(url => {
              if (!url.startsWith('http')) {
                return APIUrl.baseURL + (url.startsWith('/') ? url : '/' + url)
              }
              return url
            })
            this.loading = false
          } else {
            this.error = '未返回图片数据'
            this.loading = false
          }
        } else {
          this.error = result.msg || '加载合同失败'
          this.loading = false
        }
      } catch (e) {
        console.error('加载PDF失败:', e)
        this.error = e.message || '加载失败,请稍后重试'
        this.loading = false
      }
    }
  }
}
</script>
<style lang="css" scoped>
.wrapper {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}
 
.header {
  flex-shrink: 0;
}
 
.agreement-content {
  flex: 1;
  overflow: hidden;
  position: relative;
}
 
.loading-container,
.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #666;
}
 
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid #f11514;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 15px;
}
 
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
 
.error-container {
  color: #f56c6c;
  padding: 20px;
  text-align: center;
}
 
.retry-btn {
  margin-top: 15px;
  padding: 10px 20px;
  background: linear-gradient(-55deg, rgb(241, 22, 20), rgb(240, 40, 37));
  color: #fff;
  border: none;
  border-radius: 5px;
  font-size: 14px;
  cursor: pointer;
}
 
.pdf-wrapper {
  height: 100%;
  width: 100%;
}
</style>