Bladeren bron

登录修改

hh 1 jaar geleden
bovenliggende
commit
5ccd96a9fe
2 gewijzigde bestanden met toevoegingen van 15 en 14 verwijderingen
  1. 12 0
      entry/src/main/ets/common/util/request/RequestInstance.ets
  2. 3 14
      entry/src/main/ets/pages/LoginPage.ets

+ 12 - 0
entry/src/main/ets/common/util/request/RequestInstance.ets

@@ -0,0 +1,12 @@
+import JGRequest from './Request'
+
+const getToken = async (): Promise<string> => {
+  return await JGRequest.post("/api/auth/aioLogin", {
+    "userName": this.loginName,
+    "password": this.password,
+    "orgId": this.dept ? this.dept.id : 0,
+    "stationId": this.workstation ? this.workstation.id : 0,
+  })
+}
+
+export{getToken}

+ 3 - 14
entry/src/main/ets/pages/LoginPage.ets

@@ -1,5 +1,6 @@
 import router from '@ohos.router'
 import JGRequest from '../common/util/request/Request'
+import {getToken} from '../common/util/request/RequestInstance'
 
 @Entry
 @Component
@@ -11,17 +12,6 @@ struct LoginPage {
   @State dept: DeptInfo = null
   @State workstation: WorkstationInfo = null
 
-  token: string
-
-  async getToken(): Promise<string> {
-    return await JGRequest.post("/api/auth/aioLogin", {
-      "userName": this.loginName,
-      "password": this.password,
-      "orgId": this.dept ? this.dept.id : 0,
-      "stationId": this.workstation ? this.workstation.id : 0,
-    })
-  }
-
   // 部门选择弹框
   selectDeptController: CustomDialogController = new CustomDialogController({
     builder: SelectDeptDialog({
@@ -180,9 +170,8 @@ struct LoginPage {
         }
         .onClick(()=>{
           if (this.loginName && this.loginName.length > 0 && this.password && this.password.length > 0) {
-            this.getToken().then(token =>{
-              this.token = token
-              if (this.token && this.token.length > 0) {
+            getToken().then(token =>{
+              if (token && token.length > 0) {
                 router.pushUrl({
                   url:'pages/Index'
                 })