超管后台 - 将所有http请求硬编码改为环境变量配置
This commit is contained in:
@@ -32,7 +32,7 @@ export default function DashboardPage() {
|
|||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
try {
|
try {
|
||||||
// 获取统计信息
|
// 获取统计信息
|
||||||
const response = await fetch("http://yishi.com/dashboard/base")
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/dashboard/base`)
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
setStats(data.data)
|
setStats(data.data)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ export default function EditProjectPage({ params }: { params: { id: string } })
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchProjectDetail = async () => {
|
const fetchProjectDetail = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`http://yishi.com/company/detail/${id}`)
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/detail/${id}`)
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
@@ -71,7 +71,7 @@ export default function EditProjectPage({ params }: { params: { id: string } })
|
|||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`http://yishi.com/company/update`, {
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/update`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -45,7 +45,6 @@ export default function NewProjectPage() {
|
|||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
// 表单验证
|
|
||||||
if (formData.password !== formData.confirmPassword) {
|
if (formData.password !== formData.confirmPassword) {
|
||||||
toast.error("两次输入的密码不一致")
|
toast.error("两次输入的密码不一致")
|
||||||
return
|
return
|
||||||
@@ -54,7 +53,7 @@ export default function NewProjectPage() {
|
|||||||
setIsSubmitting(true)
|
setIsSubmitting(true)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://yishi.com/company/create", {
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/add`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -63,10 +62,10 @@ export default function NewProjectPage() {
|
|||||||
name: formData.name,
|
name: formData.name,
|
||||||
account: formData.account,
|
account: formData.account,
|
||||||
password: formData.password,
|
password: formData.password,
|
||||||
|
memo: formData.description,
|
||||||
phone: formData.phone,
|
phone: formData.phone,
|
||||||
username: formData.nickname,
|
username: formData.nickname,
|
||||||
description: formData.description,
|
status: parseInt(formData.status),
|
||||||
status: formData.status
|
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ export default function ProjectsPage() {
|
|||||||
const fetchProjects = async () => {
|
const fetchProjects = async () => {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`http://yishi.com/company/list?page=${currentPage}&limit=${pageSize}`)
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/list?page=${currentPage}&limit=${pageSize}`)
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
|
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
@@ -90,7 +90,7 @@ export default function ProjectsPage() {
|
|||||||
|
|
||||||
setIsDeleting(true)
|
setIsDeleting(true)
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://yishi.com/company/delete", {
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/delete`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -108,7 +108,7 @@ export default function ProjectsPage() {
|
|||||||
const fetchProjects = async () => {
|
const fetchProjects = async () => {
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`http://yishi.com/company/list?page=${currentPage}&limit=${pageSize}`)
|
const response = await fetch(`${process.env.NEXT_PUBLIC_API_BASE_URL}/company/list?page=${currentPage}&limit=${pageSize}`)
|
||||||
const data = await response.json()
|
const data = await response.json()
|
||||||
if (data.code === 200) {
|
if (data.code === 200) {
|
||||||
setProjects(data.data.list)
|
setProjects(data.data.list)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
export function getConfig() {
|
export function getConfig() {
|
||||||
// 优先获取环境变量中配置的API地址
|
// 优先获取环境变量中配置的API地址
|
||||||
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL || 'http://yishi.com';
|
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
apiBaseUrl
|
apiBaseUrl
|
||||||
|
|||||||
Reference in New Issue
Block a user