添加配置管理功能,包括获取和设置配置值的接口及实现
This commit is contained in:
28
Web/src/api/config.js
Normal file
28
Web/src/api/config.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import request from './request'
|
||||
|
||||
/**
|
||||
* 获取配置值
|
||||
* @param {string} key - 配置的key
|
||||
* @returns {Promise<{success: boolean, data: string}>}
|
||||
*/
|
||||
export const getConfig = (key) => {
|
||||
return request({
|
||||
url: '/Config/GetConfig',
|
||||
method: 'get',
|
||||
params: { key }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置配置值
|
||||
* @param {string} key - 配置的key
|
||||
* @param {string} value - 配置的值
|
||||
* @returns {Promise<{success: boolean}>}
|
||||
*/
|
||||
export const setConfig = (key, value) => {
|
||||
return request({
|
||||
url: '/Config/SetConfig',
|
||||
method: 'post',
|
||||
params: { key, value }
|
||||
})
|
||||
}
|
||||
@@ -6,7 +6,16 @@
|
||||
left-arrow
|
||||
placeholder
|
||||
@click-left="onClickLeft"
|
||||
/>
|
||||
>
|
||||
<template #right>
|
||||
<van-icon
|
||||
name="question-o"
|
||||
size="20"
|
||||
@click="onClickPrompt"
|
||||
style="cursor: pointer; padding-right: 12px;"
|
||||
/>
|
||||
</template>
|
||||
</van-nav-bar>
|
||||
|
||||
<div class="scroll-content analysis-content">
|
||||
<!-- 输入区域 -->
|
||||
@@ -71,13 +80,32 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示词设置弹窗 -->
|
||||
<van-dialog
|
||||
v-model:show="showPromptDialog"
|
||||
title="编辑分析提示词"
|
||||
:show-cancel-button="true"
|
||||
@confirm="confirmPrompt"
|
||||
>
|
||||
<van-field
|
||||
v-model="promptValue"
|
||||
rows="4"
|
||||
autosize
|
||||
type="textarea"
|
||||
maxlength="2000"
|
||||
placeholder="输入自定义的分析提示词..."
|
||||
show-word-limit
|
||||
/>
|
||||
</van-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, nextTick } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { showToast } from 'vant'
|
||||
import { showToast, showLoadingToast, closeToast } from 'vant'
|
||||
import { getConfig, setConfig } from '@/api/config'
|
||||
|
||||
const router = useRouter()
|
||||
const userInput = ref('')
|
||||
@@ -87,6 +115,10 @@ const resultHtml = ref('')
|
||||
const resultContainer = ref(null)
|
||||
const scrollAnchor = ref(null)
|
||||
|
||||
// 提示词弹窗相关
|
||||
const showPromptDialog = ref(false)
|
||||
const promptValue = ref('')
|
||||
|
||||
// 快捷问题
|
||||
const quickQuestions = [
|
||||
'最近三个月交通费用多少?',
|
||||
@@ -100,6 +132,45 @@ const onClickLeft = () => {
|
||||
router.back()
|
||||
}
|
||||
|
||||
// 点击提示词按钮
|
||||
const onClickPrompt = async () => {
|
||||
try {
|
||||
const response = await getConfig('BillAnalysisPrompt')
|
||||
if (response.success) {
|
||||
promptValue.value = response.data || ''
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取提示词失败:', error)
|
||||
}
|
||||
showPromptDialog.value = true
|
||||
}
|
||||
|
||||
// 确认提示词
|
||||
const confirmPrompt = async () => {
|
||||
if (!promptValue.value.trim()) {
|
||||
showToast('请输入提示词')
|
||||
return
|
||||
}
|
||||
|
||||
showLoadingToast({
|
||||
message: '保存中...',
|
||||
forbidClick: true
|
||||
})
|
||||
|
||||
try {
|
||||
const response = await setConfig('BillAnalysisPrompt', promptValue.value)
|
||||
if (response.success) {
|
||||
showToast('提示词已保存')
|
||||
showPromptDialog.value = false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存提示词失败:', error)
|
||||
showToast('保存失败,请重试')
|
||||
} finally {
|
||||
closeToast()
|
||||
}
|
||||
}
|
||||
|
||||
// 选择快捷问题
|
||||
const selectQuestion = (question) => {
|
||||
userInput.value = question
|
||||
|
||||
Reference in New Issue
Block a user