75 lines
2.0 KiB
Vue
Raw Normal View History

2022-01-05 20:52:49 +08:00
<template>
<n-space>
<n-icon size="20" :depth="3">
2022-03-14 19:52:01 +08:00
<fish-icon></fish-icon>
2022-01-05 20:52:49 +08:00
</n-icon>
<n-text @click="handleFocus">
工作空间 -
<n-button v-show="!focus" secondary round size="tiny">{{ comTitle }}</n-button>
2022-01-05 20:52:49 +08:00
</n-text>
<n-input
v-show="focus"
ref="inputInstRef"
size="small"
type="text"
maxlength="16"
show-count
round
placeholder="请输入项目名称"
v-model:value.trim="title"
@blur="handleBlur"
></n-input>
2022-01-05 20:52:49 +08:00
</n-space>
</template>
<script setup lang="ts">
2022-05-26 01:01:59 +08:00
import { ref, nextTick, computed, watchEffect } from 'vue'
import { ResultEnum } from '@/enums/httpEnum'
import { fetchRouteParamsLocation, httpErrorHandle } from '@/utils'
import { useChartEditStore } from '@/store/modules/chartEditStore/chartEditStore'
2022-05-27 11:49:25 +08:00
import { ProjectInfoEnum } from '@/store/modules/chartEditStore/chartEditStore.d'
import { updateProjectApi } from '@/api/path'
2022-05-26 01:01:59 +08:00
import { useSync } from '../../hooks/useSync.hook'
2022-01-05 20:52:49 +08:00
import { icon } from '@/plugins'
2022-05-26 01:01:59 +08:00
const chartEditStore = useChartEditStore()
const { dataSyncUpdate } = useSync()
2022-01-05 20:52:49 +08:00
const { FishIcon } = icon.ionicons5
const focus = ref<boolean>(false)
const inputInstRef = ref(null)
2022-05-26 01:01:59 +08:00
const title = ref<string>(fetchRouteParamsLocation())
2022-05-26 01:01:59 +08:00
watchEffect(() => {
2022-05-27 11:49:25 +08:00
title.value = chartEditStore.getProjectInfo.projectName || ''
2022-05-26 01:01:59 +08:00
})
2022-01-05 20:52:49 +08:00
const comTitle = computed(() => {
2022-05-26 01:01:59 +08:00
title.value = title.value && title.value.replace(/\s/g, "")
return title.value.length ? title.value : fetchRouteParamsLocation()
2022-01-05 20:52:49 +08:00
})
const handleFocus = () => {
focus.value = true
nextTick(() => {
; (<any>inputInstRef).value.focus()
2022-01-05 20:52:49 +08:00
})
}
2022-05-26 01:01:59 +08:00
const handleBlur = async () => {
2022-01-05 20:52:49 +08:00
focus.value = false
2022-05-27 11:49:25 +08:00
chartEditStore.setProjectInfo(ProjectInfoEnum.PROJECT_NAME, title.value || '')
2022-06-01 22:41:11 +08:00
const res = await updateProjectApi({
2022-05-26 01:01:59 +08:00
id: fetchRouteParamsLocation(),
projectName: title.value,
2022-06-01 22:41:11 +08:00
}) as unknown as MyResponseType
2022-05-26 01:01:59 +08:00
if(res.code === ResultEnum.SUCCESS) {
dataSyncUpdate()
} else {
httpErrorHandle()
}
2022-01-05 20:52:49 +08:00
}
</script>