mall-app-t/peach/store/app.js

186 lines
5.1 KiB
JavaScript
Raw Normal View History

2024-05-23 01:38:19 +08:00
import { ref } from "vue";
import { defineStore } from "pinia";
import $platform from "@/peach/platform";
import $router from "@/peach/router";
import user from "./user";
import useSysStore from "./sys";
2024-05-22 15:42:13 +08:00
const useAppStore = defineStore(
2024-05-23 01:38:19 +08:00
"app",
() => {
/**
* @description 应用信息
* @param string name 应用名称
* @param string logo 应用logo
* @param string version 应用版本
* @param string copyright 版权信息
* @param string copyrightTime 版权时间
* @param string cdnurl 静态资源域名
* @param string filesystem 文件系统
*/
const info = ref({
name: "",
logo: "",
version: "",
copyright: "",
copytime: "",
cdnurl: "",
filesystem: "",
});
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
/**
* @description 平台信息
* @param Array share.methods 分享方式
* @param Object share.forwardInfo 转发信息
* @param Object share.posterInfo 海报信息
* @param string share.linkAddress 分享链接地址
* @param number bindMobile 绑定手机号提醒 0: 提醒 1: 不提醒
*/
const platform = ref({
share: {
methods: [],
forwardInfo: {},
posterInfo: {},
linkAddress: "",
},
bindMobile: 0,
});
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
const chat = ref({});
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
/**
* @description 模板信息
* @param Object basic 基础模板
* @param Object tabbar 底部导航模板
*/
const template = ref({
basic: {
tabbar: {
items: [
{
activeIconUrl:
"http://mall.yudao.iocoder.cn/static/images/1-002.png",
iconUrl: "http://mall.yudao.iocoder.cn/static/images/1-001.png",
text: "首页",
url: "/pages/index/index",
},
{
activeIconUrl:
"http://mall.yudao.iocoder.cn/static/images/2-002.png",
iconUrl: "http://mall.yudao.iocoder.cn/static/images/2-001.png",
text: "分类",
url: "/pages/index/category?id=3",
},
{
activeIconUrl:
"http://mall.yudao.iocoder.cn/static/images/3-002.png",
iconUrl: "http://mall.yudao.iocoder.cn/static/images/3-001.png",
text: "购物车",
url: "/pages/index/icons",
2024-05-22 15:42:13 +08:00
},
2024-05-23 01:38:19 +08:00
{
activeIconUrl:
"http://mall.yudao.iocoder.cn/static/images/4-002.png",
iconUrl: "http://mall.yudao.iocoder.cn/static/images/4-001.png",
text: "我的",
url: "/pages/index/user",
},
],
style: {
activeColor: "#fc4141",
bgColor: "#fff",
bgType: "color",
color: "#282828",
},
theme: "red",
},
},
});
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
// 全局分享信息
const shareInfo = ref({});
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
// 小程序发货信息管理 0: 没有 1
const hasWechatTradeManaged = ref(0);
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
/**
* @author Ankkaya
* @description 小程序初始化
* @param {Type} -
* @returns {Type}
*/
async function init() {
// 检查网络
const networkStatus = await $platform.checkNetwork();
if (!networkStatus) {
$router.error("NetworkError");
}
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
if (true) {
this.info = {
name: "🍑商城",
logo: "https://static.iocoder.cn/ruoyi-vue-pro-logo.png",
version: "1.0.0",
copyright: "全部开源,个人与企业可 100% 免费使用",
copytime: "Copyright© 2018-2024",
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
cdnurl: "https://file.sheepjs.com", // 云存储域名
filesystem: "qcloud", // 云存储平台
};
this.platform = {
share: {
methods: ["poster", "link"],
linkAddress: "https://shopro.sheepjs.com/#/",
posterInfo: {
user_bg: "/static/img/shop/config/user-poster-bg.png",
goods_bg: "/static/img/shop/config/goods-poster-bg.png",
groupon_bg: "/static/img/shop/config/groupon-poster-bg.png",
},
},
bind_mobile: 0,
};
this.chat = {
chat_domain: "https://api.shopro.sheepjs.com/chat",
room_id: "admin",
};
this.has_wechat_trade_managed = 0;
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
// 加载主题
const sysStore = useSysStore();
sysStore.setTheme();
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
// 模拟用户登录
const userStore = user();
if (userStore.isLogin) {
userStore.loginAfter();
2024-05-22 15:42:13 +08:00
}
2024-05-23 01:38:19 +08:00
return Promise.resolve(true);
} else {
$router.error("InitError", res.msg || "加载失败");
}
}
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
return {
info,
platform,
chat,
template,
shareInfo,
hasWechatTradeManaged,
init,
};
},
{
persist: {
enabled: true,
strategies: [
{
key: "app-store",
2024-05-22 15:42:13 +08:00
},
2024-05-23 01:38:19 +08:00
],
},
}
);
2024-05-22 15:42:13 +08:00
2024-05-23 01:38:19 +08:00
export default useAppStore;