index.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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">
  9. <span class="title">
  10. {{ comTitle }}
  11. </span>
  12. </n-button>
  13. </n-text>
  14. <n-input
  15. v-show="focus"
  16. ref="inputInstRef"
  17. size="small"
  18. type="text"
  19. maxlength="16"
  20. show-count
  21. round
  22. placeholder="请输入项目名称"
  23. v-model:value.trim="title"
  24. @keyup.enter="handleBlur"
  25. @blur="handleBlur"
  26. ></n-input>
  27. </n-space>
  28. </template>
  29. <script setup lang="ts">
  30. import { ref, nextTick, computed } from 'vue'
  31. import { fetchRouteParamsLocation, setTitle } from '@/utils'
  32. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  33. import { EditCanvasConfigEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
  34. import { icon } from '@/plugins'
  35. const { FishIcon } = icon.ionicons5
  36. const chartEditStore = useChartEditStore()
  37. const focus = ref<boolean>(false)
  38. const inputInstRef = ref(null)
  39. // 根据路由 id 参数获取项目信息
  40. const fetchProhectInfoById = () => {
  41. const id = fetchRouteParamsLocation()
  42. if (id.length) {
  43. return id[0]
  44. }
  45. return ''
  46. }
  47. const title = ref<string>(fetchProhectInfoById() || '')
  48. const comTitle = computed(() => {
  49. // eslint-disable-next-line vue/no-side-effects-in-computed-properties
  50. title.value = title.value.replace(/\s/g, '')
  51. const newTitle = title.value.length ? title.value : '新项目'
  52. setTitle(`工作空间-${newTitle}`)
  53. chartEditStore.setEditCanvasConfig(EditCanvasConfigEnum.PROJECT_NAME, newTitle)
  54. return newTitle
  55. })
  56. const handleFocus = () => {
  57. focus.value = true
  58. nextTick(() => {
  59. inputInstRef.value && (inputInstRef.value as any).focus()
  60. })
  61. }
  62. const handleBlur = () => {
  63. focus.value = false
  64. }
  65. </script>
  66. <style lang="scss" scoped>
  67. .title {
  68. font-size: 15px;
  69. }
  70. </style>