景徳镇旅游微信小程序
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.2 KiB

8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 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. cartList : [//购物车列表
  17. {
  18. id : 1,
  19. title : '桌布租赁',
  20. num : 1,
  21. price : 299,
  22. unit : '120*40*75【桌子尺寸】',
  23. },
  24. {
  25. id : 2,
  26. title : '桌布租赁',
  27. num : 1,
  28. price : 299,
  29. unit : '120*40*75【桌子尺寸】',
  30. },//购物车列表
  31. ],
  32. cartCheckboxValue : [],//选中的购物车
  33. },
  34. getters: {
  35. // 角色 true为水洗店 false为酒店
  36. userShop(state){
  37. return state.shop
  38. }
  39. },
  40. mutations: {
  41. // 初始化配置
  42. initConfig(state){
  43. // api('getConfig', res => {
  44. // if(res.code == 200){
  45. // state.configList = res.result
  46. // }
  47. // })
  48. let config = ['getPrivacyPolicy', 'getUserAgreement']
  49. config.forEach(k => {
  50. api(k, res => {
  51. if (res.code == 200) {
  52. state.configList[k] = res.result
  53. }
  54. })
  55. })
  56. },
  57. login(state){
  58. uni.showLoading({
  59. title: '登录中...'
  60. })
  61. uni.login({
  62. success(res) {
  63. if(res.errMsg != "login:ok"){
  64. return
  65. }
  66. api('wxLogin', {
  67. code : res.code,
  68. latitude : state.position.latitude,
  69. longitude : state.position.longitude,
  70. }, res => {
  71. uni.hideLoading()
  72. if(res.code != 200){
  73. return
  74. }
  75. state.userInfo = res.result.userInfo
  76. uni.setStorageSync('token', res.result.token)
  77. // if(!state.userInfo.nickName || !state.userInfo.headImage){
  78. // uni.navigateTo({
  79. // url: '/pages_order/auth/wxUserInfo'
  80. // })
  81. // }else{
  82. uni.navigateBack(-1)
  83. // }
  84. })
  85. }
  86. })
  87. },
  88. getUserInfo(state){
  89. api('infoGetInfo', res => {
  90. if(res.code == 200){
  91. state.userInfo = res.result
  92. }
  93. })
  94. },
  95. getPosition(state){
  96. Position.getLocation(res => {
  97. console.log(res);
  98. state.position = res
  99. })
  100. },
  101. },
  102. actions: {},
  103. })
  104. export default store