removed prefetch
gitea/salix/1466-print_refactor This commit looks good Details

This commit is contained in:
Joan Sanchez 2019-10-16 08:39:45 +02:00
parent 6ed5695063
commit 9e0ab17d47
2 changed files with 17 additions and 21 deletions

View File

@ -2,7 +2,6 @@ const Vue = require('vue');
const VueI18n = require('vue-i18n');
const renderer = require('vue-server-renderer').createRenderer();
const fs = require('fs-extra');
// const pdf = require('phantom-html2pdf');
const pdf = require('html-pdf');
const juice = require('juice');
@ -23,25 +22,21 @@ module.exports = {
*/
async render(name, ctx) {
const component = require(`${this.path}/${name}`);
const result = await this.preFetch(component, ctx);
const i18n = new VueI18n({
locale: 'es',
fallbackLocale: 'es',
silentTranslationWarn: true
});
const app = new Vue({i18n,
render: h => h(result.component)});
render: h => h(component)});
Vue.set(component, 'test', 'asd1');
return renderer.renderToString(app);
},
/**
* Prefetch all component data from asyncData method
*
* @param {Object} orgComponent - Component object
* @param {Object} ctx - Request context
*/
async preFetch(orgComponent, ctx) {
/* async preFetch(orgComponent, ctx) {
let component = Object.create(orgComponent);
let mergedData = {};
let asyncData = {};
@ -87,9 +82,9 @@ module.exports = {
}
return {component};
},
}, */
async attachAssets(component) {
/* async attachAssets(component) {
const localePath = `${this.path}/${component.name}/locale`;
const templatePath = `${this.path}/${component.name}/index.html`;
const stylePath = `${this.path}/${component.name}/assets/css/index`;
@ -100,7 +95,7 @@ module.exports = {
component.i18n = require(localePath);
component.template = juice.inlineContent(template, css, cssOptions);
},
}, */
async toPdf(name, ctx) {
const html = await this.render(name, ctx);

View File

@ -4,12 +4,12 @@ const UserException = require(`${appPath}/lib/exceptions/userException`);
module.exports = {
name: 'rpt-receipt',
/* serverPrefetch() {
console.log(arguments);
return new Promise(accept => {
this.client = this.getReceipt();
});
}, */
serverPrefetch() {
console.log(this.test);
/* return new Promise(accept => {
this.client = this.fetchClient();
}); */
},
async asyncData(ctx, params) {
Object.assign(this, this.methods);
@ -22,8 +22,8 @@ module.exports = {
return {client, receipt};
},
created() {
if (this.client.locale)
this.$i18n.locale = this.client.locale;
/* if (this.client.locale)
this.$i18n.locale = this.client.locale; */
const embeded = [];
this.files.map(file => {
@ -68,4 +68,5 @@ module.exports = {
'report-header': require('../report-header'),
'report-footer': require('../report-footer'),
},
template: '<div>asd</div>'
};