Skip to content

Commit c53fa56

Browse files
feat(Workplace): Add wrokplace demo
feat(Component): Add Highlight component feat(hooks): Add useTimeAgo hook
1 parent 3fc79c0 commit c53fa56

File tree

13 files changed

+552
-8
lines changed

13 files changed

+552
-8
lines changed

src/assets/imgs/avatar.jpg

85.6 KB
Loading

src/components/Highlight/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Highlight from './src/Highlight.vue'
2+
3+
export { Highlight }
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<script lang="tsx">
2+
import { defineComponent, PropType, computed, h, unref } from 'vue'
3+
import { propTypes } from '@/utils/propTypes'
4+
5+
export default defineComponent({
6+
name: 'Highlight',
7+
props: {
8+
tag: propTypes.string.def('span'),
9+
keys: {
10+
type: Array as PropType<string[]>,
11+
default: () => []
12+
},
13+
color: propTypes.string.def('var(--el-color-primary)')
14+
},
15+
emits: ['click'],
16+
setup(props, { emit, slots }) {
17+
const keyNodes = computed(() => {
18+
return props.keys.map((key) => {
19+
return h(
20+
'span',
21+
{
22+
onClick: () => {
23+
emit('click', key)
24+
},
25+
style: {
26+
color: props.color,
27+
cursor: 'pointer'
28+
}
29+
},
30+
key
31+
)
32+
})
33+
})
34+
35+
const parseText = (text: string) => {
36+
props.keys.forEach((key, index) => {
37+
const regexp = new RegExp(key, 'g')
38+
text = text.replace(regexp, `{{${index}}}`)
39+
})
40+
return text.split(/{{|}}/)
41+
}
42+
43+
const renderText = () => {
44+
if (!slots?.default) return null
45+
const node = slots?.default()[0].children
46+
47+
if (!node) {
48+
return slots?.default()[0]
49+
}
50+
51+
const textArray = parseText(node as string)
52+
const regexp = /^[0-9]*$/
53+
const nodes = textArray.map((t) => {
54+
if (regexp.test(t)) {
55+
return unref(keyNodes)[Math.floor(Number(t))] || t
56+
}
57+
return t
58+
})
59+
return h(props.tag, nodes)
60+
}
61+
62+
return () => renderText()
63+
}
64+
})
65+
</script>

src/components/UserInfo/src/UserInfo.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ const loginOut = () => {
3838
<template>
3939
<ElDropdown :class="prefixCls" trigger="click">
4040
<div class="flex items-center">
41-
<img src="@/assets/imgs/avatar.png" alt="" class="w-[calc(var(--tags-view-height)-10px)]" />
41+
<img
42+
src="@/assets/imgs/avatar.jpg"
43+
alt=""
44+
class="w-[calc(var(--tags-view-height)-10px)] rounded-[50%]"
45+
/>
4246
<span class="<lg:hidden text-14px pl-[5px] text-[var(--top-header-text-color)]">Archer</span>
4347
</div>
4448
<template #dropdown>

src/hooks/web/useTimeAgo.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useTimeAgo as useTimeAgoCore, UseTimeAgoMessages } from '@vueuse/core'
2+
import { computed, unref } from 'vue'
3+
import { useLocaleStoreWithOut } from '@/store/modules/locale'
4+
5+
const TIME_AGO_MESSAGE_MAP: {
6+
'zh-CN': UseTimeAgoMessages
7+
en: UseTimeAgoMessages
8+
} = {
9+
'zh-CN': {
10+
justNow: '刚刚',
11+
past: (n) => (n.match(/\d/) ? `${n}前` : n),
12+
future: (n) => (n.match(/\d/) ? `${n}后` : n),
13+
month: (n, past) => (n === 1 ? (past ? '上个月' : '下个月') : `${n} 个月`),
14+
year: (n, past) => (n === 1 ? (past ? '去年' : '明年') : `${n} 年`),
15+
day: (n, past) => (n === 1 ? (past ? '昨天' : '明天') : `${n} 天`),
16+
week: (n, past) => (n === 1 ? (past ? '上周' : '下周') : `${n} 周`),
17+
hour: (n) => `${n} 小时`,
18+
minute: (n) => `${n} 分钟`,
19+
second: (n) => `${n} 秒`
20+
},
21+
en: {
22+
justNow: '刚刚',
23+
past: (n) => (n.match(/\d/) ? `${n} ago` : n),
24+
future: (n) => (n.match(/\d/) ? `in ${n}` : n),
25+
month: (n, past) =>
26+
n === 1 ? (past ? 'last month' : 'next month') : `${n} month${n > 1 ? 's' : ''}`,
27+
year: (n, past) =>
28+
n === 1 ? (past ? 'last year' : 'next year') : `${n} year${n > 1 ? 's' : ''}`,
29+
day: (n, past) => (n === 1 ? (past ? 'yesterday' : 'tomorrow') : `${n} day${n > 1 ? 's' : ''}`),
30+
week: (n, past) =>
31+
n === 1 ? (past ? 'last week' : 'next week') : `${n} week${n > 1 ? 's' : ''}`,
32+
hour: (n) => `${n} hour${n > 1 ? 's' : ''}`,
33+
minute: (n) => `${n} minute${n > 1 ? 's' : ''}`,
34+
second: (n) => `${n} second${n > 1 ? 's' : ''}`
35+
}
36+
}
37+
38+
export const useTimeAgo = (time: Date | number | string) => {
39+
const localeStore = useLocaleStoreWithOut()
40+
41+
const currentLocale = computed(() => localeStore.getCurrentLocale)
42+
43+
const timeAgo = useTimeAgoCore(time, {
44+
messages: TIME_AGO_MESSAGE_MAP[unref(currentLocale).lang]
45+
})
46+
47+
return timeAgo
48+
}

