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

219 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. 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('goLogin')
  108. return false
  109. }
  110. }
  111. }
  112. }
  113. export default user
  114. // h5高德地图
  115. function gaoDeFn(longitude,latitude,commit,resolve, reject,) {
  116. uni.request({
  117. method: 'GET',
  118. url: 'https://restapi.amap.com/v3/geocode/regeo?parameters',
  119. data: {
  120. key: 'a0dde4c05390e689ea2c19d8ec447f62',
  121. location: `${longitude},${latitude}`,
  122. output: 'JSON'
  123. },
  124. success: (res) => {
  125. console.log(res) // 数据结构见下方
  126. let result = res.data.regeocode.addressComponent
  127. let obj = {
  128. lat: latitude,
  129. lng: longitude,
  130. city: result.city,
  131. cityCode: result.adcode,
  132. province: result.province,
  133. district: result.district
  134. }
  135. commit('update_vuex_cityInfo', obj)
  136. resolve(obj)
  137. uni.hideLoading()
  138. },
  139. fail: res => {
  140. reject(new Error('获取地理位置信息失败'))
  141. uni.hideLoading()
  142. }
  143. })
  144. }
  145. function wxAdsFn(longitude,latitude, commit,resolve, reject,) {
  146. console.log(longitude)
  147. console.log(latitude)
  148. var qqmapKey = new qqmapWx({
  149. key: 'NRWBZ-TKRWV-CSAPH-5PFDS-J4HT6-IWF4O'
  150. })
  151. qqmapKey.reverseGeocoder({
  152. location: {
  153. latitude: latitude,
  154. longitude:longitude
  155. },
  156. success(res2) {
  157. console.log('城市信息')
  158. console.log(res2)
  159. let result = res2.result
  160. let obj = {
  161. lat: latitude,
  162. lng: longitude,
  163. city: result.address_component.city,
  164. cityCode: result.ad_info.adcode,
  165. province: result.address_component.province,
  166. district: result.address_component.district
  167. }
  168. commit('update_vuex_cityInfo', obj)
  169. resolve(obj)
  170. uni.hideLoading();
  171. },
  172. fail: function(res3) {
  173. console.log('出什么问题了?')
  174. console.log(res3)
  175. let obj = {
  176. lat: latitude,
  177. lng: longitude
  178. }
  179. // reject(res3)
  180. commit('update_vuex_cityInfo', obj)
  181. uni.hideLoading();
  182. },
  183. })
  184. }
  185. function getCityInfo(resolve, reject, commit) {
  186. // uni.showLoading({
  187. // title: '加载中...'
  188. // })
  189. console.log('来到这是里了吗?')
  190. uni.getLocation({
  191. type: 'wgs84',
  192. // type: 'gcj02',
  193. success: function(res) {
  194. console.log('当前位置的经度:' + res.longitude);
  195. // console.log('当前位置的纬度:' + res);
  196. // #ifdef H5
  197. gaoDeFn(res.longitude,res.latitude, commit, resolve, reject,);
  198. // #endif
  199. // #ifdef MP-WEIXIN
  200. wxAdsFn(res.longitude,res.latitude, commit,resolve, reject,)
  201. // #endif
  202. },
  203. fail(e) {
  204. console.log(e)
  205. uni.hideLoading()
  206. }
  207. })
  208. }