common.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import http from '@/utils/http'
  2. // const appId = uni.getAccountInfoSync().miniProgram.appId
  3. export function loginByCode(data) {
  4. return new Promise((resolve, reject) => {
  5. uni.login({
  6. provider: 'weixin',
  7. success: function (res) {
  8. http.post('wxMini/login', {
  9. code: res.code,
  10. }, {
  11. isAuth: false,
  12. showLoading: false
  13. }).then(res => {
  14. resolve(res)
  15. }).catch(err => {
  16. reject(err)
  17. })
  18. }
  19. })
  20. })
  21. }
  22. export function login(data) {
  23. return http.post('user/login', data)
  24. }
  25. export function wxLogin(data) {
  26. return new Promise((resolve, reject) => {
  27. uni.login({
  28. provider: 'weixin',
  29. success: function (res) {
  30. http.post('wxMini/authLogin', {
  31. encryptedData: data.encryptedData,
  32. ivStr: data.iv,
  33. userInfo: JSON.stringify(data.userInfo),
  34. code: res.code,
  35. }, {
  36. isAuth: false,
  37. loadingTitle: '登录中...'
  38. }).then(res => {
  39. resolve(res)
  40. }).catch(err => {
  41. reject(err)
  42. })
  43. }
  44. })
  45. })
  46. }
  47. export function logout(data) {
  48. return http.post('user/logout', data)
  49. }
  50. export function miniAppLogin() {
  51. return new Promise((resolve, reject) => {
  52. // uni.login({
  53. // provider: 'weixin',
  54. // success: function (res) {
  55. // http.post('common/user/login',
  56. // { jsCode: res.code },
  57. // {
  58. // isAuth: false,
  59. // showLoading: true,
  60. // loadingTitle: '登录中...',
  61. // header: { 'content-type': 'application/json' },
  62. // }).then(res => {
  63. // resolve(res)
  64. // }).catch(err => {
  65. // reject(err)
  66. // })
  67. // },
  68. // fail: function (err) {}
  69. // })
  70. resolve({
  71. success: true,
  72. token: 'token',
  73. roles: [{ name: 'admin' }],
  74. openId: 'openId',
  75. user: { name: 'admin', mobile: '13700594535', photo: '', sex: 1 },
  76. })
  77. })
  78. }
  79. export function getSchoolInfo(schoolId) {
  80. return http.get(`schools/${schoolId}`, {}, { isAuth: false })
  81. }
  82. export function getSchoolGrades(schoolId) {
  83. return http.get(`schools/${schoolId}/grades`, {}, { isAuth: false })
  84. }
  85. export function getGradeClasses(schoolId, grade) {
  86. return http.get(`schools/${schoolId}/grades-with-classes`, { grade }, { isAuth: false })
  87. }
  88. export function addAdvice(data) {
  89. return http.post('user/advice', data)
  90. }
  91. // 意见反馈列表
  92. export function getAdviceList() {
  93. return http.get('user/advice/list')
  94. }
  95. // 版本信息
  96. export function getVersionList(data) {
  97. return http.get('user/version', data)
  98. }
  99. // 协议、隐私
  100. export function getPolicy() {
  101. return http.get('user/privacyPolicy')
  102. }
  103. export function getAgreement() {
  104. return http.get('user/userServiceAgreement')
  105. }
  106. export function addStudent(data) {
  107. return http.post('students', data, { isAuth: false })
  108. }
  109. export function getIncompleteVisionStudents(classId, params = {}) {
  110. return http.get(`classes/${classId}/incomplete-vision-students`, params, { isAuth: false })
  111. }
  112. export function inputVisionData(data) {
  113. return http.post('vision/input-vision', data, { isAuth: false })
  114. }
  115. export function inputRefractionData(data) {
  116. return http.post('vision/input-refraction', data, { isAuth: false })
  117. }
  118. export function getStudentVisionData(studentId) {
  119. return http.get(`students/${studentId}/vision-data`, {}, { isAuth: false })
  120. }
  121. export function updateVisionData(visionDataId, data) {
  122. return http.put(`vision-data/${visionDataId}`, data, { isAuth: false })
  123. }