Skip to content

Commit

Permalink
fix:版本号比较
Browse files Browse the repository at this point in the history
  • Loading branch information
glennliao committed Jul 12, 2023
1 parent 2c59940 commit c8e6dc5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
12 changes: 7 additions & 5 deletions ui/src/layout/Footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
import { computed, ref } from 'vue'
import { RightOutlined } from '@ant-design/icons-vue'
import { apiJson } from '../api'
import { compareVersion } from '@/utils/str-utils'

const version = import.meta.env.VITE_app_version.trim()
const latestVersion = ref('')
const version = import.meta.env.VITE_app_version.trim()
const latestVersion = ref('v0.0.0')

function checkNewVersion () {
apiJson.get({
'version()': 'latestVersion()'
}).then(data => {
latestVersion.value = data.version
if(typeof data.version === "string"){
latestVersion.value = data.version
}
})
}

const canUpdate = computed(() => {
return latestVersion.value > version
return compareVersion(latestVersion.value||"",version) > 0
})

checkNewVersion()
Expand All @@ -39,7 +42,6 @@ checkNewVersion()
<a-badge dot>
<a target="_blank" href="https://github.com/glennliao/bookmark" class="ml-1">{{ latestVersion }}</a>
</a-badge>

</span>
</footer>
</template>
Expand Down
34 changes: 34 additions & 0 deletions ui/src/utils/str-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,37 @@ export function colorByURL (url: string):string {

return '#' + '00000'.substring(0, 6 - c.length) + c
}

export function compareVersion(version1:string, version2:string) {
const arr1 = version1.split('.')
const arr2 = version2.split('.')
const length1 = arr1.length
const length2 = arr2.length
const minlength = Math.min(length1, length2)
let i = 0
for (i ; i < minlength; i++) {
let a = parseInt(arr1[i])
let b = parseInt(arr2[i])
if (a > b) {
return 1
} else if (a < b) {
return -1
}
}
if (length1 > length2) {
for(let j = i; j < length1; j++) {
if (parseInt(arr1[j]) != 0) {
return 1
}
}
return 0
} else if (length1 < length2) {
for(let j = i; j < length2; j++) {
if (parseInt(arr2[j]) != 0) {
return -1
}
}
return 0
}
return 0
}
1 change: 0 additions & 1 deletion ui/src/utils/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export function treeEach (tree: any[], call: (any) => any): void {
treeEach(item.children, call)
}

console.log("item",item)
call(item)
})
}

0 comments on commit c8e6dc5

Please sign in to comment.