Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
221 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createI18n, DefineDateTimeFormat }from 'vue-i18n'; | ||
import { Language } from '@/constants'; | ||
import zhCN from './locales/zh-CN.json'; | ||
import en from './locales/en.json'; | ||
|
||
const dateTimeFormats: DefineDateTimeFormat = { | ||
short: { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
}, | ||
weekday: { | ||
weekday: 'short', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
}, | ||
long: { | ||
year: 'numeric', | ||
month: 'short', | ||
day: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
hour12: false, | ||
}, | ||
}; | ||
|
||
export const i18n = createI18n({ | ||
legacy: false, | ||
datetimeFormats: { | ||
en: dateTimeFormats, | ||
'zh-CN': dateTimeFormats, | ||
}, | ||
locale: Language.EN, | ||
messages: { | ||
en, | ||
'zh-CN': zhCN, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/** | ||
* 生成provide key通用函数 | ||
* @param module 模块名称 | ||
* @returns func | ||
*/ | ||
export const provideKeyFactory = (module: string) => (key: string) => Symbol(`@${module}:${key}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import dayjs from 'dayjs'; | ||
import today from 'dayjs/plugin/isToday'; | ||
import yesterday from 'dayjs/plugin/isYesterday'; | ||
import between from 'dayjs/plugin/isBetween'; | ||
|
||
dayjs.extend(today); | ||
dayjs.extend(yesterday); | ||
dayjs.extend(between); | ||
|
||
/** | ||
* 显示聊天时间 | ||
* @param time 时间戳 | ||
* @returns 展示的时间 | ||
*/ | ||
export const getChatDate = (time?: number): string => { | ||
if (!time) { | ||
return ''; | ||
} | ||
const date = dayjs(time); | ||
if (date.isToday()) { | ||
return date.format('HH:mm'); | ||
} | ||
return date.format('YYYY/MM/DD'); | ||
}; | ||
|
||
|
||
/** | ||
* 是否为昨天 | ||
*/ | ||
export const isYesterday = (time: number | string) => dayjs(time).isYesterday(); | ||
|
||
/** | ||
* 是否在今天 | ||
*/ | ||
export const isToday = (time: number | string) => dayjs(time).isToday(); | ||
|
||
/** | ||
* 是否为上周 | ||
*/ | ||
export const isLatestWeek = (time: number | string) => { | ||
const left = dayjs(dayjs().subtract(7, 'd')).format('YYYY-MM-DD'); | ||
const right = dayjs().format('YYYY-MM-DD'); | ||
return dayjs(time).isBetween(left, right, 'day', '[)'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,3 @@ | ||
import dayjs from 'dayjs'; | ||
import MarkdownIt from 'markdown-it'; | ||
import hljs from 'highlight.js'; | ||
import CopyDocument from '@/assets/copy-document.svg?raw'; | ||
|
||
const md = new MarkdownIt({ | ||
linkify: true, | ||
breaks: true, | ||
highlight: (str: string, lang: string): string => { | ||
let content = str; | ||
if (lang && hljs.getLanguage(lang)) { | ||
try { | ||
content = hljs.highlight(str, { | ||
language: lang, | ||
ignoreIllegals: true, | ||
}).value; | ||
} catch (e) { | ||
console.log('语法高亮错误', e); | ||
return str; | ||
} | ||
} else { | ||
content = md.utils.escapeHtml(str); | ||
} | ||
|
||
lang = (lang || 'txt'); | ||
|
||
return [ | ||
'<pre class="code-prefix"><div class="code-wrapper ps-r"><pre>', | ||
`<code class="language-${lang}">${content}</code></pre>`, | ||
`<div class="code-label ps-a">${lang.toUpperCase()}</div>`, | ||
`<div class="code-helper ps-a"><span class="copy-action">${CopyDocument}</span></div>`, | ||
'</div></pre>', | ||
].join(''); | ||
}, | ||
}); | ||
|
||
/** | ||
* 生成provide key通用函数 | ||
* @param module 模块名称 | ||
* @returns func | ||
*/ | ||
export const provideKeyFactory = (module: string) => (key: string) => Symbol(`@${module}:${key}`); | ||
|
||
/** | ||
* 显示聊天时间 | ||
* @param time 时间戳 | ||
* @returns 展示的时间 | ||
*/ | ||
export const getChatDate = (time?: number): string => { | ||
if (!time) { | ||
return ''; | ||
} | ||
const date = dayjs(time); | ||
if (date.isBefore(dayjs(), 'd')) { | ||
return date.format('YYYY/MM/DD'); | ||
} | ||
return date.format('HH:mm'); | ||
}; | ||
|
||
export const renderMarkDown = (content: string): string => { | ||
return md.render(content); | ||
}; | ||
export * from './common'; | ||
export * from './markdown'; | ||
export * from './date'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import MarkdownIt from 'markdown-it'; | ||
import hljs from 'highlight.js'; | ||
import CopyDocument from '@/assets/copy-document.svg?raw'; | ||
|
||
const md = new MarkdownIt({ | ||
linkify: true, | ||
breaks: true, | ||
highlight: (str: string, lang: string): string => { | ||
let content = str; | ||
if (lang && hljs.getLanguage(lang)) { | ||
try { | ||
content = hljs.highlight(str, { | ||
language: lang, | ||
ignoreIllegals: true, | ||
}).value; | ||
} catch (e) { | ||
console.log('语法高亮错误', e); | ||
return str; | ||
} | ||
} else { | ||
content = md.utils.escapeHtml(str); | ||
} | ||
|
||
lang = (lang || 'txt'); | ||
|
||
return [ | ||
'<pre class="code-prefix"><div class="code-wrapper ps-r"><pre>', | ||
`<code class="language-${lang}">${content}</code></pre>`, | ||
`<div class="code-label ps-a">${lang.toUpperCase()}</div>`, | ||
`<div class="code-helper ps-a"><span class="copy-action">${CopyDocument}</span></div>`, | ||
'</div></pre>', | ||
].join(''); | ||
}, | ||
}); | ||
|
||
export const renderMarkDown = (content: string): string => { | ||
return md.render(content); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<template> | ||
<div | ||
class="date t-assist ta-c pvert-8" | ||
v-if="date" | ||
> | ||
{{ date }} | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from 'vue'; | ||
import dayjs from 'dayjs'; | ||
import { isToday, isYesterday, isLatestWeek } from '@/utils'; | ||
import { useI18n } from 'vue-i18n'; | ||
const TIME_SPACE = 10 * 60 * 1000; // 十分钟间隔 | ||
const { t, d } = useI18n(); | ||
const props = defineProps<{ | ||
latest?: number, | ||
current: number, | ||
}>(); | ||
// 根据间隔来判断是否渲染时间 | ||
const date = computed(() => { | ||
const { latest, current } = props; | ||
if (!latest || current - latest >= TIME_SPACE) { | ||
return getDate(current); | ||
} | ||
return ''; | ||
}); | ||
const getDate = (time: string | number): string => { | ||
const date = dayjs(time); | ||
if (isToday(time)) { | ||
return date.format('HH:mm'); | ||
} | ||
if (isYesterday(time)) { | ||
return `${t('Yesterday')} ${date.format('HH:mm')}`; | ||
} | ||
if (isLatestWeek(time)) { | ||
return d(time ,'weekday'); | ||
} | ||
return d(time, 'long'); | ||
}; | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
.date { | ||
user-select: none; | ||
cursor: default; | ||
} | ||
</style> |
Oops, something went wrong.