Skip to content
Snippets Groups Projects
Commit f9a5eaf9 authored by yz's avatar yz
Browse files

feat: webConnect

parent ac06cd9d
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,8 @@ export default class webAPI { ...@@ -17,6 +17,8 @@ export default class webAPI {
static token = '' static token = ''
static userId = -1 static userId = -1
static userName = '' static userName = ''
static ipAddr = '${webAPI.ipAddr}' //previewer
// static ipAddr = '10.0.2.2' //实机
static async getCurrentUser(): Promise<string> { static async getCurrentUser(): Promise<string> {
/* /*
...@@ -32,7 +34,7 @@ export default class webAPI { ...@@ -32,7 +34,7 @@ export default class webAPI {
let httpRequest = http.createHttp() let httpRequest = http.createHttp()
let result = 'error' // 默认返回 error let result = 'error' // 默认返回 error
try { try {
const data = await httpRequest.request('localhost:8080/api/users/userInfo', { const data = await httpRequest.request(`${webAPI.ipAddr}:8080/api/users/userInfo`, {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
header: { header: {
'token': webAPI.token 'token': webAPI.token
...@@ -65,7 +67,7 @@ export default class webAPI { ...@@ -65,7 +67,7 @@ export default class webAPI {
let httpRequest = http.createHttp() let httpRequest = http.createHttp()
let result = '' // 初始值为空字符串 let result = '' // 初始值为空字符串
try { try {
const data = await httpRequest.request(`localhost:8080/api/users/login?phone=${phone}&password=${psw}`, { const data = await httpRequest.request(`${webAPI.ipAddr}:8080/api/users/login?phone=${phone}&password=${psw}`, {
method: http.RequestMethod.POST, method: http.RequestMethod.POST,
}); });
if (data.responseCode === 200) { if (data.responseCode === 200) {
...@@ -98,7 +100,7 @@ export default class webAPI { ...@@ -98,7 +100,7 @@ export default class webAPI {
let httpRequest = http.createHttp() let httpRequest = http.createHttp()
let result = 'error' // 默认返回 error let result = 'error' // 默认返回 error
try { try {
const data = await httpRequest.request('localhost:8080/api/users/register', { const data = await httpRequest.request(`${webAPI.ipAddr}:8080/api/users/register`, {
method: http.RequestMethod.POST, method: http.RequestMethod.POST,
header: { header: {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
...@@ -136,7 +138,7 @@ export default class webAPI { ...@@ -136,7 +138,7 @@ export default class webAPI {
} }
let httpRequest = http.createHttp() let httpRequest = http.createHttp()
try { try {
const data = await httpRequest.request(`localhost:8080/api/todolist/${webAPI.userId}`, { const data = await httpRequest.request(`${webAPI.ipAddr}:8080/api/todolist/${webAPI.userId}`, {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
header: { header: {
'token': webAPI.token 'token': webAPI.token
...@@ -173,7 +175,7 @@ export default class webAPI { ...@@ -173,7 +175,7 @@ export default class webAPI {
let httpRequest = http.createHttp() let httpRequest = http.createHttp()
let result = 'error' // 默认返回 error let result = 'error' // 默认返回 error
try { try {
const data = await httpRequest.request('localhost:8080/api/todolist/add', { const data = await httpRequest.request(`${webAPI.ipAddr}:8080/api/todolist/add`, {
method: http.RequestMethod.POST, method: http.RequestMethod.POST,
header: { header: {
'token': webAPI.token 'token': webAPI.token
...@@ -211,7 +213,7 @@ export default class webAPI { ...@@ -211,7 +213,7 @@ export default class webAPI {
} }
let httpRequest = http.createHttp() let httpRequest = http.createHttp()
try { try {
const data = await httpRequest.request(`localhost:8080/api/todolist/${webAPI.userId}/count`, { const data = await httpRequest.request(`${webAPI.ipAddr}:8080/api/todolist/${webAPI.userId}/count`, {
method: http.RequestMethod.GET, method: http.RequestMethod.GET,
header: { header: {
'token': webAPI.token 'token': webAPI.token
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment