You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
2.9 KiB
126 lines
2.9 KiB
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
|
|
/**
|
|
* @typedef {object} storeType
|
|
* @property {string} count - 购物车数量
|
|
* @property {string} searchValue - 搜索内容
|
|
* @property {string} homeTypeIndex - 首页点击的分类下标
|
|
* @property {string} goodsCheckedItems - 结算商品
|
|
* @property {string} cartList - 购物车列表
|
|
* @property {string} showVoice - 是否显示语音弹窗
|
|
* @property {method} increment - 增加购物车角标数量
|
|
* @property {method} changeCartList - 修改购物车列表
|
|
* @property {method} changeShowVoice - 修改语音弹窗是否显示
|
|
* @property {method} changeCount - 修改购物车数量
|
|
* @property {method} changeSearchValue - 修改搜索内容
|
|
* @property {method} clearSearchValue - 清空搜索值
|
|
* @property {method} changeHomeType - 首页点击分类
|
|
* @property {method} setGoodsCheckedItems - 设置去结算商品
|
|
*/
|
|
|
|
export default defineStore("store",
|
|
/**
|
|
* @returns {storeType}
|
|
*/
|
|
() => {
|
|
/**
|
|
* 购物车数量
|
|
*/
|
|
const count = ref(0);
|
|
/**
|
|
* 搜索内容
|
|
*/
|
|
const searchValue = ref("");
|
|
/**
|
|
* 首页点击的分类下标
|
|
*/
|
|
const homeTypeIndex = ref(-1);
|
|
/**
|
|
* 结算商品
|
|
*/
|
|
const goodsCheckedItems = ref([]);
|
|
/**
|
|
* 购物车列表
|
|
*/
|
|
const cartList = ref([]);
|
|
/**
|
|
* 是否显示语音弹窗
|
|
*/
|
|
const showVoice = ref(false);
|
|
|
|
/**
|
|
* 修改购物车数量
|
|
* @param {*} info
|
|
*/
|
|
function increment(info) {
|
|
count.value = info;
|
|
if (info > 0) {
|
|
uni.setTabBarBadge({
|
|
index: 3, // 你的tabBar索引
|
|
text: info > 999 ? "99+" : info.toString(),
|
|
fail: () => {}, // 失败时不做处理
|
|
});
|
|
}
|
|
else {
|
|
uni.removeTabBarBadge({
|
|
index: 3,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改搜索内容
|
|
* @param {*} info
|
|
*/
|
|
function changeSearchValue(info) {
|
|
searchValue.value = info;
|
|
}
|
|
/**
|
|
* 清空搜索值
|
|
*/
|
|
function clearSearchValue() {
|
|
searchValue.value = "";
|
|
}
|
|
/**
|
|
* 首页点击分类
|
|
*/
|
|
function changeHomeType(info) {
|
|
homeTypeIndex.value = info;
|
|
}
|
|
|
|
/**
|
|
* 设置去结算商品
|
|
*/
|
|
function setGoodsCheckedItems(info) {
|
|
goodsCheckedItems.value = info;
|
|
}
|
|
/**
|
|
* 修改购物车列表
|
|
*/
|
|
function changeCartList(info) {
|
|
cartList.value = info;
|
|
}
|
|
/**
|
|
* 语音弹窗是否显示
|
|
*/
|
|
function changeShowVoice(info) {
|
|
showVoice.value = info;
|
|
}
|
|
|
|
return {
|
|
count,
|
|
searchValue,
|
|
homeTypeIndex,
|
|
goodsCheckedItems,
|
|
cartList,
|
|
showVoice,
|
|
increment,
|
|
changeSearchValue,
|
|
clearSearchValue,
|
|
changeHomeType,
|
|
setGoodsCheckedItems,
|
|
changeCartList,
|
|
changeShowVoice,
|
|
};
|
|
});
|