index.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, watchEffect } from 'vue'
  26. import { ResultEnum } from '@/enums/httpEnum'
  27. import { fetchRouteParamsLocation, httpErrorHandle } from '@/utils'
  28. import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
  29. import { ProjectInfoEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
  30. import { updateProjectApi } from '@/api/path'
  31. import { useSync } from '../../hooks/useSync.hook'
  32. import { icon } from '@/plugins'
  33. const chartEditStore = useChartEditStore()
  34. const { dataSyncUpdate } = useSync()
  35. const { FishIcon } = icon.ionicons5
  36. const focus = ref<boolean>(false)
  37. const inputInstRef = ref(null)
  38. const title = ref<string>(fetchRouteParamsLocation())
  39. watchEffect(() => {
  40. title.value = chartEditStore.getProjectInfo.projectName || ''
  41. })
  42. const comTitle = computed(() => {
  43. title.value = title.value && title.value.replace(/\s/g, "")
  44. return title.value.length ? title.value : fetchRouteParamsLocation()
  45. })
  46. const handleFocus = () => {
  47. focus.value = true
  48. nextTick(() => {
  49. ; (<any>inputInstRef).value.focus()
  50. })
  51. }
  52. const handleBlur = async () => {
  53. focus.value = false
  54. chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '')
  55. const res = await updateProjectApi({
  56. id: fetchRouteParamsLocation(),
  57. projectName: title.value,
  58. }) as unknown as MyResponseType
  59. if(res.code === ResultEnum.SUCCESS) {
  60. dataSyncUpdate()
  61. } else {
  62. httpErrorHandle()
  63. }
  64. }
  65. </script>