Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './auth'
export * from './build-menus'
export * from './rest'
export * from './time'
export * from './version'

/**
* diff 两层,Object 浅层比较,引用不一致返回整个不一样的 Object
Expand Down Expand Up @@ -81,7 +82,7 @@ export function toPascalCase(string: string) {
.replaceAll(new RegExp(/[^\s\w]/, 'g'), '')
.replaceAll(
new RegExp(/\s+(.)(\w*)/, 'g'),
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`,
(_$1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`,
)
.replace(new RegExp(/\w/), (s) => s.toUpperCase())
}
Expand Down
59 changes: 59 additions & 0 deletions src/utils/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export function isNewerVersion(current: string, latest: string): boolean {
const cleanCurrent = current.replace(/^v/, '')
const cleanLatest = latest.replace(/^v/, '')
const [currentBase, currentPre] = splitVersion(cleanCurrent)
const [latestBase, latestPre] = splitVersion(cleanLatest)
const currentParts = currentBase.split('.').map(Number)
const latestParts = latestBase.split('.').map(Number)

const maxLength = Math.max(currentParts.length, latestParts.length)
for (let i = 0; i < maxLength; i++) {
const currentPart = currentParts[i] || 0
const latestPart = latestParts[i] || 0

if (latestPart > currentPart) return true
if (latestPart < currentPart) return false
}

if (!latestPre && currentPre) return true
if (latestPre && !currentPre) return false

if (latestPre && currentPre) {
return comparePrereleaseVersion(currentPre, latestPre)
}

return false
}

function splitVersion(version: string): [string, string] {
const hyphenIndex = version.indexOf('-')
if (hyphenIndex === -1) {
return [version, '']
}
return [version.substring(0, hyphenIndex), version.substring(hyphenIndex + 1)]
}

function comparePrereleaseVersion(current: string, latest: string): boolean {
const order = ['alpha', 'beta', 'rc']

const currentType = order.find((type) => current.startsWith(type))
const latestType = order.find((type) => latest.startsWith(type))

if (currentType && latestType && currentType !== latestType) {
return order.indexOf(latestType) > order.indexOf(currentType)
}

const currentNum = extractNumber(current)
const latestNum = extractNumber(latest)

if (currentNum !== null && latestNum !== null) {
return latestNum > currentNum
}

return latest > current
}

function extractNumber(str: string): number | null {
const match = str.match(/\d+/)
return match ? parseInt(match[0], 10) : null
}
18 changes: 10 additions & 8 deletions src/views/dashboard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { RouteName } from '~/router/name'
import { AppStore } from '~/stores/app'
import { UserStore } from '~/stores/user'
import { parseDate, RESTManager } from '~/utils'
import { isNewerVersion } from '~/utils/version'

import PKG from '../../../package.json'
import { Card } from './card'
Expand Down Expand Up @@ -190,12 +191,12 @@ export const DashBoardView = defineComponent({
trigger="hover"
triggerEl={<span>{userStore.user.value?.lastLoginIp}</span>}
ip={userStore.user.value?.lastLoginIp}
></IpInfoPopover>
/>
) : (
'N/A'
)}
</span>
<div class="pt-[.5rem]"></div>
<div class="pt-[.5rem]" />
<span>
上次登录时间:{' '}
{userStore.user.value?.lastLoginTime ? (
Expand All @@ -211,7 +212,7 @@ export const DashBoardView = defineComponent({
</span>
</p>

<div class="pb-4"></div>
<div class="pb-4" />
</>
))

Expand Down Expand Up @@ -640,7 +641,8 @@ const AppIF = defineComponent({
system: null as string | null,
})

const { openModal: openUpdateModal, Modal: UpdateDetailModal } = useUpdateDetailModal()
const { openModal: openUpdateModal, Modal: UpdateDetailModal } =
useUpdateDetailModal()

const portal = usePortalElement()
const handleUpdate = () => {
Expand All @@ -657,15 +659,15 @@ const AppIF = defineComponent({
const { dashboard, system } = await checkUpdateFromGitHub()

if (
dashboard !== PKG.version &&
isNewerVersion(PKG.version, dashboard) &&
closedTips.value.dashboard !== dashboard
) {
const $notice = notice.info({
title: '[管理中台] 有新版本啦!',
content: () => (
<div>
<p>{`当前版本:${PKG.version},最新版本:${dashboard}`}</p>
<div class={'text-right space-x-2'}>
<div class={'space-x-2 text-right'}>
<NButton
size="small"
onClick={() => {
Expand Down Expand Up @@ -722,14 +724,14 @@ const AppIF = defineComponent({
app.value.version !== 'dev' &&
versionMap.value.system &&
closedTips.value.system !== versionMap.value.system &&
versionMap.value.system !== app.value.version
isNewerVersion(app.value.version, versionMap.value.system)
) {
notice.info({
title: '[系统] 有新版本啦!',
content: () => (
<div>
<p>{`当前版本:${app.value?.version || 'N/A'},最新版本:${versionMap.value.system}`}</p>
<div class={'text-right space-x-2'}>
<div class={'space-x-2 text-right'}>
<NButton
size="small"
onClick={() => {
Expand Down