Skip to content

Commit

Permalink
perf: custom variables and methods are introduced automatically (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
ayangweb committed Mar 23, 2023
1 parent bb88573 commit 14d83c3
Show file tree
Hide file tree
Showing 22 changed files with 128 additions and 116 deletions.
42 changes: 41 additions & 1 deletion .eslintrc-auto-import.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
{
"globals": {
"BaseDirectory": true,
"Component": true,
"ComponentPublicInstance": true,
"ComputedRef": true,
"DEFAULT_ROLE": true,
"DEFAULT_SHORTCUT_KEY": true,
"EffectScope": true,
"InjectionKey": true,
"Message": true,
"OPENAI_CHAT_URL": true,
"OPENAI_CREDIT_URL": true,
"OPEN_AI_MODEL": true,
"PropType": true,
"Ref": true,
"THEME": true,
"VNode": true,
"acceptHMRUpdate": true,
"computed": true,
"copyCode": true,
"copyText": true,
"createApp": true,
"createPinia": true,
"customRef": true,
"defineAsyncComponent": true,
"defineComponent": true,
"defineStore": true,
"deleteConfirm": true,
"deleteSQL": true,
"dialogErrorMessage": true,
"effectScope": true,
"executeSQL": true,
"generalKeys": true,
"getActivePinia": true,
"getAiMessage": true,
"getCurrentInstance": true,
"getCurrentScope": true,
"getKeySymbol": true,
"getOpenAICreditApi": true,
"getOpenAIResultApi": true,
"getOpenAIResultStreamApi": true,
"h": true,
"hotkeys": true,
"initSQL": true,
"inject": true,
"insertSQL": true,
"isHotKey": true,
"isNil": true,
"isObject": true,
"isProxy": true,
"isReactive": true,
"isReadonly": true,
"isRef": true,
"isSpecialKey": true,
"isString": true,
"mapActions": true,
"mapGetters": true,
"mapState": true,
Expand All @@ -50,25 +78,37 @@
"reactive": true,
"readonly": true,
"ref": true,
"request": true,
"resolveComponent": true,
"saveImage": true,
"saveMarkdown": true,
"selectSQL": true,
"setActivePinia": true,
"setMapStoreSuffix": true,
"shallowReactive": true,
"shallowReadonly": true,
"shallowRef": true,
"specialKeys": true,
"storeToRefs": true,
"toRaw": true,
"toRef": true,
"toRefs": true,
"triggerRef": true,
"unref": true,
"updateSQL": true,
"useAttrs": true,
"useCssModule": true,
"useCssVars": true,
"useObserverLink": true,
"useRoleStore": true,
"useSessionStore": true,
"useSettingsStore": true,
"useSlots": true,
"watch": true,
"watchEffect": true,
"watchPostEffect": true,
"watchSyncEffect": true
"watchSyncEffect": true,
"writeBinaryFile": true,
"writeTextFile": true
}
}
3 changes: 0 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<script setup lang="ts">
import { appWindow } from '@tauri-apps/api/window'
import { type } from '@tauri-apps/api/os'
import { initSQL } from '@/sqls'
import { useSettingsStore } from '@/stores'
import { useObserverLink } from '@/hooks'
const { isFix, windowFocused } = storeToRefs(useSettingsStore())
Expand Down
6 changes: 0 additions & 6 deletions src/api/openAi.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import { Body } from '@tauri-apps/api/http'
import { Message } from '@arco-design/web-vue'
import { request } from '.'
import { OPENAI_CHAT_URL, OPEN_AI_MODEL, OPENAI_CREDIT_URL } from '@/constants'
import {
fetchEventSource,
type EventSourceMessage
} from '@microsoft/fetch-event-source'
import { useSessionStore, useSettingsStore, useRoleStore } from '@/stores'
import { executeSQL } from '@/sqls'
import { dialogErrorMessage } from '@/utils'
import type { MessageData, SessionData } from '@/types'

/**
Expand Down
7 changes: 2 additions & 5 deletions src/components/Fixed/index.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
<script setup lang="ts">
import { useSettingsStore } from '@/stores'
import { IconPushpin } from '@arco-design/web-vue/es/icon'
const { isFix } = storeToRefs(useSettingsStore())
</script>

<template>
<div class="swap swap-rotate" @click="isFix = !isFix">
<input type="checkbox" v-model="isFix" />

<IconPushpin class="swap-on text-[rgb(var(--primary-6))]" />
<icon-pushpin class="swap-on text-[rgb(var(--primary-6))]" />

<div class="swap-off">
<IconPushpin class="-rotate-45" />
<icon-pushpin class="-rotate-45" />
</div>
</div>
</template>
16 changes: 4 additions & 12 deletions src/components/Function/components/HistoryDrawer.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<script setup lang="ts">
import { useSessionStore } from '@/stores'
import {
IconDelete,
IconEdit,
IconCheck,
IconClose
} from '@arco-design/web-vue/es/icon'
import type { SessionPayload } from '@/types'
import { Message } from '@arco-design/web-vue'
const props = defineProps<{ visible: boolean; setVisible: () => void }>()
Expand Down Expand Up @@ -126,17 +118,17 @@ const handleCancle = (item: SessionPayload) => {
v-if="!item.isEdit"
class="text-5 flex gap-2 opacity-0 group-hover:opacity-100"
>
<IconEdit @click="handleEdit(item)" />
<IconDelete
<icon-edit @click="handleEdit(item)" />
<icon-delete
@click="deleteSession(item)"
:class="{
'pointer-events-none opacity-50': item.id === currentSession?.id
}"
/>
</div>
<div v-else class="text-5 flex gap-2 opacity-0 group-hover:opacity-100">
<IconCheck @click="handleUpdate(item)" />
<IconClose @click="handleCancle(item)" />
<icon-check @click="handleUpdate(item)" />
<icon-close @click="handleCancle(item)" />
</div>
</li>
</ul>
Expand Down
4 changes: 0 additions & 4 deletions src/components/Function/components/SettingsModal.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
<script setup lang="ts">
import { useSettingsStore } from '@/stores'
import ShortcutKey from './ShortcutKey.vue'
import { getOpenAICreditApi } from '@/api'
const props = defineProps<{ visible: boolean; setVisible: () => void }>()
const { apiKey, autoStart, isMemory, isRememberPosition } = storeToRefs(
Expand Down
3 changes: 0 additions & 3 deletions src/components/Function/components/ShortcutKey.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<script setup lang="ts">
import { useSettingsStore } from '@/stores'
import { hotkeys, isHotKey, isSpecialKey, getKeySymbol } from '@/utils'
const { shortcutKeys, isBinding } = storeToRefs(useSettingsStore())
// 获取最后一位快捷键
Expand Down
10 changes: 4 additions & 6 deletions src/components/Function/index.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script setup lang="ts">
// TODO:vue component 渲染组件不会被自动导入,看看有没有什么解决办法
import {
IconPlusCircle,
IconRefresh,
Expand All @@ -8,9 +9,6 @@ import {
IconStop,
IconImage
} from '@arco-design/web-vue/es/icon'
import { useRoleStore, useSessionStore } from '@/stores'
import { getAiMessage } from '@/api'
import { saveImage } from '@/utils'
import { emit } from '@tauri-apps/api/event'
const { currentRole } = storeToRefs(useRoleStore())
Expand Down Expand Up @@ -93,9 +91,9 @@ const triggerScroll = () => {
<!-- 当前聊天角色对象 -->
<div class="top-50% left-50% text-4 -translate-1/2 absolute">
正在与
<span class="mark cursor-pointer" @click="triggerScroll">{{
currentRole?.name
}}</span>
<span class="mark cursor-pointer" @click="triggerScroll">
{{ currentRole?.name }}
</span>
对话
</div>

Expand Down
16 changes: 4 additions & 12 deletions src/components/Input/components/RoleList.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
<script setup lang="ts">
import {
IconEdit,
IconCheck,
IconDelete,
IconClose
} from '@arco-design/web-vue/es/icon'
import { Message } from '@arco-design/web-vue'
import { useRoleStore, useSessionStore } from '@/stores'
import type { RolePayload } from '@/types'
const roleStore = useRoleStore()
Expand Down Expand Up @@ -182,8 +174,8 @@ const handleClose = () => {
<div v-if="!item.is_default" @click.stop>
<div v-if="!item.isEdit" class="text-5 flex gap-5">
<IconEdit @click="handleEdit(item)" />
<IconDelete
<icon-edit @click="handleEdit(item)" />
<icon-delete
@click="deleteRole(item.id!)"
:class="{
'pointer-events-none opacity-50':
Expand All @@ -192,8 +184,8 @@ const handleClose = () => {
/>
</div>
<div v-else class="text-5 flex gap-5">
<IconCheck @click="handleUpdate(item)" />
<IconClose @click="handleClose" />
<icon-check @click="handleUpdate(item)" />
<icon-close @click="handleClose" />
</div>
</div>
</li>
Expand Down
3 changes: 0 additions & 3 deletions src/components/Input/index.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<script setup lang="ts">
import { appWindow } from '@tauri-apps/api/window'
import { Message } from '@arco-design/web-vue'
import { useSessionStore, useRoleStore } from '@/stores'
import { getAiMessage } from '@/api'
const recordStore = useSessionStore()
const { isThinking } = storeToRefs(recordStore)
Expand Down
2 changes: 0 additions & 2 deletions src/components/Session/components/NoSession.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script setup lang="ts">
import { useSettingsStore } from '@/stores'
const { shortcutKeys } = storeToRefs(useSettingsStore())
</script>

Expand Down
58 changes: 33 additions & 25 deletions src/components/Session/index.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<script setup lang="ts">
import { listen } from '@tauri-apps/api/event'
import MarkdownIt from 'markdown-it'
import MarkdownItHighlight from 'markdown-it-highlightjs'
import { IconImage, IconCaretUp } from '@arco-design/web-vue/es/icon'
import dayjs from 'dayjs'
import utc from 'dayjs/plugin/utc'
import { copyText, copyCode, saveImage, saveMarkdown } from '@/utils'
import { useSettingsStore, useSessionStore, useRoleStore } from '@/stores'
import { listen } from '@tauri-apps/api/event'
dayjs.extend(utc)
Expand All @@ -17,7 +14,7 @@ const marked = new MarkdownIt({
.use(copyCode)
const { uuid } = storeToRefs(useSettingsStore())
const { sessionDataList } = storeToRefs(useSessionStore())
const { sessionDataList, currentSession } = storeToRefs(useSessionStore())
const { currentRole } = storeToRefs(useRoleStore())
const getLocalTime = (time: string) =>
Expand All @@ -26,31 +23,32 @@ const getLocalTime = (time: string) =>
const sessionElement = ref<HTMLDivElement | null>(null)
const isAutoScroll = ref(true)
/** 自动滚动到底部 */
const autoScroll = (isAuto = false) => {
/**
* 自动滚动到底部
* @param isAuto
*/
const autoScroll = (isSmooth = false) => {
if (!sessionElement.value || !isAutoScroll.value) return
sessionElement.value.scroll({
top: sessionElement.value.scrollHeight,
behavior: isAuto ? 'smooth' : 'auto'
behavior: isSmooth ? 'smooth' : 'auto'
})
}
onMounted(() => {
listen('scroll-to-bottom', () => {
isAutoScroll.value = true
autoScroll(true)
})
})
//用户滚轮操作滚动条
/**
* 滚轮事件
* @param event 滚轮事件参数
*/
const handleWheel = (event: WheelEvent) => {
if (event.deltaY < 0) {
isAutoScroll.value = false
}
if (event.deltaY > 0) return
isAutoScroll.value = false
}
//监听消息页面滚动
/**
* 滚动事件
*/
const handleScroll = () => {
if (!sessionElement.value) return
Expand All @@ -61,8 +59,18 @@ const handleScroll = () => {
}
}
onUpdated(() => {
autoScroll()
onMounted(() => {
listen('scroll-to-bottom', () => {
isAutoScroll.value = true
autoScroll(true)
})
})
onUpdated(autoScroll)
watch(currentSession, () => {
isAutoScroll.value = true
})
</script>

Expand Down Expand Up @@ -114,10 +122,10 @@ onUpdated(() => {
<div
class="markdown"
:id="`markdown-${item.id}`"
@click="saveMarkdown(item.message.content)"
@click="saveMarkdown($event, item.message.content)"
></div>

<IconImage @click="saveImage(`session-data-${item.id}`)" />
<icon-image @click="saveImage(`session-data-${item.id}`)" />
</div>

<div
Expand Down Expand Up @@ -145,7 +153,7 @@ onUpdated(() => {
>
<a-button type="primary" shape="circle">
<template #icon>
<IconCaretUp />
<icon-caret-up />
</template>
</a-button>
</a-back-top>
Expand Down
Loading

0 comments on commit 14d83c3

Please sign in to comment.