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

130 lines
2.6 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year 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 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. banner : {},
  33. cartCheckboxValue : [],//选中的购物车
  34. },
  35. getters: {
  36. // 角色 true为水洗店 false为酒店
  37. userShop(state){
  38. return state.shop
  39. }
  40. },
  41. mutations: {
  42. // 初始化配置
  43. initConfig(state){
  44. // api('getConfig', res => {
  45. // if(res.code == 200){
  46. // state.configList = res.result
  47. // }
  48. // })
  49. let config = ['getPrivacyPolicy', 'getUserAgreement']
  50. config.forEach(k => {
  51. api(k, res => {
  52. if (res.code == 200) {
  53. state.configList[k] = res.result
  54. }
  55. })
  56. })
  57. },
  58. getBanner(state){
  59. // 0-首页 1-遗产路径 2-我要跟拍 3-非遗体验 4-无忧服务 5申遗历程
  60. let config = ['path', 'follow', 'experience', 'service', 'course']
  61. config.forEach((k, i) => {
  62. api('queryBannerList', {
  63. bannerCategoryType : i + 1,
  64. }, res => {
  65. if(res.code == 200){
  66. state.banner[k] = res.result
  67. }
  68. })
  69. })
  70. },
  71. login(state){
  72. uni.showLoading({
  73. title: '登录中...'
  74. })
  75. uni.login({
  76. success(res) {
  77. if(res.errMsg != "login:ok"){
  78. return
  79. }
  80. api('wxLogin', {
  81. code : res.code,
  82. latitude : state.position.latitude,
  83. longitude : state.position.longitude,
  84. }, res => {
  85. uni.hideLoading()
  86. if(res.code != 200){
  87. return
  88. }
  89. state.userInfo = res.result.userInfo
  90. uni.setStorageSync('token', res.result.token)
  91. // if(!state.userInfo.nickName || !state.userInfo.headImage){
  92. // uni.navigateTo({
  93. // url: '/pages_order/auth/wxUserInfo'
  94. // })
  95. // }else{
  96. uni.navigateBack(-1)
  97. // }
  98. })
  99. }
  100. })
  101. },
  102. getUserInfo(state){
  103. api('infoGetInfo', res => {
  104. if(res.code == 200){
  105. state.userInfo = res.result
  106. }
  107. })
  108. },
  109. getPosition(state){
  110. Position.getLocation(res => {
  111. console.log(res);
  112. state.position = res
  113. })
  114. },
  115. },
  116. actions: {},
  117. })
  118. export default store