src/locales/en.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default {
7171
menu12: 'Menu1-2',
7272
menu2: 'Menu2',
7373
dashboard: 'Dashboard',
74-
analysis: 'Analysis'
74+
analysis: 'Analysis',
75+
workplace: 'Workplace'
7576
},
7677
analysis: {
7778
newUser: 'New user',
@@ -109,6 +110,28 @@ export default {
109110
saturday: 'Saturday',
110111
sunday: 'Sunday'
111112
},
113+
workplace: {
114+
goodMorning: 'Good morning',
115+
happyDay: 'Wish you happy every day!',
116+
toady: `It's sunny today`,
117+
project: 'Project',
118+
access: 'Project access',
119+
toDo: 'To do',
120+
introduction: 'A serious introduction',
121+
more: 'More',
122+
shortcutOperation: 'Shortcut operation',
123+
operation: 'Operation',
124+
index: 'Index',
125+
personal: 'Personal',
126+
team: 'Team',
127+
quote: 'Quote',
128+
contribution: 'Contribution',
129+
hot: 'Hot',
130+
yield: 'Yield',
131+
dynamic: 'Dynamic',
132+
push: 'push',
133+
pushCode: 'Archer push code to GitHub'
134+
},
112135
formDemo: {
113136
input: 'Input',
114137
inputNumber: 'InputNumber',

src/locales/zh-CN.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ export default {
7171
menu12: '菜单1-2',
7272
menu2: '菜单2',
7373
dashboard: '首页',
74-
analysis: '分析页'
74+
analysis: '分析页',
75+
workplace: '工作台'
7576
},
7677
analysis: {
7778
newUser: '新增用户',
@@ -109,6 +110,28 @@ export default {
109110
saturday: '周六',
110111
sunday: '周日'
111112
},
113+
workplace: {
114+
goodMorning: '早安',
115+
happyDay: '祝你开心每一天!',
116+
toady: '今日晴',
117+
project: '项目数',
118+
access: '项目访问',
119+
toDo: '待办',
120+
introduction: '一个正经的简介',
121+
more: '更多',
122+
shortcutOperation: '快捷操作',
123+
operation: '操作',
124+
index: '指数',
125+
personal: '个人',
126+
team: '团队',
127+
quote: '引用',
128+
contribution: '贡献',
129+
hot: '热度',
130+
yield: '产量',
131+
dynamic: '动态',
132+
push: '推送',
133+
pushCode: 'Archer 推送 代码到 Github'
134+
},
112135
formDemo: {
113136
input: '输入框',
114137
inputNumber: '数字输入框',

src/plugins/echarts/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import * as echarts from 'echarts/core'
22

3-
import { BarChart, LineChart, PieChart, MapChart, PictorialBarChart } from 'echarts/charts'
3+
import {
4+
BarChart,
5+
LineChart,
6+
PieChart,
7+
MapChart,
8+
PictorialBarChart,
9+
RadarChart
10+
} from 'echarts/charts'
411

512
import {
613
TitleComponent,
@@ -27,7 +34,8 @@ echarts.use([
2734
PieChart,
2835
MapChart,
2936
CanvasRenderer,
30-
PictorialBarChart
37+
PictorialBarChart,
38+
RadarChart
3139
])
3240

3341
export default echarts

src/router/index.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [
5454
name: 'Analysis',
5555
meta: {
5656
title: t('router.analysis'),
57-
noCache: true,
58-
affix: true
57+
noCache: true
58+
}
59+
},
60+
{
61+
path: 'workplace',
62+
component: () => import('@/views/Dashboard/Workplace.vue'),
63+
name: 'Workplace',
64+
meta: {
65+
title: t('router.workplace'),
66+
noCache: true
5967
}
6068
}
6169
]

src/utils/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,35 @@ export const findIndex = <T = Recordable>(ary: Array<T>, fn: Fn): number => {
6363
export const trim = (str: string) => {
6464
return str.replace(/(^\s*)|(\s*$)/g, '')
6565
}
66+
67+
/**
68+
* @param {Date | number | string} time 需要转换的时间
69+
* @param {String} fmt 需要转换的格式 如 yyyy-MM-dd、yyyy-MM-dd HH:mm:ss
70+
*/
71+
export function formatTime(time: Date | number | string, fmt: string) {
72+
if (!time) return ''
73+
else {
74+
const date = new Date(time)
75+
const o = {
76+
'M+': date.getMonth() + 1,
77+
'd+': date.getDate(),
78+
'H+': date.getHours(),
79+
'm+': date.getMinutes(),
80+
's+': date.getSeconds(),
81+
'q+': Math.floor((date.getMonth() + 3) / 3),
82+
S: date.getMilliseconds()
83+
}
84+
if (/(y+)/.test(fmt)) {
85+
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
86+
}
87+
for (const k in o) {
88+
if (new RegExp('(' + k + ')').test(fmt)) {
89+
fmt = fmt.replace(
90+
RegExp.$1,
91+
RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
92+
)
93+
}
94+
}
95+
return fmt
96+
}
97+
}

src/views/Dashboard/Analysis.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ setTimeout(() => {
3232
<ElCol :span="24">
3333
<ElCard shadow="hover" class="mb-20px">
3434
<ElSkeleton :loading="loading" animated :rows="4">
35-
<Echart :options="lineOptions" :height="400" />
35+
<Echart :options="lineOptions" :height="350" />
3636
</ElSkeleton>
3737
</ElCard>
3838
</ElCol>

0 commit comments

Comments
 (0)