Skip to content

Commit

Permalink
refactor(game): 优化前端代码
Browse files Browse the repository at this point in the history
  • Loading branch information
lovezhangchuangxin committed Nov 23, 2024
1 parent 0e1505b commit 88cbfec
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/game/src/api/structure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { req } from './req'

export class StructureApi {
/**
* 获取我的建组
* 获取我的建筑
*/
static async getStructures() {
return req<{
Expand Down
36 changes: 16 additions & 20 deletions packages/game/src/components/number/NumberFormat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

<script setup lang="ts">
import { numberWithCommas } from '@/utils/number'
import { onMounted, ref, watch } from 'vue'
import { ref, toRefs, watchEffect } from 'vue'
const { value = 0 } = defineProps({
value: Number,
})
const unit = ref<string>('')
const valueFormat = ref<string>('0')
const valueFullFormat = ref<string>('0')
interface NumberFormatProps {
value?: number
}
const props = defineProps<NumberFormatProps>()
const { value } = toRefs(props)
const unit = ref('')
const valueFormat = ref('0')
const valueFullFormat = ref('0')
const unitName = [
'',
'K',
Expand All @@ -35,7 +38,11 @@ const unitName = [
'AH',
]
const format = (value: number = 0) => {
watchEffect(() => {
format(value.value)
})
function format(value: number = 0) {
let tempValue = value
const bit = Math.log10(tempValue)
const hideUnit = Math.ceil((bit - 6) / 3)
Expand All @@ -48,17 +55,6 @@ const format = (value: number = 0) => {
valueFullFormat.value = numberWithCommas(value)
valueFormat.value = numberWithCommas(tempValue)
}
onMounted(() => {
format(value)
})
watch(
() => value,
(newData: number) => {
format(newData)
},
{ immediate: true },
)
</script>

<style scoped lang="less"></style>
5 changes: 0 additions & 5 deletions packages/game/src/utils/env.ts

This file was deleted.

2 changes: 2 additions & 0 deletions packages/game/src/utils/number.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import relativeTime from 'dayjs/plugin/relativeTime'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'

dayjs.extend(relativeTime)
dayjs.locale('zh-cn')

export const timeFromNow = (timestamp: number): string => {
return dayjs(timestamp).fromNow()
}
Expand Down

0 comments on commit 88cbfec

Please sign in to comment.