Skip to content

Commit

Permalink
feat: prompt 使用新窗口打开
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghonglu.neo committed Mar 23, 2023
1 parent ca87447 commit 8ed5a77
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ jobs:
# force_orphan: true

- name: Query version number
run: echo "version=${GITHUB_REF:11}" >> $GITHUB_ENV
run: echo "version=${GITHUB_REF:11}" >> $GITHUB_ENV
3 changes: 2 additions & 1 deletion src-tauri/src/app/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod gpt;
pub mod download;
pub mod download;
pub mod window;
33 changes: 33 additions & 0 deletions src-tauri/src/app/cmd/window.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use tauri::{Manager};

#[tauri::command]
pub fn new_window(app: tauri::AppHandle, label: String, title: String, url: String){
let win = app.get_window(&label);

if win.is_none() {
tauri::async_runtime::spawn(async move {
tauri::WindowBuilder::new(&app, label, tauri::WindowUrl::App(url.parse().unwrap()))
.title(title)
.inner_size(700.0, 550.0)
.resizable(true)
.build()
.unwrap();
});
} else if let Some(v) = win {
if !v.is_visible().unwrap() {
v.show().unwrap();
}
v.eval("window.location.reload()").unwrap();
v.set_focus().unwrap();
}
}

#[tauri::command]
pub fn window_reload(app: tauri::AppHandle, label: &str) {
app
.app_handle()
.get_window(label)
.unwrap()
.eval("window.location.reload()")
.unwrap();
}
5 changes: 4 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod app;
mod utils;

use app::{builder, cmd};
use tauri::Manager;
use tauri_plugin_log::{
fern::colors::{Color, ColoredLevelConfig},
LogTarget,
Expand Down Expand Up @@ -38,7 +39,8 @@ fn main() {
.plugin(log.build())
.invoke_handler(tauri::generate_handler![
cmd::gpt::fetch_chat_api,
cmd::download::download_img
cmd::download::download_img,
cmd::window::new_window
])
.setup(builder::setup);

Expand All @@ -50,6 +52,7 @@ fn main() {
if win.label() == "core" {
win.minimize().unwrap();
}else {
cmd::window::window_reload(event.window().app_handle(), "core");
event.window().close().unwrap();
}
api.prevent_close();
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@
"pubkey": "dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXk6IDM2OUUyQUQ5QjE1Q0FEMTEKUldRUnJWeXgyU3FlTmxOS0N0aVBhNGUwL3c3QlBIY29uMHFUdmhUZS9YNmpKNE83L1BKZ3dER2QK"
}
}
}
}
21 changes: 1 addition & 20 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
<script setup lang="ts">
import { NConfigProvider } from 'naive-ui'
import { appWindow } from '@tauri-apps/api/window'
import { os } from '@tauri-apps/api'
import { computed, onMounted, ref } from 'vue'
import { NaiveProvider } from '@/components/common'
import { useTheme } from '@/hooks/useTheme'
import { useLanguage } from '@/hooks/useLanguage'
const { theme, themeOverrides } = useTheme()
const { language } = useLanguage()
const isDarwin = ref<boolean>(false)
onMounted(async () => {
const o_s = await os.platform()
isDarwin.value = (o_s === 'darwin')
})
const configClass = computed(() => {
if (isDarwin.value)
return ['h-full', 'pt-8']
else
return ['h-full']
})
</script>

