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.
159 lines
3.8 KiB
159 lines
3.8 KiB
import { defineStore } from "pinia";
|
|
import { ref } from "vue";
|
|
|
|
/**
|
|
* @typedef {object} storeType
|
|
* @property {string} count - 购物车数量
|
|
* @property {string} searchValue - 搜索内容
|
|
* @property {string} homeTypeIndex - 首页点击的分类下标
|
|
* @property {string} cartList - 购物车列表
|
|
* @property {string} productTypeId - 商品分类id
|
|
* @property {string} showVoice - 是否显示语音弹窗
|
|
* @property {string} tabbarBottomHeight - 底部导航高度
|
|
* @property {string} tabbarItemWidth - 底部导航每个的宽度
|
|
* @property {string} fontScale - 字体缩放比例
|
|
* @property {method} increment - 增加购物车角标数量
|
|
* @property {method} getCartTotalQuantity - 获取购物车商品数量
|
|
* @property {method} getCartMap - 获取购物车映射表(格式:specId_price -> quantity)
|
|
* @property {method} changeCartList - 修改购物车列表
|
|
* @property {method} changeShowVoice - 修改语音弹窗是否显示
|
|
* @property {method} changeSearchValue - 修改搜索内容
|
|
* @property {method} clearSearchValue - 清空搜索值
|
|
* @property {method} changeHomeType - 首页点击分类
|
|
*/
|
|
|
|
export default defineStore("store",
|
|
/**
|
|
* @returns {storeType} 返回 store 实例
|
|
*/
|
|
() => {
|
|
/**
|
|
* 购物车数量
|
|
*/
|
|
const count = ref(0);
|
|
/**
|
|
* 搜索内容
|
|
*/
|
|
const searchValue = ref("");
|
|
/**
|
|
* 首页点击的分类下标
|
|
*/
|
|
const homeTypeIndex = ref(-1);
|
|
// /**
|
|
// * 结算商品
|
|
// */
|
|
// const goodsCheckedItems = ref([]);
|
|
/**
|
|
* 购物车列表
|
|
*/
|
|
const cartList = ref([]);
|
|
/**
|
|
* 商品分类id
|
|
*/
|
|
const productTypeId = ref("");
|
|
/**
|
|
* 是否显示语音弹窗
|
|
*/
|
|
const showVoice = ref(false);
|
|
/**
|
|
* 底部导航高度
|
|
*/
|
|
const tabbarBottomHeight = ref(76);
|
|
/**
|
|
* 底部导航每个的宽度
|
|
*/
|
|
const tabbarItemWidth = ref(82);
|
|
/**
|
|
* 字体缩放比例
|
|
*/
|
|
const fontScale = ref(1);
|
|
|
|
const cache = ref({
|
|
keyboardConfirm: () => {},
|
|
});
|
|
|
|
/**
|
|
* 修改购物车数量
|
|
* @param {*} info
|
|
*/
|
|
function increment(info) {
|
|
count.value = info;
|
|
}
|
|
|
|
/**
|
|
* 修改搜索内容
|
|
* @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 getGoodsCheckedItemsSize() {
|
|
// return .value.length;
|
|
// }
|
|
/**
|
|
* 修改购物车列表
|
|
*/
|
|
function changeCartList(info) {
|
|
cartList.value = info;
|
|
}
|
|
/**
|
|
* 获取购物车商品数量
|
|
*/
|
|
function getCartTotalQuantity() {
|
|
return cartList.value.reduce((acc, cur) => acc + cur.quantity, 0);
|
|
}
|
|
/**
|
|
* 获取购物车映射表(格式:specId_price -> quantity)
|
|
*/
|
|
function getCartMap() {
|
|
return cartList.value.reduce((acc, cur) => {
|
|
return { ...acc, [`${cur.specId}_${cur.price}`]: cur.quantity };
|
|
}, {});
|
|
}
|
|
/**
|
|
* 语音弹窗是否显示
|
|
*/
|
|
function changeShowVoice(info) {
|
|
showVoice.value = info;
|
|
}
|
|
|
|
return {
|
|
count,
|
|
searchValue,
|
|
homeTypeIndex,
|
|
cartList,
|
|
productTypeId,
|
|
showVoice,
|
|
tabbarBottomHeight,
|
|
tabbarItemWidth,
|
|
fontScale,
|
|
cache,
|
|
increment,
|
|
changeSearchValue,
|
|
clearSearchValue,
|
|
changeHomeType,
|
|
changeCartList,
|
|
getCartTotalQuantity,
|
|
getCartMap,
|
|
changeShowVoice,
|
|
};
|
|
});
|