| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <template>
- <div>
- <div @click="detail">
- <slot name="title">
- <el-button type="primary" text>查看</el-button>
- </slot>
- </div>
- <el-image-viewer
- v-if="showImage"
- :url-list="preList"
- @close="showImage = false"
- />
- <el-drawer v-model="show" :size="1200">
- <template #title>
- <h4
- class="ml-20 black flex flex-center flex-justify-start full-width font-16 bold"
- >
- {{ data ? data.title : '' }}
- </h4>
- </template>
- <div>
- <div v-if="data">
- <div v-if="data.imgs.length === 0" class="flex flex-center">
- <div v-html="data.content" class="preview"></div>
- </div>
- <div v-else v-for="item in data.imgs" :key="item.id">
- <img :src="item.filePath" style="width: 1100px" />
- </div>
- </div>
- <div
- class="bottom flex flex-center flex-justify-center"
- v-if="isAccess === 2 || showAction"
- >
- <el-button type="primary" icon="Download" @click="downloadClick"
- >下 载
- </el-button>
- <share
- class="ml-20"
- :project-id="projectId"
- :ids="id"
- v-if="isAccess === 2"
- />
- </div>
- </div>
- </el-drawer>
- </div>
- </template>
- <script>
- import api from '@/api/index.js'
- import share from '@/views/resource/component/share.vue'
- export default {
- components: {
- share
- },
- props: {
- title: {
- type: String,
- default: () => {
- return ''
- }
- },
- isAccess: {
- type: Number,
- default: 3
- },
- showAction: {
- type: Boolean,
- default: false
- },
- projectId: {
- type: String,
- default: ''
- },
- id: {
- type: String,
- default: null
- }
- },
- data() {
- return {
- show: false,
- data: null,
- preList: [],
- showImage: false,
- watermarkOptions: {
- content: 'watermark',
- gap: [20, 20],
- offset: [10, 10],
- zIndex: 5,
- rotate: -20
- }
- }
- },
- methods: {
- detail() {
- if (Number(this.id, 10).toString() === 'NaN') {
- console.log('yyyy')
- // 如果id 不是数字开头,即mongo 62开头的id,查看文章详情
- this.$api.resource.fileDetail(this.id).then(res => {
- if (res.code === 200) {
- this.data = res.data
- this.show = true
- }
- })
- } else {
- this.$api.resource.fileInfo({ id: this.id }).then(res => {
- if (res.code === 200) {
- const tmp = res.data
- if (api.offices.includes(tmp.suffix)) {
- this.openByFile()
- } else {
- this.preList.length = 0
- this.preList.push(tmp.filePath)
- this.showImage = true
- }
- }
- })
- }
- },
- openByFile() {
- this.$api.resource.fileDetailByFile(this.id).then(res => {
- if (res.code === 200) {
- this.data = res.data
- this.show = true
- }
- })
- },
- async downloadClick() {
- const link = document.createElement('a')
- link.href = this.data.url
- link.download = this.data.title
- link.click()
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .preview {
- width: 960px;
- padding: 20px;
- }
- .bottom {
- position: fixed;
- bottom: 0;
- box-shadow: -2px 0px 2px rgba(0, 0, 0, 0.1);
- background-color: white;
- height: 30px;
- padding: 10px;
- width: 1200px;
- border: #e6e8ed solid 1px;
- }
- :deep(.el-drawer__body) {
- padding: 0;
- }
- </style>
|