index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <n-space>
  3. <n-icon size="20" :depth="3">
  4. <fish-icon></fish-icon>
  5. </n-icon>
  6. <n-text @click="handleFocus">
  7. 工作空间 -
  8. <n-button v-show="!focus" secondary round size="tiny">{{ comTitle }}</n-button>
  9. </n-text>
  10. <n-input
  11. v-show="focus"
  12. ref="inputInstRef"
  13. size="small"
  14. type="text"
  15. maxlength="16"
  16. show-count
  17. round
  18. placeholder="请输入项目名称"
  19. v-model:value.trim="title"
  20. @blur="handleBlur"
  21. ></n-input>
  22. </n-space>
  23. </template>
  24. <script setup lang="ts">
  25. import { ref, nextTick, computed } from 'vue'
  26. import { fetchRouteParams } from '@/utils'
  27. import { icon } from '@/plugins'
  28. const { FishIcon } = icon.ionicons5
  29. const focus = ref<boolean>(false)
  30. const inputInstRef = ref(null)
  31. // 根据路由 id 参数获取项目信息
  32. const fetchProhectInfoById = () => {
  33. const routeParamsRes = fetchRouteParams()
  34. if (!routeParamsRes) return
  35. const { id } = routeParamsRes
  36. if (id.length) {
  37. // todo 从后端获取项目信息并存储
  38. return id[0]
  39. }
  40. return ''
  41. }
  42. const title = ref<string>(fetchProhectInfoById() || '')
  43. const comTitle = computed(() => {
  44. title.value = title.value.replace(/\s/g, "");
  45. return title.value.length ? title.value : '新项目'
  46. })
  47. const handleFocus = () => {
  48. focus.value = true
  49. nextTick(() => {
  50. ; (<any>inputInstRef).value.focus()
  51. })
  52. }
  53. const handleBlur = () => {
  54. focus.value = false
  55. }
  56. </script>