mirror of
https://github.com/MustangYM/OSXChatGpt.git
synced 2025-11-25 11:29:43 +08:00
add function
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
CB27656A29D1E65100897E0E /* Conversation+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB27656829D1E65100897E0E /* Conversation+CoreDataProperties.swift */; };
|
||||
CB27656D29D1E6A100897E0E /* Prompt+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB27656B29D1E6A100897E0E /* Prompt+CoreDataClass.swift */; };
|
||||
CB27656E29D1E6A100897E0E /* Prompt+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB27656C29D1E6A100897E0E /* Prompt+CoreDataProperties.swift */; };
|
||||
CB27657329D30F1400897E0E /* AIPromptViewMdoel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB27657229D30F1400897E0E /* AIPromptViewMdoel.swift */; };
|
||||
CB27657529D33D7A00897E0E /* AIPromptInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB27657429D33D7A00897E0E /* AIPromptInputView.swift */; };
|
||||
CB28A52229C07BE500F0286A /* KeyboardMonitor.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB28A52129C07BE500F0286A /* KeyboardMonitor.swift */; };
|
||||
CB28A52829C1569900F0286A /* ThinkingAnimationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB28A52729C1569900F0286A /* ThinkingAnimationView.swift */; };
|
||||
CB2F971F29CE12B6004EBD96 /* MarkdownUI in Frameworks */ = {isa = PBXBuildFile; productRef = CB2F971E29CE12B6004EBD96 /* MarkdownUI */; };
|
||||
@@ -74,6 +76,8 @@
|
||||
CB27656829D1E65100897E0E /* Conversation+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Conversation+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
||||
CB27656B29D1E6A100897E0E /* Prompt+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Prompt+CoreDataClass.swift"; sourceTree = "<group>"; };
|
||||
CB27656C29D1E6A100897E0E /* Prompt+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Prompt+CoreDataProperties.swift"; sourceTree = "<group>"; };
|
||||
CB27657229D30F1400897E0E /* AIPromptViewMdoel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AIPromptViewMdoel.swift; sourceTree = "<group>"; };
|
||||
CB27657429D33D7A00897E0E /* AIPromptInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AIPromptInputView.swift; sourceTree = "<group>"; };
|
||||
CB28A52129C07BE500F0286A /* KeyboardMonitor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardMonitor.swift; sourceTree = "<group>"; };
|
||||
CB28A52729C1569900F0286A /* ThinkingAnimationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ThinkingAnimationView.swift; sourceTree = "<group>"; };
|
||||
CB2F972129CED6AE004EBD96 /* ChatRoomInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatRoomInputView.swift; sourceTree = "<group>"; };
|
||||
@@ -126,6 +130,7 @@
|
||||
CB2F972129CED6AE004EBD96 /* ChatRoomInputView.swift */,
|
||||
182B436429BC5C8700F06778 /* UserInitializeView.swift */,
|
||||
CB27656529D1DA9800897E0E /* AIPromptView.swift */,
|
||||
CB27657429D33D7A00897E0E /* AIPromptInputView.swift */,
|
||||
182B436129BC5C8700F06778 /* View.swift */,
|
||||
182B437A29BC5FBE00F06778 /* EnterAPIView.swift */,
|
||||
188FB46629C1FA9700E3C18F /* EidtSessionRemarkView.swift */,
|
||||
@@ -149,6 +154,7 @@
|
||||
182B436F29BC5D1B00F06778 /* CoreDataManager.swift */,
|
||||
182B437029BC5D1B00F06778 /* ViewModel.swift */,
|
||||
CB28A52129C07BE500F0286A /* KeyboardMonitor.swift */,
|
||||
CB27657229D30F1400897E0E /* AIPromptViewMdoel.swift */,
|
||||
);
|
||||
path = DataProvider;
|
||||
sourceTree = "<group>";
|
||||
@@ -320,6 +326,7 @@
|
||||
CB0F5A6029D059C4005B71D2 /* SplashCodeSyntaxHighlighter.swift in Sources */,
|
||||
CBC4B12429B8D28D00650296 /* Message+CoreDataProperties.swift in Sources */,
|
||||
182B436529BC5C8700F06778 /* SessionsView.swift in Sources */,
|
||||
CB27657529D33D7A00897E0E /* AIPromptInputView.swift in Sources */,
|
||||
CB27656D29D1E6A100897E0E /* Prompt+CoreDataClass.swift in Sources */,
|
||||
182B437229BC5D1B00F06778 /* HTTPClient.swift in Sources */,
|
||||
182B436829BC5C8700F06778 /* MainContentView.swift in Sources */,
|
||||
@@ -328,6 +335,7 @@
|
||||
CB2F972229CED6AE004EBD96 /* ChatRoomInputView.swift in Sources */,
|
||||
CB2F972829CEFB65004EBD96 /* ChatRoomToolBar.swift in Sources */,
|
||||
CBC4B12329B8D28D00650296 /* Message+CoreDataClass.swift in Sources */,
|
||||
CB27657329D30F1400897E0E /* AIPromptViewMdoel.swift in Sources */,
|
||||
CB27655C29D1C12C00897E0E /* MarkdownView.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
||||
52
OSXChatGPT/OSXChatGPT/DataProvider/AIPromptViewMdoel.swift
Normal file
52
OSXChatGPT/OSXChatGPT/DataProvider/AIPromptViewMdoel.swift
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// AIPromptViewMdoel.swift
|
||||
// OSXChatGPT
|
||||
//
|
||||
// Created by CoderChan on 2023/3/28.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
|
||||
class AIPromptViewMdoel {
|
||||
let isSession: Bool
|
||||
@Published var allPrompts: [Prompt] = []
|
||||
@Published var prompts: [Prompt] = []
|
||||
|
||||
init(isSession: Bool) {
|
||||
self.isSession = isSession
|
||||
if isSession {
|
||||
fetchPrompts()
|
||||
}else {
|
||||
fetchAllPrompts()
|
||||
}
|
||||
}
|
||||
|
||||
static func randomColor() -> Color {
|
||||
let color = Color(hue: Double.random(in: 0...1),
|
||||
saturation: Double.random(in: 0.5...1),
|
||||
brightness: Double.random(in: 0.5...1))
|
||||
return color
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
extension AIPromptViewMdoel {
|
||||
private func fetchAllPrompts() {
|
||||
let completedDateSort = NSSortDescriptor(keyPath: \Prompt.serial, ascending: false)
|
||||
let aa: [Prompt] = CoreDataManager.shared.fetch("Prompt", sorting: [completedDateSort])
|
||||
allPrompts = aa
|
||||
}
|
||||
|
||||
private func fetchPrompts() {
|
||||
let completedDateSort = NSSortDescriptor(keyPath: \Prompt.serial, ascending: false)
|
||||
let aa: [Prompt] = CoreDataManager.shared.fetch("Prompt", sorting: [completedDateSort])
|
||||
|
||||
prompts = aa
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
150
OSXChatGPT/OSXChatGPT/WindowView/AIPromptInputView.swift
Normal file
150
OSXChatGPT/OSXChatGPT/WindowView/AIPromptInputView.swift
Normal file
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// AIPromptInputView.swift
|
||||
// OSXChatGPT
|
||||
//
|
||||
// Created by CoderChan on 2023/3/28.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct AIPromptInputView: View {
|
||||
@Binding var isPresented: Bool
|
||||
@State private var title: String = ""
|
||||
@State private var prompt: String = ""
|
||||
@State private var author: String = ""
|
||||
@State private var isToggleOn: Bool = true
|
||||
func cancelAction() {
|
||||
self.isPresented = false
|
||||
}
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack {
|
||||
Spacer()
|
||||
Text("自定义提示")
|
||||
.font(.title3)
|
||||
.foregroundColor(.black.opacity(0.9))
|
||||
Spacer()
|
||||
}.frame(height: 40)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.background(.white)
|
||||
|
||||
VStack {
|
||||
HStack {
|
||||
Text("标题")
|
||||
.font(.title3)
|
||||
.padding(.top, 5)
|
||||
.padding(.leading, 20)
|
||||
.padding(.bottom, 0)
|
||||
.frame(height: 18)
|
||||
Text("*必填")
|
||||
.font(Font.system(size: 11))
|
||||
.padding(.top, 5)
|
||||
.foregroundColor(.gray.opacity(0.6))
|
||||
.frame(height: 18)
|
||||
Spacer()
|
||||
}
|
||||
HStack {
|
||||
TextField("", text: $title)
|
||||
.accentColor(nil)
|
||||
.textFieldStyle(PlainTextFieldStyle())
|
||||
.font(Font.system(size: 14))
|
||||
.padding(10)
|
||||
.background(Color.white)
|
||||
.cornerRadius(8)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
}.padding(.leading, 20)
|
||||
.padding(.trailing, 20)
|
||||
|
||||
HStack {
|
||||
Text("Prompt")
|
||||
.font(.title3)
|
||||
.padding(.top, 5)
|
||||
.padding(.leading, 20)
|
||||
.padding(.bottom, 0)
|
||||
.frame(height: 18)
|
||||
Text("*必填")
|
||||
.font(Font.system(size: 11))
|
||||
.padding(.top, 5)
|
||||
.foregroundColor(.gray.opacity(0.6))
|
||||
.frame(height: 18)
|
||||
Spacer()
|
||||
}.padding(.top, 5)
|
||||
|
||||
HStack {
|
||||
TextEditor(text: $prompt)
|
||||
.font(Font.system(size: 13))
|
||||
.padding(8)
|
||||
.background(Color.white)
|
||||
.cornerRadius(8)
|
||||
.frame(height: 90)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
}.padding(.leading, 20)
|
||||
.padding(.trailing, 20)
|
||||
|
||||
HStack {
|
||||
Text("作者")
|
||||
.font(.title3)
|
||||
.padding(.top, 5)
|
||||
.padding(.leading, 20)
|
||||
.padding(.bottom, 0)
|
||||
.frame(height: 18)
|
||||
Text("(选填)可分享")
|
||||
.font(Font.system(size: 11))
|
||||
.padding(.top, 5)
|
||||
.foregroundColor(.gray.opacity(0.6))
|
||||
.frame(height: 18)
|
||||
Spacer()
|
||||
}.padding(.top, 5)
|
||||
HStack {
|
||||
TextField("", text: $author)
|
||||
.accentColor(nil)
|
||||
.textFieldStyle(PlainTextFieldStyle())
|
||||
.font(Font.system(size: 14))
|
||||
.padding(10)
|
||||
.background(Color.white)
|
||||
.cornerRadius(8)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
}.padding(.leading, 20)
|
||||
.padding(.trailing, 20)
|
||||
|
||||
}
|
||||
Spacer()
|
||||
|
||||
VStack {
|
||||
HStack {
|
||||
Toggle("是否上传至云端", isOn: $isToggleOn)
|
||||
.padding()
|
||||
.foregroundColor(.gray)
|
||||
.font(Font.system(size: 13))
|
||||
|
||||
Spacer()
|
||||
Button {
|
||||
self.isPresented = false
|
||||
} label: {
|
||||
Text("取消")
|
||||
}
|
||||
|
||||
Button {
|
||||
self.isPresented = false
|
||||
} label: {
|
||||
Text("确定")
|
||||
}.padding(.trailing, 20)
|
||||
}
|
||||
|
||||
}.frame(height: 44)
|
||||
.frame(minWidth: 0, maxWidth: .infinity)
|
||||
.background(.white)
|
||||
|
||||
|
||||
|
||||
}.frame(width: 500, height: 380)
|
||||
.background(.gray.opacity(0.3))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//struct AIPromptInputView_Previews: PreviewProvider {
|
||||
// static var previews: some View {
|
||||
// AIPromptInputView()
|
||||
// }
|
||||
//}
|
||||
@@ -12,10 +12,106 @@ import SwiftUI
|
||||
|
||||
struct AIPromptView: View {
|
||||
let sesstionId: String? //有则表示在会话中打开
|
||||
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
struct ListItem: Identifiable, Hashable {
|
||||
let id = UUID()
|
||||
let name: String
|
||||
var isSelected: Bool = false
|
||||
var title: String = "11"
|
||||
var content: String = "444"
|
||||
}
|
||||
struct AIPromptPopView: View {
|
||||
@Binding var showInputView: Bool
|
||||
@Binding var showPopover: Bool
|
||||
@State private var isPresented = false
|
||||
@State var selectedItem :ListItem?
|
||||
let items: [ListItem] = [ListItem(name: "123", isSelected: false),
|
||||
ListItem(name: "345", isSelected: false),
|
||||
ListItem(name: "567", isSelected: true)]
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// Spacer()
|
||||
VStack {
|
||||
Spacer()
|
||||
Text("选择提示")
|
||||
.font(.title3)
|
||||
.foregroundColor(.black.opacity(0.9))
|
||||
Spacer()
|
||||
|
||||
}
|
||||
HStack {
|
||||
Spacer()
|
||||
Button {
|
||||
self.showPopover = false
|
||||
self.showInputView = true
|
||||
} label: {
|
||||
Text("自定义")
|
||||
}
|
||||
.padding(10)
|
||||
}
|
||||
}
|
||||
List(items) { item in
|
||||
AIPromptPopCellView(
|
||||
item: item,
|
||||
isSelected: self.selectedItem == item
|
||||
) {
|
||||
self.selectedItem = item
|
||||
}
|
||||
}.frame(width: 560, height: 380)
|
||||
}
|
||||
}
|
||||
|
||||
struct AIPromptPopCellView: View {
|
||||
let item: ListItem
|
||||
let isSelected: Bool
|
||||
let action: () -> Void
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
if self.isSelected {
|
||||
Image(systemName: "checkmark.square.fill")
|
||||
.resizable()
|
||||
.scaledToFit()
|
||||
.frame(width: 20, height: 20)
|
||||
.foregroundColor(.white)
|
||||
.background(Color.blue)
|
||||
.clipShape(Circle())
|
||||
.padding(5)
|
||||
|
||||
} else {
|
||||
Circle()
|
||||
.stroke(Color.blue, lineWidth: 1)
|
||||
.frame(width: 20, height: 20)
|
||||
.padding(5)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(item.title)
|
||||
.font(.headline)
|
||||
.foregroundColor(.primary)
|
||||
Text(item.content)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
}.padding(.leading, 2)
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.frame(height: 60)
|
||||
.padding(.vertical, 5)
|
||||
.padding(.horizontal, 10)
|
||||
.background(
|
||||
AIPromptViewMdoel.randomColor()
|
||||
)
|
||||
.cornerRadius(6)
|
||||
.onTapGesture {
|
||||
self.action()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AIPromptView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
|
||||
@@ -9,6 +9,7 @@ import SwiftUI
|
||||
|
||||
struct ChatRoomToolBar: View {
|
||||
@State private var showPopover = false
|
||||
@State private var showInputView = false
|
||||
@EnvironmentObject var viewModel: ViewModel
|
||||
|
||||
@State private var isAnswerTypeTrue = ChatGPTManager.shared.answerType.valueBool
|
||||
@@ -32,8 +33,7 @@ struct ChatRoomToolBar: View {
|
||||
showPopover.toggle()
|
||||
}
|
||||
.popover(isPresented: $showPopover) {
|
||||
AIPromptView(sesstionId: viewModel.currentConversation?.sesstionId)
|
||||
.frame(width: 600, height: 400)
|
||||
AIPromptPopView(showInputView: $showInputView, showPopover: $showPopover)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
@@ -46,6 +46,11 @@ struct ChatRoomToolBar: View {
|
||||
}.padding(.trailing, 15)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
.sheet(isPresented: $showInputView) {
|
||||
// 在 sheet 中呈现表格
|
||||
AIPromptInputView(isPresented: $showInputView)
|
||||
}
|
||||
.padding(.leading, 12)
|
||||
.background(Color.clear)
|
||||
|
||||
Reference in New Issue
Block a user