@opendesign-plus/components 0.0.1-rc.6 → 0.0.1-rc.8

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.
Files changed (138) hide show
  1. package/dist/chunk-OElCookieNotice.cjs.js +1 -0
  2. package/dist/chunk-OElCookieNotice.es.js +281 -0
  3. package/dist/components/OFooter.vue.d.ts +25 -0
  4. package/dist/components/OHeader.vue.d.ts +23 -0
  5. package/dist/components/OHeaderMoblie.vue.d.ts +33 -0
  6. package/dist/components/OHeaderUser.vue.d.ts +40 -0
  7. package/dist/components/OSourceCode.vue.d.ts +20 -0
  8. package/dist/components/events/OEventsApply.vue.d.ts +16 -0
  9. package/dist/components/events/OEventsCalendar.vue.d.ts +5 -0
  10. package/dist/components/events/OEventsList.vue.d.ts +26 -0
  11. package/dist/components/events/config.d.ts +27 -0
  12. package/dist/components/events/index.d.ts +78 -0
  13. package/dist/components/events/types.d.ts +66 -0
  14. package/dist/components/events/utils.d.ts +7 -0
  15. package/dist/components.cjs.js +3 -1
  16. package/dist/components.css +1 -1
  17. package/dist/components.element.cjs.js +1 -1
  18. package/dist/components.element.es.js +2 -214
  19. package/dist/components.es.js +3001 -444
  20. package/dist/index.d.ts +8 -1
  21. package/docs/design.md +27 -27
  22. package/docs/design_banner.md +41 -41
  23. package/docs/design_section.md +27 -27
  24. package/package.json +2 -1
  25. package/scripts/generate-components-index.js +99 -80
  26. package/src/assets/events/city/beijing.jpg +0 -0
  27. package/src/assets/events/city/chengdu.jpg +0 -0
  28. package/src/assets/events/city/default-cover.jpg +0 -0
  29. package/src/assets/events/city/guangzhou.jpg +0 -0
  30. package/src/assets/events/city/hangzhou.jpg +0 -0
  31. package/src/assets/events/city/nanjing.jpg +0 -0
  32. package/src/assets/events/city/shanghai.jpg +0 -0
  33. package/src/assets/events/city/shenzhen1.jpg +0 -0
  34. package/src/assets/events/city/shenzhen2.jpg +0 -0
  35. package/src/assets/events/city/suzhou.jpg +0 -0
  36. package/src/assets/events/city/tianjin.jpg +0 -0
  37. package/src/assets/events/city/wuhan.jpg +0 -0
  38. package/src/assets/events/city/wuxi.jpg +0 -0
  39. package/src/assets/events/city/xian.jpg +0 -0
  40. package/src/assets/events/city/zhengzhou.jpg +0 -0
  41. package/src/assets/events/svg-icons/icon-checked.svg +3 -0
  42. package/src/assets/events/svg-icons/icon-competition.svg +7 -0
  43. package/src/assets/events/svg-icons/icon-events.svg +4 -0
  44. package/src/assets/events/svg-icons/icon-release.svg +4 -0
  45. package/src/assets/events/svg-icons/icon-summit.svg +4 -0
  46. package/src/assets/svg-icons/icon-arrow-left.svg +3 -0
  47. package/src/assets/svg-icons/icon-avatar-line.svg +3 -0
  48. package/src/assets/svg-icons/icon-caret-left.svg +3 -0
  49. package/src/assets/svg-icons/icon-caret-right.svg +3 -0
  50. package/src/assets/svg-icons/icon-chevron-down.svg +3 -0
  51. package/src/assets/svg-icons/icon-chevron-right.svg +3 -3
  52. package/src/assets/svg-icons/icon-close.svg +3 -3
  53. package/src/assets/svg-icons/icon-delete.svg +3 -3
  54. package/src/assets/svg-icons/icon-header-back.svg +3 -3
  55. package/src/assets/svg-icons/icon-header-delete.svg +3 -3
  56. package/src/assets/svg-icons/icon-header-menu.svg +3 -0
  57. package/src/assets/svg-icons/icon-header-person.svg +3 -0
  58. package/src/assets/svg-icons/icon-header-search.svg +4 -4
  59. package/src/assets/svg-icons/icon-locale.svg +3 -0
  60. package/src/assets/svg-icons/icon-log-off.svg +3 -0
  61. package/src/assets/svg-icons/icon-message.svg +3 -0
  62. package/src/assets/svg-icons/icon-moon.svg +3 -3
  63. package/src/assets/svg-icons/icon-outlink.svg +3 -0
  64. package/src/assets/svg-icons/icon-overview.svg +3 -0
  65. package/src/assets/svg-icons/icon-setting.svg +3 -0
  66. package/src/assets/svg-icons/icon-sun.svg +3 -3
  67. package/src/components/OBanner.vue +390 -390
  68. package/src/components/OCookieNotice.vue +423 -423
  69. package/src/components/OFooter.vue +566 -0
  70. package/src/components/OHeader.vue +97 -0
  71. package/src/components/OHeaderMoblie.vue +149 -0
  72. package/src/components/OHeaderSearch.vue +601 -601
  73. package/src/components/OHeaderUser.vue +304 -0
  74. package/src/components/OPlusConfigProvider.vue +32 -32
  75. package/src/components/OSection.vue +178 -178
  76. package/src/components/OSourceCode.vue +153 -0
  77. package/src/components/OThemeSwitcher.vue +108 -108
  78. package/src/components/common/AppAvatar.vue +83 -0
  79. package/src/components/common/ClientOnlyWrapper.ts +21 -21
  80. package/src/components/common/ContentWrapper.vue +85 -85
  81. package/src/components/common/HeaderEulerNav.vue +1118 -0
  82. package/src/components/common/HeaderNavMoblie.vue +344 -0
  83. package/src/components/common/HeaderUbmcNav.vue +597 -0
  84. package/src/components/element-plus/OElCookieNotice.vue +412 -412
  85. package/src/components/element-plus/index.ts +3 -3
  86. package/src/components/events/OEventsApply.vue +487 -0
  87. package/src/components/events/OEventsCalendar.vue +613 -0
  88. package/src/components/events/OEventsList.vue +402 -0
  89. package/src/components/events/config.ts +49 -0
  90. package/src/components/events/index.ts +23 -0
  91. package/src/components/events/types.ts +80 -0
  92. package/src/components/events/utils.ts +9 -0
  93. package/src/components/meeting/npmcachae/_cacache/content-v2/sha512/3e/17/1865217b9acb9f4921c53a09b5c76587cd2ab748beb2699ff6cfb1341d73b1aa56ed91ffc5ab2c9c9b3fbe626103b35d9a79ff29ff6b8cbb8d89755fe1a2 +1 -0
  94. package/src/components/meeting/npmcachae/_cacache/content-v2/sha512/a6/15/47bb7552ec9248079e839a5feecc1742d4de19524fdf041cf581701cf4760a5025106036145e279ba193b07c8fa5b07ae3d75f1b6032f0cb2219115b6167 +1 -0
  95. package/src/components/meeting/npmcachae/_cacache/content-v2/sha512/d1/4c/133b32e09c97101a27a07cc4432f94e470cff02d120d21babcea77c3f5cd436793516dc1a8e282ee1a568f923c148b1a48f4a43233462a530d35e8b41c67 +1 -0
  96. package/src/components/meeting/npmcachae/_cacache/index-v5/54/0d/a4909047714a0a7198bb9bd37020992464e47c79a791889919b84d90aab0 +3 -0
  97. package/src/components/meeting/npmcachae/_cacache/index-v5/8e/2b/21a79778e2ac08cf5663baf83cb35f951995a496007eb2e2f7fba54021a4 +3 -0
  98. package/src/components/meeting/npmcachae/_cacache/index-v5/eb/a0/b70c8132e5b57a0f1e129b8cc941796420a9c147c0baa680710083740898 +2 -0
  99. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_03_54_955Z-debug-0.log +277 -0
  100. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_03_57_842Z-debug-0.log +277 -0
  101. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_04_00_016Z-debug-0.log +277 -0
  102. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_04_02_191Z-debug-0.log +277 -0
  103. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_04_04_425Z-debug-0.log +277 -0
  104. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_04_06_642Z-debug-0.log +277 -0
  105. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_04_08_826Z-debug-0.log +277 -0
  106. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_25_36_140Z-debug-0.log +433 -0
  107. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_25_39_573Z-debug-0.log +433 -0
  108. package/src/components/meeting/npmcachae/_logs/2026-03-20T07_25_42_134Z-debug-0.log +212 -0
  109. package/src/components/meeting/npmcachae/_update-notifier-last-checked +0 -0
  110. package/src/draft/Banner.vue +265 -265
  111. package/src/draft/ButtonCards.vue +105 -105
  112. package/src/draft/Feature.vue +133 -133
  113. package/src/draft/Footer.vue +512 -512
  114. package/src/draft/HorizontalAnchor.vue +165 -165
  115. package/src/draft/ItemSwiper.vue +133 -133
  116. package/src/draft/Logo.vue +141 -141
  117. package/src/draft/LogoCard.vue +74 -74
  118. package/src/draft/LogoV2.vue +19 -19
  119. package/src/draft/MainCard.vue +38 -38
  120. package/src/draft/MultiCard.vue +94 -94
  121. package/src/draft/MultiIconCard.vue +73 -73
  122. package/src/draft/OInfoCard.vue +176 -176
  123. package/src/draft/Process.vue +81 -81
  124. package/src/draft/Section.vue +167 -167
  125. package/src/draft/SingleTabCard.vue +84 -84
  126. package/src/draft/SliderCard.vue +110 -110
  127. package/src/env.d.ts +1 -1
  128. package/src/i18n/en.ts +20 -20
  129. package/src/i18n/index.ts +42 -42
  130. package/src/i18n/zh.ts +14 -9
  131. package/src/index.ts +15 -1
  132. package/src/shared/provide.ts +6 -6
  133. package/src/shims-vue-dompurify-html.d.ts +17 -0
  134. package/src/vue.d.ts +9 -9
  135. package/tsconfig.json +33 -33
  136. package/vite.config.ts +102 -101
  137. package/dist/chunk-index.cjs.js +0 -1
  138. package/dist/chunk-index.es.js +0 -64
