common.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import request from '@/api/request'
  2. import { platform } from '@/utils/platform'
  3. import funWxShare from '@/utils/wxShare0.0'
  4. const state = {
  5. userinfo: {
  6. user_head_img_url: '', // 用户头像
  7. user_nickname: '', // 用户昵称
  8. user_sex: '', // 用户性别
  9. user_balance: 0, // 用户可提现余额(单位为分)
  10. user_crash_balance: 0, // 累计提现(单位为分)
  11. user_unreceive_balance: 0, // 用户未结算金额(单位为分)
  12. created_at: '', // 注册时间
  13. id: '' // 用户ID
  14. },
  15. orderType: [], // 订单类型
  16. inviteId: '' // 邀请人ID,分享链接携带
  17. }
  18. const getters = {
  19. userinfo (state) {
  20. return state.userinfo
  21. },
  22. orderType (state) {
  23. return state.orderType
  24. },
  25. inviteId (state) {
  26. return state.inviteId
  27. }
  28. }
  29. const actions = {
  30. async getUserInfo ({ commit }) {
  31. try {
  32. const { status, data } = await request({
  33. method: 'GET',
  34. url: '/api/user/info'
  35. })
  36. if (status) {
  37. commit('UPDATE_USERINFO', data)
  38. platform.isWeixin && funWxShare('返不停', '一个省钱、赚钱又返钱的生活平台', `${location.origin}/img/share.png`, `${location.origin}${location.pathname}?invite_id=${data.id}`)
  39. }
  40. } catch (err) {
  41. console.log(err)
  42. }
  43. },
  44. async getOrdertype ({ commit }) {
  45. try {
  46. const { status, data } = await request({
  47. method: 'GET',
  48. url: '/api/order/type/list'
  49. })
  50. if (status) {
  51. commit('UPDATE_ORDER_TYPE', data)
  52. }
  53. } catch (err) {
  54. console.log(err)
  55. }
  56. }
  57. }
  58. const mutations = {
  59. UPDATE_USERINFO (state, value) {
  60. state.userinfo = {
  61. ...value
  62. }
  63. },
  64. UPDATE_ORDER_TYPE (state, value) {
  65. state.orderType = [...value]
  66. },
  67. UPDATE_INVITE_ID (state, value) {
  68. state.inviteId = value
  69. }
  70. }
  71. export default {
  72. namespaced: true,
  73. state,
  74. getters,
  75. actions,
  76. mutations
  77. }