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

151 lines
3.4 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
11 months ago
10 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
11 months ago
1 year ago
1 year ago
1 year ago
10 months ago
1 year ago
11 months ago
1 year ago
10 months ago
10 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year ago
11 months ago
1 year 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('pages_order.huodong_detail.complete_info_required') // 请您先完善必要信息
  87. })
  88. uni.navigateTo({
  89. url: '/pages_login/wxUserInfo'
  90. })
  91. }
  92. }
  93. })
  94. },
  95. // getRiceInfo(state){
  96. // api('getRiceInfo', {
  97. // token : uni.getStorageSync('token') || ''
  98. // },res => {
  99. // if(res.code == 200){
  100. // state.riceInfo = res.result
  101. // }
  102. // })
  103. // },
  104. // 退出登录
  105. logout(state){
  106. uni.showModal({
  107. title: i18n.t('common.confirm_logout'), // 确认退出登录吗
  108. success(r) {
  109. if (r.confirm) {
  110. state.userInfo = {}
  111. state.token = ""
  112. uni.removeStorageSync('token')
  113. uni.reLaunch({
  114. url: '/pages/index/index'
  115. })
  116. }
  117. }
  118. })
  119. },
  120. // 查询地区
  121. getArea(state, fn){
  122. api('getArea', res => {
  123. if(res.code == 200){
  124. res.result.unshift({
  125. city : i18n.t('common.all'), // 全部
  126. id : '',
  127. })
  128. state.areaList = res.result
  129. fn && fn(res.result)
  130. }
  131. })
  132. },
  133. setArea(state, index){
  134. state.selectArea = state.areaList[index]
  135. },
  136. },
  137. actions: {},
  138. })
  139. export default store