酒店桌布为微信小程序
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.

97 lines
1.8 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
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. import Position from '@/utils/position.js'
  6. //Vuex.Store 构造器选项
  7. const store = new Vuex.Store({
  8. state: {
  9. configList: [], //配置列表
  10. shop : false,
  11. position : {//定位信息
  12. latitude : 0,
  13. longitude : 0,
  14. },
  15. userInfo : {},//用户信息
  16. },
  17. getters: {
  18. // 角色 true为水洗店 false为酒店
  19. userShop(state){
  20. return state.shop
  21. }
  22. },
  23. mutations: {
  24. // 初始化配置
  25. initConfig(state){
  26. // api('getConfig', res => {
  27. // if(res.code == 200){
  28. // state.configList = res.result
  29. // }
  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){
  41. uni.showLoading({
  42. title: '登录中...'
  43. })
  44. uni.login({
  45. success(res) {
  46. if(res.errMsg != "login:ok"){
  47. return
  48. }
  49. api('wxLogin', {
  50. code : res.code,
  51. latitude : state.position.latitude,
  52. longitude : state.position.longitude,
  53. }, res => {
  54. uni.hideLoading()
  55. if(res.code != 200){
  56. return
  57. }
  58. state.userInfo = res.result.userInfo
  59. uni.setStorageSync('token', res.result.token)
  60. if(!state.userInfo.nickName || !state.userInfo.headImage){
  61. uni.navigateTo({
  62. url: '/pages_order/auth/wxUserInfo'
  63. })
  64. }else{
  65. uni.navigateBack(-1)
  66. }
  67. })
  68. }
  69. })
  70. },
  71. getUserInfo(state){
  72. api('getInfo', res => {
  73. if(res.code == 200){
  74. state.userInfo = res.result
  75. }
  76. })
  77. },
  78. getPosition(state){
  79. Position.getLocation(res => {
  80. console.log(res);
  81. state.position = res
  82. })
  83. },
  84. },
  85. actions: {},
  86. })
  87. export default store