refactor: enhance avatar upload functionality to support shared and resource management contexts

This commit is contained in:
CaptainB 2025-07-04 17:50:43 +08:00
parent 168fb2e9a8
commit 9ae64d871c

View File

@ -55,14 +55,17 @@
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue' import {computed, ref, watch} from 'vue'
import ToolApi from '@/api/tool/tool' import ToolApi from '@/api/tool/tool'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { MsgError, MsgSuccess } from '@/utils/message' import { MsgError, MsgSuccess } from '@/utils/message'
import { defaultIcon, isAppIcon } from '@/utils/common' import { defaultIcon, isAppIcon } from '@/utils/common'
import { t } from '@/locales' import { t } from '@/locales'
import {loadSharedApi} from "@/utils/dynamics-api/shared-api.ts";
import {useRoute} from "vue-router";
const emit = defineEmits(['refresh']) const emit = defineEmits(['refresh'])
const route = useRoute()
const iconFile = ref<any>(null) const iconFile = ref<any>(null)
const fileURL = ref<any>(null) const fileURL = ref<any>(null)
@ -72,6 +75,19 @@ const loading = ref(false)
const detail = ref<any>(null) const detail = ref<any>(null)
const radioType = ref('default') const radioType = ref('default')
const apiType = computed(() => {
if (route.path.includes('shared')) {
return 'systemShare'
} else if (route.path.includes('resource-management')) {
return 'systemManage'
} else {
return 'workspace'
}
})
const isShared = computed(() => {
return route.path.includes('shared')
})
watch(dialogVisible, (bool) => { watch(dialogVisible, (bool) => {
if (!bool) { if (!bool) {
iconFile.value = null iconFile.value = null
@ -106,10 +122,11 @@ function submit() {
} else if (radioType.value === 'custom' && iconFile.value) { } else if (radioType.value === 'custom' && iconFile.value) {
const fd = new FormData() const fd = new FormData()
fd.append('file', iconFile.value.raw) fd.append('file', iconFile.value.raw)
ToolApi.putToolIcon(detail.value.id, fd, loading).then((res: any) => { loadSharedApi({ type: 'tool', systemType: apiType.value })
emit('refresh', res.data) .putToolIcon(detail.value.id, fd, loading).then((res: any) => {
dialogVisible.value = false emit('refresh', res.data)
}) dialogVisible.value = false
})
} else { } else {
MsgError(t('common.EditAvatarDialog.uploadImagePrompt')) MsgError(t('common.EditAvatarDialog.uploadImagePrompt'))
} }