mirror of
https://github.com/mokuappio/serverless-invoices.git
synced 2025-10-29 08:51:07 -04:00
Be able to embed logo (base64)
This commit is contained in:
@ -46,9 +46,9 @@ export default {
|
|||||||
close() {
|
close() {
|
||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
},
|
},
|
||||||
onSelected(content) {
|
onSelected(payload) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(content);
|
const data = JSON.parse(payload.content);
|
||||||
|
|
||||||
this.$store.dispatch('data/importJson', data);
|
this.$store.dispatch('data/importJson', data);
|
||||||
this.close();
|
this.close();
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
<label :for="inputRef" class="btn btn-sm btn-link pointer mb-0">
|
<label :for="inputRef" class="btn btn-sm btn-link pointer mb-0">
|
||||||
<i class="material-icons md-18 mr-2 va-tt">cloud_upload</i>{{ buttonText }}
|
<i class="material-icons md-18 mr-2 va-tt">cloud_upload</i>{{ buttonText }}
|
||||||
</label>
|
</label>
|
||||||
<input v-if="ready" class="d-none" type="file" :id="inputRef" :ref="inputRef" @change="handleFileUpload()"/>
|
<input v-if="ready" class="d-none" :accept="accept" type="file" :id="inputRef" :ref="inputRef"
|
||||||
|
@change="handleFileUpload()"/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -15,6 +16,10 @@ export default {
|
|||||||
buttonText: {
|
buttonText: {
|
||||||
default: 'Select file',
|
default: 'Select file',
|
||||||
},
|
},
|
||||||
|
outputType: {
|
||||||
|
default: 'text',
|
||||||
|
},
|
||||||
|
accept: {},
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -28,10 +33,18 @@ export default {
|
|||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = (e) => {
|
reader.onload = (e) => {
|
||||||
this.$emit('selected', e.target.result);
|
this.$emit('selected', {
|
||||||
|
content: e.target.result,
|
||||||
|
mime: file.type,
|
||||||
|
size: file.size,
|
||||||
|
});
|
||||||
this.reset();
|
this.reset();
|
||||||
};
|
};
|
||||||
|
if (this.outputType === 'text') {
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
} else if (this.outputType === 'base64') {
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
reset() {
|
reset() {
|
||||||
this.ready = false;
|
this.ready = false;
|
||||||
|
|||||||
@ -6,10 +6,14 @@
|
|||||||
<img v-if="team.logo_url"
|
<img v-if="team.logo_url"
|
||||||
v-b-modal.team_logo_url
|
v-b-modal.team_logo_url
|
||||||
:src="team.logo_url" style="width:100%; max-width:200px;">
|
:src="team.logo_url" style="width:100%; max-width:200px;">
|
||||||
<button class="btn btn-sm" v-b-modal.team_logo_url v-else>
|
<AppFileInput :class="{'text-muted': !!team.logo_url }"
|
||||||
|
accept="image/*"
|
||||||
|
class="d-print-none" @selected="logoSelected"
|
||||||
|
button-text="Select logo" output-type="base64"/>
|
||||||
|
<!--<button class="btn btn-sm" v-b-modal.team_logo_url v-else>
|
||||||
<i class="material-icons material-icons-round md-36">file_upload</i>
|
<i class="material-icons material-icons-round md-36">file_upload</i>
|
||||||
</button>
|
</button>-->
|
||||||
<AppError :errors="errors" field="team.logos"/>
|
<AppError :errors="errors" field="logo_url"/>
|
||||||
</div>
|
</div>
|
||||||
<InvoiceHeader :invoice="invoice" :errors="errors" @update="updateProp"
|
<InvoiceHeader :invoice="invoice" :errors="errors" @update="updateProp"
|
||||||
class="col-8 text-right mb-2"/>
|
class="col-8 text-right mb-2"/>
|
||||||
@ -88,12 +92,14 @@ import AppEditable from '@/components/form/AppEditable';
|
|||||||
import AppError from '@/components/form/AppError';
|
import AppError from '@/components/form/AppError';
|
||||||
import { BModal, VBModal } from 'bootstrap-vue';
|
import { BModal, VBModal } from 'bootstrap-vue';
|
||||||
import AppInput from '@/components/form/AppInput';
|
import AppInput from '@/components/form/AppInput';
|
||||||
|
import AppFileInput from '@/components/form/AppFileInput';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
directives: {
|
directives: {
|
||||||
'b-modal': VBModal,
|
'b-modal': VBModal,
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
AppFileInput,
|
||||||
InvoiceTotals,
|
InvoiceTotals,
|
||||||
InvoiceHeader,
|
InvoiceHeader,
|
||||||
InvoiceContactDetails,
|
InvoiceContactDetails,
|
||||||
@ -136,6 +142,13 @@ export default {
|
|||||||
updateTeam(props) {
|
updateTeam(props) {
|
||||||
this.$store.dispatch('teams/updateTeam', props);
|
this.$store.dispatch('teams/updateTeam', props);
|
||||||
},
|
},
|
||||||
|
logoSelected(payload) {
|
||||||
|
this.errors.clear();
|
||||||
|
if (payload.size / 1000 > 512) {
|
||||||
|
return this.errors.set({ logo_url: ['Logo has to be under 512kb.'] });
|
||||||
|
}
|
||||||
|
this.updateTeam({ logo_url: payload.content });
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user