app.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. // 加载装修配置
  55. await adaptTemplate(this.template, templateId)
  56. // TODO 芋艿:未来支持管理后台可配;对应 https://api.shopro.sheepjs.com/shop/api/init
  57. if (true) {
  58. this.info = {
  59. name: '芋道商城',
  60. logo: 'https://static.iocoder.cn/ruoyi-vue-pro-logo.png',
  61. version: '2.2.0',
  62. copyright: '全部开源,个人与企业可 100% 免费使用',
  63. copytime: 'Copyright© 2018-2024',
  64. cdnurl: 'https://file.sheepjs.com', // 云存储域名
  65. filesystem: 'qcloud', // 云存储平台
  66. };
  67. this.platform = {
  68. share: {
  69. methods: ["poster", "link"],
  70. linkAddress: "http://127.0.0.1:3000", // TODO 芋艿:可以考虑改到 .env 那
  71. posterInfo: {
  72. "user_bg": "/static/img/shop/config/user-poster-bg.png",
  73. "goods_bg": "/static/img/shop/config/goods-poster-bg.png",
  74. "groupon_bg": "/static/img/shop/config/groupon-poster-bg.png"
  75. }
  76. },
  77. bind_mobile: 0
  78. };
  79. this.has_wechat_trade_managed = 0;
  80. // 加载主题
  81. const sysStore = sys();
  82. sysStore.setTheme();
  83. // 模拟用户登录
  84. const userStore = user();
  85. if (userStore.isLogin) {
  86. userStore.loginAfter();
  87. }
  88. return Promise.resolve(true);
  89. } else {
  90. $router.error('InitError', res.msg || '加载失败');
  91. }
  92. },
  93. },
  94. persist: {
  95. enabled: true,
  96. strategies: [
  97. {
  98. key: 'app-store',
  99. },
  100. ],
  101. },
  102. });
  103. // todo: @owen 先做数据适配,后期重构
  104. const adaptTemplate = async (appTemplate, templateId) => {
  105. console.log(appTemplate, templateId,'ppppppppppppppppppppppppppp');
  106. const { data: diyTemplate } = templateId
  107. // 查询指定模板,一般是预览时使用
  108. ? await DiyApi.getDiyTemplate(templateId)
  109. : await DiyApi.getUsedDiyTemplate();
  110. console.log(diyTemplate,'uuuuuuuuuuuuuuu')
  111. // 模板不存在
  112. if (!diyTemplate) {
  113. $router.error('TemplateError');
  114. return
  115. }
  116. const tabBar = diyTemplate?.property?.tabBar;
  117. if (tabBar) {
  118. appTemplate.basic.tabbar = tabBar
  119. if (tabBar?.theme) {
  120. appTemplate.basic.theme = tabBar?.theme;
  121. }
  122. }
  123. appTemplate.home = diyTemplate?.home;
  124. appTemplate.user = diyTemplate?.user;
  125. }
  126. export default app;