app.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import appApi from '@/sheep/api/app';
  2. import diyTemplateApi from '@/sheep/api/promotion/diy/template';
  3. import { defineStore } from 'pinia';
  4. import $platform from '@/sheep/platform';
  5. import $router from '@/sheep/router';
  6. import user from './user';
  7. import sys from './sys';
  8. const app = defineStore({
  9. id: 'app',
  10. state: () => ({
  11. info: {
  12. // 应用信息
  13. name: '', // 商城名称
  14. logo: '', // logo
  15. version: '', // 版本号
  16. cdnurl: '', // 云存储域名
  17. filesystem: '', // 云存储平台
  18. user_protocol: {}, // 用户协议
  19. privacy_protocol: {}, // 隐私协议
  20. about_us: {}, // 关于我们
  21. copyright: '', // 版权信息 I
  22. copytime: '', // 版权信息 II
  23. },
  24. platform: {
  25. payment: [], // 支持的支付方式
  26. recharge_payment: [], // 支持的充值支付方式
  27. share: {
  28. methods: [], // 支持的分享方式
  29. forwardInfo: {}, // 默认转发信息
  30. posterInfo: {}, // 海报信息
  31. linkAddress: '', // 复制链接地址
  32. },
  33. auto_login: 0, // 自动登陆
  34. bind_mobile: 0, // 登陆后绑定手机号提醒 (弱提醒,可手动关闭)
  35. },
  36. chat: {},
  37. template: {
  38. // 店铺装修模板
  39. basic: {}, // 基本信息
  40. home: {
  41. // 首页模板
  42. style: {},
  43. data: [],
  44. },
  45. user: {
  46. // 个人中心模板
  47. style: {},
  48. data: [],
  49. },
  50. },
  51. shareInfo: {}, // 全局分享信息
  52. has_wechat_trade_managed: 0 // 小程序发货信息管理 0 没有 || 1 有
  53. }),
  54. actions: {
  55. // 获取Shopro应用配置和模板
  56. async init(templateId = null) {
  57. //检查网络
  58. const networkStatus = await $platform.checkNetwork();
  59. if (!networkStatus) {
  60. $router.error('NetworkError');
  61. }
  62. const res = await appApi.init(templateId);
  63. if (res.error === 0) {
  64. this.info = res.data.app;
  65. this.platform = res.data.platform;
  66. this.template = res.data.template;
  67. this.has_wechat_trade_managed = res.data.has_wechat_trade_managed;
  68. if (!res.data.template) {
  69. $router.error('TemplateError');
  70. }
  71. this.chat = res.data.chat;
  72. const diyTemplate = await diyTemplateApi.getUsedDiyTemplate();
  73. if (diyTemplate?.data?.property) {
  74. const templateProperty = JSON.parse(diyTemplate?.data?.property)
  75. this.template.basic.tabbar = templateProperty.tabBar
  76. if (templateProperty?.tabBar.theme) {
  77. this.template.basic.theme = templateProperty?.tabBar.theme;
  78. }
  79. } else {
  80. $router.error('TemplateError');
  81. }
  82. // 加载主题
  83. const sysStore = sys();
  84. sysStore.setTheme();
  85. // 模拟用户登录
  86. const userStore = user();
  87. if (userStore.isLogin) {
  88. userStore.loginAfter();
  89. }
  90. return Promise.resolve(true);
  91. } else {
  92. $router.error('InitError', res.msg || '加载失败');
  93. }
  94. },
  95. },
  96. persist: {
  97. enabled: true,
  98. strategies: [
  99. {
  100. key: 'app-store',
  101. },
  102. ],
  103. },
  104. });
  105. export default app;