const { createApp } = Vue; // 自定义主题 const customTheme = { // ... [保留原有主题配置不变] ... }; const app = createApp({ data() { return { currentTheme: Varlet.Themes.md3Light, customTheme: customTheme, floating: false, title: "FuxBms", UserInfo: null, loading: true, loading_d: "加载中", page: "www", userlogo: null, cart: null, cart_fid: null, cart_sid: null, purchases: null, wm: null }; }, mounted() { Varlet.StyleProvider(Varlet.Themes.md3Light); this.getinfo(); }, watch: { cart_fid(newVal) { if ( newVal && this.cart && this.cart[newVal] && Object.keys(this.cart[newVal]).length > 0 ) { this.cart_sid = Object.keys(this.cart[newVal])[0]; } } }, methods: { checkin() { this.loading = true; this.loading_d = "签到中"; axios.get("/Main/CheckIn/").then((response) => { this.loading = false; if (response.data.code === 200) { this.getinfo(); Varlet.Snackbar.success(response.data.msg); } else { Varlet.Snackbar.warning(response.data.msg); } }); }, getpurchases() { this.loading = true; this.loading_d = "拉取数据中"; axios.get("/Main/GetProducts/").then((response) => { this.loading = false; if (response.data.code === 200) { this.purchases = response.data.msg; } else { Varlet.Snackbar.warning(response.data.msg); } }); }, buygoods(product_id) { this.loading = true; this.loading_d = "提交订单中"; axios .post("/Main/BuyGoods/", { product_id }) .then((response) => { this.loading = false; const { code, msg } = response.data; if (code === 200) { Varlet.Snackbar.success(msg); this.getpurchases(); this.page = "purchases"; } else { Varlet.Snackbar.warning(msg); } }) .catch(() => { Varlet.Snackbar.error("请求失败"); }); }, login() { window.location.href = "/Main/Login"; }, viewcart() { this.loading = true; this.loading_d = "获取产品中"; axios.get("/Main/GetGoods/").then((response) => { this.loading = false; this.cart = response.data; if (this.cart && Object.keys(this.cart).length > 0) { this.cart_fid = Object.keys(this.cart)[0]; } }); }, getinfo() { this.loading = true; this.loading_d = "获取用户信息"; axios.get("/Main/GetInfo/").then((response) => { this.loading = false; if (response.data.code === 200) { this.UserInfo = response.data.msg; this.page = "home"; if (response.data.msg.qq != null) { this.userlogo = `https://q1.qlogo.cn/g?b=qq&nk=${response.data.msg.qq}&s=640`; } } else { Varlet.Snackbar.warning("请登录"); this.page = "www"; } }); }, // 主题切换方法保持不变 switchToM3LightTheme() { this.currentTheme = Varlet.Themes.md3Light; Varlet.StyleProvider(this.currentTheme); }, switchToM3DarkTheme() { this.currentTheme = Varlet.Themes.md3Dark; Varlet.StyleProvider(this.currentTheme); }, switchToM2LightTheme() { this.currentTheme = null; Varlet.StyleProvider(this.currentTheme); }, switchToM2DarkTheme() { this.currentTheme = Varlet.Themes.dark; Varlet.StyleProvider(this.currentTheme); }, switchToCustomTheme() { this.currentTheme = this.customTheme; Varlet.StyleProvider(this.currentTheme); } } }); app.use(Varlet); app.mount("#app");