index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import actions from "./actions"
  2. import mutations from "./mutations"
  3. // #ifdef H5
  4. // 解析地址栏参数
  5. function getQueryVariable(variable) {
  6. // 从?开始获取后面的所有数据
  7. var query = window.location.search.substring(1);
  8. // 从字符串&开始分隔成数组split
  9. var vars = query.split('&');
  10. // 遍历该数组
  11. for (var i = 0; i < vars.length; i++) {
  12. // 从等号部分分割成字符
  13. var pair = vars[i].split('=');
  14. // 如果第一个元素等于 传进来的参的话 就输出第二个元素
  15. if (pair[0] == variable) {
  16. return pair[1];
  17. }
  18. }
  19. return undefined;
  20. }
  21. var token = getQueryVariable("x-token")
  22. if (token) {
  23. uni.setStorageSync('recycle_mobile_token', token)
  24. }
  25. var openId = getQueryVariable("openId")
  26. if (openId) {
  27. uni.setStorageSync('recycle_mobile_openId', openId)
  28. }
  29. var username = getQueryVariable("username")
  30. if (username) {
  31. uni.setStorageSync('recycle_mobile_name', username)
  32. }
  33. var useravatar = getQueryVariable("useravatar")
  34. if (useravatar) {
  35. uni.setStorageSync('recycle_mobile_avatar', useravatar)
  36. }
  37. var userId = getQueryVariable("userId")
  38. if (userId) {
  39. uni.setStorageSync('recycle_mobile_userId', userId)
  40. }
  41. var miniProgram = getQueryVariable("miniProgram")
  42. if (miniProgram) {
  43. uni.setStorageSync('miniProgram', miniProgram)
  44. }
  45. // #endif
  46. const state = {
  47. openId: uni.getStorageSync('recycle_mobile_openId') || '',
  48. token: uni.getStorageSync('recycle_mobile_token') || '',
  49. name: uni.getStorageSync('recycle_mobile_name') || '',
  50. avatar: uni.getStorageSync('recycle_mobile_avatar') || '',
  51. userId: uni.getStorageSync('recycle_mobile_userId') || '',
  52. }
  53. export default {
  54. namespaced: true,
  55. state,
  56. mutations,
  57. actions
  58. }