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

View File

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