@rocketsearch/nuxt-uappi 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -13,4 +13,7 @@ modules: [
|
|
|
13
13
|
]
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
+
Landing page ("Personalizado" no painel): `<RocketLanding>` mostra todas as vitrines da landing, na ordem do
|
|
17
|
+
painel. O identificador vem do nome da rota (`/black-friday` → `black-friday`) ou de `custom-key="..."`.
|
|
18
|
+
|
|
16
19
|
Documentação completa: https://api.rocketsearch.com.br/sdk/uappi/docs.html
|
package/package.json
CHANGED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<!-- Vue 2 exige um elemento raiz: display: contents faz as vitrines herdarem o espaçamento do container do tema. -->
|
|
3
|
+
<div v-if="showcases.length" class="rocket-search-landing" style="display: contents">
|
|
4
|
+
<RocketShowcase
|
|
5
|
+
v-for="showcase in showcases"
|
|
6
|
+
:key="showcase.id"
|
|
7
|
+
page-type="custom"
|
|
8
|
+
:custom-key="key"
|
|
9
|
+
:showcase-id="showcase.id"
|
|
10
|
+
:position="(showcase.placement && showcase.placement.position) || 'middle'"
|
|
11
|
+
:media-size="mediaSize"
|
|
12
|
+
>
|
|
13
|
+
<template v-if="$scopedSlots.default" #default="scope">
|
|
14
|
+
<slot v-bind="scope" />
|
|
15
|
+
</template>
|
|
16
|
+
<template v-if="$scopedSlots.product" #product="scope">
|
|
17
|
+
<slot name="product" v-bind="scope" />
|
|
18
|
+
</template>
|
|
19
|
+
</RocketShowcase>
|
|
20
|
+
</div>
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<script>
|
|
24
|
+
import RocketShowcase from './RocketShowcase.vue';
|
|
25
|
+
|
|
26
|
+
// Landing page ("Personalizado" no painel): todas as vitrines da landing, empilhadas pela ordem
|
|
27
|
+
// do painel (a API já responde por display_order).
|
|
28
|
+
export default {
|
|
29
|
+
name: 'RocketLanding',
|
|
30
|
+
components: { RocketShowcase },
|
|
31
|
+
props: {
|
|
32
|
+
// Identificador da landing no painel; sem ele, o nome da rota (/black-friday -> black-friday).
|
|
33
|
+
customKey: { type: String, default: '' },
|
|
34
|
+
mediaSize: { type: String, default: 'medium' }
|
|
35
|
+
},
|
|
36
|
+
data () {
|
|
37
|
+
return { showcases: [] };
|
|
38
|
+
},
|
|
39
|
+
computed: {
|
|
40
|
+
key () {
|
|
41
|
+
if (this.customKey) return this.customKey;
|
|
42
|
+
return ((this.$route && this.$route.path) || '').split('/').filter(Boolean).pop() || '';
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
watch: {
|
|
46
|
+
key: 'load'
|
|
47
|
+
},
|
|
48
|
+
mounted () {
|
|
49
|
+
this.load();
|
|
50
|
+
},
|
|
51
|
+
methods: {
|
|
52
|
+
async load () {
|
|
53
|
+
const key = this.key;
|
|
54
|
+
const showcases = key ? await this.$rocket.getPageShowcases('custom', key, true) : [];
|
|
55
|
+
// Troca rápida de rota: a resposta da landing anterior não sobrescreve a atual.
|
|
56
|
+
if (key === this.key) this.showcases = showcases;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
</script>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div
|
|
3
|
-
v-if="showcase || loading || debug"
|
|
4
|
-
:class="['rocket-search', { 'rocket-search--empty': !showcase && !loading }]"
|
|
5
|
-
:data-rocket-showcase-position="position"
|
|
3
|
+
v-if="showcase || loading || debug || restIds.length"
|
|
4
|
+
:class="['rocket-search', { 'rocket-search--empty': !showcase && !loading && !restIds.length, 'rocket-search--stacked': stacked }]"
|
|
5
|
+
:data-rocket-showcase-position="stacked ? null : position"
|
|
6
6
|
>
|
|
7
7
|
<div v-if="loading" class="rocket-search__showcase rocket-search__showcase--skeleton" :style="columnsStyle">
|
|
8
8
|
<div class="rocket-search__showcase__title rocket-search__product-placeholder__item" />
|
|
@@ -47,6 +47,26 @@
|
|
|
47
47
|
<button type="button" class="rocket-search__swiper-button-next" aria-label="Próximos" @click="slide(1)" />
|
|
48
48
|
</slot>
|
|
49
49
|
</section>
|
|
50
|
+
|
|
51
|
+
<!-- Demais vitrines da mesma posição, na ordem da API: cada uma medida por conta própria. -->
|
|
52
|
+
<RocketShowcase
|
|
53
|
+
v-for="id in restIds"
|
|
54
|
+
:key="id"
|
|
55
|
+
:position="position"
|
|
56
|
+
:page-type="pageType"
|
|
57
|
+
:custom-key="customKey"
|
|
58
|
+
:showcase-id="id"
|
|
59
|
+
:media-size="mediaSize"
|
|
60
|
+
stacked
|
|
61
|
+
@products-loaded="$emit('products-loaded', $event)"
|
|
62
|
+
>
|
|
63
|
+
<template v-if="$scopedSlots.default" #default="scope">
|
|
64
|
+
<slot v-bind="scope" />
|
|
65
|
+
</template>
|
|
66
|
+
<template v-if="$scopedSlots.product" #product="scope">
|
|
67
|
+
<slot name="product" v-bind="scope" />
|
|
68
|
+
</template>
|
|
69
|
+
</RocketShowcase>
|
|
50
70
|
</div>
|
|
51
71
|
</template>
|
|
52
72
|
|
|
@@ -63,10 +83,17 @@ export default {
|
|
|
63
83
|
position: { type: String, required: true },
|
|
64
84
|
// Força o pageType; sem ele vem da página atual (dadosPageAtual do tema).
|
|
65
85
|
pageType: { type: String, default: '' },
|
|
66
|
-
|
|
86
|
+
// Landing (page-type="custom"): identificador cadastrado no painel em "Personalizado".
|
|
87
|
+
customKey: { type: String, default: '' },
|
|
88
|
+
// Vitrine específica (a landing tem várias na mesma posição); sem ele, todas as da posição.
|
|
89
|
+
showcaseId: { type: [String, Number], default: null },
|
|
90
|
+
mediaSize: { type: String, default: 'medium' },
|
|
91
|
+
// Uso interno: vitrine empilhada abaixo da primeira da posição. Sem o atributo de posição,
|
|
92
|
+
// o debug contorna a posição uma vez só.
|
|
93
|
+
stacked: { type: Boolean, default: false }
|
|
67
94
|
},
|
|
68
95
|
data () {
|
|
69
|
-
return { showcase: null, products: [], loading: false, debug: false };
|
|
96
|
+
return { showcase: null, products: [], restIds: [], loading: false, debug: false };
|
|
70
97
|
},
|
|
71
98
|
computed: {
|
|
72
99
|
columns () {
|
|
@@ -112,9 +139,14 @@ export default {
|
|
|
112
139
|
if (this.started) return;
|
|
113
140
|
this.started = true;
|
|
114
141
|
try {
|
|
115
|
-
const showcases = await this.$rocket.getPageShowcases(this.pageType || undefined);
|
|
116
|
-
const
|
|
142
|
+
const showcases = await this.$rocket.getPageShowcases(this.pageType || undefined, this.customKey || undefined);
|
|
143
|
+
const inPosition = showcases.filter(s => ((s.placement && s.placement.position) || s.position) === this.position);
|
|
144
|
+
const showcase = this.showcaseId != null
|
|
145
|
+
? showcases.find(s => String(s.id) === String(this.showcaseId))
|
|
146
|
+
: inPosition[0];
|
|
117
147
|
if (!showcase) return;
|
|
148
|
+
// Posição sem showcaseId: este slot mostra a primeira e empilha as demais logo abaixo.
|
|
149
|
+
if (this.showcaseId == null) this.restIds = inPosition.slice(1).map(s => s.id);
|
|
118
150
|
// Banner autônomo: render direto, sem produtos, skeleton nem impressão de vitrine
|
|
119
151
|
// (o RocketBannerItem mede o criativo).
|
|
120
152
|
if (isBannerItem(showcase)) {
|
package/runtime/css/showcase.css
CHANGED
package/runtime/rocket.js
CHANGED
|
@@ -123,7 +123,10 @@ export function createRocket (config) {
|
|
|
123
123
|
|
|
124
124
|
rocket.setPage = function (next) {
|
|
125
125
|
page = Object.assign({ section: null, productId: null, categoryId: null, product: null }, next);
|
|
126
|
-
|
|
126
|
+
// A landing (custom) não depende do contexto da página e fica: senão, um setPage entre a busca
|
|
127
|
+
// do RocketLanding e a montagem das vitrines dele dispararia uma segunda chamada. Ela se
|
|
128
|
+
// renova quando o RocketLanding monta (refresh).
|
|
129
|
+
Object.keys(pageShowcases).forEach((k) => { if (k.indexOf('custom|') !== 0) delete pageShowcases[k]; });
|
|
127
130
|
};
|
|
128
131
|
rocket.getPage = () => page;
|
|
129
132
|
|
|
@@ -282,13 +285,15 @@ export function createRocket (config) {
|
|
|
282
285
|
return res.json();
|
|
283
286
|
};
|
|
284
287
|
|
|
285
|
-
|
|
288
|
+
// customKey: identificador da landing (pageType=custom); sem ele a API responde 400.
|
|
289
|
+
rocket.getShowcasesByContext = async function (type, customKey) {
|
|
286
290
|
const pageType = resolvePageType(type);
|
|
287
291
|
if (!pageType) return [];
|
|
288
292
|
const sessionId = await getSessionIdWithTimeout();
|
|
289
293
|
const params = { storeId: config.storeId, pageType, page: pageType, sessionId };
|
|
290
294
|
if (pageType === 'product' && page.productId) params.productId = page.productId;
|
|
291
295
|
if (pageType === 'category' && page.categoryId) params.categoryId = page.categoryId;
|
|
296
|
+
if (pageType === 'custom') params.customKey = customKey;
|
|
292
297
|
|
|
293
298
|
const res = await fetch(config.apiUrl + '/showcases/context?' + query(params), { headers: headers() });
|
|
294
299
|
const showcases = await res.json();
|
|
@@ -305,11 +310,13 @@ export function createRocket (config) {
|
|
|
305
310
|
};
|
|
306
311
|
|
|
307
312
|
// Uma chamada por página, repartida entre os slots (<RocketShowcase position>) — na Linx
|
|
308
|
-
// era o fetchShowCases único distribuindo por data-rocket-showcase-position.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
+
// era o fetchShowCases único distribuindo por data-rocket-showcase-position. Por pageType +
|
|
314
|
+
// customKey: a landing e o contexto da página são chamadas distintas. O setPage zera só o contexto.
|
|
315
|
+
let pageShowcases = {};
|
|
316
|
+
rocket.getPageShowcases = function (type, customKey, refresh) {
|
|
317
|
+
const key = (type || '') + '|' + (customKey || '');
|
|
318
|
+
if (refresh || !pageShowcases[key]) pageShowcases[key] = rocket.getShowcasesByContext(type, customKey).catch(() => []);
|
|
319
|
+
return pageShowcases[key];
|
|
313
320
|
};
|
|
314
321
|
|
|
315
322
|
// Só banners (DTO banner-native). Gated pela flag `banners`: loja sem ela recebe [].
|