feat:商品管理

This commit is contained in:
weiwei committed 2025-09-11 12:38:54 +08:00
1 parent f716bd685f
commit a64cda2312
9 files changed
+411 -91

No files matched your search

@@ -1,54 +1,72 @@
<script lang="ts" setup>
import { ref, computed, onMounted, onBeforeUnmount, watch, type PropType, getCurrentInstance, type ComponentInstance, onUpdated, nextTick, VueElement, inject } from 'vue';
import { arrayNumberValid, arrayNumberValidByStyleMP, covetUniNumber, arrayNumberValidByStyleBorderColor, linearValid, getUnit, getUid } from "../../libs/tool";
import { getDefaultColor, getDefaultColorObj, getOutlineColorObj, getTextColorObj, getThinColorObj } from "../../libs/colors";
import { useTmConfig } from "../../libs/config";
import pickerItem from './picker-item.vue';
import {
ref,
computed,
onMounted,
onBeforeUnmount,
watch,
type PropType,
getCurrentInstance,
type ComponentInstance,
onUpdated,
nextTick,
VueElement,
inject,
} from "vue"
import {
arrayNumberValid,
arrayNumberValidByStyleMP,
covetUniNumber,
arrayNumberValidByStyleBorderColor,
linearValid,
getUnit,
getUid,
} from "../../libs/tool"
import { getDefaultColor, getDefaultColorObj, getOutlineColorObj, getTextColorObj, getThinColorObj } from "../../libs/colors"
import { useTmConfig } from "../../libs/config"
import pickerItem from "./picker-item.vue"
const { config } = useTmConfig()
type TM_PICKER_X_ITEM = Record<string, any>
const boxHeight = ref(0)
const id = ('tmPickerItem-' + getUid())
const id = "tmPickerItem-" + getUid()
const nowCurrentIndex = ref([0])
let tid = 0
let tid2 = 1
const emits = defineEmits(['changeDeep'])
const emits = defineEmits(["changeDeep"])
const props = defineProps({
list: {
type: Array as PropType<TM_PICKER_X_ITEM[][]>,
default: (): TM_PICKER_X_ITEM[] => [] as TM_PICKER_X_ITEM[]
default: (): TM_PICKER_X_ITEM[] => [] as TM_PICKER_X_ITEM[],
},
selectedIndex: {
type: Array as PropType<number[]>,
default: (): number[] => [] as number[]
default: (): number[] => [] as number[],
},
cellUnits: {
type: Array as PropType<string[]>,
default: (): string[] => [] as string[]
default: (): string[] => [] as string[],
},
fontSize: {
type: String,
default: "30"
default: "30",
},
/**
* 自定义标识id
*/
rangKey: {
type: String,
default: "id"
default: "id",
},
/**
* 自定义标识文本字段名
*/
rangText: {
type: String,
default: "title"
default: "title",
},
})
const _fontSize = computed((): string => {
@@ -62,34 +80,28 @@ const _fontSize = computed((): string => {
return (sizeNumber * config.fontSizeScale).toString() + getUnit(props.fontSize)
})
const refreshKey = ref(12)
const _cellUnits = computed((): string[] => props.cellUnits as string[])
const _list = computed((): TM_PICKER_X_ITEM[][] => props.list.slice(0))
const _isDark = computed((): boolean => config.mode == 'dark')
const _isDark = computed((): boolean => config.mode == "dark")
const _maskStyle = computed((): string => {
if (_isDark.value) {
return 'background-image:linear-gradient(180deg,rgba(0, 0, 0, 0),rgba(0, 0, 0, 0)),linear-gradient(0deg, rgba(0, 0, 0, 0),rgba(0, 0, 0, 0))'
return "background-image:linear-gradient(180deg,rgba(0, 0, 0, 0),rgba(0, 0, 0, 0)),linear-gradient(0deg, rgba(0, 0, 0, 0),rgba(0, 0, 0, 0))"
}
return 'background-image:linear-gradient(180deg,rgba(255,255,255,0),rgba(255,255,255,0)),linear-gradient(0deg, rgba(255,255,255,0),rgba(255,255,255,0))'
return "background-image:linear-gradient(180deg,rgba(255,255,255,0),rgba(255,255,255,0)),linear-gradient(0deg, rgba(255,255,255,0),rgba(255,255,255,0))"
})
const _selectedMaskStyle = computed((): string => {
return _isDark.value ? 'rgba(255,255,255,0.05)' : 'rgba(0,0,0,0.05)'
return _isDark.value ? "rgba(255,255,255,0.05)" : "rgba(0,0,0,0.05)"
})
const onChange = (event: any) => {
if (event.detail.value.length == 0 || _list.value.length == 0) return;
let indexs = event.detail.value!;
if (indexs.join('') == nowCurrentIndex.value.join('')) return;
if (event.detail.value.length == 0 || _list.value.length == 0) return
let indexs = event.detail.value!
if (indexs.join("") == nowCurrentIndex.value.join("")) return
nowCurrentIndex.value = indexs
emits("changeDeep", indexs)
}
@@ -102,18 +114,21 @@ onBeforeUnmount(() => {
clearTimeout(tid2)
})
watch(() => props.selectedIndex, (newvalue: number[]) => {
if (newvalue.join('') == nowCurrentIndex.value.join('')) return;
nowCurrentIndex.value = newvalue.slice(0)
}, { deep: true })
watch(_list, (newvalue) => {
refreshKey.value += 1;
}, { deep: true })
watch(
() => props.selectedIndex,
(newvalue: number[]) => {
if (newvalue.join("") == nowCurrentIndex.value.join("")) return
nowCurrentIndex.value = newvalue.slice(0)
},
{ deep: true },
)
watch(
_list,
(newvalue) => {
refreshKey.value += 1
},
{ deep: true },
)
</script>
<script lang="ts">
export default {
@@ -123,29 +138,41 @@ export default {
addGlobalClass: true,
multipleSlots: true,
},
};
}
</script>
<template>
<view>
<view class="tmPickerViewUnit" v-if="_cellUnits.length > 0">
<view v-for="(item, index) in _cellUnits" :key="index" style="flex: 1;text-align: center;">
<view v-for="(item, index) in _cellUnits" :key="index" style="flex: 1; text-align: center">
<tm-text font-size="24" class="tmPickerViewUnitText">{{ item }}</tm-text>
</view>
</view>
<picker-view :key="refreshKey" :immediate-change="true" :value="nowCurrentIndex" @change="onChange"
:style="{ height: '250px', width: '100%' }" :mask-style="`${_maskStyle}`"
:indicator-style="`height:50px;border:none;border-radius:10px`">
<picker-view
:key="refreshKey"
:immediate-change="true"
:value="nowCurrentIndex"
@change="onChange"
:style="{ height: '250px', width: '100%' }"
:mask-style="`${_maskStyle}`"
:indicator-style="`height:50px;border:none;border-radius:10px`"
>
<picker-view-column v-for="(item2, index2) in _list" :key="index2">
<view
:style="{ background: nowCurrentIndex[index2] == index ? _selectedMaskStyle : 'none', margin: '0 4px' }"
v-for="(item, index) in item2" :key="index" class="tmPickerViewWrapCoumn">
<text class="tmPickerViewWrapCoumnText" :style="{
fontSize: _fontSize,
lineHeight: 1,
fontWeight: nowCurrentIndex[index2] == index ? 'bold' : 'inherit',
opacity: item.disabled ? 0.4 : (nowCurrentIndex[index2] == index ? 1 : 0.6),
color: _isDark ? 'rgba(255,255,255,0.8)' : '#000000'
}">
v-for="(item, index) in item2"
:key="index"
class="tmPickerViewWrapCoumn"
>
<text
class="tmPickerViewWrapCoumnText"
:style="{
fontSize: _fontSize,
lineHeight: 1,
fontWeight: nowCurrentIndex[index2] == index ? 'bold' : 'inherit',
opacity: item.disabled ? 0.4 : nowCurrentIndex[index2] == index ? 1 : 0.6,
color: _isDark ? 'rgba(255,255,255,0.8)' : '#000000',
}"
>
{{ item[rangText] || "" }}
</text>
</view>
@@ -183,7 +210,6 @@ export default {
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
}
.tmPickerView {
@@ -221,7 +247,6 @@ export default {
border-radius: 10px;
margin: 0 3px;
flex: 1;
}
.tmPickerContent {
@@ -239,4 +264,4 @@ export default {
border-radius: 10px;
/* background-color: #f5f5f5; */
}
</style>
</style>