app.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import DiyApi from '@/sheep/api/promotion/diy';
  2. import { defineStore } from 'pinia';
  3. import $platform from '@/sheep/platform';
  4. import $router from '@/sheep/router';
  5. import user from './user';
  6. import sys from './sys';
  7. const app = defineStore({
  8. id: 'app',
  9. state: () => ({
  10. info: {
  11. // 应用信息
  12. name: '', // 商城名称
  13. logo: '', // logo
  14. version: '', // 版本号
  15. copyright: '', // 版权信息 I
  16. copytime: '', // 版权信息 II
  17. cdnurl: '', // 云存储域名
  18. filesystem: '', // 云存储平台
  19. },
  20. platform: {
  21. share: {
  22. methods: [], // 支持的分享方式
  23. forwardInfo: {}, // 默认转发信息
  24. posterInfo: {}, // 海报信息
  25. linkAddress: '', // 复制链接地址
  26. },
  27. bind_mobile: 0, // 登陆后绑定手机号提醒 (弱提醒,可手动关闭)
  28. },
  29. template: {
  30. // 店铺装修模板
  31. basic: {}, // 基本信息
  32. home: {
  33. // 首页模板
  34. style: {},
  35. data: [],
  36. },
  37. user: {
  38. // 个人中心模板
  39. style: {},
  40. data: [],
  41. },
  42. },
  43. shareInfo: {}, // 全局分享信息
  44. has_wechat_trade_managed: 0 // 小程序发货信息管理 0 没有 || 1 有
  45. }),
  46. actions: {
  47. // 获取Shopro应用配置和模板
  48. async init(templateId = null) {
  49. // 检查网络
  50. const networkStatus = await $platform.checkNetwork();
  51. if (!networkStatus) {
  52. $router.error('NetworkError');
  53. }
  54. // FIXME masage templateId=3
  55. templateId=3
  56. // 加载装修配置
  57. await adaptTemplate(this.template, templateId)
  58. // TODO 芋艿:未来支持管理后台可配;对应 https://api.shopro.sheepjs.com/shop/api/init
  59. if (true) {
  60. this.info = {
  61. name: '纽森商城',
  62. logo: 'https://static.iocoder.cn/ruoyi-vue-pro-logo.png',
  63. version: '2.2.0',
  64. copyright: 'APP服务备案号:鲁ICP备2022017261号-1',
  65. copytime: 'Copyright© 2019-2024',
  66. cdnurl: 'https://file.sheepjs.com', // 云存储域名
  67. filesystem: 'qcloud', // 云存储平台
  68. };
  69. this.platform = {
  70. share: {
  71. methods: ["poster", "link"],
  72. linkAddress: "http://127.0.0.1:3000", // TODO 芋艿:可以考虑改到 .env 那
  73. posterInfo: {
  74. "user_bg": "/static/img/shop/config/user-poster-bg.png",
  75. "goods_bg": "/static/img/shop/config/goods-poster-bg.png",
  76. "groupon_bg": "/static/img/shop/config/groupon-poster-bg.png"
  77. }
  78. },
  79. bind_mobile: 0
  80. };
  81. this.has_wechat_trade_managed = 0;
  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. // todo: @owen 先做数据适配,后期重构
  106. const adaptTemplate = async (appTemplate, templateId) => {
  107. console.log(appTemplate, templateId,'ppppppppppppppppppppppppppp');
  108. const { data: diyTemplate } = templateId
  109. // 查询指定模板,一般是预览时使用
  110. ? await DiyApi.getDiyTemplate(templateId)
  111. : await DiyApi.getUsedDiyTemplate();
  112. console.log(diyTemplate,'uuuuuuuuuuuuuuu')
  113. // 模板不存在
  114. if (!diyTemplate) {
  115. $router.error('TemplateError');
  116. return
  117. }
  118. const tabBar = diyTemplate?.property?.tabBar;
  119. if (tabBar) {
  120. appTemplate.basic.tabbar = tabBar
  121. if (tabBar?.theme) {
  122. appTemplate.basic.theme = tabBar?.theme;
  123. }
  124. }
  125. appTemplate.home = diyTemplate?.home;
  126. appTemplate.user = diyTemplate?.user;
  127. }
  128. export default app;