-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathStorefrontApp.vue
577 lines (506 loc) · 22.7 KB
/
StorefrontApp.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<!--
- Copyright (c) 2023. Selldone® Business OS™
-
- Author: M.Pajuhaan
- Web: https://selldone.com
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-
- All rights reserved. In the weave of time, where traditions and innovations intermingle, this content was crafted.
- From the essence of thought, through the corridors of creativity, each word, and sentiment has been molded.
- Not just to exist, but to inspire. Like an artist's stroke or a sculptor's chisel, every nuance is deliberate.
- Our journey is not just about reaching a destination, but about creating a masterpiece.
- Tread carefully, for you're treading on dreams.
-->
<!--
🍉 This view will be shown in the HTML ▶ BODY ▶ <div id="app">.
Banner
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Campaign Banner ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Main Content
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ router-view ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Absolute/Fixed widgets
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Private / Restricted Shop ┃
┃ Social links (Floating) ┃
┃ Payment ┃
┃ Products Comparison ┃
┃ Need Login ┃
┃ ... ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
-->
<template>
<div id="banners-placeholder"></div>
<v-app
v-if="shop"
:class="[
{
'is-mobile': isMobile,
'before-load-icon-font': !IconFontsLoaded,
blurred: blur,
},
]"
:style="[
{
/* Global theme variable of the storefront */
'--theme-dark': ThemeColorDark,
'--theme-light': ThemeColorLight,
'--theme-deep-dark': ThemeColorDeepDark,
'--theme-info': ThemeColorInfo,
'--theme-btn-color': color_buy_button,
'--background': page_background_color,
},
page_bg,
]"
class="s--shop blur-animate"
:key="unique_key_shop"
>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Main router view ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<router-view v-if="!is_private || customer_has_access" :shop="shop" />
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Private / Restricted Shop ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-access-private-check v-else></s-access-private-check>
<template v-if="delay_loaded">
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Campaign banner ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<Teleport to="#banners-placeholder">
<s-campaign-banner />
</Teleport>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Social links (Floating) ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-storefront-social-buttons
active-only
class="social-stick"
vertical
></s-storefront-social-buttons>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Payment ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-storefront-master-payment-dialog />
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Products Comparison ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-comparison-button v-if="has_comparison" />
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Need Login ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-storefront-need-login-dialog />
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Notifications (Small bottom-Right) ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<u-notification-side />
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Application Shop Login ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-storefront-application-login></s-storefront-application-login>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Select Address ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<u-map-dialog></u-map-dialog>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Cookie Agreement ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-cookie-consent v-if="has_gdpr"></s-cookie-consent>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ PWA Update Snackbar ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-pwa-version-check
:style="$vuetify.display.smAndDown ? 'margin-top:-42px' : ''"
></s-pwa-version-check>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Bottom navigation bar ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-footer-navigation v-if="isMobile"></s-footer-navigation>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Popup ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-storefront-popup></s-storefront-popup>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Open fullscreen images ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-fullscreen-view-animator></s-fullscreen-view-animator>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Retrieve basket from secure links ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-storefront-retrieve-share-order></s-storefront-retrieve-share-order>
<!-- ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Webapp debug view ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ -->
<s-debugger></s-debugger>
</template>
</v-app>
</template>
<script lang="ts">
import { debounce, delay } from "lodash-es";
import { FirebaseNotificationCategories } from "@selldone/core-js/enums/push-notification/FirebaseNotificationCategories";
import { Language } from "@selldone/core-js/enums/language/Language";
import { SetupService } from "@selldone/core-js/server/SetupService";
import { FontHelper } from "@selldone/core-js/helper/font/FontHelper";
import { ShopRestriction } from "@selldone/core-js/enums/shop/options/ShopRestriction";
import { EventBus, EventName } from "@selldone/core-js/events/EventBus";
import ScrollHelper from "@selldone/core-js/utils/scroll/ScrollHelper";
import { StorefrontShopHealthCheck } from "@app-storefront/helpers/StorefrontShopHealthCheck";
import { computed, defineAsyncComponent } from "vue";
import TemplateMixin from "@selldone/components-vue/mixin/template/TemplateMixin";
import AuthMixin from "@selldone/components-vue/mixin/auth/AuthMixin.ts";
import NotificationService from "@selldone/components-vue/plugins/notification/NotificationService.ts";
import SAccessPrivateCheck from "@selldone/components-vue/storefront/access/private/check/SAccessPrivateCheck.vue";
export default {
name: "StorefrontApp",
mixins: [TemplateMixin, AuthMixin],
components: {
SAccessPrivateCheck,
SStorefrontRetrieveShareOrder: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/order/share-order/SStorefrontRetrieveShareOrder.vue"
),
),
SFullscreenViewAnimator: defineAsyncComponent(
() =>
import("@selldone/components-vue/ui/image/SFullscreenViewAnimator.vue"),
),
UNotificationSide: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/ui/notification/side/UNotificationSide.vue"
),
),
SStorefrontNeedLoginDialog: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/login/SStorefrontNeedLoginDialog.vue"
),
),
SCookieConsent: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/cookie/consent/SCookieConsent.vue"
),
),
SFooterNavigation: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/footer/navigarion/SFooterNavigation.vue"
),
),
SStorefrontApplicationLogin: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/login/SStorefrontApplicationLogin.vue"
),
),
SComparisonButton: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/comparison/button/SComparisonButton.vue"
),
),
SDebugger: defineAsyncComponent(
() => import("@selldone/components-vue/storefront/debuger/SDebugger.vue"),
),
UMapDialog: defineAsyncComponent(
() => import("@selldone/components-vue/ui/map/dialog/UMapDialog.vue"),
),
SCampaignBanner: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/campaign/banner/SCampaignBanner.vue"
),
),
SStorefrontSocialButtons: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/social/SStorefrontSocialButtons.vue"
),
),
SStorefrontPopup: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/popup/SStorefrontPopup.vue"
),
),
SStorefrontMasterPaymentDialog: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/storefront/payment/SStorefrontMasterPaymentDialog.vue"
),
),
SPwaVersionCheck: defineAsyncComponent(
() =>
import(
"@selldone/components-vue/system/pwa/version-check/SPwaVersionCheck.vue"
),
),
},
/**
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
* 🔷 Provide
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
provide() {
return {
$shop: computed(() => this.shop),
};
},
/**
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
* 🔷 Data
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
data: () => ({
IconFontsLoaded: false,
blur: false,
delay_loaded: false,
}),
/**
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
* 🔷 Compute Section
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
computed: {
shop() {
return this.getShop();
},
isMobile() {
return this.$vuetify.display.smAndDown;
},
/**
* We use it to force update entire app.
* @return {string}
*/
unique_key_shop() {
console.log(
"🔵 Update App Global Status",
`${this.shop?.id}-${window.$storefront.currency?.code}-${this.language}`,
);
return `${this.shop?.id}-${window.$storefront.currency?.code}-${this.language}`;
},
language() {
return this.getCurrentLanguage()?.code;
},
theme() {
return this.shop?.theme;
},
color_buy_button() {
return this.theme?.color_buy ? this.theme.color_buy : "#0061e0";
},
is_private() {
return (
this.shop && this.shop.restriction === ShopRestriction.PRIVATE.code
);
},
user() {
return this.USER();
},
customer_has_access() {
return this.user && this.user.access;
},
has_gdpr() {
return (
SetupService.GetGDPREnable() &&
this.shop &&
this.shop.options &&
this.shop.options.some((e) => e.code === "gdpr" && e.value === true)
);
},
// --------------------------------------------------------------------------------
has_comparison() {
return this.$route.matched.some((record) => record.meta.comparison);
},
// --------------------------------------------------------------------------------
page_background_color() {
const custom_bg_meta = [...this.$route.matched]
.reverse()
.find((record) => record.meta.bg_color);
if (custom_bg_meta) return custom_bg_meta.meta.bg_color;
return "#fff";
},
page_bg() {
const meta_bg = this.$route.matched.find(
(record) => record.meta.page_background,
);
// console.log("page_background", meta_bg);
if (meta_bg) {
return meta_bg.meta.page_background;
}
return "";
},
},
/**
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
* 🔷 Watch Section
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
watch: {
$route(_new, _old) {
this.blur = false; // Reset blur!
// Do not scroll if only query parameters have changed
if (_old.path === _new.path) return;
if (_new.query["no-scroll"]) return; // Do not scroll if no-scroll query exist!
this.$nextTick(function () {
/*First shop page is not category page! but same elements so we do not want to suddenly jump up!*/
const smooth =
_old?.name === _new?.name ||
(Array.isArray(
[
window.$storefront.routes.SHOP_PAGE,
window.$storefront.routes.SHOP_CATEGORY_PAGE,
],
_old?.name,
) &&
Array.isArray(
[
window.$storefront.routes.SHOP_PAGE,
window.$storefront.routes.SHOP_CATEGORY_PAGE,
],
_new?.name,
));
//console.log("🔵 Scroll to top", smooth ? "smooth" : "instant", _old?.name, _new?.name,);
ScrollHelper.scrollToTop(0, smooth ? "smooth" : "instant");
});
},
},
/**
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
* 🔷 Component Lifecycle
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
beforeCreate() {
/**
* Creates and dispatches an event called "selldone-app-loaded".
* External systems or scripts can listen for this event to know when the
* Selldone app has been loaded and take necessary actions, like hiding a
* loading view.
*
* Example Usage:
*
* ```javascript
* document.addEventListener("selldone-app-loaded", function (event) {
* document.getElementById('first_loading_view').style.display = "none";
* });
* ```
*/
const event = new Event("selldone-app-loaded");
document.dispatchEvent(event); // Dispatch the event.
},
created() {
// Set initial language by meta tags: (Better user experience)
if (
SetupService.GetInitialLanguage() /*Serverside set initial language*/ &&
!window.$storefront.database.language.getLanguage() /*User not set any language locally*/
)
this.setCurrentLanguage(SetupService.GetInitialLanguage());
//this.$vuetify.locale.isRtl = this.getCurrentLanguage().dir === "rtl";
/**
* Auto RTL/LTR set by linked i18n to vuetify instance. {@see VuetifyInstance}
*/
//――――――――――――――――――――――――― Save Entry Channel ―――――――――――――――――――――――――
const route_channel = this.$route.matched.find(
(record) => record.meta.channel,
);
if (route_channel) {
console.log("⚡ Load sales channel mode:", route_channel.meta.channel);
this.$store.commit("setChannelEntry", route_channel.meta.channel);
}
//█████████████████████████████████████████████████████████████
//――――――――――――――――――――――――― Event Bus ―――――――――――――――――――――――――
//█████████████████████████████████████████████████████████████
EventBus.$on(EventName.FIREBASE_RECEIVE_MESSAGE, (payload) => {
// Show only if user is being in shop:
if (payload.data.shop && payload.data.shop.name === this.shop.name) {
if (payload.notification) {
const category =
FirebaseNotificationCategories[payload.notification.tag];
let icon = category ? category.icon : "done";
let color = category ? category.color : this.TemplateColorDark;
const img = payload.notification ? payload.notification.icon : null;
NotificationService.showNotificationAlert(
payload.notification.title,
payload.notification.body,
icon,
color,
img,
);
}
}
});
EventBus.$on(EventName.FIREBASE_GET_TOKEN, (token) => {
if (!window.axios.defaults.headers.common["Authorization"]) return; // User not authorized! FCM added only for authorized users.
const fun = debounce((token) => {
// Debounce: Speed up first load!
window.$storefront.user
.setFcmToken(token)
.then(({}) => {})
.catch((error) => {
console.error(error);
});
}, 5000);
fun(token);
});
//▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆ Blur App ▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆
EventBus.$on(EventName.BLUR_APP, (blur) => {
// console.log("🔵 BLUR_APP", blur);
this.blur = blur;
});
//█████████████████████████████████████████████████████████████
//―――――――――――――――――――――――― Get User Info ――――――――――――――――――――――――
//█████████████████████████████████████████████████████████████
this.UpdateUserInfo();
//―――――――――――――――――――――― Font loader listener ――――――――――――――――――――
FontHelper.ListenOnFontIconsLoaded(() => {
this.IconFontsLoaded = true;
});
// Load shop info fast:
if (window.shop) {
// 🧿 Auto fix Shop:
StorefrontShopHealthCheck.Check(this.$router, window.shop);
this.$store.commit("setShop", window.shop);
// 🞧 Header: Language (Important to load content - product article - in selected language) ASAP!
const local_save_lang =
window.$storefront.database.language.getLanguage();
window.axios.defaults.headers.common["X-Localization"] = local_save_lang
? local_save_lang.code /*user selected language*/
: this.shop.language /*shop default language*/;
}
this.fetchBasketAndShop();
},
mounted() {
//―――――――――――――――――――――― Server Message ――――――――――――――――――――
if (window.server_message)
NotificationService.showMessage(null, window.server_message);
//―――――――――――――――――――――― Global key listener ――――――――――――――――――――
document.addEventListener("keyup", (e) => {
// Register your global hot keys for the shop here:
if (e.ctrlKey && e.key === "q") this.SwitchLanguage(e);
});
// ――――――――――――――――――――― Auto update rates every 5 minutes if some exchange rates are auto mode ―――――――――――――――――――――
// Update shop exchange rates by interval if auto mode in rates exist:
this.update_exchange_rates_interval = setInterval(() => {
this.UpdateExchangeRates();
}, 5 * 60000); // every 5 minutes
delay(() => {
this.$nextTick(() => {
this.delay_loaded = true;
});
}, 3000);
},
beforeUnmount() {
EventBus.$off(EventName.FIREBASE_RECEIVE_MESSAGE);
EventBus.$off(EventName.FIREBASE_GET_TOKEN);
EventBus.$off(EventName.BLUR_APP);
if (this.update_exchange_rates_interval)
clearInterval(this.update_exchange_rates_interval);
},
/**
* ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
* 🔷 Component Methods
* ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
*/
methods: {
/**
* Just for testing RTL/LTR!
* Hot key to change language instantly!
* @constructor
*/
SwitchLanguage() {
let new_lang =
this.getCurrentLanguage() === Language.en ? Language.fa : Language.en;
this.setCurrentLanguage(new_lang.code);
console.log("🌐 SwitchLanguage", new_lang.code);
},
},
};
</script>
<!-- ━━━━━━━━━━━━━━━━━━━ 🦄 Style ● Global ━━━━━━━━━━━━━━━━━━━-->
<style lang="scss" src="./style/storefront.scss"></style>
<style lang="scss">
/*
━━━━━━━━━━━━━━━━━━━━ 🎺 Variables ━━━━━━━━━━━━━━━━━━━━
*/
.s--shop {
--background: #fff;
--products-filter-width: 300px;
}
/*
━━━━━━━━━━━━━━━━━━━━ 🪅 Classes ━━━━━━━━━━━━━━━━━━━━
*/
.s--shop {
background: var(--background) !important;
font-weight: 400;
overflow: hidden;
}
</style>