江西小程序管理端
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.

163 lines
4.5 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. import addApi from '../../common/sdk/qqmap-wx-jssdk.min.js'; // 引入
  2. const user = {
  3. state: {
  4. identity: uni.getStorageSync('identity')?uni.getStorageSync('identity'):1,
  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. vuex_TenantId: uni.getStorageSync('vuex_TenantId') ? uni.getStorageSync('vuex_TenantId') : '',
  9. vuex_role: {
  10. schoolManager: '校长',
  11. schoolFinance: '驾校财务',
  12. coach: '实操教练',
  13. examSiteCoach: '考场模拟教练',
  14. bookingSimulationTeacher: '模拟器老师'
  15. }
  16. },
  17. mutations: {
  18. // 更新用户身份
  19. upDateIdentity(state, val) {
  20. state.identity = val
  21. uni.setStorageSync('identity', val);
  22. },
  23. update_vuex_cityInfo(state, payload) {
  24. state.vuex_cityInfo = payload
  25. uni.setStorageSync('vuex_cityInfo', payload);
  26. },
  27. update_vuex_loginInfo(state, payload) {
  28. state.vuex_loginInfo = payload
  29. uni.setStorageSync('vuex_loginInfo', payload);
  30. },
  31. update_vuex_userInfo(state, payload) {
  32. state.vuex_userInfo = payload
  33. uni.setStorageSync('vuex_userInfo', payload);
  34. },
  35. upDateTenantId(state, val) {
  36. state.vuex_TenantId = val
  37. uni.setStorageSync('vuex_TenantId', val);
  38. uni.$u.http.setConfig((config) => {
  39. config.header['tenant-id'] = val
  40. return config
  41. })
  42. },
  43. goLogin(state) {
  44. uni.clearStorageSync()
  45. state.vuex_loginInfo = {}
  46. state.vuex_userInfo = {}
  47. state.vuex_TenantId = ''
  48. uni.navigateTo({
  49. url: '/pages/login/login'
  50. })
  51. }
  52. },
  53. actions: {
  54. // 获取用户信息
  55. async getUserInfo({commit}) {
  56. const http = uni.$u.http
  57. let config = { custom: { auth: false }, header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'} }
  58. const res = await http.get('system/auth/get-permission-info-app',config)
  59. commit('update_vuex_userInfo',res.data)
  60. },
  61. // 刷新token
  62. async refreshToken({state, commit}) {
  63. const http = uni.$u.http
  64. let config = { header: {'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}, custom: { noToken: true } }
  65. let refreshToken = state.vuex_loginInfo.refreshToken
  66. const res = await http.post('system/auth/refresh-token?refreshToken='+ refreshToken, config)
  67. console.log('刷新token结果')
  68. console.log(res)
  69. commit('update_vuex_loginInfo',res.data)
  70. uni.$u.http.setConfig((config) => {
  71. config.header.Authorization = 'Bearer ' + res.data.accessToken
  72. return config
  73. })
  74. },
  75. getCity({commit}) {
  76. return new Promise((resolve, reject) => {
  77. // #ifdef APP-PLUS||H5
  78. getCityInfo(resolve, reject,commit)
  79. // #endif
  80. // #ifdef MP-WEIXIN
  81. uni.authorize({
  82. scope: 'scope.userLocation',
  83. success() {
  84. getCityInfo(resolve, reject,commit)
  85. },
  86. fail: function(res4) {
  87. uni.showModal({
  88. title: '提示',
  89. content: '小程序想要获取您的地里位置',
  90. success: function(res) {
  91. if (res.confirm) {
  92. uni.openSetting({
  93. success(res) {
  94. getCityInfo(resolve, reject,commit)
  95. }
  96. });
  97. } else if (res.cancel) {
  98. console.log('用户点击取消');
  99. }
  100. }
  101. })
  102. },
  103. })
  104. // #endif
  105. })
  106. },
  107. }
  108. }
  109. function getCityInfo(resolve, reject, commit) {
  110. uni.showLoading({
  111. title: '加载中...'
  112. })
  113. var qqmapKey = new qqmapWx({
  114. key: '2BTBZ-6BQRB-ZG4UG-NOYYG-KZMH7-B4BYN'
  115. })
  116. uni.getLocation({
  117. type: 'wgs84',
  118. // type: 'gcj02',
  119. success: function(res) {
  120. console.log('当前位置的经度:' + res.longitude);
  121. console.log('当前位置的纬度:' + res.latitude);
  122. qqmapKey.reverseGeocoder({
  123. location: {
  124. latitude: res.latitude,
  125. longitude: res.longitude
  126. },
  127. success(res2) {
  128. // console.log('城市信息')
  129. // console.log(res2.result)
  130. let result = res2.result
  131. let obj = {
  132. latitude: res.latitude,
  133. longitude: res.longitude,
  134. city: result.address_component.city,
  135. cityCode: result.ad_info.adcode,
  136. province: result.address_component.province,
  137. district: result.address_component.district
  138. }
  139. commit('update_vuex_cityInfo', obj)
  140. resolve(obj)
  141. uni.hideLoading();
  142. },
  143. fail: function(res3) {
  144. reject(res3)
  145. uni.hideLoading();
  146. },
  147. })
  148. },
  149. fail(e) {
  150. console.log(e)
  151. }
  152. })
  153. }
  154. export default user