1+ const options = {
2+ value : {
3+ algorithm : "md5" ,
4+ } ,
5+ schema : {
6+ fields : [ {
7+ type : "select" ,
8+ label : "Algorithm" ,
9+ key : "algorithm" ,
10+ items : [ {
11+ text : "MD5" ,
12+ value : "md5"
13+ } , {
14+ text : "SHA1" ,
15+ value : "sha1"
16+ } , {
17+ text : "SHA224" ,
18+ value : "sha224"
19+ } , {
20+ text : "SHA256" ,
21+ value : "sha256"
22+ } , {
23+ text : "SHA384" ,
24+ value : "sha384"
25+ } , {
26+ text : "SHA512" ,
27+ value : "sha512"
28+ } , {
29+ text : "CRC32" ,
30+ value : "crc32"
31+ } , ] ,
32+ cols : 3
33+
34+ } ]
35+
36+ }
37+ }
38+
39+
40+ module . exports = {
41+ name : 'getter' ,
42+ data ( ) {
43+ return {
44+ loading : false ,
45+ file : '' ,
46+ output : '' ,
47+ options : options . value ,
48+ schema : options . schema
49+ }
50+ } ,
51+ template : `
52+ <v-container fluid class="ma-2">
53+ <ext-loading absolute :show="loading"></ext-loading>
54+ <ext-form :model="options" :schema="schema">
55+ </ext-form>
56+ <v-row height="40" >
57+ <v-toolbar flat >
58+ <v-text-field type="text" :value="file" outline readonly label="File">
59+ <template v-slot:append-outer>
60+ <v-btn elevation="2" @click="openFile" text >Select...</v-btn>
61+ </template>
62+ </v-text-field>
63+ </v-toolbar>
64+ </v-row>
65+ <v-row>
66+ <v-col>
67+ <ext-editor v-model="output" readonly>
68+ </ext-editor>
69+ </v-col>
70+ </v-row>
71+ </v-container>
72+
73+ ` ,
74+ watch : {
75+ options : {
76+ async handler ( newValue ) {
77+ await this . invoke ( ) ;
78+ } ,
79+ deep : true ,
80+ } ,
81+ } ,
82+ methods : {
83+ async openFile ( ) {
84+ this . fileData = await this . $openFile ( 'Open file' ) ;
85+
86+ await this . invoke ( ) ;
87+ } ,
88+
89+ async invoke ( ) {
90+ if ( this . fileData ) {
91+ this . loading = true ;
92+
93+ this . file = this . fileData . file ;
94+
95+ let result ;
96+
97+ if ( this . options . algorithm === "md5"
98+ || this . options . algorithm === "sha1"
99+ || this . options . algorithm === "sha224"
100+ || this . options . algorithm === "sha256"
101+ || this . options . algorithm === "sha384"
102+ || this . options . algorithm === "sha512" ) {
103+ result = await this . $extInvoke ( 'ext.app.misc.file-hash.get' , this . fileData , this . options ) ;
104+ } else if ( this . options . algorithm === "crc32" ) {
105+ result = await this . $extInvoke ( 'ext.app.misc.file-crc32.get' , this . fileData ) ;
106+ }
107+
108+ if ( result && result . success ) {
109+ this . output = result . output ;
110+ }
111+ else {
112+ this . output = '' ;
113+ this . $store . dispatch ( "showSnackbar" , result . message ) ;
114+ }
115+
116+ this . loading = false ;
117+ } else {
118+ this . file = '' ;
119+ this . output = '' ;
120+ }
121+ }
122+
123+
124+ }
125+ }
0 commit comments