forked from syncfusion/ej2-vue-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-upload.vue
139 lines (131 loc) · 5.45 KB
/
file-upload.vue
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
<template>
<div>
<div class="control-section file-upload">
<div id='uploadFileManager' class="fileupload">
<ejs-uploader ref="uploadObj" id='defaultfileupload' name="UploadFiles">
</ejs-uploader>
<ejs-button id="openBtn" v-on:click.native="btnClick">File Browser</ejs-button>
</div>
<div id='target' class="control-section">
<ejs-dialog ref="uploadDialog" id="dialog" v-bind:visible="false" :header='dialogHeader' :animationSettings='animationSettings' :showCloseIcon='showCloseIcon' :open="dialogOpen" :close="dialogClose" :target='target'
:width='dialogWidth'>
<ejs-filemanager id="filemanager" :ajaxSettings='ajaxSettings' :contextMenuSettings="contextMenuSettings" :toolbarSettings="toolbarSettings" v-bind:allowMultiSelection="false" :fileOpen="onFileOpen" >
</ejs-filemanager>
</ejs-dialog>
</div>
</div>
<div id="action-description">
<p>This sample demonstrates the real-time use case of File Manager in a web application. Dialog and Uploader components are integrated with the File Manager. Click the browse button in the Uploader element to open the File Manager inside the Dialog control. </p>
</div>
<div id="description">
<p>
The <b>File Manager</b> component is used to explore a file system through a web application, similar to the windows explorer for windows. It supports all the basic file operations such as create, rename, delete, refresh and so on.
</p>
<p>
<b>Note: </b>File Manager's upload functionality is restricted in the online demo. If you need to test upload functionality, please install
<a target="_blank" href="https://www.syncfusion.com/downloads"> Syncfusion Essential Studio </a>on your machine and run the demo.
</p>
</div>
</div>
</template>
<style>
.file-upload .fileupload {
max-width: 500px;
margin: auto;
}
.file-upload #openBtn {
position: absolute;
top: 34px;
left: 43%;
}
.file-upload #target {
height: 550px;
}
.file-upload #dialog {
top: 20px !important;
max-height: 500px !important;
left: 30px !important;
}
.file-upload #uploadFileManager .e-file-drop, .file-upload #uploadFileManager .e-css.e-btn {
display: none;
}
.tailwind #openBtn,
.tailwind-dark #openBtn {
top: 28px;
}
.bootstrap5 #openBtn,
.bootstrap5-dark #openBtn {
top: 26px;
}
.bootstrap #openBtn,
.bootstrap-dark #openBtn {
top: 30px;
}
</style>
<script>
import Vue from "vue";
import { UploaderPlugin } from '@syncfusion/ej2-vue-inputs';
import { ButtonPlugin } from "@syncfusion/ej2-vue-buttons";
import { DialogPlugin } from '@syncfusion/ej2-vue-popups';
import { FileManagerPlugin, NavigationPane, Toolbar, DetailsView, FileManagerComponent } from "@syncfusion/ej2-vue-filemanager";
Vue.use(FileManagerPlugin);
Vue.use(DialogPlugin);
Vue.use(UploaderPlugin);
Vue.use(ButtonPlugin);
/**
* File Manager real time use case sample
*/
let hostUrl = 'https://ej2-aspcore-service.azurewebsites.net/';
let contextmenuItems = ['Open', '|', 'Cut', 'Copy', 'Delete', 'Rename', '|', 'Details'];
export default Vue.extend({
data: function(){
return {
dialogHeader: 'Select a file',
showCloseIcon: true,
target: '#target',
animationSettings: { effect: 'None' },
dialogWidth: '850px',
ajaxSettings: {
url: hostUrl + 'api/FileManager/FileOperations',
getImageUrl: hostUrl + 'api/FileManager/GetImage',
uploadUrl: hostUrl + 'api/FileManager/Upload',
downloadUrl: hostUrl + 'api/FileManager/Download'
},
toolbarSettings: {items: ["NewFolder", "Upload", 'Cut', 'Copy', "Delete", "Rename", "SortBy", "Refresh", "Selection", "View", "Details"]},
contextMenuSettings: {
file: this.contextmenuItems,
folder: this.contextmenuItems
}
}
},
provide: {
filemanager: [NavigationPane, DetailsView, Toolbar]
},
methods:{
btnClick: function(event) {
this.$refs.uploadDialog.show();
let fileObj = document.getElementById('filemanager').ej2_instances[0];
fileObj.path = "/";
fileObj.selectedItems = [];
fileObj.refresh();
},
// Uploader will be hidden, if Dialog is opened
dialogOpen: function() {
document.getElementById('uploadFileManager').style.display = 'none';
},
// Uploader will be shown, if Dialog is closed
dialogClose: function() {
document.getElementById('uploadFileManager').style.display = 'block';
},
// File Manager's fileOpen event function
onFileOpen: function(args) {
let file = args.fileDetails;
if (file.isFile) {
args.cancel = true;
this.$refs.uploadObj.files = [{name: file.name, size: file.size, type: file.type }];
this.$refs.uploadDialog.hide();
}
}
}
});
</script>