推广小程序前端代码
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.

159 lines
3.5 KiB

7 months ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
6 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
6 months ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
7 months ago
7 months ago
2 weeks ago
7 months ago
7 months ago
7 months ago
2 weeks ago
6 months ago
2 weeks ago
6 months ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
7 months ago
2 weeks ago
2 weeks ago
7 months ago
6 months ago
7 months ago
2 weeks ago
5 months ago
5 months ago
7 months ago
6 months ago
2 weeks ago
6 months ago
2 weeks ago
6 months ago
7 months ago
2 weeks ago
6 months ago
7 months ago
2 weeks ago
7 months ago
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue.use(Vuex); //vue的插件机制
  4. import api from '@/api/api.js'
  5. import i18n from '@/locale/index.js'
  6. //Vuex.Store 构造器选项
  7. const store = new Vuex.Store({
  8. state: {
  9. token: uni.getStorageSync('token') || '',
  10. configList: {}, //配置列表
  11. userInfo: uni.getStorageSync('userInfo') ? JSON.parse(uni.getStorageSync('userInfo')) : {}, //用户信息
  12. // riceInfo : {},//用户相关信息
  13. areaList: [], //地区列表信息
  14. selectArea: {}, //当前选择的地区
  15. },
  16. getters: {
  17. userInfo: state => state.userInfo,
  18. isLogin: state => state.token ? true : false
  19. },
  20. mutations: {
  21. // 初始化配置
  22. initConfig(state) {
  23. api('getConfig', res => {
  24. if (res.code == 200) {
  25. res.result.forEach(n => {
  26. state.configList[n.keyName] = n.keyContent
  27. })
  28. }
  29. console.log("initConfig===============", res);
  30. })
  31. // let config = ['getPrivacyPolicy', 'getUserAgreement']
  32. // config.forEach(k => {
  33. // api(k, res => {
  34. // if (res.code == 200) {
  35. // state.configList[k] = res.result
  36. // }
  37. // })
  38. // })
  39. },
  40. login(state, commit) {
  41. uni.showLoading({
  42. title: i18n.t('common.logging_in') // 登录中...
  43. })
  44. uni.login({
  45. success(res) {
  46. if (res.errMsg != "login:ok") {
  47. return
  48. }
  49. let data = {
  50. code: res.code
  51. }
  52. if (uni.getStorageSync('shareId')) {
  53. data.shareId = uni.getStorageSync('shareId')
  54. }
  55. api('wxLogin', data, res => {
  56. uni.hideLoading()
  57. if (res.code != 200) {
  58. return
  59. }
  60. state.userInfo = res.result.userInfo
  61. state.token = res.result.token
  62. uni.setStorageSync('token', res.result.token)
  63. if (!state.userInfo.nickName || !state.userInfo.headImage) {
  64. uni.navigateTo({
  65. url: '/pages_login/wxUserInfo'
  66. })
  67. } else {
  68. uni.switchTab({
  69. url: '/pages/index/index'
  70. })
  71. }
  72. })
  73. }
  74. })
  75. },
  76. getUserInfo(state) {
  77. api('getInfo', res => {
  78. if (res.code == 200) {
  79. uni.setStorageSync('userInfo', JSON.stringify(res.result))
  80. state.userInfo = res.result
  81. if (!state.userInfo.nickName ||
  82. !state.userInfo.headImage ||
  83. !state.userInfo.phone ||
  84. !state.userInfo.sex) {
  85. uni.showToast({
  86. title: i18n.t(
  87. 'pages_order.huodong_detail.complete_info_required') // 请您先完善必要信息
  88. })
  89. uni.navigateTo({
  90. url: '/pages_login/wxUserInfo'
  91. })
  92. }
  93. }
  94. })
  95. },
  96. // getRiceInfo(state){
  97. // api('getRiceInfo', {
  98. // token : uni.getStorageSync('token') || ''
  99. // },res => {
  100. // if(res.code == 200){
  101. // state.riceInfo = res.result
  102. // }
  103. // })
  104. // },
  105. // 退出登录
  106. logout(state) {
  107. uni.showModal({
  108. title: i18n.t('common.confirm_logout'), // 确认退出登录吗
  109. success(r) {
  110. if (r.confirm) {
  111. state.userInfo = {}
  112. state.token = ""
  113. uni.removeStorageSync('token')
  114. uni.reLaunch({
  115. url: '/pages/index/index'
  116. })
  117. }
  118. }
  119. })
  120. },
  121. // 查询地区
  122. getArea(state, fn) {
  123. api('getArea', res => {
  124. if (res.code == 200) {
  125. res.result.unshift({
  126. city: i18n.t('common.all'), // 全部
  127. id: '',
  128. })
  129. state.areaList = res.result
  130. fn && fn(res.result)
  131. }
  132. })
  133. },
  134. setArea(state, index) {
  135. state.selectArea = state.areaList[index]
  136. },
  137. hanlderManager(state, fn){
  138. api('joinRecruitInfo')
  139. .then(res => {
  140. fn && fn(res)
  141. })
  142. },
  143. },
  144. actions: {
  145. },
  146. })
  147. export default store