index.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // #ifndef VUE3
  2. import Vue from 'vue'
  3. import Vuex from 'vuex'
  4. Vue.use(Vuex)
  5. const store = new Vuex.Store({
  6. // #endif
  7. // #ifdef VUE3
  8. import { createStore } from 'vuex'
  9. const store = createStore({
  10. // #endif
  11. state: {
  12. hasLogin: false,
  13. isUniverifyLogin: false,
  14. loginProvider: "",
  15. openid: null,
  16. testvuex: false,
  17. colorIndex: 0,
  18. colorList: ['#FF0000', '#00FF00', '#0000FF'],
  19. noMatchLeftWindow: true,
  20. active: 'componentPage',
  21. leftWinActive: '/pages/component/view/view',
  22. activeOpen: '',
  23. menu: [],
  24. univerifyErrorMsg: ''
  25. },
  26. mutations: {
  27. login(state, provider) {
  28. state.hasLogin = true;
  29. state.loginProvider = provider;
  30. },
  31. logout(state) {
  32. state.hasLogin = false
  33. state.openid = null
  34. },
  35. setOpenid(state, openid) {
  36. state.openid = openid
  37. },
  38. setTestTrue(state) {
  39. state.testvuex = true
  40. },
  41. setTestFalse(state) {
  42. state.testvuex = false
  43. },
  44. setColorIndex(state, index) {
  45. state.colorIndex = index
  46. },
  47. setMatchLeftWindow(state, matchLeftWindow) {
  48. state.noMatchLeftWindow = !matchLeftWindow
  49. },
  50. setActive(state, tabPage) {
  51. state.active = tabPage
  52. },
  53. setLeftWinActive(state, leftWinActive) {
  54. state.leftWinActive = leftWinActive
  55. },
  56. setActiveOpen(state, activeOpen) {
  57. state.activeOpen = activeOpen
  58. },
  59. setMenu(state, menu) {
  60. state.menu = menu
  61. },
  62. setUniverifyLogin(state, payload) {
  63. typeof payload !== 'boolean' ? payload = !!payload : '';
  64. state.isUniverifyLogin = payload;
  65. },
  66. setUniverifyErrorMsg(state,payload = ''){
  67. state.univerifyErrorMsg = payload
  68. }
  69. },
  70. getters: {
  71. currentColor(state) {
  72. return state.colorList[state.colorIndex]
  73. }
  74. },
  75. actions: {
  76. // lazy loading openid
  77. getUserOpenId: async function({
  78. commit,
  79. state
  80. }) {
  81. return await new Promise((resolve, reject) => {
  82. if (state.openid) {
  83. resolve(state.openid)
  84. } else {
  85. uni.login({
  86. success: (data) => {
  87. commit('login')
  88. setTimeout(function() { //模拟异步请求服务器获取 openid
  89. const openid = '123456789'
  90. console.log('uni.request mock openid[' + openid + ']');
  91. commit('setOpenid', openid)
  92. resolve(openid)
  93. }, 1000)
  94. },
  95. fail: (err) => {
  96. console.log('uni.login 接口调用失败,将无法正常使用开放接口等服务', err)
  97. reject(err)
  98. }
  99. })
  100. }
  101. })
  102. },
  103. getPhoneNumber: function({
  104. commit
  105. }, univerifyInfo) {
  106. return new Promise((resolve, reject) => {
  107. uni.request({
  108. url: 'https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/univerify-login',
  109. method: 'POST',
  110. data: univerifyInfo,
  111. success: (res) => {
  112. const data = res.data
  113. if (data.success) {
  114. resolve(data.phoneNumber)
  115. } else {
  116. reject(res)
  117. }
  118. },
  119. fail: (err) => {
  120. reject(res)
  121. }
  122. })
  123. })
  124. }
  125. }
  126. })
  127. export default store