123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <template>
- <div id="saga-upload">
- <div id="uploadFile">
- <div v-if="item && filesArr.length" v-for="(item,index) in filesArr">
- <el-button type="text" @click="download(item)">{{delFile(item)}}</el-button>
- <i
- v-if="!readOnly"
- class="el-icon-close delete-icon"
- style="margin-left:10px; cursor:pointer"
- @click="deleteFile(index,item)"
- ></i>
- </div>
- <el-upload
- v-if="filesArr.length < max"
- class="upload-file"
- action
- :http-request="uploadAndSubmit"
- :show-file-list="false"
- drag
- >
- <el-button size="small" type="primary" v-if="!readOnly">点击上传</el-button>
- <div slot="tip" class="el-upload__tip" v-if="!readOnly">请上传文件</div>
- </el-upload>
- </div>
- </div>
- </template>
- <script>
- import tools from "@/utils/scan/tools";
- export default {
- props: {
- keysArr: {
- type: [Array, String],
- default: function () {
- return []
- }
- },
- readOnly: {
- type: Boolean,
- default: false
- },
- max: {
- type: [Number, String],
- default: 6
- },
- defined: null
- },
- data() {
- return {
- filesArr: []
- };
- },
- created() {
- let type = typeof (this.keysArr)
- this.fileFalg()
- },
- methods: {
-
- fileFalg() {
- let type = typeof (this.keysArr)
- console.log(this.keysArr, "keysAee")
- if (type == 'string') {
- this.filesArr = [this.keysArr]
- } else {
- this.filesArr = tools.deepCopy(this.keysArr)
- }
- if (!this.keysArr) {
- this.filesArr = []
- }
- },
-
- delFile(name) {
- console.log(name, "name")
- return name.length > 20 ? name.substring(0, 20) + "..." : ""
- },
- resetFile() {
- this.filesArr = []
- },
-
- download(key) {
- console.log(key)
- window.open("/image-service/common/file_get/" + key + "?systemId=dataPlatform")
- },
-
- deleteFile(i, key) {
- this.filesArr.splice(i, 1);
- this.$emit("change", this.filesArr, this.defined);
- },
-
- uploadAndSubmit(item) {
-
-
-
-
- let file = item.file;
-
- let reader = new FileReader();
- let vm = this;
- let fileType = file.name.split(".");
- let type = fileType[fileType.length - 1];
- let key = "&key=" + fileType[0] + file.uid + "." + type
- reader.onloadstart = function () {
-
- };
- reader.onprogress = function (p) {
-
- };
- reader.onload = function () {
-
- };
- reader.onloadend = function () {
-
- if (reader.error) {
- } else {
-
-
- var xhr = new XMLHttpRequest();
- xhr.open(
-
- "POST",
-
- "/img/image-service/common/file_upload?systemId=dataPlatform&secret=9e0891a7a8c8e885&overwrite=true" + key
-
- );
-
- xhr.send(reader.result);
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4) {
- console.log(xhr)
- if (xhr.status == 200) {
- vm.filesArr.push(
- key.split("=")[1]
- );
- console.log(vm.filesArr)
- vm.$emit("change", vm.filesArr, vm.defined);
- } else {
- this.$message.error(res.data.ResultMsg)
- }
- }
- };
- }
- };
- reader.readAsArrayBuffer(file);
- }
- },
- watch: {
- keysArr: function (val) {
- this.fileFalg()
- }
- }
- };
- </script>
- <style lang="less">
- #saga-upload {
- .dill-image {
- position: absolute;
- right: 0px;
- top: 0px;
- font-size: 20px;
- }
- .el-upload-dragger {
- width: 180px;
- height: 180px;
- }
- img {
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- width: 100%;
- height: 100%;
- }
- #uploadFile {
- .upload-file {
- overflow: hidden;
- .el-upload-dragger {
- width: inherit;
- height: inherit;
- border: none;
- }
- }
- }
- }
- </style>
|