提交 9bd6f7eb authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 e8fff8e5
# VITE_API_URL_WORD = https://zijingebook.ezijing.com/file/ VITE_API_URL = https://zijingebook.ezijing.com/api
VITE_API_URL_WORD = https://zijingebook.ezijing.com/api
VITE_API_BASE_API_PREFFIX = /api VITE_API_PREFIX = /api
# VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com # VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com
VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com/ws VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com/ws
VITE_API_OPENAI_URL = https://model-platform-skyagents.tiangong.cn
\ No newline at end of file
# VITE_API_URL_WORD = https://book-admin-web.ezijing.com/api VITE_API_URL = https://zijingebook.ezijing.com/api
VITE_API_URL_WORD = https://zijingebook.ezijing.com/api
VITE_API_BASE_API_PREFFIX = /api VITE_API_PREFIX = /api
# VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com # VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com
VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com/ws VITE_API_WEBSOCKET_URL = wss://zijingebook.ezijing.com/ws
VITE_API_OPENAI_URL = https://model-platform-skyagents.tiangong.cn
\ No newline at end of file
import axios from '@/utils/wenku'
// 文件上传前置
export function uploadPrepare(data) {
return axios.post('/api/wenku/wenchain/partner/uploadprepare', data)
}
// 生成论文大纲
export function usePaperOutline() {}
// 文档下载
export function useDownload() {}
// 文档上传
export function useUpload() {}
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
Form, Form,
Modal, Modal,
message, message,
Image Image,
} from 'antd' } from 'antd'
const { RangePicker } = DatePicker const { RangePicker } = DatePicker
const { TextArea } = Input const { TextArea } = Input
...@@ -46,7 +46,7 @@ const Sensitive = () => { ...@@ -46,7 +46,7 @@ const Sensitive = () => {
const [isadd, setisadd] = useState(true) const [isadd, setisadd] = useState(true)
const [word_name, setword_name] = useState('') const [word_name, setword_name] = useState('')
const [file, setFile] = useState('') const [file, setFile] = useState('')
const handleEdit = obj => { const handleEdit = (obj) => {
setid(obj.id) setid(obj.id)
form.setFieldsValue(obj) form.setFieldsValue(obj)
setisadd(false) setisadd(false)
...@@ -59,7 +59,7 @@ const Sensitive = () => { ...@@ -59,7 +59,7 @@ const Sensitive = () => {
setData(list) setData(list)
setLoading(false) setLoading(false)
} }
const changeWord = ev => { const changeWord = (ev) => {
let val = ev.target.value let val = ev.target.value
setword_name(val) setword_name(val)
if (val == '') { if (val == '') {
...@@ -69,7 +69,7 @@ const Sensitive = () => { ...@@ -69,7 +69,7 @@ const Sensitive = () => {
const handleFilter = async () => { const handleFilter = async () => {
init({ word_name }) init({ word_name })
} }
const submitForm = async obj => { const submitForm = async (obj) => {
console.log('点解了编辑的提交表单') console.log('点解了编辑的提交表单')
let bool let bool
if (isadd) { if (isadd) {
...@@ -77,7 +77,7 @@ const Sensitive = () => { ...@@ -77,7 +77,7 @@ const Sensitive = () => {
} else { } else {
bool = await editWords({ bool = await editWords({
...obj, ...obj,
id id,
}) })
} }
bool && init() bool && init()
...@@ -106,7 +106,7 @@ const Sensitive = () => { ...@@ -106,7 +106,7 @@ const Sensitive = () => {
} }
setFile(file) setFile(file)
return false return false
} },
} }
const [importRes, setimportRes] = useState(false) const [importRes, setimportRes] = useState(false)
const [importMsg, setimportMsg] = useState(false) const [importMsg, setimportMsg] = useState(false)
...@@ -129,7 +129,7 @@ const Sensitive = () => { ...@@ -129,7 +129,7 @@ const Sensitive = () => {
} }
// 下载模板 // 下载模板
const handleDownload = async () => { const handleDownload = async () => {
window.open(import.meta.env.VITE_API_URL_WORD + '/敏感词导入示例.xlsx') window.open(import.meta.env.VITE_API_URL + '/敏感词导入示例.xlsx')
} }
useEffect(() => { useEffect(() => {
if (!showModal) { if (!showModal) {
...@@ -146,19 +146,19 @@ const Sensitive = () => { ...@@ -146,19 +146,19 @@ const Sensitive = () => {
title: 'ID', title: 'ID',
key: 'id', key: 'id',
dataIndex: 'id', dataIndex: 'id',
align: 'center' align: 'center',
}, },
{ {
title: '敏感词', title: '敏感词',
key: 'word_name', key: 'word_name',
dataIndex: 'word_name', dataIndex: 'word_name',
align: 'center' align: 'center',
}, },
{ {
title: '创建时间', title: '创建时间',
key: 'create_time', key: 'create_time',
dataIndex: 'create_time', dataIndex: 'create_time',
align: 'center' align: 'center',
}, },
{ {
title: '操作', title: '操作',
...@@ -183,8 +183,8 @@ const Sensitive = () => { ...@@ -183,8 +183,8 @@ const Sensitive = () => {
</Button> </Button>
</Space> </Space>
) )
} },
} },
] ]
return ( return (
<div className="classify"> <div className="classify">
...@@ -210,7 +210,7 @@ const Sensitive = () => { ...@@ -210,7 +210,7 @@ const Sensitive = () => {
display: 'inline-block', display: 'inline-block',
width: '11px', width: '11px',
height: '10px', height: '10px',
pointerEvents: 'none' pointerEvents: 'none',
}}> }}>
<Image src={reset} /> <Image src={reset} />
</span> </span>
...@@ -226,7 +226,7 @@ const Sensitive = () => { ...@@ -226,7 +226,7 @@ const Sensitive = () => {
display: 'inline-block', display: 'inline-block',
width: '13px', width: '13px',
height: '12px', height: '12px',
pointerEvents: 'none' pointerEvents: 'none',
}}> }}>
<Image src={filter} /> <Image src={filter} />
</span> </span>
...@@ -234,7 +234,7 @@ const Sensitive = () => { ...@@ -234,7 +234,7 @@ const Sensitive = () => {
ghost ghost
onClick={() => { onClick={() => {
setPage(1) setPage(1)
Object.values(filterObj).some(item => item) ? init(filterObj) : init() Object.values(filterObj).some((item) => item) ? init(filterObj) : init()
}}> }}>
筛选 筛选
</Button> </Button>
...@@ -247,12 +247,12 @@ const Sensitive = () => { ...@@ -247,12 +247,12 @@ const Sensitive = () => {
display: 'inline-block', display: 'inline-block',
width: '10px', width: '10px',
height: '12px', height: '12px',
pointerEvents: 'none' pointerEvents: 'none',
}}> }}>
<Image src={reload} /> <Image src={reload} />
</span> </span>
} }
onClick={() => (Object.values(filterObj).some(item => item) ? init(filterObj) : init())}> onClick={() => (Object.values(filterObj).some((item) => item) ? init(filterObj) : init())}>
刷新 刷新
</Button> </Button>
</Space> </Space>
...@@ -269,7 +269,7 @@ const Sensitive = () => { ...@@ -269,7 +269,7 @@ const Sensitive = () => {
display: 'inline-block', display: 'inline-block',
width: '11px', width: '11px',
height: '12px', height: '12px',
pointerEvents: 'none' pointerEvents: 'none',
}}> }}>
<Image src={imports} /> <Image src={imports} />
</span> </span>
...@@ -290,7 +290,7 @@ const Sensitive = () => { ...@@ -290,7 +290,7 @@ const Sensitive = () => {
display: 'inline-block', display: 'inline-block',
width: '13px', width: '13px',
height: '12px', height: '12px',
pointerEvents: 'none' pointerEvents: 'none',
}}> }}>
<Image src={Add} /> <Image src={Add} />
</span> </span>
...@@ -389,7 +389,7 @@ const Sensitive = () => { ...@@ -389,7 +389,7 @@ const Sensitive = () => {
key="err" key="err"
ghost ghost
onClick={() => { onClick={() => {
window.open(import.meta.env.VITE_API_URL_WORD + '/敏感词导入失败.xlsx') window.open(import.meta.env.VITE_API_URL + '/敏感词导入失败.xlsx')
}}> }}>
下载导入失败的数据 下载导入失败的数据
</Button> </Button>
...@@ -401,7 +401,7 @@ const Sensitive = () => { ...@@ -401,7 +401,7 @@ const Sensitive = () => {
setUploadModal(false) setUploadModal(false)
}}> }}>
完成 完成
</Button> </Button>,
]} ]}
/> />
)} )}
......
...@@ -21,7 +21,7 @@ function showLoginModal() { ...@@ -21,7 +21,7 @@ function showLoginModal() {
onOk() { onOk() {
localStorage.removeItem('kiwi.gpt.token') localStorage.removeItem('kiwi.gpt.token')
location.href = '/login' location.href = '/login'
} },
}) })
} }
...@@ -31,14 +31,14 @@ function alphabeticalSort(a, b) { ...@@ -31,14 +31,14 @@ function alphabeticalSort(a, b) {
} }
const httpRequest = axios.create({ const httpRequest = axios.create({
// baseURL: import.meta.env.VITE_API_BASE_API_PREFFIX, // baseURL: import.meta.env.VITE_API_PREFIX,
// timeout: 60000, // timeout: 60000,
withCredentials: true withCredentials: true,
}) })
// 请求拦截器 // 请求拦截器
httpRequest.interceptors.request.use( httpRequest.interceptors.request.use(
config => { (config) => {
const token = getToken() const token = getToken()
// 应用设置 // 应用设置
const appId = 'TzEU5jPk2tu80266' const appId = 'TzEU5jPk2tu80266'
...@@ -51,7 +51,7 @@ httpRequest.interceptors.request.use( ...@@ -51,7 +51,7 @@ httpRequest.interceptors.request.use(
appSecret, appSecret,
timestamp, timestamp,
token, token,
url: config.url url: config.url,
} }
const signStr = qs.stringify(signData, { sort: alphabeticalSort }) const signStr = qs.stringify(signData, { sort: alphabeticalSort })
...@@ -64,7 +64,7 @@ httpRequest.interceptors.request.use( ...@@ -64,7 +64,7 @@ httpRequest.interceptors.request.use(
AppId: appId, AppId: appId,
AppSecret: appSecret, AppSecret: appSecret,
Timestamp: timestamp, Timestamp: timestamp,
Sign: sign Sign: sign,
} }
config.headers = { ...config.headers, ...defaultHeaders } config.headers = { ...config.headers, ...defaultHeaders }
...@@ -75,14 +75,14 @@ httpRequest.interceptors.request.use( ...@@ -75,14 +75,14 @@ httpRequest.interceptors.request.use(
return config return config
}, },
error => { (error) => {
return Promise.reject(error) return Promise.reject(error)
} }
) )
// 响应拦截器 // 响应拦截器
httpRequest.interceptors.response.use( httpRequest.interceptors.response.use(
response => { (response) => {
const { data } = response const { data } = response
if (data.code === 401 || data.code === 403) { if (data.code === 401 || data.code === 403) {
if (location.pathname !== '/login') { if (location.pathname !== '/login') {
...@@ -96,7 +96,7 @@ httpRequest.interceptors.response.use( ...@@ -96,7 +96,7 @@ httpRequest.interceptors.response.use(
} }
return data return data
}, },
error => { (error) => {
if (error.response) { if (error.response) {
const { status, data = {} } = error.response const { status, data = {} } = error.response
if (status === 401 || status === 403) { if (status === 401 || status === 403) {
......
...@@ -150,8 +150,8 @@ export const findParentsExpanded = (treeData, targetKey = 'id') => { ...@@ -150,8 +150,8 @@ export const findParentsExpanded = (treeData, targetKey = 'id') => {
export const treeRouterData = (source, id = 'menuId', parentId = 'pid', children = 'children') => { export const treeRouterData = (source, id = 'menuId', parentId = 'pid', children = 'children') => {
const cloneData = JSON.parse(JSON.stringify(source)) const cloneData = JSON.parse(JSON.stringify(source))
if (source.length === 0) return source if (source.length === 0) return source
return cloneData.filter(father => { return cloneData.filter((father) => {
const branchArr = cloneData.filter(child => parseFloat(father[id]) === parseFloat(child[parentId])) const branchArr = cloneData.filter((child) => parseFloat(father[id]) === parseFloat(child[parentId]))
father[children] = branchArr.length > 0 ? branchArr : null father[children] = branchArr.length > 0 ? branchArr : null
return father[parentId] === 0 return father[parentId] === 0
...@@ -162,13 +162,13 @@ export const treeRouterData = (source, id = 'menuId', parentId = 'pid', children ...@@ -162,13 +162,13 @@ export const treeRouterData = (source, id = 'menuId', parentId = 'pid', children
export function convertToAntdTreeData(data, target = 'label') { export function convertToAntdTreeData(data, target = 'label') {
const antdTreeData = [] const antdTreeData = []
const convertNode = node => { const convertNode = (node) => {
const antdTreeNode = { const antdTreeNode = {
...node, ...node,
title: node[target], title: node[target],
key: node.id, key: node.id,
select: false, select: false,
edit: false edit: false,
} }
if (node.children && node.children.length > 0) { if (node.children && node.children.length > 0) {
...@@ -261,7 +261,7 @@ export const findAllParents = (tree, key, value, parents = []) => { ...@@ -261,7 +261,7 @@ export const findAllParents = (tree, key, value, parents = []) => {
export const findAllChildren = (tree, key, value) => { export const findAllChildren = (tree, key, value) => {
for (const node of tree) { for (const node of tree) {
const currentKey = node[key] const currentKey = node[key]
const currentChildren = (node.children || []).map(child => child[key]) const currentChildren = (node.children || []).map((child) => child[key])
if (currentKey === value) { if (currentKey === value) {
return currentChildren return currentChildren
...@@ -275,11 +275,11 @@ export const findAllChildren = (tree, key, value) => { ...@@ -275,11 +275,11 @@ export const findAllChildren = (tree, key, value) => {
} }
// 将树形结构转为一维数组 // 将树形结构转为一维数组
export const treeDataToArray = source => { export const treeDataToArray = (source) => {
const res = [] const res = []
// 第二种方式 // 第二种方式
source.length && source.length &&
source.forEach(item => { source.forEach((item) => {
res.push(item) res.push(item)
item.children && res.push(...treeDataToArray(item.children)) item.children && res.push(...treeDataToArray(item.children))
}) })
...@@ -306,7 +306,7 @@ export const getStyleValue = (elem, styleKey) => { ...@@ -306,7 +306,7 @@ export const getStyleValue = (elem, styleKey) => {
} }
// 根据id 查找树中的节点内容 // 根据id 查找树中的节点内容
export const findFirstNotHasChildren = tree => { export const findFirstNotHasChildren = (tree) => {
if (tree.length > 0) { if (tree.length > 0) {
if (tree[0].children && tree[0].children.length > 0) { if (tree[0].children && tree[0].children.length > 0) {
return findFirstNotHasChildren(tree[0].children) return findFirstNotHasChildren(tree[0].children)
...@@ -321,7 +321,7 @@ export const findParentLevelOne = (data, key = 'id', value) => { ...@@ -321,7 +321,7 @@ export const findParentLevelOne = (data, key = 'id', value) => {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
const item = data[i] const item = data[i]
if (item.children) { if (item.children) {
const child = item.children.find(c => c[key] === value) const child = item.children.find((c) => c[key] === value)
if (child) { if (child) {
// 找到目标子元素,返回其父元素 // 找到目标子元素,返回其父元素
return item return item
...@@ -340,11 +340,11 @@ export const findParentLevelOne = (data, key = 'id', value) => { ...@@ -340,11 +340,11 @@ export const findParentLevelOne = (data, key = 'id', value) => {
// 找所在位置 // 找所在位置
export const findTreeToIndex = (data, key, value) => { export const findTreeToIndex = (data, key, value) => {
let index = data.findIndex(item => item[key] === value) let index = data.findIndex((item) => item[key] === value)
return index > -1 ? index : -1 return index > -1 ? index : -1
} }
export const hexToRgb = hex => { export const hexToRgb = (hex) => {
// 移除前缀#符号 // 移除前缀#符号
let hexTemp = hex.replace(/^\s*#|\s*$/g, '') let hexTemp = hex.replace(/^\s*#|\s*$/g, '')
...@@ -361,7 +361,7 @@ export const hexToRgb = hex => { ...@@ -361,7 +361,7 @@ export const hexToRgb = hex => {
? { ? {
r: parseInt(rgb[1], 16), r: parseInt(rgb[1], 16),
g: parseInt(rgb[2], 16), g: parseInt(rgb[2], 16),
b: parseInt(rgb[3], 16) b: parseInt(rgb[3], 16),
} }
: null : null
} }
...@@ -420,8 +420,8 @@ export const clacTopicText = (type, radio, checkbox, judge, fill, textarea) => { ...@@ -420,8 +420,8 @@ export const clacTopicText = (type, radio, checkbox, judge, fill, textarea) => {
} }
export const downloadFile = (res = '') => { export const downloadFile = (res = '') => {
window.open(import.meta.env.VITE_API_URL_WORD + '/' + res) window.open(import.meta.env.VITE_API_URL + '/' + res)
} }
// 延时函数 // 延时函数
export const sleep = time => new Promise(resolve => setTimeout(resolve, time)) export const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time))
...@@ -18,8 +18,8 @@ let pending = [] // 存储每个ajax请求的取消函数和ajax标识 ...@@ -18,8 +18,8 @@ let pending = [] // 存储每个ajax请求的取消函数和ajax标识
let CancelToken = Axios.CancelToken let CancelToken = Axios.CancelToken
// 取消请求 方法 // 取消请求 方法
// 取消请求 方法 // 取消请求 方法
let cancelPending = config => { let cancelPending = (config) => {
pending.forEach(item => { pending.forEach((item) => {
item.cancel() // 取消请求 item.cancel() // 取消请求
}) })
pending = [] // 清空数组 pending = [] // 清空数组
...@@ -28,8 +28,8 @@ let cancelPending = config => { ...@@ -28,8 +28,8 @@ let cancelPending = config => {
// Axios.defaults.withCredentials = true; // 默认为false 表示跨域请求时是否需要使用凭证 // Axios.defaults.withCredentials = true; // 默认为false 表示跨域请求时是否需要使用凭证
const axios = Axios.create({ const axios = Axios.create({
baseURL: import.meta.env.VITE_API_BASE_API_PREFFIX, baseURL: import.meta.env.VITE_API_PREFIX,
timeout: 999999 timeout: 999999,
}) })
function getToken() { function getToken() {
...@@ -37,7 +37,7 @@ function getToken() { ...@@ -37,7 +37,7 @@ function getToken() {
} }
// 请求拦截器 // 请求拦截器
axios.interceptors.request.use( axios.interceptors.request.use(
config => { (config) => {
// 登录流程控制中,根据本地是否存在token判断用户的登录情况 // 登录流程控制中,根据本地是否存在token判断用户的登录情况
// 但是即使token存在,也有可能token是过期的,所以在每次的请求头中携带token // 但是即使token存在,也有可能token是过期的,所以在每次的请求头中携带token
// 后台根据携带的token判断用户的登录情况,并返回给我们对应的状态码 // 后台根据携带的token判断用户的登录情况,并返回给我们对应的状态码
...@@ -68,7 +68,7 @@ axios.interceptors.request.use( ...@@ -68,7 +68,7 @@ axios.interceptors.request.use(
if (config.url.indexOf('.tiangong.cn') > -1) { if (config.url.indexOf('.tiangong.cn') > -1) {
s = config.url s = config.url
} else { } else {
s = import.meta.env.VITE_API_URL_WORD + config.url s = import.meta.env.VITE_API_URL + config.url
s = s.replace('/api', '') s = s.replace('/api', '')
} }
signData.url = decodeURIComponent(s) signData.url = decodeURIComponent(s)
...@@ -105,7 +105,7 @@ axios.interceptors.request.use( ...@@ -105,7 +105,7 @@ axios.interceptors.request.use(
} */ } */
// 在请求拦截器中,为每个请求创建一个取消令牌,并将其添加到pending数组 // 在请求拦截器中,为每个请求创建一个取消令牌,并将其添加到pending数组
config.cancelToken = new CancelToken(cancel => { config.cancelToken = new CancelToken((cancel) => {
pending.push({ url: config.url, cancel }) pending.push({ url: config.url, cancel })
}) })
...@@ -116,7 +116,7 @@ axios.interceptors.request.use( ...@@ -116,7 +116,7 @@ axios.interceptors.request.use(
return config return config
}, },
error => { (error) => {
Promise.reject(error) Promise.reject(error)
} }
) )
...@@ -139,7 +139,7 @@ axios.interceptors.response.use( ...@@ -139,7 +139,7 @@ axios.interceptors.response.use(
onOk() { onOk() {
localStorage.removeItem('kiwi.gpt.token') localStorage.removeItem('kiwi.gpt.token')
window.location.pathname = '/login' window.location.pathname = '/login'
} },
}) })
cancelPending(response.config) // 取消后续请求 cancelPending(response.config) // 取消后续请求
return Promise.reject(response) return Promise.reject(response)
...@@ -147,7 +147,7 @@ axios.interceptors.response.use( ...@@ -147,7 +147,7 @@ axios.interceptors.response.use(
} }
return response return response
}, },
error => { (error) => {
const { response = {}, config = {} } = error const { response = {}, config = {} } = error
console.error('我要的response', response, error) console.error('我要的response', response, error)
const status = get(response, 'status', 0) const status = get(response, 'status', 0)
...@@ -164,7 +164,7 @@ axios.interceptors.response.use( ...@@ -164,7 +164,7 @@ axios.interceptors.response.use(
onOk() { onOk() {
localStorage.removeItem('kiwi.gpt.token') localStorage.removeItem('kiwi.gpt.token')
window.location.href = '/login' window.location.href = '/login'
} },
}) })
} }
break break
...@@ -179,27 +179,27 @@ axios.interceptors.response.use( ...@@ -179,27 +179,27 @@ axios.interceptors.response.use(
onOk() { onOk() {
localStorage.removeItem('kiwi.gpt.token') localStorage.removeItem('kiwi.gpt.token')
window.location.href = '/login' window.location.href = '/login'
} },
}) })
} }
break break
case 404: case 404:
notification.error({ notification.error({
message: 'Error: 404 Not Found', message: 'Error: 404 Not Found',
description: `url: ${urlPath}, The requested URL was not found on the server.` description: `url: ${urlPath}, The requested URL was not found on the server.`,
}) })
break break
case 500: case 500:
notification.error({ notification.error({
message: 'Error: 500', message: 'Error: 500',
description: `url: ${urlPath}` description: `url: ${urlPath}`,
}) })
break break
default: default:
if (status) { if (status) {
notification.error({ notification.error({
message: `Error: ${status}`, message: `Error: ${status}`,
description: `url: ${urlPath}` description: `url: ${urlPath}`,
}) })
} }
} }
......
import axios from './request'; import axios from './request'
import { get } from 'lodash-es'; import { get } from 'lodash-es'
import { message } from 'antd'; import { message } from 'antd'
// 统一上传 // 统一上传
const uploadFiles = async (obj) => { export const uploadFiles = async (obj) => {
try { try {
const res = await axios.post('/common/OssUpload/uploadFiles', obj, { const res = await axios.post('/common/OssUpload/uploadFiles', obj, {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
}, },
}); })
const code = get(res, 'data.code', 0); const code = get(res, 'data.code', 0)
const data = get(res, 'data.data', []); const data = get(res, 'data.data', [])
const msg = get(res, 'data.message', '数据获取失败!'); const msg = get(res, 'data.message', '数据获取失败!')
if (code === 200) { if (code === 200) {
message.success(msg); message.success(msg)
return data; return data
} else { } else {
message.error(msg); message.error(msg)
return false; return false
} }
} catch (error) { } catch (error) {
return false; return false
} }
}; }
export { uploadFiles };
import axios from 'axios'
import md5 from 'js-md5'
import { fetchEventSource } from '@fortaine/fetch-event-source'
export const PartnerID = '8980934e767f5acfa1c7cd92'
export const PartnerKey = 'N64IJm!e#iAWsac'
export const generateHeaders = () => {
const TS = Date.now()
return {
'Content-Type': 'application/json',
PartnerID,
TS,
Version: '1.0.1',
Authorization: md5(`${PartnerID}+${PartnerKey}+${TS}`),
}
}
const httpRequest = axios.create({
withCredentials: true,
})
// 请求拦截器
httpRequest.interceptors.request.use((config) => {
config.headers = { ...config.headers, ...generateHeaders() }
return config
})
export default httpRequest
export async function fetchEventSourceFn(url, options) {
const messages = []
const defaultOptions = {
method: 'POST',
headers: generateHeaders(),
onmessage(res) {
const message = JSON.parse(res.data)
messages.push(message)
},
}
return await fetchEventSource(url, { ...defaultOptions, ...options }).then(() => messages)
}
...@@ -14,28 +14,28 @@ export default defineConfig(({ mode }) => { ...@@ -14,28 +14,28 @@ export default defineConfig(({ mode }) => {
host: 'dev.ezijing.com', host: 'dev.ezijing.com',
proxy: { proxy: {
'/api': { '/api': {
target: env.VITE_API_URL_WORD, target: env.VITE_API_URL,
changeOrigin: true, changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '') // 将请求路径中的“/api”前缀替换为空字符串 rewrite: (path) => path.replace(/^\/api/, ''), // 将请求路径中的“/api”前缀替换为空字符串
}, },
'/openapi': { '/api/wenku': {
target: env.VITE_API_OPENAI_URL, target: 'https://wenchain.baidu.com',
changeOrigin: true, changeOrigin: true,
rewrite: path => path.replace(/^\/openapi/, '/openapi') // 将请求路径中的“/api”前缀替换为空字符串 rewrite: (path) => path.replace(/^\/api\/wenku/, '/'), // 将请求路径中的“/api”前缀替换为空字符串
} },
} },
}, },
resolve: { resolve: {
alias: { alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)) '@': fileURLToPath(new URL('./src', import.meta.url)),
} },
}, },
css: { css: {
preprocessorOptions: { preprocessorOptions: {
less: { less: {
javascriptEnabled: true javascriptEnabled: true,
} },
} },
} },
} }
}) })
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论