@waline/client 2.0.6 → 2.1.1
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/dist/component.js +1 -1
- package/dist/component.js.map +1 -1
- package/dist/legacy.d.ts +9 -7
- package/dist/legacy.js +1 -1
- package/dist/legacy.js.map +1 -1
- package/dist/pageview.cjs.js +1 -1
- package/dist/pageview.cjs.js.map +1 -1
- package/dist/pageview.d.ts +9 -1
- package/dist/pageview.esm.js +1 -1
- package/dist/pageview.esm.js.map +1 -1
- package/dist/pageview.js +1 -1
- package/dist/pageview.js.map +1 -1
- package/dist/shim.d.ts +38 -11
- package/dist/shim.esm.d.ts +38 -11
- package/dist/shim.esm.js +1 -1
- package/dist/shim.esm.js.map +1 -1
- package/dist/shim.js +1 -1
- package/dist/shim.js.map +1 -1
- package/dist/waline.cjs.d.ts +38 -11
- package/dist/waline.cjs.js +1 -1
- package/dist/waline.cjs.js.map +1 -1
- package/dist/waline.css +1 -1
- package/dist/waline.css.map +1 -1
- package/dist/waline.d.ts +38 -11
- package/dist/waline.esm.d.ts +38 -11
- package/dist/waline.esm.js +1 -1
- package/dist/waline.esm.js.map +1 -1
- package/dist/waline.js +1 -1
- package/dist/waline.js.map +1 -1
- package/package.json +23 -6
- package/src/comment.ts +11 -0
- package/src/components/CommentBox.vue +14 -8
- package/src/components/CommentCard.vue +5 -0
- package/src/components/Waline.vue +21 -40
- package/src/composables/timeAgo.ts +2 -48
- package/src/config/i18n/en.ts +6 -0
- package/src/config/i18n/generate.ts +6 -0
- package/src/config/i18n/zh-CN.ts +6 -0
- package/src/config/i18n/zh-TW.ts +6 -0
- package/src/entrys/legacy.ts +1 -1
- package/src/pageview.ts +12 -1
- package/src/styles/card.scss +4 -4
- package/src/styles/config.scss +2 -2
- package/src/styles/layout.scss +3 -3
- package/src/typings/comment.ts +1 -0
- package/src/typings/locale.ts +9 -6
- package/src/typings/waline.ts +1 -1
- package/src/utils/config.ts +1 -2
- package/src/utils/date.ts +54 -0
- package/src/utils/emoji.ts +2 -2
- package/src/utils/fetch.ts +20 -7
- package/src/widgets/recentComments.ts +11 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waline/client",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "client for waline comment system",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"valine",
|
|
@@ -24,9 +24,23 @@
|
|
|
24
24
|
"require": "./dist/shim.js",
|
|
25
25
|
"default": "./dist/shim.js"
|
|
26
26
|
},
|
|
27
|
-
"./dist":
|
|
27
|
+
"./dist": {
|
|
28
|
+
"import": "./dist/shim.esm.js",
|
|
29
|
+
"require": "./dist/shim.js",
|
|
30
|
+
"default": "./dist/shim.js"
|
|
31
|
+
},
|
|
32
|
+
"./dist/pageview": {
|
|
33
|
+
"import": "./dist/pageview.esm.js",
|
|
34
|
+
"require": "./dist/pageview.cjs.js",
|
|
35
|
+
"default": "./dist/pageview.js"
|
|
36
|
+
},
|
|
37
|
+
"./dist/waline": {
|
|
38
|
+
"import": "./dist/waline.esm.js",
|
|
39
|
+
"require": "./dist/waline.cjs.js",
|
|
40
|
+
"default": "./dist/waline.js"
|
|
41
|
+
},
|
|
28
42
|
"./dist/waline.css": "./dist/waline.css",
|
|
29
|
-
"./dist/*": "./dist
|
|
43
|
+
"./dist/*": "./dist/*",
|
|
30
44
|
"./src/*": "./src/*",
|
|
31
45
|
"./package.json": "./package.json"
|
|
32
46
|
},
|
|
@@ -40,9 +54,10 @@
|
|
|
40
54
|
"scripts": {
|
|
41
55
|
"build": "npm run rollup && npm run style",
|
|
42
56
|
"clean": "rimraf ./dist",
|
|
57
|
+
"dev": "vite -c config/vite.config.js",
|
|
43
58
|
"lint": "eslint --ext .ts,.vue .",
|
|
44
59
|
"prepublish": "npm run clean && npm run build",
|
|
45
|
-
"rollup": "rollup -c ./
|
|
60
|
+
"rollup": "rollup -c ./config/rollup.config.js",
|
|
46
61
|
"style": "sass ./src/styles/index.scss ./dist/waline.css --style=compressed"
|
|
47
62
|
},
|
|
48
63
|
"browserslist": {
|
|
@@ -63,12 +78,14 @@
|
|
|
63
78
|
"@vueuse/core": "^8.3.1",
|
|
64
79
|
"autosize": "^5.0.1",
|
|
65
80
|
"hanabi": "^0.4.0",
|
|
66
|
-
"marked": "^4.0.
|
|
81
|
+
"marked": "^4.0.15",
|
|
67
82
|
"vue": "^3.2.33"
|
|
68
83
|
},
|
|
69
84
|
"devDependencies": {
|
|
70
85
|
"@types/autosize": "^4.0.1",
|
|
71
|
-
"@types/marked": "^4.0.3"
|
|
86
|
+
"@types/marked": "^4.0.3",
|
|
87
|
+
"@vitejs/plugin-vue": "^2.3.1",
|
|
88
|
+
"vite": "^2.9.6"
|
|
72
89
|
},
|
|
73
90
|
"engines": {
|
|
74
91
|
"node": ">=12.20.0"
|
package/src/comment.ts
CHANGED
|
@@ -27,12 +27,22 @@ export interface WalineCommentCountOptions {
|
|
|
27
27
|
* @default window.location.pathname
|
|
28
28
|
*/
|
|
29
29
|
path?: string;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 错误提示消息所使用的语言
|
|
33
|
+
*
|
|
34
|
+
* Language of error message
|
|
35
|
+
*
|
|
36
|
+
* @default 'zh-CN'
|
|
37
|
+
*/
|
|
38
|
+
lang?: string;
|
|
30
39
|
}
|
|
31
40
|
|
|
32
41
|
export const commentCount = ({
|
|
33
42
|
serverURL,
|
|
34
43
|
path = window.location.pathname,
|
|
35
44
|
selector = '.waline-comment-count',
|
|
45
|
+
lang = 'zh-CN',
|
|
36
46
|
}: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
47
|
WalineCommentCountOptions): WalineAbort => {
|
|
38
48
|
const controller = new AbortController();
|
|
@@ -48,6 +58,7 @@ WalineCommentCountOptions): WalineAbort => {
|
|
|
48
58
|
paths: Array.from(elements).map((element) =>
|
|
49
59
|
decodePath(element.dataset.path || element.getAttribute('id') || path)
|
|
50
60
|
),
|
|
61
|
+
lang,
|
|
51
62
|
signal: controller.signal,
|
|
52
63
|
token: userInfo.value?.token,
|
|
53
64
|
})
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
</a>
|
|
79
79
|
|
|
80
80
|
<button
|
|
81
|
+
v-show="emoji.tabs.length"
|
|
81
82
|
ref="emojiButtonRef"
|
|
82
83
|
class="wl-action"
|
|
83
84
|
:class="{ actived: showEmoji }"
|
|
@@ -395,16 +396,19 @@ export default defineComponent({
|
|
|
395
396
|
if (login === 'force') return;
|
|
396
397
|
|
|
397
398
|
// check nick
|
|
398
|
-
if (
|
|
399
|
-
(requiredMeta.indexOf('nick') > -1 || comment.nick) &&
|
|
400
|
-
!comment.nick
|
|
401
|
-
) {
|
|
399
|
+
if (requiredMeta.indexOf('nick') > -1 && !comment.nick) {
|
|
402
400
|
inputRefs.value.nick?.focus();
|
|
403
401
|
return alert(locale.value.nickError);
|
|
404
402
|
}
|
|
405
403
|
|
|
406
404
|
// check mail
|
|
407
|
-
if (
|
|
405
|
+
if (
|
|
406
|
+
(requiredMeta.indexOf('mail') > -1 && !comment.mail) ||
|
|
407
|
+
(comment.mail &&
|
|
408
|
+
!/^\w(?:[\w._-]*\w)?@(?:\w(?:[\w-]*\w)?\.){0,2}\w+$/.exec(
|
|
409
|
+
comment.mail
|
|
410
|
+
))
|
|
411
|
+
) {
|
|
408
412
|
inputRefs.value.mail?.focus();
|
|
409
413
|
return alert(locale.value.mailError);
|
|
410
414
|
}
|
|
@@ -602,9 +606,11 @@ export default defineComponent({
|
|
|
602
606
|
watch(
|
|
603
607
|
() => config.value.emoji,
|
|
604
608
|
(emojiConfig) =>
|
|
605
|
-
getEmojis(emojiConfig).then(
|
|
606
|
-
|
|
607
|
-
|
|
609
|
+
getEmojis(Array.isArray(emojiConfig) ? emojiConfig : []).then(
|
|
610
|
+
(config) => {
|
|
611
|
+
emoji.value = config;
|
|
612
|
+
}
|
|
613
|
+
),
|
|
608
614
|
{ immediate: true }
|
|
609
615
|
);
|
|
610
616
|
});
|
|
@@ -23,6 +23,11 @@
|
|
|
23
23
|
v-text="locale.admin"
|
|
24
24
|
/>
|
|
25
25
|
<span v-if="comment.sticky" class="wl-badge" v-text="locale.sticky" />
|
|
26
|
+
<span
|
|
27
|
+
v-if="comment.level >= 0"
|
|
28
|
+
class="wl-badge"
|
|
29
|
+
v-text="locale[`level${comment.level}`] || `Level ${comment.level}`"
|
|
30
|
+
/>
|
|
26
31
|
|
|
27
32
|
<span class="wl-time" v-text="time" />
|
|
28
33
|
|
|
@@ -61,16 +61,8 @@
|
|
|
61
61
|
</template>
|
|
62
62
|
|
|
63
63
|
<script lang="ts">
|
|
64
|
-
import {
|
|
65
|
-
|
|
66
|
-
defineComponent,
|
|
67
|
-
onBeforeUnmount,
|
|
68
|
-
onMounted,
|
|
69
|
-
provide,
|
|
70
|
-
ref,
|
|
71
|
-
watch,
|
|
72
|
-
watchEffect,
|
|
73
|
-
} from 'vue';
|
|
64
|
+
import { useStyleTag } from '@vueuse/core';
|
|
65
|
+
import { computed, defineComponent, onMounted, provide, ref, watch } from 'vue';
|
|
74
66
|
import CommentBox from './CommentBox.vue';
|
|
75
67
|
import CommentCard from './CommentCard.vue';
|
|
76
68
|
import { LoadingIcon } from './Icons';
|
|
@@ -171,23 +163,24 @@ export default defineComponent({
|
|
|
171
163
|
},
|
|
172
164
|
|
|
173
165
|
emoji: {
|
|
174
|
-
type: Array as PropType<(string | WalineEmojiInfo)[]>,
|
|
166
|
+
type: [Array, Boolean] as PropType<(string | WalineEmojiInfo)[] | false>,
|
|
175
167
|
...(SHOULD_VALIDATE
|
|
176
168
|
? {
|
|
177
169
|
validator: (value: unknown): boolean =>
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
(
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
typeof item
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
(
|
|
189
|
-
|
|
190
|
-
|
|
170
|
+
value === false ||
|
|
171
|
+
(Array.isArray(value) &&
|
|
172
|
+
value.every(
|
|
173
|
+
(item) =>
|
|
174
|
+
typeof item === 'string' ||
|
|
175
|
+
(typeof item === 'object' &&
|
|
176
|
+
typeof item.name === 'string' &&
|
|
177
|
+
typeof item.folder === 'string' &&
|
|
178
|
+
typeof item.icon === 'string' &&
|
|
179
|
+
Array.isArray(item.items) &&
|
|
180
|
+
(item.items as unknown[]).every(
|
|
181
|
+
(icon) => typeof icon === 'string'
|
|
182
|
+
))
|
|
183
|
+
)),
|
|
191
184
|
}
|
|
192
185
|
: {}),
|
|
193
186
|
},
|
|
@@ -225,9 +218,10 @@ export default defineComponent({
|
|
|
225
218
|
|
|
226
219
|
const darkmodeStyle = computed(() => getDarkStyle(config.value.dark));
|
|
227
220
|
|
|
221
|
+
useStyleTag(darkmodeStyle);
|
|
222
|
+
|
|
228
223
|
// eslint-disable-next-line vue/no-setup-props-destructure
|
|
229
224
|
let abort: () => void;
|
|
230
|
-
let stop: () => void;
|
|
231
225
|
|
|
232
226
|
const fetchComment = (pageNumber: number): void => {
|
|
233
227
|
const { serverURL, path, pageSize } = config.value;
|
|
@@ -239,6 +233,7 @@ export default defineComponent({
|
|
|
239
233
|
|
|
240
234
|
fetchCommentList({
|
|
241
235
|
serverURL,
|
|
236
|
+
lang: config.value.lang,
|
|
242
237
|
path,
|
|
243
238
|
pageSize,
|
|
244
239
|
page: pageNumber,
|
|
@@ -293,21 +288,7 @@ export default defineComponent({
|
|
|
293
288
|
|
|
294
289
|
watch(() => props.path, refresh);
|
|
295
290
|
|
|
296
|
-
onMounted(() =>
|
|
297
|
-
refresh();
|
|
298
|
-
|
|
299
|
-
const style = document.createElement('style');
|
|
300
|
-
|
|
301
|
-
style.innerText = darkmodeStyle.value;
|
|
302
|
-
|
|
303
|
-
document.querySelector('[data-waline]')?.appendChild(style);
|
|
304
|
-
|
|
305
|
-
stop = watchEffect(() => {
|
|
306
|
-
style.innerText = darkmodeStyle.value;
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
onBeforeUnmount(() => stop());
|
|
291
|
+
onMounted(() => refresh());
|
|
311
292
|
|
|
312
293
|
return {
|
|
313
294
|
config,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useNow } from '@vueuse/core';
|
|
2
2
|
import { computed } from 'vue';
|
|
3
|
-
import {
|
|
3
|
+
import { getTimeAgo } from '../utils';
|
|
4
4
|
|
|
5
5
|
import type { ComputedRef } from 'vue';
|
|
6
6
|
import type { WalineLocale } from '../typings';
|
|
@@ -11,51 +11,5 @@ export const useTimeAgo = (
|
|
|
11
11
|
): ComputedRef<string> => {
|
|
12
12
|
const now = useNow();
|
|
13
13
|
|
|
14
|
-
return computed(() =>
|
|
15
|
-
if (!date) return '';
|
|
16
|
-
|
|
17
|
-
const time =
|
|
18
|
-
typeof date === 'string'
|
|
19
|
-
? new Date(date.indexOf(' ') !== -1 ? date.replace(/-/g, '/') : date)
|
|
20
|
-
: date;
|
|
21
|
-
|
|
22
|
-
const timepassed = now.value.getTime() - time.getTime();
|
|
23
|
-
|
|
24
|
-
const days = Math.floor(timepassed / (24 * 3600 * 1000));
|
|
25
|
-
|
|
26
|
-
if (days === 0) {
|
|
27
|
-
// 计算相差小时数
|
|
28
|
-
|
|
29
|
-
// 计算天数后剩余的毫秒数
|
|
30
|
-
const leave1 = timepassed % (24 * 3600 * 1000);
|
|
31
|
-
const hours = Math.floor(leave1 / (3600 * 1000));
|
|
32
|
-
|
|
33
|
-
if (hours === 0) {
|
|
34
|
-
//计算相差分钟数
|
|
35
|
-
|
|
36
|
-
// 计算小时数后剩余的毫秒数
|
|
37
|
-
const leave2 = leave1 % (3600 * 1000);
|
|
38
|
-
const minutes = Math.floor(leave2 / (60 * 1000));
|
|
39
|
-
|
|
40
|
-
// 计算相差秒数
|
|
41
|
-
if (minutes === 0) {
|
|
42
|
-
// 计算分钟数后剩余的毫秒数
|
|
43
|
-
const leave3 = leave2 % (60 * 1000);
|
|
44
|
-
const seconds = Math.round(leave3 / 1000);
|
|
45
|
-
|
|
46
|
-
return `${seconds} ${locale.seconds}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return `${minutes} ${locale.minutes}`;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return `${hours} ${locale.hours}`;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (days < 0) return locale.now;
|
|
56
|
-
|
|
57
|
-
if (days < 8) return `${days} ${locale.days}`;
|
|
58
|
-
|
|
59
|
-
return dateFormat(time);
|
|
60
|
-
});
|
|
14
|
+
return computed(() => getTimeAgo(date, now.value, locale));
|
|
61
15
|
};
|
package/src/config/i18n/en.ts
CHANGED
package/src/config/i18n/zh-CN.ts
CHANGED
package/src/config/i18n/zh-TW.ts
CHANGED
package/src/entrys/legacy.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { WalineInitOptions } from '../typings';
|
|
|
10
10
|
export { WalineInstance } from '../init';
|
|
11
11
|
|
|
12
12
|
warning(
|
|
13
|
-
' This is a legacy package
|
|
13
|
+
' This is a legacy package compatible with Valine and Waline@v1, please switch to Waline@v2 using https://<CDN.LINK>/@waline/client/dist/waline.js instead!'
|
|
14
14
|
);
|
|
15
15
|
|
|
16
16
|
// inject css styles
|
package/src/pageview.ts
CHANGED
|
@@ -41,6 +41,15 @@ export interface WalinePageviewCountOptions {
|
|
|
41
41
|
* @default true
|
|
42
42
|
*/
|
|
43
43
|
update?: boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 错误提示消息所使用的语言
|
|
47
|
+
*
|
|
48
|
+
* Language of error message
|
|
49
|
+
*
|
|
50
|
+
* @default 'zh-CN'
|
|
51
|
+
*/
|
|
52
|
+
lang?: string;
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
const renderVisitorCount = (
|
|
@@ -57,6 +66,7 @@ export const pageviewCount = ({
|
|
|
57
66
|
path = window.location.pathname,
|
|
58
67
|
selector = '.waline-pageview-count',
|
|
59
68
|
update = true,
|
|
69
|
+
lang = 'zh-CN',
|
|
60
70
|
}: WalinePageviewCountOptions): WalineAbort => {
|
|
61
71
|
const controller = new AbortController();
|
|
62
72
|
|
|
@@ -75,6 +85,7 @@ export const pageviewCount = ({
|
|
|
75
85
|
fetchPageviews({
|
|
76
86
|
serverURL,
|
|
77
87
|
paths: elements.map((element) => getQuery(element) || path),
|
|
88
|
+
lang,
|
|
78
89
|
signal: controller.signal,
|
|
79
90
|
})
|
|
80
91
|
.then((counts) => renderVisitorCount(counts, elements))
|
|
@@ -85,7 +96,7 @@ export const pageviewCount = ({
|
|
|
85
96
|
const normalElements = elements.filter((element) => !filter(element));
|
|
86
97
|
const elementsNeedstoBeFetched = elements.filter(filter);
|
|
87
98
|
|
|
88
|
-
void updatePageviews({ serverURL, path }).then((count) =>
|
|
99
|
+
void updatePageviews({ serverURL, path, lang }).then((count) =>
|
|
89
100
|
renderVisitorCount(
|
|
90
101
|
new Array<number>(normalElements.length).fill(count),
|
|
91
102
|
normalElements
|
package/src/styles/card.scss
CHANGED
|
@@ -85,12 +85,12 @@
|
|
|
85
85
|
.wl-badge {
|
|
86
86
|
display: inline-block;
|
|
87
87
|
|
|
88
|
-
margin-right:
|
|
88
|
+
margin-right: 1em;
|
|
89
89
|
padding: 0 0.3em;
|
|
90
|
-
border
|
|
90
|
+
border: 1px solid var(--waline-badge-color);
|
|
91
|
+
border-radius: 4px;
|
|
91
92
|
|
|
92
|
-
|
|
93
|
-
color: var(--waline-white);
|
|
93
|
+
color: var(--waline-badge-color);
|
|
94
94
|
|
|
95
95
|
font-size: var(--waline-badge-font-size);
|
|
96
96
|
}
|
package/src/styles/config.scss
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
:root {
|
|
2
2
|
// font-size
|
|
3
|
-
--waline-font-size:
|
|
3
|
+
--waline-font-size: 1rem;
|
|
4
4
|
|
|
5
5
|
// regular colors
|
|
6
6
|
--waline-white: #fff;
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
// badge
|
|
32
32
|
--waline-badge-color: #3498db;
|
|
33
|
-
--waline-badge-font-size: 0.
|
|
33
|
+
--waline-badge-font-size: 0.75em;
|
|
34
34
|
|
|
35
35
|
// info
|
|
36
36
|
--waline-info-bgcolor: #f8f8f8;
|
package/src/styles/layout.scss
CHANGED
package/src/typings/comment.ts
CHANGED
package/src/typings/locale.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface WalineDateLocale {
|
|
2
|
+
seconds: string;
|
|
3
|
+
minutes: string;
|
|
4
|
+
hours: string;
|
|
5
|
+
days: string;
|
|
6
|
+
now: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface WalineLocale extends WalineDateLocale {
|
|
2
10
|
nick: string;
|
|
3
11
|
nickError: string;
|
|
4
12
|
mail: string;
|
|
@@ -16,11 +24,6 @@ export interface WalineLocale {
|
|
|
16
24
|
preview: string;
|
|
17
25
|
emoji: string;
|
|
18
26
|
uploadImage: string;
|
|
19
|
-
seconds: string;
|
|
20
|
-
minutes: string;
|
|
21
|
-
hours: string;
|
|
22
|
-
days: string;
|
|
23
|
-
now: string;
|
|
24
27
|
uploading: string;
|
|
25
28
|
login: string;
|
|
26
29
|
logout: string;
|
package/src/typings/waline.ts
CHANGED
package/src/utils/config.ts
CHANGED
|
@@ -50,7 +50,7 @@ export const getConfig = ({
|
|
|
50
50
|
path = location.pathname,
|
|
51
51
|
lang = defaultLang,
|
|
52
52
|
locale,
|
|
53
|
-
emoji = ['//unpkg.com/@waline/emojis@1.0.1/weibo
|
|
53
|
+
emoji = ['//unpkg.com/@waline/emojis@1.0.1/weibo'],
|
|
54
54
|
meta = ['nick', 'mail', 'link'],
|
|
55
55
|
requiredMeta = [],
|
|
56
56
|
dark = false,
|
|
@@ -69,7 +69,6 @@ export const getConfig = ({
|
|
|
69
69
|
...(locales[lang] || locales[defaultLang]),
|
|
70
70
|
...(typeof locale === 'object' ? locale : {}),
|
|
71
71
|
},
|
|
72
|
-
// emoji: getEmojis(emoji),
|
|
73
72
|
wordLimit: getWordLimit(wordLimit),
|
|
74
73
|
meta: getMeta(meta),
|
|
75
74
|
requiredMeta: getMeta(requiredMeta),
|
package/src/utils/date.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { WalineDateLocale } from '../typings';
|
|
2
|
+
|
|
1
3
|
const padWithZeros = (vNumber: number, width: number): string => {
|
|
2
4
|
let numAsString = vNumber.toString();
|
|
3
5
|
|
|
@@ -15,3 +17,55 @@ export const dateFormat = (date: Date): string => {
|
|
|
15
17
|
|
|
16
18
|
return `${vYear}-${vMonth}-${vDay}`;
|
|
17
19
|
};
|
|
20
|
+
|
|
21
|
+
export const getTimeAgo = (
|
|
22
|
+
date: Date | string,
|
|
23
|
+
now: Date,
|
|
24
|
+
locale: WalineDateLocale
|
|
25
|
+
): string => {
|
|
26
|
+
if (!date) return '';
|
|
27
|
+
|
|
28
|
+
const time =
|
|
29
|
+
typeof date === 'string'
|
|
30
|
+
? new Date(date.indexOf(' ') !== -1 ? date.replace(/-/g, '/') : date)
|
|
31
|
+
: date;
|
|
32
|
+
|
|
33
|
+
const timepassed = now.getTime() - time.getTime();
|
|
34
|
+
|
|
35
|
+
const days = Math.floor(timepassed / (24 * 3600 * 1000));
|
|
36
|
+
|
|
37
|
+
if (days === 0) {
|
|
38
|
+
// 计算相差小时数
|
|
39
|
+
|
|
40
|
+
// 计算天数后剩余的毫秒数
|
|
41
|
+
const leave1 = timepassed % (24 * 3600 * 1000);
|
|
42
|
+
const hours = Math.floor(leave1 / (3600 * 1000));
|
|
43
|
+
|
|
44
|
+
if (hours === 0) {
|
|
45
|
+
//计算相差分钟数
|
|
46
|
+
|
|
47
|
+
// 计算小时数后剩余的毫秒数
|
|
48
|
+
const leave2 = leave1 % (3600 * 1000);
|
|
49
|
+
const minutes = Math.floor(leave2 / (60 * 1000));
|
|
50
|
+
|
|
51
|
+
// 计算相差秒数
|
|
52
|
+
if (minutes === 0) {
|
|
53
|
+
// 计算分钟数后剩余的毫秒数
|
|
54
|
+
const leave3 = leave2 % (60 * 1000);
|
|
55
|
+
const seconds = Math.round(leave3 / 1000);
|
|
56
|
+
|
|
57
|
+
return `${seconds} ${locale.seconds}`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return `${minutes} ${locale.minutes}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return `${hours} ${locale.hours}`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (days < 0) return locale.now;
|
|
67
|
+
|
|
68
|
+
if (days < 8) return `${days} ${locale.days}`;
|
|
69
|
+
|
|
70
|
+
return dateFormat(time);
|
|
71
|
+
};
|
package/src/utils/emoji.ts
CHANGED
|
@@ -16,7 +16,7 @@ const fetchEmoji = (link: string): Promise<WalineEmojiInfo> => {
|
|
|
16
16
|
const result = hasVersion(link);
|
|
17
17
|
|
|
18
18
|
if (result) {
|
|
19
|
-
const info = emojiStore.value
|
|
19
|
+
const info = emojiStore.value[link];
|
|
20
20
|
|
|
21
21
|
if (info) return Promise.resolve(info);
|
|
22
22
|
}
|
|
@@ -29,7 +29,7 @@ const fetchEmoji = (link: string): Promise<WalineEmojiInfo> => {
|
|
|
29
29
|
...emojiInfo,
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
if (result) emojiStore.value
|
|
32
|
+
if (result) emojiStore.value[link] = info;
|
|
33
33
|
|
|
34
34
|
return info;
|
|
35
35
|
});
|