uses.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const useStore = common_vendor.defineStore("user", {
  4. state: () => ({
  5. userInfo: {},
  6. // 用户信息
  7. token: "",
  8. // uploadUrl: 'http://192.168.1.3:8080/ai-file/upload/oss', // 上传资源的服务器网址
  9. uploadUrl: "https://gc.sdzcq.com/prod-api/ai-file/upload/oss"
  10. // 上传资源的服务器网址
  11. }),
  12. getters: {},
  13. actions: {
  14. setUserInfo(data) {
  15. if (data.userId) {
  16. console.log("更新全局的用户信息-也更新本地存储", data);
  17. this.userInfo = data;
  18. common_vendor.index.setStorageSync("userInfo", JSON.stringify(data));
  19. } else {
  20. common_vendor.index.removeStorageSync("userInfo");
  21. }
  22. },
  23. setToken(token) {
  24. if (token) {
  25. console.log("更新全局的 token -也更新本地存储", token);
  26. this.token = token;
  27. common_vendor.index.setStorageSync("token", token);
  28. } else {
  29. common_vendor.index.removeStorageSync("token");
  30. }
  31. }
  32. }
  33. });
  34. exports.useStore = useStore;