186 lines
5.1 KiB
JavaScript
186 lines
5.1 KiB
JavaScript
import { ref } from "vue";
|
||
import { defineStore } from "pinia";
|
||
import $platform from "@/peach/platform";
|
||
import $router from "@/peach/router";
|
||
import useUserStore from "./user";
|
||
import useSysStore from "./sys";
|
||
|
||
const useAppStore = defineStore(
|
||
"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: "",
|
||
});
|
||
|
||
/**
|
||
* @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,
|
||
});
|
||
|
||
const chat = ref({});
|
||
|
||
/**
|
||
* @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/product",
|
||
},
|
||
{
|
||
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/order/list",
|
||
},
|
||
{
|
||
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/my",
|
||
},
|
||
],
|
||
style: {
|
||
activeColor: "#fc4141",
|
||
bgColor: "#fff",
|
||
bgType: "color",
|
||
color: "#282828",
|
||
},
|
||
theme: "red",
|
||
},
|
||
},
|
||
});
|
||
|
||
// 全局分享信息
|
||
const shareInfo = ref({});
|
||
|
||
// 小程序发货信息管理 0: 没有 1:有
|
||
const hasWechatTradeManaged = ref(0);
|
||
|
||
/**
|
||
* @author Ankkaya
|
||
* @description 小程序初始化
|
||
* @param {Type} -
|
||
* @returns {Type}
|
||
*/
|
||
async function init() {
|
||
// 检查网络
|
||
const networkStatus = await $platform.checkNetwork();
|
||
if (!networkStatus) {
|
||
$router.error("NetworkError");
|
||
}
|
||
|
||
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",
|
||
|
||
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;
|
||
|
||
// 加载主题
|
||
const sysStore = useSysStore();
|
||
sysStore.setTheme();
|
||
|
||
// 模拟用户登录
|
||
const userStore = useUserStore();
|
||
if (userStore.isLogin) {
|
||
userStore.loginAfter();
|
||
}
|
||
return Promise.resolve(true);
|
||
} else {
|
||
$router.error("InitError", res.msg || "加载失败");
|
||
}
|
||
}
|
||
|
||
return {
|
||
info,
|
||
platform,
|
||
chat,
|
||
template,
|
||
shareInfo,
|
||
hasWechatTradeManaged,
|
||
init,
|
||
};
|
||
},
|
||
{
|
||
persist: {
|
||
enabled: true,
|
||
strategies: [
|
||
{
|
||
key: "app-store",
|
||
},
|
||
],
|
||
},
|
||
}
|
||
);
|
||
|
||
export default useAppStore;
|