【PT.SCC实名制管理系统】24.10.01 -30天,考勤打卡小程序
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.

114 lines
2.1 KiB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months 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. //Vuex.Store 构造器选项
  6. const store = new Vuex.Store({
  7. state: {
  8. configList: [], //配置列表
  9. userInfo : {}, //用户信息
  10. teamList : [],//团队列表
  11. },
  12. getters: {
  13. },
  14. mutations: {
  15. // 初始化配置
  16. initConfig(state){
  17. // api('getConfig', res => {
  18. // if(res.code == 200){
  19. // state.configList = res.result
  20. // }
  21. // })
  22. let config = ['getPrivacyPolicy', 'getUserAgreement']
  23. config.forEach(k => {
  24. api(k, res => {
  25. if (res.code == 200) {
  26. state.configList[k] = res.result
  27. }
  28. })
  29. })
  30. },
  31. login(state){
  32. uni.showLoading({
  33. title: '登录中...'
  34. })
  35. let self = this
  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/login/wxUserInfo'
  53. })
  54. }else{
  55. self.commit('getUserInfo')
  56. uni.navigateBack(-1)
  57. }
  58. })
  59. }
  60. })
  61. },
  62. logout(state){
  63. uni.showModal({
  64. title: '确认退出登录吗',
  65. success(r) {
  66. if(r.confirm){
  67. state.userInfo = {}
  68. state.role = false
  69. uni.removeStorageSync('token')
  70. uni.reLaunch({
  71. url: '/pages/index/index'
  72. })
  73. }
  74. }
  75. })
  76. },
  77. getUserInfo(state){
  78. api('getInfo', res => {
  79. if(res.code == 200){
  80. state.userInfo = res.result
  81. if(!state.userInfo.team){
  82. uni.navigateTo({
  83. url: "/pages/subPack/team/team"
  84. })
  85. }else if(!state.userInfo.auth){
  86. uni.navigateTo({
  87. url: "/pages/subPack/autonym/autonym"
  88. })
  89. }
  90. }
  91. })
  92. },
  93. getTeam(state){
  94. api('teamList', res => {
  95. if(res.code == 200){
  96. state.teamList = res.result
  97. }
  98. })
  99. },
  100. },
  101. actions: {},
  102. })
  103. export default store