Переглянути джерело

竖排双按钮弹框样式,云调用方法封装

una 4 роки тому
батько
коміт
ba265dc277

+ 1 - 1
client/app.js

@@ -14,6 +14,6 @@ App({
     // options.query == {number:1}
   },
   globalData:{
-    
+    userInfo:{},
   }
 });

+ 2 - 1
client/app.json

@@ -4,7 +4,8 @@
     "pages/servant/myCustomerList/myCustomerList",
     "pages/customer/myServantList/myServantList",
     "pages/servant/servantCenter/servantCenter",
-    "pages/customer/createServant/createServant"
+    "pages/customer/createServant/createServant",
+    "pages/customer/customerCenter/customerCenter"
   ],
   "window": {
     "defaultTitle": "保姆管家"

+ 47 - 12
client/pages/common/index/index.js

@@ -1,13 +1,26 @@
 import request from '../../../util/http'
+import apiUrl from '../../../util/apiUrl'
 import util from '../../../util/util'
 import moment from 'moment'
-
+var app = getApp();
 Page({
   onLoad(query) {
     // 页面加载
     console.log('onLoad');
     console.info(`Page onLoad with query: ${JSON.stringify(query)}`);
-    this.authInit();
+    let storageRes = my.getStorageSync({ key: 'userInfo' });
+    console.log(storageRes);
+    //  this.authInit();
+    if(storageRes.data==null){
+      // 没有用户信息获取授权
+       this.authInit();
+    }else{
+     let id= storageRes.data.id;
+      // 有用户信息更新用户信息
+      let params={'id':id};
+      this.getUserInfo(params);
+    }
+      
   },
   onReady() {
     // 页面加载完成
@@ -39,26 +52,48 @@ Page({
     };
   },
   // 授权登录
-  authInit(){
+   authInit(){
  my.authorize({
   scopes: 'scope.userInfo',
   success: (res) => {
     my.getAuthUserInfo({
-      success: (userInfo) => {
+      success:  (userInfo) => {
         console.log(userInfo);
-        my.alert({
-      content: userInfo.nickName
-    });
-        request.httpService();
+      //  let  data= await request.httpServicePost(apiUrl.registerUserPath);
+        request.httpServicePost(apiUrl.registerUserPath).then(data=>{
+        console.log(data);
+        let userInfo=data;
+        //  授权注册成功后将用户信息存到本地存储和globalData
+        my.setStorageSync({
+          key: 'userInfo',
+         data: userInfo
+           });
+        })
+        app.globalData.userInfo = userInfo;
+         
       }
     });
   },
 });
   },
-  requestPost(){
-   
-  
-  
+
+  // 获取用户信息
+       getUserInfo(params){
+      request.httpServiceGet(apiUrl.getUserInfoPath,params).then(data=>{
+        console.log(data);
+        //  授权用户信息后将用户信息存到本地存储和globalData
+        // if(data!=undefined){
+           app.globalData.userInfo=data;
+       my.setStorageSync({
+         key:"userInfo",
+         data:data
+       });
+        // }
+      
+        })
+
+      // let  res=await request.httpServiceGet(apiUrl.getUserInfoPath,params);
+      // console.log(res);
   }
 
 });

+ 0 - 0
client/pages/customer/customerCenter/customerCenter.acss


+ 3 - 0
client/pages/customer/customerCenter/customerCenter.axml

@@ -0,0 +1,3 @@
+<view>
+  New Page
+</view>

+ 4 - 0
client/pages/customer/customerCenter/customerCenter.js

@@ -0,0 +1,4 @@
+Page({
+  data: {},
+  onLoad() {},
+});

+ 3 - 0
client/pages/customer/customerCenter/customerCenter.json

@@ -0,0 +1,3 @@
+{
+   "defaultTitle": "保姆工作站"
+}

+ 15 - 0
client/util/apiUrl.js

@@ -0,0 +1,15 @@
+let baseService='/servantappletservice';
+// 授权后注册
+const registerUserPath=baseService+'/auth/registerUser';
+// 获取用户信息/user/getUserInfo
+const getUserInfoPath=baseService+'/user/getUserInfo';
+
+// POST /auth/chooseIdentity 身份选择
+const chooseIdentityPath=baseService+'/auth/chooseIdentity'
+
+
+export default{
+registerUserPath,
+getUserInfoPath,
+chooseIdentityPath
+}

+ 74 - 9
client/util/http.js

@@ -1,27 +1,92 @@
-const httpService= async ()=>{
+// get请求
+const httpServiceGet= async (path,params)=>{
+  const {cloud} = getApp();
+  try {
+    console.log('request begin'); 
+  const result = await  cloud.application.httpRequest({
+ //不需要完整域名,只需要接口访问路径即可
+  // 'path' : '/servantappletservice/auth/registerUser', 
+    'path' : path, 
+  'method':'GET',
+  'headers':{ },
+  'params':params,
+  'body':{  },
+ //对于一个小程序关联多个云应用的场景,调用非默认云应用,需要指定对应的云应用Id,超时时间单位ms
+  'exts':{  "cloudAppId":"21907" ,"timeout":60000}  });
+   console.log('response');
+  console.log(result);
+//      my.alert({
+//   content: JSON.stringify(result) 
+//  }); 
+
+if(result.errno=='0'){
+  return result.data;
+}
+
+//  return new Promise((resolve,reject) => {
+//    if(result.errno=='0'){
+//         resolve(result.data);
+//    }else{
+//       my.alert({
+//     content: result.errmsg 
+//  });  
+//     reject('error')
+//    }
+       
+      // })
+    
+  } catch(e) {
+    console.log(e);
+  my.alert({
+    
+  // content: 'error'+e.message 
+    content: e.msg 
+ });  
+ } 
+} 
+// post请求
+const httpServicePost= async (path,params)=>{
   const {cloud} = getApp();
   try {
     console.log('request begin');
   const result = await cloud.application.httpRequest({
  //不需要完整域名,只需要接口访问路径即可
-  'path' : '/servantappletservice/getKey', 
-  'method':'GET',
-  'headers':{  "mc-dd":"test",  },
-  'params':{"key":1},
-  'body':{  "xftest":"hhh",  "id":"1234",  },
+  // 'path' : '/servantappletservice/auth/registerUser', 
+    'path' : path, 
+  'method':'POST',
+  'headers':{ 'Content-type': 'application/json' },
+  'params':{},
+  'body':params,
  //对于一个小程序关联多个云应用的场景,调用非默认云应用,需要指定对应的云应用Id,超时时间单位ms
   'exts':{  "cloudAppId":"21907" ,"timeout":60000}  });
+   console.log(result);
    console.log('response');
-  console.log(JSON.stringify(result));
+  // console.log(JSON.stringify(result));
      my.alert({
   content: JSON.stringify(result) 
  }); 
+ console.log(result);
+if(result.errno=='0'){
+  return result.data;
+}
+//   return new Promise((resolve) => {
+//         if(result.errno=='0'){
+//         resolve(result.data);
+//    }else{
+//       my.alert({
+//     content: result.errmsg 
+//  });  
+//    }
+//       })
   } catch(e) {
+    console.log(e);
   my.alert({
-  content: 'error'+e.message 
+     content: 'false'+JSON.stringify(e) 
+  // content: 'error'+e.msg 
  });  
  } 
 } 
 export default{
-  httpService
+  httpServiceGet,
+  httpServicePost
 }