import { Zindex } from '../../libs/config/zIndex'; import color from '../../libs/function/color'; import { PropType, computed, ExtractPropTypes, CSSProperties, reactive, ref } from 'vue'; import string from '../../libs/function/string'; export interface GoodsNavOptions { icon: string // 图标名称 text: string // 显示的文本 count?: string // 角标的值 countBackgroundColor?: string // 角标背景颜色 countFontColor?: string // 角标字体颜色 iconColor?: string // 图标颜色 textColor?: string // 文本颜色 avatar?: string // 显示头像(此时将不显示图标和文本) fontColor?: string; showAvatar?: boolean; showBadge?: boolean } export interface GoodsNavButtonGoup { text:string // 显示的文本 backgroundColor:string // 按钮背景颜色 color: string // 文本颜色 backgroundColorClass?: string colorClass?: string backgroundColorStyle?: string colorStyle?: string } export interface IState { // 保存选项数据 optionsData: Array // 保存按钮组数据 buttonGroupsData: Array } export const goodsNavProps = { // 选项信息 // 建议不超过3个 // { // icon: '', // 图标名称 // text: '', // 显示的文本 // count: '', // 角标的值 // countBackgroundColor: '', // 角标背景颜色 // countFontColor: '', // 角标字体颜色 // iconColor: '', // 图标颜色 // textColor: '', // 文本颜色 // avatar: '', // 显示头像(此时将不显示图标和文本) // } options: { type: Array as PropType, default() { return [{ icon: 'shop', text: '店铺' },{ icon: 'service', text: '客服' },{ icon: 'star', text: '收藏' }] } }, // 按钮组 // 建议不超过2个 // { // text: '', // 显示的文本 // backgroundColor: '', // 按钮背景颜色 // color: '' // 文本颜色 // } buttonGroups: { type: Array as PropType, default() { return [{ text: '加入购物车', backgroundColor: '#FFA726', color: '#FFFFFF' },{ text: '结算', backgroundColor: '#FF7043', color: '#FFFFFF' }] } }, // 背景颜色 backgroundColor: { type: String, default: '' }, // 导航的高度,单位rpx height: { type: Number, default: 0 }, // 显示阴影 shadow: { type: Boolean, default: false }, // 导航的层级 zIndex: { type: Number, default: 0 }, // 按钮类型 // rect -> 方形 paddingRect -> 上下带边距方形 round -> 圆角 buttonType: { type: String, default: 'rect' }, // 是否固定在底部 fixed: { type: Boolean, default: false }, // 是否开启底部安全区适配,开启的话,会在iPhoneX机型底部添加一定的内边距 safeAreaInsetBottom: { type: Boolean, default: false } } export const useGoodsNav = (props: ExtractPropTypes, state: IState) => { const backgroundColorStyle = computed(() => { return color.getBackgroundColorStyle(props.backgroundColor) }) const backgroundColorClass = computed(() => { return color.getBackgroundColorInternalClass(props.backgroundColor) }) const navStyle = computed(() => { let style: CSSProperties = {} if (props.height) { style.height = props.height + 'rpx' } style.zIndex = props.zIndex ? props.zIndex : Zindex.goodsNav return style }) // 选项style const optionStyle = (index: number, type: string) => { let style = reactive({}) const item = state.optionsData[index] if (type === 'icon' && item.iconColor) { style.color = item.iconColor } else if (type === 'text' && item.fontColor) { style.color = item.fontColor } return style } // 按钮class const buttonClass = (index: number) => { let clazz = reactive>({}) const item = state.buttonGroupsData[index] if (item.backgroundColorClass) { clazz[item.backgroundColorClass] = true } if (item.colorClass) { clazz[item.colorClass] = true } clazz[`buttons__item--${string.humpConvertChar(props.buttonType, '-')}`] = true return clazz } // 按钮style const buttonStyle = (index: number) => { let style = reactive({}) const item = state.buttonGroupsData[index] if (item.backgroundColorStyle) { style.backgroundColor = item.backgroundColorStyle } if (item.colorStyle) { style.color = item.colorStyle } return style } return { backgroundColorClass, backgroundColorStyle, navStyle, optionStyle, buttonClass, buttonStyle } }