73 lines
1.6 KiB
Vue
Raw Normal View History

2022-01-05 20:52:49 +08:00
<template>
<n-space>
<n-icon size="20" :depth="3">
2022-03-14 19:52:01 +08:00
<fish-icon></fish-icon>
2022-01-05 20:52:49 +08:00
</n-icon>
<n-text @click="handleFocus">
工作空间 -
2022-06-03 20:10:52 +08:00
<n-button v-show="!focus" secondary round size="tiny">
<span class="title">
{{ comTitle }}
</span>
</n-button>
2022-01-05 20:52:49 +08:00
</n-text>
<n-input
v-show="focus"
ref="inputInstRef"
size="small"
type="text"
maxlength="16"
show-count
round
placeholder="请输入项目名称"
v-model:value.trim="title"
2022-08-31 14:27:06 +08:00
@keyup.enter="handleBlur"
2022-01-05 20:52:49 +08:00
@blur="handleBlur"
></n-input>
2022-01-05 20:52:49 +08:00
</n-space>
</template>
<script setup lang="ts">
import { ref, nextTick, computed } from 'vue'
2022-11-12 16:16:03 +08:00
import { fetchRouteParamsLocation } from '@/utils'
2022-01-05 20:52:49 +08:00
import { icon } from '@/plugins'
const { FishIcon } = icon.ionicons5
const focus = ref<boolean>(false)
const inputInstRef = ref(null)
// 根据路由 id 参数获取项目信息
const fetchProhectInfoById = () => {
2022-11-12 16:16:03 +08:00
const id = fetchRouteParamsLocation()
if (id.length) {
2022-03-12 15:25:26 +08:00
return id[0]
}
return ''
}
2022-03-06 02:08:14 +08:00
const title = ref<string>(fetchProhectInfoById() || '')
2022-01-05 20:52:49 +08:00
const comTitle = computed(() => {
// eslint-disable-next-line vue/no-side-effects-in-computed-properties
title.value = title.value.replace(/\s/g, '')
2022-01-05 20:52:49 +08:00
return title.value.length ? title.value : '新项目'
})
const handleFocus = () => {
focus.value = true
nextTick(() => {
inputInstRef.value && (inputInstRef.value as any).focus()
2022-01-05 20:52:49 +08:00
})
}
const handleBlur = () => {
focus.value = false
}
</script>
2022-06-03 20:10:52 +08:00
<style lang="scss" scoped>
.title {
font-size: 15px;
}
</style>