<template>
<div v-if="isDarwin" class="absolute h-8 w-full window-top" @mousedown="appWindow.startDragging" @touchstart="appWindow.startDragging" />
<NConfigProvider
:class="configClass"
class="h-full"
:theme="theme"
:theme-overrides="themeOverrides"
:locale="language"
Expand Down
225 changes: 92 additions & 133 deletions src/components/common/PromptStore/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,11 @@ interface DataProps {
value: string
}
interface Props {
visible: boolean
}
interface Emit {
(e: 'update:visible', visible: boolean): void
}
const props = defineProps<Props>()
const emit = defineEmits<Emit>()
const message = useMessage()
const show = computed({
get: () => props.visible,
set: (visible: boolean) => emit('update:visible', visible),
})
const showModal = ref(false)
const importLoading = ref(false)
const exportLoading = ref(false)
const searchValue = ref<string>('')
Expand Down Expand Up @@ -193,20 +175,6 @@ const importPromptTemplate = () => {
}
}
// 模板导出
const exportPromptTemplate = () => {
exportLoading.value = true
const jsonDataStr = JSON.stringify(promptList.value)
const blob = new Blob([jsonDataStr], { type: 'application/json' })
const url = URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = url
link.download = 'ChatGPTPromptTemplate.json'
link.click()
URL.revokeObjectURL(url)
exportLoading.value = false
}
// 模板在线导入
const downloadPromptTemplate = async () => {
try {
Expand Down Expand Up @@ -326,113 +294,104 @@ const dataSource = computed(() => {

<template>
<NMessageProvider>
<NModal v-model:show="show" style="width: 90%; max-width: 900px;" preset="card">
<div class="space-y-4">
<NTabs type="segment">
<NTabPane name="local" :tab="$t('store.local')">
<div
class="flex gap-3"
:class="[isMobile ? 'flex-col' : 'flex-row justify-between']"
>
<div class="flex items-center space-x-4">
<NButton
type="primary"
size="small"
@click="changeShowModal('add')"
>
{{ $t('common.add') }}
</NButton>
<NButton
size="small"
@click="changeShowModal('local_import')"
>
{{ $t('common.import') }}
</NButton>
<NButton
size="small"
:loading="exportLoading"
@click="exportPromptTemplate()"
>
{{ $t('common.export') }}
</NButton>
<NPopconfirm @positive-click="clearPromptTemplate">
<template #trigger>
<NButton size="small">
{{ $t('common.clear') }}
</NButton>
</template>
{{ $t('store.clearStoreConfirm') }}
</NPopconfirm>
</div>
<div class="flex items-center">
<NInput v-model:value="searchValue" style="width: 100%" />
</div>
</div>
<br>
<NDataTable
:max-height="400"
:columns="columns"
:data="dataSource"
:pagination="pagination"
:bordered="false"
/>
</NTabPane>
<NTabPane name="download" :tab="$t('store.online')">
<p class="mb-4">
{{ $t('store.onlineImportWarning') }}
</p>
<div class="flex items-center gap-4">
<NInput v-model:value="downloadURL" placeholder="" />
<div class="space-y-4">
<NTabs type="segment">
<NTabPane name="local" :tab="$t('store.local')">
<div
class="flex gap-3"
:class="[isMobile ? 'flex-col' : 'flex-row justify-between']"
>
<div class="flex items-center space-x-4">
<NButton
type="primary"
size="small"
@click="changeShowModal('add')"
>
{{ $t('common.add') }}
</NButton>
<NButton
strong
secondary
:disabled="downloadDisabled"
:loading="importLoading"
@click="downloadPromptTemplate()"
size="small"
@click="changeShowModal('local_import')"
>
{{ $t('common.download') }}
{{ $t('common.import') }}
</NButton>
<NPopconfirm @positive-click="clearPromptTemplate">
<template #trigger>
<NButton size="small">
{{ $t('common.clear') }}
</NButton>
</template>
{{ $t('store.clearStoreConfirm') }}
</NPopconfirm>
</div>
<div class="flex items-center">
<NInput v-model:value="searchValue" style="width: 100%" />
</div>
<NDivider />
<NLayoutContent
style="height: 360px"
content-style="background: none;"
:native-scrollbar="false"
</div>
<br>
<NDataTable
:max-height="320"
:columns="columns"
:data="dataSource"
:pagination="pagination"
:bordered="false"
/>
</NTabPane>
<NTabPane name="download" :tab="$t('store.online')">
<p class="mb-4">
{{ $t('store.onlineImportWarning') }}
</p>
<div class="flex items-center gap-4">
<NInput v-model:value="downloadURL" placeholder="" />
<NButton
strong
secondary
:disabled="downloadDisabled"
:loading="importLoading"
@click="downloadPromptTemplate()"
>
{{ $t('common.download') }}
</NButton>
</div>
<NDivider />
<NLayoutContent
:max-height="320"
content-style="background: none;"
:native-scrollbar="false"
>
<NCard
v-for="info in promptRecommendList"
:key="info.key" :title="info.key"
style="margin: 5px;"
embedded
:bordered="true"
>
<NCard
v-for="info in promptRecommendList"
:key="info.key" :title="info.key"
style="margin: 5px;"
embedded
:bordered="true"
<p
class="overflow-hidden text-ellipsis whitespace-nowrap"
:title="info.desc"
>
<p
class="overflow-hidden text-ellipsis whitespace-nowrap"
:title="info.desc"
>
{{ info.desc }}
</p>
<template #footer>
<div class="flex items-center justify-end space-x-4">
<NButton text>
<a
:href="info.url"
target="_blank"
>
<SvgIcon class="text-xl" icon="ri:link" />
</a>
</NButton>
<NButton text @click="setDownloadURL(info.downloadUrl) ">
<SvgIcon class="text-xl" icon="ri:add-fill" />
</NButton>
</div>
</template>
</NCard>
</NLayoutContent>
</NTabPane>
</NTabs>
</div>
</NModal>
{{ info.desc }}
</p>
<template #footer>
<div class="flex items-center justify-end space-x-4">
<NButton text>
<a
:href="info.url"
target="_blank"
>
<SvgIcon class="text-xl" icon="ri:link" />
</a>
</NButton>
<NButton text @click="setDownloadURL(info.downloadUrl) ">
<SvgIcon class="text-xl" icon="ri:add-fill" />
</NButton>
</div>
</template>
</NCard>
</NLayoutContent>
</NTabPane>
</NTabs>
</div>
<NModal v-model:show="showModal" style="width: 90%; max-width: 600px;" preset="card">
<NSpace v-if="modalMode === 'add' || modalMode === 'modify'" vertical>
{{ t('store.title') }}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Setting/User.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function saveUserInfo() {
</script>

<template>
<div class="p-4 space-y-5 min-h-[200px]">
<div class="p-4 space-y-5 min-h-[200px] max-h-80 overflow-auto">
<NForm ref="formRef" :model="model" :rules="rules">
<NFormItem path="avatar" :label="$t('setting.avatarLink')">
<NInput v-model:value="model.avatar" :placeholder="$t('setting.avatarLinkPlaceholder')" />
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/Setting/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const show = computed({
</script>

<template>
<NModal v-model:show="show" :auto-focus="false" preset="card" :title="$t('setting.setting')" style="width: 95%; max-width: 640px">
<NModal v-model:show="show" :auto-focus="false" preset="card" :title="$t('setting.setting')" style="width: 95%; max-width: 640px;">
<div>
<NTabs v-model:value="active" type="line" animated>
<NTabPane name="User" tab="User">
Expand Down
Loading

0 comments on commit 8ed5a77

Please sign in to comment.