Browse Source

自动登录

zhangshuling 4 years ago
parent
commit
305919986d
5 changed files with 323 additions and 20 deletions
  1. 78 0
      pages/index/index.js
  2. 37 15
      pages/login/login.js
  3. 1 1
      project.config.json
  4. 163 0
      utils/urls.js
  5. 44 4
      utils/util.js

+ 78 - 0
pages/index/index.js

@@ -0,0 +1,78 @@
+// pages/login/login.js
+const app = getApp()
+const util = require("../../utils/util")
+const urls = require("../../utils/urls")
+Page({
+
+    /**
+     * 页面的初始数据
+     */
+    data: {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面加载
+     */
+    onLoad: function (options) {
+
+        util.apiPost(urls.urls.get_cur_user,{}).then(rs => {
+            console.log(JSON.stringify(rs));
+        });
+
+
+        // util.apiPost(urls.urls.get_holidays, { 'q.companyId': loginUser.attr.orgId }).then(rs => {
+        //     console.log(JSON.stringify(rs));
+        // });
+    },
+    /**
+     * 生命周期函数--监听页面初次渲染完成
+     */
+    onReady: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面隐藏
+     */
+    onHide: function () {
+
+    },
+
+    /**
+     * 生命周期函数--监听页面卸载
+     */
+    onUnload: function () {
+
+    },
+
+
+
+    /**
+     * 页面相关事件处理函数--监听用户下拉动作
+     */
+    onPullDownRefresh: function () {
+
+    },
+
+    /**
+     * 页面上拉触底事件的处理函数
+     */
+    onReachBottom: function () {
+
+    },
+
+    /**
+     * 用户点击右上角分享
+     */
+    onShareAppMessage: function () {
+
+    }
+})

+ 37 - 15
pages/login/login.js

@@ -21,21 +21,21 @@ Page({
     this.getOpenId()
   },
 
-   // 登录
+  // 登录
   getOpenId: function () {
     wx.login({
       success: res => {
         util.doPost(
           'getOpenId', {
-            appId: app.globalData.appId,
-            code: res.code
-          },
+          appId: app.globalData.appId,
+          code: res.code
+        },
         ).then(res => {
           if (res.success == 1) {
             wx.setStorageSync('openId', res.data.openId)
             wx.hideLoading({
             })
-          } 
+          }
         })
       },
       fail: res => {
@@ -62,16 +62,14 @@ Page({
       })
       util.doPost(
         'getPhoneNumber', {
-          encryptedData: e.detail.encryptedData,
-          iv: e.detail.iv,
-          openId: wx.getStorageSync('openId'),
-        }
+        encryptedData: e.detail.encryptedData,
+        iv: e.detail.iv,
+        openId: wx.getStorageSync('openId'),
+      }
       ).then(rs => {
         if (rs.success > 0) {
-          wx.setStorageSync('phone', rs.data.phoneNumber)
-          wx.showToast({
-            title: '登录成功',
-          })
+          wx.setStorageSync('phone', rs.data.phoneNumber);
+          this.autoLogin();
         } else {
           wx.showToast({
             title: '手机号验证失败',
@@ -85,6 +83,30 @@ Page({
     })
   },
 
+  autoLogin: function () {
+    util.doPost(
+      'autoLogin', {
+      openId: wx.getStorageSync('openId'),
+    }
+    ).then(rs => {
+      if (rs.success > 0) {
+        wx.setStorageSync('sso-token', rs.data.token);
+        wx.showToast({
+          title: '登录成功',
+        })
+        wx.switchTab({
+          url: '/pages/index/index'
+        })
+      } else {
+        wx.showToast({
+          title: rs.errMsg
+        })
+      }
+      wx.hideLoading({ })
+    })
+
+  },
+
 
   /**
    * 生命周期函数--监听页面初次渲染完成
@@ -111,10 +133,10 @@ Page({
    * 生命周期函数--监听页面卸载
    */
   onUnload: function () {
-    
+
   },
 
- 
+
 
   /**
    * 页面相关事件处理函数--监听用户下拉动作

+ 1 - 1
project.config.json

@@ -21,7 +21,7 @@
     "checkSiteMap": true,
     "uploadWithSourceMap": true,
     "compileHotReLoad": false,
-    "useMultiFrameRuntime": true,
+    "useMultiFrameRuntime": false,
     "useApiHook": true,
     "babelSetting": {
       "ignore": [],

+ 163 - 0
utils/urls.js

@@ -0,0 +1,163 @@
+const baseUrl = 'https://demo.schoolwisdoms.com';
+// const baseUrl = 'https://app.schoolwisdoms.com';
+
+const ssoBase = baseUrl + '/sso';
+const platformBase = baseUrl + '/admin';
+const schoolBase = baseUrl + '/schoolbaby';
+const h5Base = baseUrl + '/h5';
+const crudListBase = schoolBase + '/crud/list';
+const crudSaveBase = schoolBase + '/crud/save';
+const crud_save_all = schoolBase + '/crud/save-all';
+const crudGetBase = schoolBase + '/crud/get-one';
+const platformListBase = platformBase + '/crud/list';
+
+export const urls = {
+  baseUrl: baseUrl,
+  h5Url: baseUrl + '/h5/',
+  login: ssoBase + '/login',
+  logout: ssoBase + '/logout',
+
+  get_cur_user: platformBase + '/user/current',
+  change_user: platformBase + '/user/change',
+  get_resource: platformBase + '/permissions/student',
+  get_advert: crudListBase + '?statement=AdvertMapper.list',
+  get_leave_count: crudGetBase + '?statement=StudentLeaveMapper.getLeaveCount',
+  day_report: crudSaveBase + '/dayReport',
+  day_report_get: crudGetBase + '?statement=DayReportMapper.list',
+  message_list: crudListBase + '?statement=NoticeMapper.queryListByOrg',
+  message_detail: crudListBase + '?statement=NoticeMapper.list',
+  user_sign: crudSaveBase + '/userSign',
+  user_sign_get: crudGetBase + '?statement=UserSignMapper.list',
+  leave_get_classes_date: crudListBase + '?statement=StudentClassesMapper.getClassesDate',
+  leave_get_classes_info: crudListBase + '?statement=StudentClassesMapper.getLeaveClassesInfo',
+  leave_save: crudSaveBase + '/studentLeave',
+  leave_detail_save: crudSaveBase + '/studentLeaveDetail',
+  update_password: platformBase + '/user/updatePasswd',
+  get_suggest_moudles: platformListBase + '?statement=DictDetailMapper.list&q.headId=1004',
+  suggest_save: crudSaveBase + '/userFeedBack',
+  suggest_image_save: crud_save_all + '/userFeedBackImage',
+  leave_history_list: crudListBase + '?statement=StudentLeaveMapper.list',
+  file_upload: schoolBase + '/file/upload',
+  teacher_list: crudListBase + '?statement=TeacherMapper.list',
+  get_user_head: platformListBase + '?statement=UserMapper.getHead',
+  update_user_head: platformBase + '/crud/execute?statement=UserMapper.updateHead',
+  file_load: schoolBase + '/api/file-load?key=',
+  oss_file: 'https://file.schoolwisdoms.com/',
+  evaluate_teacher_list: crudListBase + '?statement=EvaluateResultMapper.teacherList',
+  evaluate_teacher_history_list: crudListBase + '?statement=EvaluateResultMapper.teacherHistoryList',
+  evaluate_list: crudListBase + '?statement=EvaluateResultMapper.headList',
+  evaluate_item_list: crudListBase + '?statement=EvaluateResultMapper.itemListByHead',
+  evaluate_result_clear: crudListBase + '?statement=EvaluateResultMapper.clearResult',
+  evaluate_result_save: crud_save_all + '/evaluateResult',
+  get_week: crudListBase + '?statement=TeacherAttenceMapper.getWeekByDate',
+  get_schedule_week: crudListBase + '?statement=StudentAttenceMapper.getScheduleByWeek',
+  get_schedule_month: crudListBase + '?statement=StudentAttenceMapper.getScheduleByMonth',
+  get_transfer_target_list: crudListBase + '?statement=ClassesSwitchingMapper.courseList',
+  get_homework: crudListBase + '?statement=HomeworkStudentMapper.list',
+  my_homework: crudListBase + '?statement=HomeworkStudentMapper.queryByStudentId',
+  complete_homework: schoolBase + '/crud/execute?statement=HomeworkStudentMapper.doHomeWork',
+  file_delete: schoolBase + '/file/delete',
+  video_upload: schoolBase + '/video/upload',
+  video_upload_split: schoolBase + '/video/uploads',
+  video_delete: schoolBase + '/video/delete',
+  video_loadImg: schoolBase + '/video/load-image?videoId=',
+  video_loadInfo: schoolBase + '/video/load-info?videoId=',
+  video_play: schoolBase + '/nav/video-play?videoId=',
+  video_auth: schoolBase + '/video/playauth?videoId=',
+  video_create_upload: schoolBase + '/video/createUploadVideo',
+  video_refresh_upload: schoolBase + '/video/refreshUploadVideo?videoId=',
+  get_course_order: crudListBase + '?statement=StudentOrderMapper.getStudentOrder',
+  get_cooperate_corp_type: platformListBase + '?statement=DictDetailMapper.list&q.headId=1008',
+  cooperate_save: crudSaveBase + '/otherCooperate',
+  get_activity_list: crudListBase + '?statement=ActivityMapper.list',
+  get_activity_detail: crudListBase + '?statement=ActivitySignMapper.queryActivitySign',
+  activity_sign_save: crudSaveBase + '/activitySign',
+  activity_sign_delete: schoolBase + '/crud/execute?statement=ActivitySignMapper.deleteActivitySign',
+  get_course_report: crudListBase + '?statement=StudentAttenceMapper.getCourseReport',
+  get_course_money: crudListBase + '?statement=StudentAttenceMapper.getAttenceCount',
+  get_qr_code: schoolBase + '/api/code/generate',
+  get_activity_share: crudListBase + '?statement=ActivityShareMapper.list',
+  examine_score: crudListBase + '?statement=ExamineMapper.queryExamineScoreByStudentId',
+  get_growth_image: crudListBase + '?statement=GrowthRecordMapper.getImageByOrg',
+  get_switch_course_list: crudListBase + '?statement=TimetableMapper.listChangeCourse',
+  classes_switch_save: schoolBase + '/classesSwitching/save',
+  get_chat_contact_single: crudListBase + '?statement=ClassesJpushGroupMapper.queryStudentContact',
+  get_chat_contact_group: crudListBase + '?statement=ClassesJpushGroupMapper.queryStudentGroupContact',
+  get_classes: crudGetBase + '?statement=ClassesMapper.list',
+  attence_student_save: crudSaveBase + '/studentAttence',
+  get_im_auto_reply: crudListBase + '?statement=JpushAutoReplyMapper.list',
+  get_student_star: crudListBase + '?statement=StudentAttenceMapper.getStudentStar',
+  get_student_comment: crudListBase + '?statement=StudentAttenceMapper.getStudentComment',
+  get_student: crudGetBase + '?statement=StudentMapper.list',
+  get_student_payout: crudListBase + '?statement=StudentAttenceMapper.queryPayOutRecord',
+  get_student_date: crudListBase + '?statement=GrowthRecordMapper.getStudentDay',
+  query_join_day: crudListBase + '?statement=StudentAttenceMapper.queryJoinDay',
+  query_join_classes: crudListBase + '?statement=StudentAttenceMapper.queryJoinClasses',
+  query_join_classes_student: crudListBase + '?statement=StudentAttenceMapper.queryJoinClassesStudent',
+  query_attence_count: crudListBase + '?statement=StudentAttenceMapper.queryAttenceCount',
+  query_attence_time_length: crudListBase + '?statement=StudentAttenceMapper.queryAttenceTimeLength',
+  query_attence_data: crudListBase + '?statement=StudentAttenceMapper.queryAttenceData',
+  query_attence_evaluate_count: crudListBase + '?statement=StudentAttenceMapper.queryAttenceEvaluateCount',
+  query_attence_evaluate_max_score: crudListBase + '?statement=StudentAttenceMapper.queryAttenceEvaluateMaxScore',
+  query_class_notice: crudListBase + '?statement=NoticeMapper.queryClassNoticeByStudent',
+  my_coupon: crudListBase + '?statement=CouponDefMapper.queryCouponMoney',
+  student_leave: schoolBase + '/studentLeave/save',
+  student_leave_detail: crudListBase + '?statement=StudentLeaveMapper.queryByAttenceStudent',
+  student_makeup: schoolBase + '/classesSupplement/save',
+  makeup_list: crudListBase + '?statement=StudentLeaveMapper.makeupList',
+  makeup_detail: crudListBase + '?statement=StudentLeaveMapper.queryCourseInfoByStudAttence',
+  coupon_rule: crudListBase + '?statement=CouponRuleMapper.list',
+  get_invitation_coupon: crudListBase + '?statement=ActivityShareMapper.queryCoupon',
+  add_classes_list: crudListBase + '?statement=ClassesAddMapper.queryStudentClasses',
+  get_last_classes: crudGetBase + '?statement=ClassesAddMapper.getLastClasses',
+  add_classes: schoolBase + '/classesAdd/save',
+  notice_receive: schoolBase + '/crud/execute?statement=ClassesStudentNoticeMapper.receive',
+  homework_receive: schoolBase + '/crud/execute?statement=HomeworkStudentMapper.receive',
+  get_params: platformListBase + '?statement=ParamsMapper.paramsList',
+  get_attendance_rate: crudListBase + '?statement=ReportMapper.getStudentAttendanceRate',
+  get_last_comment: crudGetBase + '?statement=StudentAttenceMapper.getStudentComment',
+  get_invitation_count: crudGetBase + '?statement=ClientMapper.selectCountByIntroducer',
+  get_invitation_enroll: crudGetBase + '?statement=ClientMapper.selectEnrollByIntroducer',
+  get_invitation_coin: crudListBase + '?statement=ClientMapper.selectCoinByIntroducer',
+  update_video_viewcount: schoolBase + '/crud/execute?statement=CourseVideoMapper.updateViewCount',
+  get_rand_video_list: crudListBase + '?statement=CourseVideoMapper.getRandVideoList',
+  get_video_list: crudListBase + '?statement=CourseVideoMapper.getVideoList',
+  get_holidays: crudListBase + '?statement=HolidayMapper.list',
+  get_teacherLeave: crudListBase + '?statement=TeacherLeaveMapper.list',
+  feedback_list: crudListBase + '?statement=FeedBackMapper.list',
+  feedback_get: crudGetBase + '?statement=FeedBackMapper.list',
+  feedback_image: crudListBase + '?statement=FeedBackMapper.getImageUrlById',
+  query_student_evaluate: crudListBase + '?statement=ReportMapper.queryStudentEvaluate',
+  query_student_star: crudListBase + '?statement=ReportMapper.queryStudentStar',
+  coupon_receive_list: crudListBase + '?statement=CouponDefMapper.queryCouponReceive',
+  coupon_receive: schoolBase + '/coupon/receive',
+  video_save: crudSaveBase + '/video',
+  person_video_save: crudSaveBase + '/personVideo',
+  person_video_view_save: crudSaveBase + '/personVideoView',
+  person_video_course: crudListBase + '?statement=PersonVideoMapper.studentCourse',
+  person_video_list: crudListBase + '?statement=PersonVideoMapper.list&q.status=1',
+  person_video_delete: schoolBase + '/crud/execute?statement=PersonVideoMapper.deleteByVideoId',
+  person_video_views_delete: schoolBase + '/crud/execute?statement=PersonVideoMapper.deleteViewsByVideoId',
+  get_order: crudListBase + '?statement=StudentOrderMapper.getOrderById',
+  get_thumbsup_count: crudGetBase + '?statement=PersonVideoMapper.thumbsUpCount',
+  get_sys_params: crudListBase + '?statement=ParamsMapper.list',
+  get_contract_images: crudListBase + '?statement=StudentOrderMapper.queryOrderContractImages',
+  get_attence_count: crudGetBase + '?statement=StudentAttenceMapper.studentAttenceCount',
+  query_video_creator: crudGetBase + '?statement=PersonVideoMapper.queryCreatorByVideoId',
+  query_invitation_list: crudListBase + '?statement=ClientMapper.queryInvitationList',
+  cooperate_send_message: schoolBase + '/jMessage/sendCooperateMessage',
+  homework_complete_send_message: schoolBase + '/jMessage/sendHomeworkCompleteMessage',
+  suggest_send_message: schoolBase + '/jMessage/sendFeedBackMessage',
+  get_bill_share_image: schoolBase + '/api/billShareImage',
+  get_bill_share_url: schoolBase + '/api/billShare',
+  checkAppVersion: schoolBase + '/api/checkAppVersion',
+  show_monitor: h5Base + '/api/monitor/get',
+  get_piano_card_list: crudListBase + '?statement=ExerciseSchemeMapper.list',
+  get_mp_list: crudListBase + '?statement=WxAppMapper.list',
+  get_near_school: schoolBase + '/student/schoolList',
+  collect_school: schoolBase + '/student/collectSchool',
+  query_school_attence: schoolBase + '/student/schoolAttence',
+  do_appointment: schoolBase + '/student/appointment',
+  do_appointment_check: schoolBase + '/student/checkCard',
+  query_appointment_list: crudListBase + '?statement=ExercisePlanMapper.queryReserve',
+};

+ 44 - 4
utils/util.js

@@ -5,14 +5,13 @@ const accessHeader = {
 };
 // const notWxApiPath = 'https://app.schoolwisdoms.com/schoolbaby/api/';
 // const apiPath = 'https://app.schoolwisdoms.com/schoolbaby/api/wx/';
+
 const notWxApiPath = 'https://demo.schoolwisdoms.com/schoolbaby/api/';
 const apiPath = 'https://demo.schoolwisdoms.com/schoolbaby/api/wx/';
 
 // const notWxApiPathDemo = 'http://192.168.2.104/schoolbaby/api/';
 // const apiPathDemo = 'http://192.168.2.104/schoolbaby/api/wx/';
 
-// const notWxApiPath = 'http://192.168.0.102/schoolbaby/api/'
-// const apiPath = 'http://192.168.0.102/schoolbaby/api/wx/'
 
 //经纬度算距离
 function distance(la1, lo1, la2, lo2) {
@@ -128,7 +127,8 @@ function getHeaders() {
   return {
     'Access-Ticket': ticket,
     'Access-Key': getAccessKey(ticket),
-    'Access-AppId': accessHeader.appId
+    'Access-AppId': accessHeader.appId,
+    'SSO-TOKEN': wx.getStorageSync('sso-token')
   }
 }
 
@@ -137,6 +137,45 @@ function setAccessHeader(accessKey, appId) {
   accessHeader.accessKey = accessKey;
 }
 
+function apiPost(url, params) {
+  return new Promise((resolve, reject) => {
+    let headers = getHeaders();
+    headers['Content-Type'] = 'application/x-www-form-urlencoded';
+    wx.request({
+      url: url,
+      header: headers,
+      data: params,
+      method: 'POST',
+      success: res => {
+        if (res.success > 1 || typeof res.version != undefined) {
+          resolve(res.data)
+        } else {
+          wx.hideLoading({
+            success: (res) => {
+              wx.showToast({
+                title: '加载失败,请重试',
+                icon: 'none'
+              })
+            },
+          })
+        }
+      },
+      faild: res => {
+        // reject(res)
+        wx.hideLoading({
+          success: (res) => {
+            wx.showToast({
+              title: res.errMsg,
+            })
+          },
+        })
+      }
+    })
+  }).catch(err => {
+    console.log(err)
+  })
+}
+
 function doPost(url, params) {
   return new Promise((resolve, reject) => {
     let headers = getHeaders();
@@ -305,5 +344,6 @@ module.exports = {
   validHour: validHour,
   curTime: curTime,
   setAccessHeader: setAccessHeader,
-  distance:distance
+  distance: distance,
+  apiPost: apiPost,
 }