Blame view

ant-design-vue-jeecg/src/components/jeecg/minipop/JFilePop.vue 2.2 KB
肖超群 authored
1
2
3
4
5
6
7
8
9
10
<template>
  <div>
    <a-modal
      :title="fileType === 'image' ? '图片上传' : '文件上传'"
      :width="width"
      :visible="visible"
      @ok="ok"
      cancelText="取消"
      @cancel="close">
      <!--style="top: 20px;"-->
肖超群 authored
11
12
      <j-upload :file-type="fileType" :value="filePath" @change="handleChange" :disabled="disabled"
                :number="number"></j-upload>
肖超群 authored
13
14
15
16
17
    </a-modal>
  </div>
</template>

<script>
肖超群 authored
18
import {getFileAccessHttpUrl} from '@/api/manage';
肖超群 authored
19
肖超群 authored
20
21
22
23
const getFileName = (path) => {
  if (path.lastIndexOf("\\") >= 0) {
    let reg = new RegExp("\\\\", "g");
    path = path.replace(reg, "/");
肖超群 authored
24
  }
肖超群 authored
25
26
  return path.substring(path.lastIndexOf("/") + 1);
}
肖超群 authored
27
肖超群 authored
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
export default {
  name: 'JFilePop',
  components: {},
  props: {
    title: {
      type: String,
      default: '',
      required: false
    },
    position: {
      type: String,
      default: 'right',
      required: false
    },
    height: {
      type: Number,
      default: 200,
      required: false
    },
    width: {
      type: Number,
      default: 520,
      required: false
    },
肖超群 authored
52
肖超群 authored
53
54
55
56
57
58
59
60
61
    popContainer: {
      type: String,
      default: '',
      required: false
    },
    disabled: {
      type: Boolean,
      default: false,
      required: false
肖超群 authored
62
    },
肖超群 authored
63
64
65
66
67
68
69
70
71
72
73
74
    number: {
      type: Number,
      required: false,
      default: 0
    }
  },
  data() {
    return {
      visible: false,
      filePath: '',
      id: '',
      fileType: 'file'
肖超群 authored
75
肖超群 authored
76
77
78
79
80
    }
  },
  methods: {
    handleChange(value) {
      this.filePath = value;
肖超群 authored
81
    },
肖超群 authored
82
83
84
85
86
87
88
89
90
    show(id, value, flag) {
      this.id = id;
      this.filePath = value;
      this.visible = true
      if (flag === 'img') {
        this.fileType = 'image'
      } else {
        this.fileType = 'file'
      }
肖超群 authored
91
肖超群 authored
92
93
94
95
96
97
98
99
100
101
102
103
104
    },
    ok() {
      if (!this.filePath) {
        this.$message.error("未上传任何文件")
        return false;
      }
      let arr = this.filePath.split(",")
      let obj = {
        name: getFileName(arr[0]),
        url: getFileAccessHttpUrl(arr[0]),
        path: this.filePath,
        status: 'done',
        id: this.id
肖超群 authored
105
      }
肖超群 authored
106
107
108
109
110
      this.$emit('ok', obj)
      this.visible = false
    },
    close() {
      this.visible = false
肖超群 authored
111
112
    }
  }
肖超群 authored
113
}
肖超群 authored
114
115
116
117
118
</script>

<style scoped>

</style>