学员端小程序
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.

220 lines
5.7 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. if(!state.apiOk) {
  90. return state.refreshTokenFn
  91. }
  92. commit('update_apiOk',false)
  93. const http = uni.$u.http
  94. let config = { header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, custom: { noToken: true } }
  95. let refreshToken = state.vuex_loginInfo.refreshToken
  96. state.refreshTokenFn = await http.post('member/auth/refresh-token',{refreshToken}, config)
  97. if(state.refreshTokenFn.data||state.refreshTokenFn.data.accessToken) {
  98. console.log('刷新token结果')
  99. console.log(state.refreshTokenFn)
  100. commit('update_apiOk',true)
  101. commit('update_vuex_loginInfo',state.refreshTokenFn.data)
  102. uni.$u.http.setConfig((config) => {
  103. config.header.Authorization = 'Bearer ' + state.refreshTokenFn.data.accessToken
  104. return config
  105. })
  106. }else {
  107. commit('update_apiOk',true)
  108. commit('goLogin')
  109. return false
  110. }
  111. }
  112. }
  113. }
  114. export default user
  115. // h5高德地图
  116. function gaoDeFn(longitude,latitude,commit,resolve, reject,) {
  117. uni.request({
  118. method: 'GET',
  119. url: 'https://restapi.amap.com/v3/geocode/regeo?parameters',
  120. data: {
  121. key: 'a0dde4c05390e689ea2c19d8ec447f62',
  122. location: `${longitude},${latitude}`,
  123. output: 'JSON'
  124. },
  125. success: (res) => {
  126. console.log(res) // 数据结构见下方
  127. let result = res.data.regeocode.addressComponent
  128. let obj = {
  129. lat: latitude,
  130. lng: longitude,
  131. city: result.city,
  132. cityCode: result.adcode,
  133. province: result.province,
  134. district: result.district
  135. }
  136. commit('update_vuex_cityInfo', obj)
  137. resolve(obj)
  138. uni.hideLoading()
  139. },
  140. fail: res => {
  141. reject(new Error('获取地理位置信息失败'))
  142. uni.hideLoading()
  143. }
  144. })
  145. }
  146. function wxAdsFn(longitude,latitude, commit,resolve, reject,) {
  147. console.log(longitude)
  148. console.log(latitude)
  149. var qqmapKey = new qqmapWx({
  150. key: 'NRWBZ-TKRWV-CSAPH-5PFDS-J4HT6-IWF4O'
  151. })
  152. qqmapKey.reverseGeocoder({
  153. location: {
  154. latitude: latitude,
  155. longitude:longitude
  156. },
  157. success(res2) {
  158. console.log('城市信息')
  159. console.log(res2)
  160. let result = res2.result
  161. let obj = {
  162. lat: latitude,
  163. lng: longitude,
  164. city: result.address_component.city,
  165. cityCode: result.ad_info.adcode,
  166. province: result.address_component.province,
  167. district: result.address_component.district
  168. }
  169. commit('update_vuex_cityInfo', obj)
  170. resolve(obj)
  171. uni.hideLoading();
  172. },
  173. fail: function(res3) {
  174. console.log('出什么问题了?')
  175. console.log(res3)
  176. let obj = {
  177. lat: latitude,
  178. lng: longitude
  179. }
  180. // reject(res3)
  181. commit('update_vuex_cityInfo', obj)
  182. uni.hideLoading();
  183. },
  184. })
  185. }
  186. function getCityInfo(resolve, reject, commit) {
  187. // uni.showLoading({
  188. // title: '加载中...'
  189. // })
  190. console.log('来到这是里了吗?')
  191. uni.getLocation({
  192. type: 'wgs84',
  193. // type: 'gcj02',
  194. success: function(res) {
  195. console.log('当前位置的经度:' + res.longitude);
  196. // console.log('当前位置的纬度:' + res);
  197. // #ifdef H5
  198. gaoDeFn(res.longitude,res.latitude, commit, resolve, reject,);
  199. // #endif
  200. // #ifdef MP-WEIXIN
  201. wxAdsFn(res.longitude,res.latitude, commit,resolve, reject,)
  202. // #endif
  203. },
  204. fail(e) {
  205. console.log(e)
  206. uni.hideLoading()
  207. }
  208. })
  209. }