2024-04-23 11:03:34 +00:00
|
|
|
|
<template>
|
2024-08-07 03:17:20 +00:00
|
|
|
|
<el-dialog
|
|
|
|
|
|
:title="$t('views.applicationOverview.appInfo.EditAvatarDialog.title')"
|
|
|
|
|
|
v-model="dialogVisible"
|
2024-09-24 11:01:35 +00:00
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
:close-on-press-escape="false"
|
2024-08-07 03:17:20 +00:00
|
|
|
|
>
|
2024-04-24 07:03:58 +00:00
|
|
|
|
<el-radio-group v-model="radioType" class="radio-block mb-16">
|
2024-04-23 11:03:34 +00:00
|
|
|
|
<div>
|
|
|
|
|
|
<el-radio value="default">
|
2024-08-07 03:17:20 +00:00
|
|
|
|
<p>{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.default') }}</p>
|
2024-04-23 11:03:34 +00:00
|
|
|
|
<AppAvatar
|
|
|
|
|
|
v-if="detail?.name"
|
|
|
|
|
|
:name="detail?.name"
|
|
|
|
|
|
pinyinColor
|
|
|
|
|
|
class="mt-8 mb-8"
|
|
|
|
|
|
shape="square"
|
|
|
|
|
|
:size="32"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-radio>
|
|
|
|
|
|
</div>
|
2024-04-24 07:03:58 +00:00
|
|
|
|
<div class="mt-8">
|
2024-04-23 11:03:34 +00:00
|
|
|
|
<el-radio value="custom">
|
2024-08-07 03:17:20 +00:00
|
|
|
|
<p>{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.customizeUpload') }}</p>
|
2024-04-23 11:03:34 +00:00
|
|
|
|
<div class="flex mt-8">
|
|
|
|
|
|
<AppAvatar
|
|
|
|
|
|
v-if="fileURL"
|
|
|
|
|
|
shape="square"
|
|
|
|
|
|
:size="32"
|
|
|
|
|
|
style="background: none"
|
|
|
|
|
|
class="mr-16"
|
|
|
|
|
|
>
|
|
|
|
|
|
<img :src="fileURL" alt="" />
|
|
|
|
|
|
</AppAvatar>
|
|
|
|
|
|
<el-upload
|
|
|
|
|
|
ref="uploadRef"
|
|
|
|
|
|
action="#"
|
|
|
|
|
|
:auto-upload="false"
|
|
|
|
|
|
:show-file-list="false"
|
|
|
|
|
|
accept="image/*"
|
|
|
|
|
|
:on-change="onChange"
|
|
|
|
|
|
>
|
2024-08-07 03:17:20 +00:00
|
|
|
|
<el-button icon="Upload" :disabled="radioType !== 'custom'">{{
|
|
|
|
|
|
$t('views.applicationOverview.appInfo.EditAvatarDialog.upload')
|
|
|
|
|
|
}}</el-button>
|
2024-04-23 11:03:34 +00:00
|
|
|
|
</el-upload>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="el-upload__tip info mt-16">
|
2024-08-07 03:17:20 +00:00
|
|
|
|
{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.sizeTip') }}
|
2024-04-23 11:03:34 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</el-radio>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
<template #footer>
|
|
|
|
|
|
<span class="dialog-footer">
|
2024-08-07 03:17:20 +00:00
|
|
|
|
<el-button @click.prevent="dialogVisible = false">
|
|
|
|
|
|
{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.cancel') }}</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-button type="primary" @click="submit" :loading="loading">
|
|
|
|
|
|
{{ $t('views.applicationOverview.appInfo.EditAvatarDialog.save') }}</el-button
|
|
|
|
|
|
>
|
2024-04-23 11:03:34 +00:00
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
|
import { ref, watch } from 'vue'
|
|
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
|
import overviewApi from '@/api/application-overview'
|
|
|
|
|
|
import { cloneDeep } from 'lodash'
|
|
|
|
|
|
import { MsgSuccess, MsgError } from '@/utils/message'
|
|
|
|
|
|
import { defaultIcon, isAppIcon } from '@/utils/application'
|
|
|
|
|
|
import useStore from '@/stores'
|
2024-05-27 05:33:11 +00:00
|
|
|
|
import { t } from '@/locales'
|
2024-04-23 11:03:34 +00:00
|
|
|
|
|
|
|
|
|
|
const { application } = useStore()
|
|
|
|
|
|
|
|
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const {
|
|
|
|
|
|
params: { id } //应用id
|
|
|
|
|
|
} = route
|
|
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['refresh'])
|
|
|
|
|
|
|
|
|
|
|
|
const iconFile = ref<any>(null)
|
|
|
|
|
|
const fileURL = ref<any>(null)
|
|
|
|
|
|
|
|
|
|
|
|
const dialogVisible = ref<boolean>(false)
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const detail = ref<any>(null)
|
|
|
|
|
|
const radioType = ref('default')
|
|
|
|
|
|
|
|
|
|
|
|
watch(dialogVisible, (bool) => {
|
|
|
|
|
|
if (!bool) {
|
|
|
|
|
|
iconFile.value = null
|
|
|
|
|
|
fileURL.value = null
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const open = (data: any) => {
|
|
|
|
|
|
radioType.value = isAppIcon(data.icon) ? 'custom' : 'default'
|
|
|
|
|
|
fileURL.value = isAppIcon(data.icon) ? data.icon : null
|
|
|
|
|
|
detail.value = cloneDeep(data)
|
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const onChange = (file: any) => {
|
2024-08-07 03:21:46 +00:00
|
|
|
|
//1、判断文件大小是否合法,文件限制不能大于10MB
|
2024-08-07 03:17:20 +00:00
|
|
|
|
const isLimit = file?.size / 1024 / 1024 < 10
|
2024-04-23 11:03:34 +00:00
|
|
|
|
if (!isLimit) {
|
2024-05-27 05:33:11 +00:00
|
|
|
|
// @ts-ignore
|
|
|
|
|
|
MsgError(t('views.applicationOverview.appInfo.EditAvatarDialog.fileSizeExceeded'))
|
2024-04-23 11:03:34 +00:00
|
|
|
|
return false
|
2024-08-07 03:17:20 +00:00
|
|
|
|
} else {
|
2024-07-24 04:39:28 +00:00
|
|
|
|
iconFile.value = file
|
|
|
|
|
|
fileURL.value = URL.createObjectURL(file.raw)
|
2024-04-23 11:03:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function submit() {
|
|
|
|
|
|
if (radioType.value === 'default') {
|
|
|
|
|
|
application.asyncPutApplication(id as string, { icon: defaultIcon }, loading).then((res) => {
|
|
|
|
|
|
emit('refresh')
|
2024-05-27 05:33:11 +00:00
|
|
|
|
MsgSuccess(t('views.applicationOverview.appInfo.EditAvatarDialog.setSuccess'))
|
2024-04-23 11:03:34 +00:00
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else if (radioType.value === 'custom' && iconFile.value) {
|
|
|
|
|
|
let fd = new FormData()
|
|
|
|
|
|
fd.append('file', iconFile.value.raw)
|
|
|
|
|
|
overviewApi.putAppIcon(id as string, fd, loading).then((res: any) => {
|
|
|
|
|
|
emit('refresh')
|
2024-05-27 05:33:11 +00:00
|
|
|
|
MsgSuccess(t('views.applicationOverview.appInfo.EditAvatarDialog.setSuccess'))
|
2024-04-23 11:03:34 +00:00
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2024-05-27 05:33:11 +00:00
|
|
|
|
MsgError(t('views.applicationOverview.appInfo.EditAvatarDialog.uploadImagePrompt'))
|
2024-04-23 11:03:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
defineExpose({ open })
|
|
|
|
|
|
</script>
|
2024-04-24 07:03:58 +00:00
|
|
|
|
<style lang="scss" scope></style>
|