index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. import { getLang } from '@/utils/util'
  4. const app = getApp();
  5. Vue.use(Vuex)
  6. const store = new Vuex.Store({
  7. state: {
  8. isLogin:1,//1已登录 2未登录
  9. info:{
  10. avatar:''
  11. },
  12. language: getLang(),
  13. loginShowSign: false,
  14. loginShowCloseSign: false,
  15. eyes1:false,
  16. isVoice:false,
  17. timeZone:'',
  18. qiuNiu: JSON.parse(localStorage.getItem('qiuNiu')) || {},
  19. system:{}
  20. },
  21. modules: {},
  22. mutations: {
  23. setLang: (state, i) => {
  24. state.language = i
  25. localStorage.setItem('language', JSON.stringify(i))
  26. }
  27. },
  28. actions: {
  29. loginTim(state, data) {
  30. if(data.types == 'youke') {
  31. data.userID = data.id
  32. data.userSig = data.sig
  33. }else {
  34. let information = JSON.parse(localStorage.getItem('information')) || {data:{}}
  35. data.userID = String(information.data.id)
  36. data.userSig = information.data.userSig
  37. }
  38. return new Promise((resolve, reject) => {
  39. // const SDKAppID = app.globalData.SDKAppID;
  40. uni.$TUIKit.login(data).then((res) => {
  41. setTimeout(() => {
  42. state.dispatch('editInfo', data).then(() => {
  43. resolve()
  44. }).catch(() => {
  45. reject()
  46. })
  47. }, 1000)
  48. // uni.$aegis.reportEvent({
  49. // name: 'login',
  50. // ext1: 'login-success',
  51. // ext2: 'uniTuikitExternal',
  52. // ext3: `${SDKAppID}`,
  53. // })
  54. }).catch((error) => {
  55. console.error('errr', error)
  56. reject()
  57. // uni.$aegis.reportEvent({
  58. // name: 'login',
  59. // ext1: `login-failed#error:${error}`,
  60. // ext2: 'uniTuikitExternal',
  61. // ext3: `${SDKAppID}`,
  62. // })
  63. })
  64. })
  65. },
  66. editInfo(state, data) {
  67. return new Promise((resolve, reject) => {
  68. console.error(state.state.info.user_nickname)
  69. uni.$TUIKit.updateMyProfile({
  70. nick: state.state.info.user_nickname || data.id
  71. }).then((imResponse) => {
  72. setTimeout(() => {
  73. resolve()
  74. }, 1000)
  75. }).catch((err) => {
  76. reject()
  77. })
  78. })
  79. },
  80. getQiNiu(state, data) {
  81. uni.$u.http.get('/api/Member/getQiniuToken').then(res => {
  82. localStorage.setItem('qiuNiu', JSON.stringify(res))
  83. state.state.qiuNiu = res
  84. })
  85. }
  86. }
  87. })
  88. export default store