@@ -1,423 +1,423 @@
1
- <script lang="ts" setup>
2
- import { ref, onMounted, computed, nextTick, watch } from 'vue';
3
- import ClientOnly from './common/ClientOnlyWrapper';
4
- import { useScreen } from '@opendesign-plus/composables';
5
- import { useI18n } from '@/i18n';
6
- import { DialogActionT, OButton, ODialog, OIcon, OIconClose, OSwitch } from '@opensig/opendesign';
7
- import { useVModel } from '@vueuse/core';
8
-
9
- const NOT_SIGNED = '0';
10
- const ALL_AGREED = '1';
11
- const NECCESSARY_AGREED = '2';
12
- const NOT_SHOW_BUT_AGREED = '3';
13
- const COOKIE_KEY_ZH = 'agreed-cookiepolicy-zh';
14
- const COOKIE_KEY_EN = 'agreed-cookiepolicy-en';
15
-
16
- const props = defineProps<{
17
- visible?: boolean;
18
- enableGrid?: boolean;
19
- community: string;
20
- detailUrl: string;
21
- wrapper?: string | HTMLElement;
22
- cookieDomain: string;
23
- }>();
24
-
25
- const emit = defineEmits<{
26
- (e: 'update:visible', value: boolean): void;
27
- }>();
28
-
29
- const { lePadV, leLaptop } = useScreen();
30
- const { locale, t } = useI18n();
31
- const isZh = computed(() => locale.value === 'zh');
32
-
33
- const cookieKey = computed(() => (isZh.value ? COOKIE_KEY_ZH : COOKIE_KEY_EN));
34
-
35
- // 是否允许分析cookie
36
- const analysisAllowed = ref(false);
37
- const visibleVmodel = useVModel(props, 'visible', emit, { defaultValue: false });
38
-
39
- const getCookie = (key: string) => {
40
- const cookie = document.cookie.split(';').find((row) => row.split('=')[0].trim() === encodeURIComponent(key));
41
- if (!cookie) {
42
- return null;
43
- }
44
- return decodeURIComponent(cookie.split('=')[1]);
45
- };
46
-
47
- const setCookie = (key: string, value: string, days: number, domain: string) => {
48
- const maxAge = days ? `; max-age=${days * 24 * 60 * 60}` : '';
49
- document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}${maxAge}; path=/; domain=${domain}`;
50
- };
51
-
52
- const removeCookie = (key: string, domain: string) => {
53
- document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${domain}`;
54
- };
55
-
56
- // 显示/隐藏cookie提示
57
- const toggleNoticeVisible = (val?: boolean) => {
58
- if (typeof val === 'boolean') {
59
- visibleVmodel.value = val;
60
- } else {
61
- visibleVmodel.value = !visibleVmodel.value;
62
- }
63
- nextTick(() => {
64
- if (!visibleVmodel.value && isZh.value && getCookie(cookieKey.value) !== NOT_SHOW_BUT_AGREED) {
65
- setCookie(cookieKey.value, NOT_SHOW_BUT_AGREED, 180, props.cookieDomain ?? location.hostname);
66
- }
67
- });
68
- };
69
-
70
- // 弹出框是否显示
71
- const isDlgVisible = ref(false);
72
-
73
- // 显示/隐藏弹出框
74
- const toggleDlgVisible = (val?: boolean) => {
75
- if (typeof val === 'boolean') {
76
- isDlgVisible.value = val;
77
- } else {
78
- isDlgVisible.value = !isDlgVisible.value;
79
- }
80
- };
81
-
82
- // 是否未签署
83
- const isNotSigned = () => {
84
- if (isZh.value) {
85
- return getCookie(cookieKey.value) !== NOT_SHOW_BUT_AGREED;
86
- }
87
- return (getCookie(cookieKey.value) ?? '0') === NOT_SIGNED;
88
- };
89
-
90
- // 是否全部同意
91
- const isAllAgreed = () => {
92
- if (isZh.value) {
93
- return getCookie(cookieKey.value) === NOT_SHOW_BUT_AGREED;
94
- }
95
- return getCookie(cookieKey.value) === ALL_AGREED;
96
- };
97
-
98
- onMounted(() => {
99
- // 未签署,展示cookie notice
100
- if (isNotSigned()) {
101
- toggleNoticeVisible(true);
102
- }
103
- });
104
-
105
- watch(locale, () => {
106
- toggleNoticeVisible(isNotSigned());
107
- });
108
-
109
- // 用户同意所有cookie
110
- const acceptAll = () => {
111
- analysisAllowed.value = true;
112
- removeCookie(cookieKey.value, props.cookieDomain ?? location.hostname);
113
- setCookie(cookieKey.value, ALL_AGREED, 180, props.cookieDomain ?? location.hostname);
114
- toggleNoticeVisible(false);
115
- };
116
-
117
- // 用户拒绝所有cookie,即仅同意必要cookie
118
- const rejectAll = () => {
119
- analysisAllowed.value = false;
120
- removeCookie(cookieKey.value, props.cookieDomain ?? location.hostname);
121
- setCookie(cookieKey.value, NECCESSARY_AGREED, 180, props.cookieDomain ?? location.hostname);
122
- toggleNoticeVisible(false);
123
- };
124
-
125
- // 弹出框设置
126
- const dlgActions = computed<Array<DialogActionT>>(() => [
127
- {
128
- id: 'save',
129
- color: 'primary',
130
- label: t('cookie.saveSetting'),
131
- variant: 'outline',
132
- size: 'large',
133
- round: 'pill',
134
- onClick: () => {
135
- if (analysisAllowed.value) {
136
- acceptAll();
137
- } else {
138
- rejectAll();
139
- }
140
-
141
- toggleDlgVisible(false);
142
- },
143
- },
144
- {
145
- id: 'allowAll',
146
- color: 'primary',
147
- label: t('cookie.acceptAll'),
148
- variant: 'outline',
149
- size: 'large',
150
- round: 'pill',
151
- onClick: () => {
152
- analysisAllowed.value = true;
153
- acceptAll();
154
- toggleDlgVisible(false);
155
- },
156
- },
157
- ]);
158
-
159
- const onDlgChange = (val: boolean) => {
160
- if (val) {
161
- analysisAllowed.value = isAllAgreed();
162
- }
163
- };
164
-
165
- defineExpose({
166
- check() {
167
- const agreed = isAllAgreed();
168
- if (agreed === visibleVmodel.value) {
169
- toggleNoticeVisible();
170
- }
171
- },
172
- });
173
- </script>
174
-
175
- <template>
176
- <ClientOnly>
177
- <Teleport :to="wrapper || '#app'">
178
- <div v-if="visibleVmodel" class="cookie-notice">
179
- <div class="cookie-notice-content">
180
- <div :type="locale" :class="{ 'cookie-notice-wrap-grid': enableGrid, 'cookie-notice-wrap': !enableGrid }">
181
- <div class="cookie-notice-left">
182
- <p v-if="isZh" class="cookie-desc" style="margin-top: 0">
183
- {{ t('cookie.desc') }}
184
- <a :href="detailUrl" target="_blank" rel="noopener noreferrer">
185
- {{ t('cookie.about') }}
186
- </a>
187
- </p>
188
- <template v-else>
189
- <p class="cookie-title">{{ t('cookie.title', [community]) }}</p>
190
- <p class="cookie-desc">
191
- {{ t('cookie.desc') }}
192
- <a :href="detailUrl" target="_blank" rel="noopener noreferrer">{{ t('cookie.about') }} </a>.
193
- </p>
194
- </template>
195
- </div>
196
- <div v-if="!isZh" class="cookie-notice-right">
197
- <OButton round="pill" variant="outline" color="primary" @click="acceptAll">{{ t('cookie.acceptAll') }}</OButton>
198
- <OButton round="pill" variant="outline" color="primary" @click="rejectAll">{{ t('cookie.rejectAll') }}</OButton>
199
- <OButton round="pill" variant="outline" color="primary" @click="toggleDlgVisible(true)">
200
- {{ t('cookie.manage') }}
201
- </OButton>
202
- </div>
203
- <OIcon class="cookie-notice-close" :type="locale" @click="toggleNoticeVisible(false)">
204
- <OIconClose />
205
- </OIcon>
206
- </div>
207
- </div>
208
- <ODialog
209
- v-model:visible="isDlgVisible"
210
- :size="leLaptop ? 'medium' : 'large'"
211
- :phone-half-full="lePadV"
212
- class="cookie-dlg"
213
- :actions="dlgActions"
214
- @change="onDlgChange"
215
- >
216
- <template #header>
217
- <span class="cookie-dlg-title">{{ t('cookie.manage') }}</span>
218
- </template>
219
- <div class="cookie-dlg-content">
220
- <div class="content-item">
221
- <div class="item-header">
222
- <span class="item-title">{{ t('cookie.necessaryCookie') }}</span>
223
- <span class="item-extra">{{ t('cookie.alwaysOn') }}</span>
224
- </div>
225
- <div class="item-detail">
226
- {{ t('cookie.necessaryCookieDetail') }}
227
- </div>
228
- </div>
229
- <div class="content-item">
230
- <div class="item-header">
231
- <span class="item-title">{{ t('cookie.analyticalCookie') }}</span>
232
- <span class="item-extra">
233
- <OSwitch v-model="analysisAllowed" />
234
- </span>
235
- </div>
236
- <div class="item-detail">
237
- {{ t('cookie.analyticalCookieDetail') }}
238
- </div>
239
- </div>
240
- </div>
241
- </ODialog>
242
- </div>
243
- </Teleport>
244
- </ClientOnly>
245
- </template>
246
-
247
- <style lang="scss" scoped>
248
- .cookie-notice {
249
- position: fixed;
250
- bottom: 0;
251
- z-index: 999;
252
- width: 100%;
253
- .o-button {
254
- --o-button-font-size-mini: 14px;
255
- }
256
- .o-button + .o-button {
257
- margin-left: 16px;
258
-
259
- @media (max-width: 840px) {
260
- margin-left: 0;
261
- margin-top: 12px;
262
- }
263
- }
264
- }
265
-
266
- .cookie-notice-content {
267
- background-color: rgba(var(--o-mixedgray-1), 0.9);
268
- backdrop-filter: blur(5px);
269
- box-shadow: var(--o-shadow-1);
270
- }
271
-
272
- .cookie-notice-wrap {
273
- position: relative;
274
- display: flex;
275
- justify-content: space-between;
276
- margin: 0 auto;
277
- padding: 24px var(--layout-content-padding);
278
- max-width: var(--layout-content-max-width);
279
- &:not([type='zh']) {
280
- @media (max-width: 840px) {
281
- flex-direction: column;
282
- align-items: center;
283
- }
284
- }
285
- }
286
-
287
- .cookie-notice-wrap-grid {
288
- position: relative;
289
- display: flex;
290
- justify-content: space-between;
291
- width: var(--grid-content-width);
292
- padding: 24px 0;
293
- margin: 0 auto;
294
- &:not([type='zh']) {
295
- @media (max-width: 840px) {
296
- padding: 16px 0;
297
- flex-direction: column;
298
- align-items: center;
299
- }
300
- }
301
- }
302
-
303
- .cookie-notice-left {
304
- width: 60%;
305
-
306
- @media (max-width: 1100px) {
307
- width: 58%;
308
- }
309
-
310
- @media (max-width: 840px) {
311
- width: 100%;
312
- }
313
-
314
- .cookie-title {
315
- font-size: 16px;
316
- line-height: 28px;
317
- color: var(--o-color-info1);
318
- font-weight: 500;
319
- @media (max-width: 840px) {
320
- font-size: 16px;
321
- line-height: 24px;
322
- text-align: center;
323
- }
324
- }
325
-
326
- .cookie-desc {
327
- font-size: 12px;
328
- line-height: 18px;
329
- color: var(--o-color-info2);
330
- margin-top: 8px;
331
- }
332
- }
333
-
334
- .cookie-notice-right {
335
- display: flex;
336
- align-items: center;
337
- margin-top: 12px;
338
-
339
- @media (max-width: 840px) {
340
- width: 100%;
341
- }
342
-
343
- @media (max-width: 840px) {
344
- flex-direction: column;
345
- align-items: center;
346
- }
347
-
348
- .o-btn:not(:first-child) {
349
- margin-left: 16px;
350
- }
351
-
352
- @media (max-width: 840px) {
353
- .o-btn {
354
- align-self: stretch;
355
- &:not(:first-child) {
356
- margin-top: 12px;
357
- margin-left: 0;
358
- }
359
- }
360
- }
361
- }
362
-
363
- .cookie-notice-close {
364
- &[type='en'] {
365
- position: absolute;
366
- top: 16px;
367
- right: var(--layout-content-padding);
368
- transform-origin: center;
369
- }
370
- cursor: pointer;
371
- color: var(--o-color-info1);
372
- font-size: 20px;
373
- &:hover {
374
- color: var(--o-color-primary2);
375
- }
376
- @media (max-width: 840px) {
377
- font-size: 14px;
378
- }
379
- @include x-svg-hover;
380
- }
381
-
382
- .cookie-notice-wrap-grid .cookie-notice-close {
383
- right: 0;
384
- }
385
-
386
- .cookie-dlg-content {
387
- .content-item + .content-item {
388
- margin-top: 24px;
389
- }
390
-
391
- .content-item {
392
- .item-header {
393
- display: flex;
394
- align-items: center;
395
- .item-title {
396
- font-size: 18px;
397
- line-height: 32px;
398
- color: var(--o-color-info1);
399
- font-weight: 500;
400
- }
401
-
402
- .item-extra {
403
- font-size: 14px;
404
- line-height: 22px;
405
- color: var(--o-color-info3);
406
- margin-left: 24px;
407
- }
408
- }
409
-
410
- .item-detail {
411
- font-size: 16px;
412
- line-height: 28px;
413
- color: var(--o-color-info2);
414
- margin-top: 12px;
415
- @media (max-width: 840px) {
416
- font-size: 14px;
417
- line-height: 21px;
418
- margin-top: 8px;
419
- }
420
- }
421
- }
422
- }
423
- </style>
1
+ <script lang="ts" setup>
2
+ import { ref, onMounted, computed, nextTick, watch } from 'vue';
3
+ import ClientOnly from './common/ClientOnlyWrapper';
4
+ import { useScreen } from '@opendesign-plus/composables';
5
+ import { useI18n } from '@/i18n';
6
+ import { DialogActionT, OButton, ODialog, OIcon, OIconClose, OSwitch } from '@opensig/opendesign';
7
+ import { useVModel } from '@vueuse/core';
8
+
9
+ const NOT_SIGNED = '0';
10
+ const ALL_AGREED = '1';
11
+ const NECCESSARY_AGREED = '2';
12
+ const NOT_SHOW_BUT_AGREED = '3';
13
+ const COOKIE_KEY_ZH = 'agreed-cookiepolicy-zh';
14
+ const COOKIE_KEY_EN = 'agreed-cookiepolicy-en';
15
+
16
+ const props = defineProps<{
17
+ visible?: boolean;
18
+ enableGrid?: boolean;
19
+ community: string;
20
+ detailUrl: string;
21
+ wrapper?: string | HTMLElement;
22
+ cookieDomain: string;
23
+ }>();
24
+
25
+ const emit = defineEmits<{
26
+ (e: 'update:visible', value: boolean): void;
27
+ }>();
28
+
29
+ const { lePadV, leLaptop } = useScreen();
30
+ const { locale, t } = useI18n();
31
+ const isZh = computed(() => locale.value === 'zh');
32
+
33
+ const cookieKey = computed(() => (isZh.value ? COOKIE_KEY_ZH : COOKIE_KEY_EN));
34
+
35
+ // 是否允许分析cookie
36
+ const analysisAllowed = ref(false);
37
+ const visibleVmodel = useVModel(props, 'visible', emit, { defaultValue: false });
38
+
39
+ const getCookie = (key: string) => {
40
+ const cookie = document.cookie.split(';').find((row) => row.split('=')[0].trim() === encodeURIComponent(key));
41
+ if (!cookie) {
42
+ return null;
43
+ }
44
+ return decodeURIComponent(cookie.split('=')[1]);
45
+ };
46
+
47
+ const setCookie = (key: string, value: string, days: number, domain: string) => {
48
+ const maxAge = days ? `; max-age=${days * 24 * 60 * 60}` : '';
49
+ document.cookie = `${encodeURIComponent(key)}=${encodeURIComponent(value)}${maxAge}; path=/; domain=${domain}`;
50
+ };
51
+
52
+ const removeCookie = (key: string, domain: string) => {
53
+ document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; domain=${domain}`;
54
+ };
55
+
56
+ // 显示/隐藏cookie提示
57
+ const toggleNoticeVisible = (val?: boolean) => {
58
+ if (typeof val === 'boolean') {
59
+ visibleVmodel.value = val;
60
+ } else {
61
+ visibleVmodel.value = !visibleVmodel.value;
62
+ }
63
+ nextTick(() => {
64
+ if (!visibleVmodel.value && isZh.value && getCookie(cookieKey.value) !== NOT_SHOW_BUT_AGREED) {
65
+ setCookie(cookieKey.value, NOT_SHOW_BUT_AGREED, 180, props.cookieDomain ?? location.hostname);
66
+ }
67
+ });
68
+ };
69
+
70
+ // 弹出框是否显示
71
+ const isDlgVisible = ref(false);
72
+
73
+ // 显示/隐藏弹出框
74
+ const toggleDlgVisible = (val?: boolean) => {
75
+ if (typeof val === 'boolean') {
76
+ isDlgVisible.value = val;
77
+ } else {
78
+ isDlgVisible.value = !isDlgVisible.value;
79
+ }
80
+ };
81
+
82
+ // 是否未签署
83
+ const isNotSigned = () => {
84
+ if (isZh.value) {
85
+ return getCookie(cookieKey.value) !== NOT_SHOW_BUT_AGREED;
86
+ }
87
+ return (getCookie(cookieKey.value) ?? '0') === NOT_SIGNED;
88
+ };
89
+
90
+ // 是否全部同意
91
+ const isAllAgreed = () => {
92
+ if (isZh.value) {
93
+ return getCookie(cookieKey.value) === NOT_SHOW_BUT_AGREED;
94
+ }
95
+ return getCookie(cookieKey.value) === ALL_AGREED;
96
+ };
97
+
98
+ onMounted(() => {
99
+ // 未签署,展示cookie notice
100
+ if (isNotSigned()) {
101
+ toggleNoticeVisible(true);
102
+ }
103
+ });
104
+
105
+ watch(locale, () => {
106
+ toggleNoticeVisible(isNotSigned());
107
+ });
108
+
109
+ // 用户同意所有cookie
110
+ const acceptAll = () => {
111
+ analysisAllowed.value = true;
112
+ removeCookie(cookieKey.value, props.cookieDomain ?? location.hostname);
113
+ setCookie(cookieKey.value, ALL_AGREED, 180, props.cookieDomain ?? location.hostname);
114
+ toggleNoticeVisible(false);
115
+ };
116
+
117
+ // 用户拒绝所有cookie,即仅同意必要cookie
118
+ const rejectAll = () => {
119
+ analysisAllowed.value = false;
120
+ removeCookie(cookieKey.value, props.cookieDomain ?? location.hostname);
121
+ setCookie(cookieKey.value, NECCESSARY_AGREED, 180, props.cookieDomain ?? location.hostname);
122
+ toggleNoticeVisible(false);
123
+ };
124
+
125
+ // 弹出框设置
126
+ const dlgActions = computed<Array<DialogActionT>>(() => [
127
+ {
128
+ id: 'save',
129
+ color: 'primary',
130
+ label: t('cookie.saveSetting'),
131
+ variant: 'outline',
132
+ size: 'large',
133
+ round: 'pill',
134
+ onClick: () => {
135
+ if (analysisAllowed.value) {
136
+ acceptAll();
137
+ } else {
138
+ rejectAll();
139
+ }
140
+
141
+ toggleDlgVisible(false);
142
+ },
143
+ },
144
+ {
145
+ id: 'allowAll',
146
+ color: 'primary',
147
+ label: t('cookie.acceptAll'),
148
+ variant: 'outline',
149
+ size: 'large',
150
+ round: 'pill',
151
+ onClick: () => {
152
+ analysisAllowed.value = true;
153
+ acceptAll();
154
+ toggleDlgVisible(false);
155
+ },
156
+ },
157
+ ]);
158
+
159
+ const onDlgChange = (val: boolean) => {
160
+ if (val) {
161
+ analysisAllowed.value = isAllAgreed();
162
+ }
163
+ };
164
+
165
+ defineExpose({
166
+ check() {
167
+ const agreed = isAllAgreed();
168
+ if (agreed === visibleVmodel.value) {
169
+ toggleNoticeVisible();
170
+ }
171
+ },
172
+ });
173
+ </script>
174
+
175
+ <template>
176
+ <ClientOnly>
177
+ <Teleport :to="wrapper || '#app'">
178
+ <div v-if="visibleVmodel" class="cookie-notice">
179
+ <div class="cookie-notice-content">
180
+ <div :type="locale" :class="{ 'cookie-notice-wrap-grid': enableGrid, 'cookie-notice-wrap': !enableGrid }">
181
+ <div class="cookie-notice-left">
182
+ <p v-if="isZh" class="cookie-desc" style="margin-top: 0">
183
+ {{ t('cookie.desc') }}
184
+ <a :href="detailUrl" target="_blank" rel="noopener noreferrer">
185
+ {{ t('cookie.about') }}
186
+ </a>
187
+ </p>
188
+ <template v-else>
189
+ <p class="cookie-title">{{ t('cookie.title', [community]) }}</p>
190
+ <p class="cookie-desc">
191
+ {{ t('cookie.desc') }}
192
+ <a :href="detailUrl" target="_blank" rel="noopener noreferrer">{{ t('cookie.about') }} </a>.
193
+ </p>
194
+ </template>
195
+ </div>
196
+ <div v-if="!isZh" class="cookie-notice-right">
197
+ <OButton round="pill" variant="outline" color="primary" @click="acceptAll">{{ t('cookie.acceptAll') }}</OButton>
198
+ <OButton round="pill" variant="outline" color="primary" @click="rejectAll">{{ t('cookie.rejectAll') }}</OButton>
199
+ <OButton round="pill" variant="outline" color="primary" @click="toggleDlgVisible(true)">
200
+ {{ t('cookie.manage') }}
201
+ </OButton>
202
+ </div>
203
+ <OIcon class="cookie-notice-close" :type="locale" @click="toggleNoticeVisible(false)">
204
+ <OIconClose />
205
+ </OIcon>
206
+ </div>
207
+ </div>
208
+ <ODialog
209
+ v-model:visible="isDlgVisible"
210
+ :size="leLaptop ? 'medium' : 'large'"
211
+ :phone-half-full="lePadV"
212
+ class="cookie-dlg"
213
+ :actions="dlgActions"
214
+ @change="onDlgChange"
215
+ >
216
+ <template #header>
217
+ <span class="cookie-dlg-title">{{ t('cookie.manage') }}</span>
218
+ </template>
219
+ <div class="cookie-dlg-content">
220
+ <div class="content-item">
221
+ <div class="item-header">
222
+ <span class="item-title">{{ t('cookie.necessaryCookie') }}</span>
223
+ <span class="item-extra">{{ t('cookie.alwaysOn') }}</span>
224
+ </div>
225
+ <div class="item-detail">
226
+ {{ t('cookie.necessaryCookieDetail') }}
227
+ </div>
228
+ </div>
229
+ <div class="content-item">
230
+ <div class="item-header">
231
+ <span class="item-title">{{ t('cookie.analyticalCookie') }}</span>
232
+ <span class="item-extra">
233
+ <OSwitch v-model="analysisAllowed" />
234
+ </span>
235
+ </div>
236
+ <div class="item-detail">
237
+ {{ t('cookie.analyticalCookieDetail') }}
238
+ </div>
239
+ </div>
240
+ </div>
241
+ </ODialog>
242
+ </div>
243
+ </Teleport>
244
+ </ClientOnly>
245
+ </template>
246
+
247
+ <style lang="scss" scoped>
248
+ .cookie-notice {
249
+ position: fixed;
250
+ bottom: 0;
251
+ z-index: 999;
252
+ width: 100%;
253
+ .o-button {
254
+ --o-button-font-size-mini: 14px;
255
+ }
256
+ .o-button + .o-button {
257
+ margin-left: 16px;
258
+
259
+ @media (max-width: 840px) {
260
+ margin-left: 0;
261
+ margin-top: 12px;
262
+ }
263
+ }
264
+ }
265
+
266
+ .cookie-notice-content {
267
+ background-color: rgba(var(--o-mixedgray-1), 0.9);
268
+ backdrop-filter: blur(5px);
269
+ box-shadow: var(--o-shadow-1);
270
+ }
271
+
272
+ .cookie-notice-wrap {
273
+ position: relative;
274
+ display: flex;
275
+ justify-content: space-between;
276
+ margin: 0 auto;
277
+ padding: 24px var(--layout-content-padding);
278
+ max-width: var(--layout-content-max-width);
279
+ &:not([type='zh']) {
280
+ @media (max-width: 840px) {
281
+ flex-direction: column;
282
+ align-items: center;
283
+ }
284
+ }
285
+ }
286
+
287
+ .cookie-notice-wrap-grid {
288
+ position: relative;
289
+ display: flex;
290
+ justify-content: space-between;
291
+ width: var(--grid-content-width);
292
+ padding: 24px 0;
293
+ margin: 0 auto;
294
+ &:not([type='zh']) {
295
+ @media (max-width: 840px) {
296
+ padding: 16px 0;
297
+ flex-direction: column;
298
+ align-items: center;
299
+ }
300
+ }
301
+ }
302
+
303
+ .cookie-notice-left {
304
+ width: 60%;
305
+
306
+ @media (max-width: 1100px) {
307
+ width: 58%;
308
+ }
309
+
310
+ @media (max-width: 840px) {
311
+ width: 100%;
312
+ }
313
+
314
+ .cookie-title {
315
+ font-size: 16px;
316
+ line-height: 28px;
317
+ color: var(--o-color-info1);
318
+ font-weight: 500;
319
+ @media (max-width: 840px) {
320
+ font-size: 16px;
321
+ line-height: 24px;
322
+ text-align: center;
323
+ }
324
+ }
325
+
326
+ .cookie-desc {
327
+ font-size: 12px;
328
+ line-height: 18px;
329
+ color: var(--o-color-info2);
330
+ margin-top: 8px;
331
+ }
332
+ }
333
+
334
+ .cookie-notice-right {
335
+ display: flex;
336
+ align-items: center;
337
+ margin-top: 12px;
338
+
339
+ @media (max-width: 840px) {
340
+ width: 100%;
341
+ }
342
+
343
+ @media (max-width: 840px) {
344
+ flex-direction: column;
345
+ align-items: center;
346
+ }
347
+
348
+ .o-btn:not(:first-child) {
349
+ margin-left: 16px;
350
+ }
351
+
352
+ @media (max-width: 840px) {
353
+ .o-btn {
354
+ align-self: stretch;
355
+ &:not(:first-child) {
356
+ margin-top: 12px;
357
+ margin-left: 0;
358
+ }
359
+ }
360
+ }
361
+ }
362
+
363
+ .cookie-notice-close {
364
+ &[type='en'] {
365
+ position: absolute;
366
+ top: 16px;
367
+ right: var(--layout-content-padding);
368
+ transform-origin: center;
369
+ }
370
+ cursor: pointer;
371
+ color: var(--o-color-info1);
372
+ font-size: 20px;
373
+ &:hover {
374
+ color: var(--o-color-primary2);
375
+ }
376
+ @media (max-width: 840px) {
377
+ font-size: 14px;
378
+ }
379
+ @include x-svg-hover;
380
+ }
381
+
382
+ .cookie-notice-wrap-grid .cookie-notice-close {
383
+ right: 0;
384
+ }
385
+
386
+ .cookie-dlg-content {
387
+ .content-item + .content-item {
388
+ margin-top: 24px;
389
+ }
390
+
391
+ .content-item {
392
+ .item-header {
393
+ display: flex;
394
+ align-items: center;
395
+ .item-title {
396
+ font-size: 18px;
397
+ line-height: 32px;
398
+ color: var(--o-color-info1);
399
+ font-weight: 500;
400
+ }
401
+
402
+ .item-extra {
403
+ font-size: 14px;
404
+ line-height: 22px;
405
+ color: var(--o-color-info3);
406
+ margin-left: 24px;
407
+ }
408
+ }
409
+
410
+ .item-detail {
411
+ font-size: 16px;
412
+ line-height: 28px;
413
+ color: var(--o-color-info2);
414
+ margin-top: 12px;
415
+ @media (max-width: 840px) {
416
+ font-size: 14px;
417
+ line-height: 21px;
418
+ margin-top: 8px;
419
+ }
420
+ }
421
+ }
422
+ }
423
+ </style>