index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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">{{ comTitle }}</span>
  10. </n-button>
  11. </n-text>
  12. <n-input
  13. v-show="focus"
  14. ref="inputInstRef"
  15. size="small"
  16. type="text"
  17. maxlength="16"
  18. show-count
  19. round
  20. placeholder="请输入项目名称"
  21. v-model:value.trim="title"
  22. @blur="handleBlur"
  23. ></n-input>
  24. </n-space>
  25. </template>
  26. <script setup lang="ts">
  27. import { ref, nextTick, computed, watchEffect } from 'vue'
  28. import { ResultEnum } from '@/enums/httpEnum'
  29. import { fetchRouteParamsLocation, httpErrorHandle } from '@/utils'
  30. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  31. import { ProjectInfoEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
  32. import { updateProjectApi } from '@/api/path'
  33. import { useSync } from '../../hooks/useSync.hook'
  34. import { icon } from '@/plugins'
  35. const chartEditStore = useChartEditStore()
  36. const { dataSyncUpdate } = useSync()
  37. const { FishIcon } = icon.ionicons5
  38. const focus = ref<boolean>(false)
  39. const inputInstRef = ref(null)
  40. const title = ref<string>(fetchRouteParamsLocation())
  41. watchEffect(() => {
  42. title.value = chartEditStore.getProjectInfo.projectName || ''
  43. })
  44. const comTitle = computed(() => {
  45. title.value = title.value && title.value.replace(/\s/g, "")
  46. return title.value.length ? title.value : fetchRouteParamsLocation()
  47. })
  48. const handleFocus = () => {
  49. focus.value = true
  50. nextTick(() => {
  51. ; (<any>inputInstRef).value.focus()
  52. })
  53. }
  54. const handleBlur = async () => {
  55. focus.value = false
  56. chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '')
  57. const res = await updateProjectApi({
  58. id: fetchRouteParamsLocation(),
  59. projectName: title.value,
  60. }) as unknown as MyResponseType
  61. if(res.code === ResultEnum.SUCCESS) {
  62. dataSyncUpdate()
  63. } else {
  64. httpErrorHandle()
  65. }
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .title {
  70. font-size: 15px;
  71. }
  72. </style>