index.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. return id[0]
  38. }
  39. return ''
  40. }
  41. const title = ref<string>(fetchProhectInfoById() || '')
  42. const comTitle = computed(() => {
  43. title.value = title.value.replace(/\s/g, "");
  44. return title.value.length ? title.value : '新项目'
  45. })
  46. const handleFocus = () => {
  47. focus.value = true
  48. nextTick(() => {
  49. ; (<any>inputInstRef).value.focus()
  50. })
  51. }
  52. const handleBlur = () => {
  53. focus.value = false
  54. }
  55. </script>