学员端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.4 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. import qqmapWx from '../../common/sdk/qqmap-wx-jssdk.min.js'; // 引入
  2. import { httpPrefix } from '../../config/site.config.js';
  3. const user = {
  4. state: {
  5. vuex_cityInfo: uni.getStorageSync('vuex_cityInfo') ? uni.getStorageSync('vuex_cityInfo') : {city: '杭州市'},
  6. vuex_userInfo: uni.getStorageSync('vuex_userInfo') ? uni.getStorageSync('vuex_userInfo') : {},
  7. vuex_loginInfo: uni.getStorageSync('vuex_loginInfo') ? uni.getStorageSync('vuex_loginInfo') : {},
  8. apiOk: true,
  9. NonPlatformStudent: false,
  10. },
  11. mutations: {
  12. update_vuex_cityInfo(state, payload) {
  13. state.vuex_cityInfo = payload
  14. uni.setStorageSync('vuex_cityInfo', payload);
  15. },
  16. update_vuex_loginInfo(state, payload) {
  17. state.vuex_loginInfo = payload
  18. uni.setStorageSync('vuex_loginInfo', payload);
  19. },
  20. update_vuex_userInfo(state, payload) {
  21. state.vuex_userInfo = payload || {}
  22. uni.setStorageSync('vuex_userInfo', payload);
  23. },
  24. update_apiOk(state, payload) {
  25. state.apiOk = payload
  26. },
  27. goLogin(state) {
  28. uni.clearStorageSync()
  29. state.vuex_loginInfo = {}
  30. state.vuex_userInfo = {}
  31. uni.navigateTo({
  32. url: '/pages/userCenter/login/loginByPhone'
  33. })
  34. },
  35. // 为非平台学员开一条路
  36. updateNonPlatformStudent(state, val) {
  37. state.NonPlatformStudent = val
  38. }
  39. },
  40. actions: {
  41. getCity({commit}) {
  42. return new Promise((resolve, reject) => {
  43. // #ifdef APP-PLUS||H5
  44. console.log('h5经纬度的代码')
  45. getCityInfo(resolve, reject,commit)
  46. // #endif
  47. // #ifdef MP-WEIXIN
  48. uni.authorize({
  49. scope: 'scope.userLocation',
  50. success() {
  51. getCityInfo(resolve, reject,commit)
  52. },
  53. fail: function(res4) {
  54. uni.showModal({
  55. title: '提示',
  56. content: '小程序想要获取您的地里位置',
  57. success: function(res) {
  58. if (res.confirm) {
  59. uni.openSetting({
  60. success(res) {
  61. getCityInfo(resolve, reject,commit)
  62. }
  63. });
  64. } else if (res.cancel) {
  65. console.log('用户点击取消');
  66. }
  67. }
  68. })
  69. },
  70. })
  71. // #endif
  72. })
  73. },
  74. // 获取用户信息
  75. async getUserInfo({state, commit}) {
  76. const http = uni.$u.http
  77. let config = { custom: { auth: false }, header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'} }
  78. const res = await http.get('app/student-record/get')
  79. if(res.tenantId) {
  80. uni.$u.http.setConfig((config) => {
  81. config.header['tenant-id'] = res.tenantId
  82. return config
  83. })
  84. }
  85. commit('update_vuex_userInfo',res.data)
  86. },
  87. // 刷新token
  88. async refreshToken({state, commit}) {
  89. commit('update_apiOk',false)
  90. const http = uni.$u.http
  91. let config = { header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, custom: { noToken: true } }
  92. let refreshToken = state.vuex_loginInfo.refreshToken
  93. const res = await http.post('member/auth/refresh-token',{refreshToken}, config)
  94. console.log('刷新token结果')
  95. console.log(res)
  96. commit('update_apiOk',true)
  97. commit('update_vuex_loginInfo',res.data)
  98. uni.$u.http.setConfig((config) => {
  99. config.header.Authorization = 'Bearer ' + res.data.accessToken
  100. return config
  101. })
  102. }
  103. }
  104. }
  105. export default user
  106. // h5高德地图
  107. function gaoDeFn(longitude,latitude,commit,resolve, reject,) {
  108. uni.request({
  109. method: 'GET',
  110. url: 'https://restapi.amap.com/v3/geocode/regeo?parameters',
  111. data: {
  112. key: 'a0dde4c05390e689ea2c19d8ec447f62',
  113. location: `${longitude},${latitude}`,
  114. output: 'JSON'
  115. },
  116. success: (res) => {
  117. console.log(res) // 数据结构见下方
  118. let result = res.data.regeocode.addressComponent
  119. let obj = {
  120. lat: latitude,
  121. lng: longitude,
  122. city: result.city,
  123. cityCode: result.adcode,
  124. province: result.province,
  125. district: result.district
  126. }
  127. commit('update_vuex_cityInfo', obj)
  128. resolve(obj)
  129. uni.hideLoading()
  130. },
  131. fail: res => {
  132. reject(new Error('获取地理位置信息失败'))
  133. uni.hideLoading()
  134. }
  135. })
  136. }
  137. function wxAdsFn(longitude,latitude, commit,resolve, reject,) {
  138. console.log(longitude)
  139. console.log(latitude)
  140. var qqmapKey = new qqmapWx({
  141. key: 'NRWBZ-TKRWV-CSAPH-5PFDS-J4HT6-IWF4O'
  142. })
  143. qqmapKey.reverseGeocoder({
  144. location: {
  145. latitude: latitude,
  146. longitude:longitude
  147. },
  148. success(res2) {
  149. console.log('城市信息')
  150. console.log(res2)
  151. let result = res2.result
  152. let obj = {
  153. lat: latitude,
  154. lng: longitude,
  155. city: result.address_component.city,
  156. cityCode: result.ad_info.adcode,
  157. province: result.address_component.province,
  158. district: result.address_component.district
  159. }
  160. commit('update_vuex_cityInfo', obj)
  161. resolve(obj)
  162. uni.hideLoading();
  163. },
  164. fail: function(res3) {
  165. console.log('出什么问题了?')
  166. console.log(res3)
  167. let obj = {
  168. lat: latitude,
  169. lng: longitude
  170. }
  171. // reject(res3)
  172. commit('update_vuex_cityInfo', obj)
  173. uni.hideLoading();
  174. },
  175. })
  176. }
  177. function getCityInfo(resolve, reject, commit) {
  178. // uni.showLoading({
  179. // title: '加载中...'
  180. // })
  181. console.log('来到这是里了吗?')
  182. uni.getLocation({
  183. type: 'wgs84',
  184. // type: 'gcj02',
  185. success: function(res) {
  186. console.log('当前位置的经度:' + res.longitude);
  187. // console.log('当前位置的纬度:' + res);
  188. // #ifdef H5
  189. gaoDeFn(res.longitude,res.latitude, commit, resolve, reject,);
  190. // #endif
  191. // #ifdef MP-WEIXIN
  192. wxAdsFn(res.longitude,res.latitude, commit,resolve, reject,)
  193. // #endif
  194. },
  195. fail(e) {
  196. console.log(e)
  197. uni.hideLoading()
  198. }
  199. })
  200. }