app.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import DiyApi from '@/sheep/api/promotion/diy';
  2. import {
  3. defineStore
  4. } from 'pinia';
  5. import $platform from '@/sheep/platform';
  6. import $router from '@/sheep/router';
  7. import user from './user';
  8. import sys from './sys';
  9. const app = defineStore({
  10. id: 'app',
  11. state: () => ({
  12. info: {
  13. // 应用信息
  14. name: '', // 商城名称
  15. logo: '', // logo
  16. version: '', // 版本号
  17. copyright: '', // 版权信息 I
  18. copytime: '', // 版权信息 II
  19. cdnurl: '', // 云存储域名
  20. filesystem: '', // 云存储平台
  21. },
  22. platform: {
  23. share: {
  24. methods: [], // 支持的分享方式
  25. forwardInfo: {}, // 默认转发信息
  26. posterInfo: {}, // 海报信息
  27. linkAddress: '', // 复制链接地址
  28. },
  29. bind_mobile: 0, // 登陆后绑定手机号提醒 (弱提醒,可手动关闭)
  30. },
  31. chat: {},
  32. template: {
  33. // 店铺装修模板
  34. basic: {}, // 基本信息
  35. home: {
  36. // 首页模板
  37. style: {},
  38. data: [],
  39. },
  40. user: {
  41. // 个人中心模板
  42. style: {},
  43. data: [],
  44. },
  45. },
  46. shareInfo: {}, // 全局分享信息
  47. has_wechat_trade_managed: 0 // 小程序发货信息管理 0 没有 || 1 有
  48. }),
  49. actions: {
  50. // 获取Shopro应用配置和模板
  51. async init(templateId = null) {
  52. // 检查网络
  53. const networkStatus = await $platform.checkNetwork();
  54. if (!networkStatus) {
  55. $router.error('NetworkError');
  56. }
  57. // 加载装修配置
  58. await adaptTemplate(this.template, templateId)
  59. // TODO 芋艿:未来支持管理后台可配;对应
  60. if (true) {
  61. this.info = {
  62. name: '常来此购',
  63. logo: '/static/zxlogo.png',
  64. version: '1.1.13',
  65. copyright: '全部开源,个人与企业可 100% 免费使用',
  66. copytime: 'Copyright© 2018-2024',
  67. cdnurl: 'https://file.sheepjs.com', // 云存储域名
  68. filesystem: 'qcloud', // 云存储平台
  69. };
  70. this.platform = {
  71. share: {
  72. methods: ["poster", "link"],
  73. // linkAddress: "http://localhost/#/", //跳转链接
  74. linkAddress: import.meta.env.SHOPRO_BASE_URL+'/#/', //跳转链接
  75. posterInfo: {
  76. "user_bg": "/static/user-poster-bg.jpg",
  77. "goods_bg": "/static/user-poster-bg.jpg",
  78. "groupon_bg": "/static/img/shop/config/groupon-poster-bg.png"
  79. }
  80. },
  81. bind_mobile: 0
  82. };
  83. this.chat = {
  84. chat_domain: "https://api.shopro.sheepjs.com/chat",
  85. room_id: "admin"
  86. }
  87. this.has_wechat_trade_managed = 0;
  88. // 加载主题
  89. const sysStore = sys();
  90. sysStore.setTheme();
  91. // 模拟用户登录
  92. const userStore = user();
  93. // if (userStore.isLogin) {
  94. // console.log('app.js 调了一次loginAfter');
  95. // userStore.loginAfter();
  96. // }
  97. return Promise.resolve(true);
  98. } else {
  99. $router.error('InitError', res.msg || '加载失败');
  100. }
  101. },
  102. },
  103. persist: {
  104. enabled: true,
  105. strategies: [{
  106. key: 'app-store',
  107. }, ],
  108. },
  109. });
  110. // todo: @owen 先做数据适配,后期重构
  111. const adaptTemplate = async (appTemplate, templateId) => {
  112. const {
  113. data: diyTemplate
  114. } = templateId
  115. // 查询指定模板,一般是预览时使用
  116. ?
  117. await DiyApi.getDiyTemplate(templateId) :
  118. await DiyApi.getUsedDiyTemplate();
  119. // 模板不存在
  120. if (!diyTemplate) {
  121. $router.error('TemplateError');
  122. return
  123. }
  124. const tabBar = diyTemplate?.property?.tabBar;
  125. if (tabBar) {
  126. appTemplate.basic.tabbar = tabBar
  127. if (tabBar?.theme) {
  128. appTemplate.basic.theme = tabBar?.theme;
  129. }
  130. }
  131. appTemplate.home = diyTemplate?.home;
  132. appTemplate.user = diyTemplate?.user;
  133. }
  134. export default app;