170 lines
4.3 KiB
JavaScript
170 lines
4.3 KiB
JavaScript
|
|
import { computed, ref } from 'vue'
|
||
|
|
|
||
|
|
import { useNavigation, navItems } from './useNavigation.js'
|
||
|
|
import { useRequests } from './useRequests.js'
|
||
|
|
import { useChat } from './useChat.js'
|
||
|
|
import { useToast } from './useToast.js'
|
||
|
|
import { documents } from '../data/requests.js'
|
||
|
|
|
||
|
|
export function useAppShell() {
|
||
|
|
const loggedIn = ref(false)
|
||
|
|
const travelCreateMode = ref(false)
|
||
|
|
const detailMode = ref(false)
|
||
|
|
const selectedTravelRequest = ref(null)
|
||
|
|
const smartEntryOpen = ref(false)
|
||
|
|
const smartEntryContext = ref({ prompt: '', source: 'requests', request: null })
|
||
|
|
const smartEntrySessionId = ref(0)
|
||
|
|
|
||
|
|
const { activeView, currentView, setView } = useNavigation()
|
||
|
|
const { requests, search, filters, ranges, activeRange, filteredRequests, approveRequest, rejectRequest } = useRequests()
|
||
|
|
const { messages, draft, uploadedFiles, messageList, activeCase, prompts, sendMessage, handleUpload, openChat, openNewChat } = useChat(activeView)
|
||
|
|
const { toastText, toast } = useToast()
|
||
|
|
|
||
|
|
const docSearch = ref('')
|
||
|
|
const customRange = ref({ start: '2024-07-06', end: '2024-07-12' })
|
||
|
|
const travelPrompts = ['帮我提交出差申请', '预订机票', '预订酒店', '预订火车票', '查询差旅政策']
|
||
|
|
|
||
|
|
const topBarView = computed(() => {
|
||
|
|
if (detailMode.value) {
|
||
|
|
return {
|
||
|
|
title: '差旅报销详情',
|
||
|
|
desc: '查看报销单据详情、票据识别与审批进度'
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return currentView.value
|
||
|
|
})
|
||
|
|
|
||
|
|
const filteredDocuments = computed(() => {
|
||
|
|
const key = docSearch.value.trim().toLowerCase()
|
||
|
|
return documents.filter((doc) => {
|
||
|
|
const matchesSearch = !key || `${doc.id}${doc.applicant}${doc.destination}${doc.type}`.toLowerCase().includes(key)
|
||
|
|
return matchesSearch
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|
||
|
|
function handleLogin(credentials) {
|
||
|
|
if (credentials.username && credentials.password) {
|
||
|
|
loggedIn.value = true
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function handleRecoverPassword() {
|
||
|
|
toast('请联系系统管理员重置密码。')
|
||
|
|
}
|
||
|
|
|
||
|
|
function handleSsoLogin() {
|
||
|
|
toast('SSO 登录通道建设中。')
|
||
|
|
}
|
||
|
|
|
||
|
|
function handleApprove(request) {
|
||
|
|
const msg = approveRequest(request)
|
||
|
|
toast(msg)
|
||
|
|
}
|
||
|
|
|
||
|
|
function handleReject(request) {
|
||
|
|
const msg = rejectRequest(request)
|
||
|
|
toast(msg)
|
||
|
|
}
|
||
|
|
|
||
|
|
function handleNavigate(view) {
|
||
|
|
travelCreateMode.value = false
|
||
|
|
detailMode.value = false
|
||
|
|
selectedTravelRequest.value = null
|
||
|
|
smartEntryOpen.value = false
|
||
|
|
setView(view)
|
||
|
|
}
|
||
|
|
|
||
|
|
function handleOpenChat(request) {
|
||
|
|
travelCreateMode.value = false
|
||
|
|
openChat(request)
|
||
|
|
}
|
||
|
|
|
||
|
|
function openTravelCreate() {
|
||
|
|
smartEntryOpen.value = true
|
||
|
|
travelCreateMode.value = false
|
||
|
|
detailMode.value = false
|
||
|
|
selectedTravelRequest.value = null
|
||
|
|
smartEntryContext.value = { prompt: '', source: 'topbar', request: null }
|
||
|
|
smartEntrySessionId.value += 1
|
||
|
|
}
|
||
|
|
|
||
|
|
function openSmartEntry(payload = {}) {
|
||
|
|
smartEntryOpen.value = true
|
||
|
|
travelCreateMode.value = false
|
||
|
|
if (payload.source !== 'detail') {
|
||
|
|
detailMode.value = false
|
||
|
|
selectedTravelRequest.value = null
|
||
|
|
}
|
||
|
|
smartEntryContext.value = {
|
||
|
|
prompt: payload.prompt ?? '',
|
||
|
|
source: payload.source ?? 'workbench',
|
||
|
|
request: payload.request ?? selectedTravelRequest.value
|
||
|
|
}
|
||
|
|
smartEntrySessionId.value += 1
|
||
|
|
}
|
||
|
|
|
||
|
|
function closeSmartEntry() {
|
||
|
|
smartEntryOpen.value = false
|
||
|
|
}
|
||
|
|
|
||
|
|
function openRequestDetail(request) {
|
||
|
|
selectedTravelRequest.value = request
|
||
|
|
detailMode.value = true
|
||
|
|
activeView.value = 'requests'
|
||
|
|
}
|
||
|
|
|
||
|
|
function closeRequestDetail() {
|
||
|
|
detailMode.value = false
|
||
|
|
selectedTravelRequest.value = null
|
||
|
|
}
|
||
|
|
|
||
|
|
return {
|
||
|
|
activeCase,
|
||
|
|
activeRange,
|
||
|
|
activeView,
|
||
|
|
closeRequestDetail,
|
||
|
|
closeSmartEntry,
|
||
|
|
currentView,
|
||
|
|
customRange,
|
||
|
|
detailMode,
|
||
|
|
docSearch,
|
||
|
|
draft,
|
||
|
|
filteredDocuments,
|
||
|
|
filteredRequests,
|
||
|
|
filters,
|
||
|
|
handleApprove,
|
||
|
|
handleLogin,
|
||
|
|
handleNavigate,
|
||
|
|
handleOpenChat,
|
||
|
|
handleRecoverPassword,
|
||
|
|
handleReject,
|
||
|
|
handleSsoLogin,
|
||
|
|
handleUpload,
|
||
|
|
loggedIn,
|
||
|
|
messageList,
|
||
|
|
messages,
|
||
|
|
navItems,
|
||
|
|
openChat,
|
||
|
|
openNewChat,
|
||
|
|
openRequestDetail,
|
||
|
|
openSmartEntry,
|
||
|
|
openTravelCreate,
|
||
|
|
prompts,
|
||
|
|
ranges,
|
||
|
|
requests,
|
||
|
|
search,
|
||
|
|
selectedTravelRequest,
|
||
|
|
sendMessage,
|
||
|
|
setView,
|
||
|
|
smartEntryContext,
|
||
|
|
smartEntryOpen,
|
||
|
|
smartEntrySessionId,
|
||
|
|
toast,
|
||
|
|
toastText,
|
||
|
|
topBarView,
|
||
|
|
travelCreateMode,
|
||
|
|
travelPrompts,
|
||
|
|
uploadedFiles
|
||
|
|
}
|
||
|
|
}
|