特易招,招聘小程序
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.

80 lines
1.5 KiB

11 months ago
11 months ago
11 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. //Vuex.Store 构造器选项
  6. const store = new Vuex.Store({
  7. state: {
  8. configList: [], //配置列表
  9. // 角色 true为老板 false为工人
  10. role : false,
  11. userInfo : {}, //用户信息
  12. },
  13. getters: {
  14. },
  15. mutations: {
  16. // 初始化配置
  17. initConfig(state){
  18. // api('getConfig', res => {
  19. // if(res.code == 200){
  20. // state.configList = res.result
  21. // }
  22. // })
  23. let config = ['getPrivacyPolicy', 'getUserAgreement']
  24. config.forEach(k => {
  25. api(k, res => {
  26. if (res.code == 200) {
  27. state.configList[k] = res.result
  28. }
  29. })
  30. })
  31. },
  32. login(state){
  33. uni.showLoading({
  34. title: '登录中...'
  35. })
  36. uni.login({
  37. success(res) {
  38. if(res.errMsg != "login:ok"){
  39. return
  40. }
  41. api('wxLogin', {
  42. code : res.code
  43. }, res => {
  44. uni.hideLoading()
  45. if(res.code != 200){
  46. return
  47. }
  48. state.userInfo = res.result.userInfo
  49. uni.setStorageSync('token', res.result.token)
  50. if(!state.userInfo.nickName || !state.userInfo.headImage){
  51. uni.navigateTo({
  52. url: '/pages_order/auth/wxUserInfo'
  53. })
  54. }else{
  55. uni.navigateBack(-1)
  56. }
  57. })
  58. }
  59. })
  60. },
  61. getUserInfo(state){
  62. api('infoGetInfo', res => {
  63. if(res.code == 200){
  64. state.userInfo = res.result
  65. }
  66. })
  67. },
  68. },
  69. actions: {},
  70. })
  71. export default store