-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
126 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<script setup lang="ts"> | ||
const { maxSize = 2, imageUrl } = defineProps<{ maxSize?: number; imageUrl: string }>() | ||
const emit = defineEmits<{ | ||
(event: 'change', value: string): void | ||
(event: 'update:imageUrl', value: string): void | ||
}>() | ||
const inputFileElement = ref<HTMLInputElement | null>(null) | ||
const fileChange = (event: Event) => { | ||
const maxFileSize = maxSize * 1024 * 1024 | ||
const file = (event.target as HTMLInputElement).files![0] | ||
const acceptImageType = ['image/png', 'image/jpeg'] | ||
if (!file || !acceptImageType.includes(file.type)) { | ||
alert('仅支持上传png、jpg格式的图片') | ||
return | ||
} | ||
if (file.size > maxFileSize) { | ||
alert(`图片大小不能超过${maxSize}MB`) | ||
return | ||
} | ||
const reader = new FileReader() | ||
reader.onload = function () { | ||
emit('update:imageUrl', reader.result as string) | ||
} | ||
reader.readAsDataURL(file) | ||
} | ||
</script> | ||
|
||
<template> | ||
<img object-fill w-14 h-14 rounded-full :src="imageUrl" alt="" @click="inputFileElement?.click()"> | ||
<input ref="inputFileElement" type="file" name="avatar" class="hidden" accept=".jpg,.png" @change="fileChange($event)"> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { AZURE_KEY, AZURE_REGION, AZURE_TRANSLATE_KEY, CHAT_API_NAME, CHAT_REMEMBER_COUNT, OPEN_KEY, OPEN_MODEL, OPEN_PROXY, SELF_AVATAR_URL } from '@/constant' | ||
|
||
import { getAvatarUrl } from '@/utils' | ||
|
||
const defaultOpenKey = import.meta.env.VITE_OPENAI_API_KEY | ||
const defaultOpenProxy = import.meta.env.VITE_SERVE_PROXY | ||
const defaultAzureRegion = import.meta.env.VITE_REGION | ||
const defaultAzureKey = import.meta.env.VITE_SCRIPTION_KEY | ||
const defaultAzureTranslateKey = import.meta.env.VITE_TRANSLATE_KEY | ||
|
||
export const useGlobalSetting = () => { | ||
console.log('useGlobalSetting') | ||
|
||
const openKey = useLocalStorage(OPEN_KEY, defaultOpenKey) | ||
const openProxy = useLocalStorage(OPEN_PROXY, defaultOpenProxy) | ||
const azureRegion = useLocalStorage(AZURE_REGION, defaultAzureRegion) | ||
const azureKey = useLocalStorage(AZURE_KEY, defaultAzureKey) | ||
const azureTranslateKey = useLocalStorage(AZURE_TRANSLATE_KEY, defaultAzureTranslateKey) | ||
const openModel = useLocalStorage(OPEN_MODEL, 'gpt-3.5-turbo') | ||
const selfAvatar = useLocalStorage(SELF_AVATAR_URL, getAvatarUrl('self.png')) | ||
const chatApiName = useLocalStorage(CHAT_API_NAME, 'openai') | ||
const chatRememberCount = useLocalStorage(CHAT_REMEMBER_COUNT, '10') | ||
|
||
return { | ||
openKey, | ||
openProxy, | ||
openModel, | ||
azureRegion, | ||
azureKey, | ||
azureTranslateKey, | ||
selfAvatar, | ||
chatApiName, | ||
chatRememberCount, | ||
} | ||
} | ||
|
||
export default useGlobalSetting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters