111
This commit is contained in:
1 parent
544fb32762
commit
b85ec93e7a
10 files changed
+379
-46
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, onMounted, onBeforeUnmount, watch, PropType, getCurrentInstance, ComponentInstance, onUpdated, nextTick, VueElement, inject } from '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";
|
||||
@@ -54,7 +54,7 @@ const props = defineProps({
|
||||
* 当前选中项的id值
|
||||
*/
|
||||
modelValue: {
|
||||
type: Array<string|number>,
|
||||
type: Array<string | number>,
|
||||
default: (): string[] => [] as string[]
|
||||
},
|
||||
/**
|
||||
@@ -96,7 +96,7 @@ const props = defineProps({
|
||||
|
||||
const _cellUnits = computed(() => props.cellUnits)
|
||||
const _list = computed(() => props.list)
|
||||
const _nowShowList = ref<Record<string,any>[][]>([])
|
||||
const _nowShowList = ref<Record<string, any>[][]>([])
|
||||
const _maxDeep = computed(() => {
|
||||
if (_list.value.length == 0) return 0;
|
||||
function getdiepWidth(list: TM_PICKER_X_ITEM[]): number {
|
||||
@@ -114,28 +114,28 @@ const _maxDeep = computed(() => {
|
||||
const oninitFun = () => {
|
||||
nowValue.value = props.modelValue.slice(0)
|
||||
let currneinexs = getIndexsByids(nowValue.value).indexs;
|
||||
_modelValueIndex.value = nowValue.value.length==0||currneinexs.length==0?new Array(_maxDeep.value).fill(0):currneinexs;
|
||||
const {data,strs,ids} = getIdsByindexs(_modelValueIndex.value)
|
||||
_modelValueIndex.value = nowValue.value.length == 0 || currneinexs.length == 0 ? new Array(_maxDeep.value).fill(0) : currneinexs;
|
||||
const { data, strs, ids } = getIdsByindexs(_modelValueIndex.value)
|
||||
_nowShowList.value = data.slice(0)
|
||||
if(nowValue.value.length==0){
|
||||
nowValue.value = ids.slice(0)
|
||||
nextTick(()=>{
|
||||
emits('update:modelStr', strs.join(","))
|
||||
emits('update:modelValue', ids.slice(0))
|
||||
|
||||
})
|
||||
if (nowValue.value.length == 0) {
|
||||
nowValue.value = ids.slice(0)
|
||||
nextTick(() => {
|
||||
emits('update:modelStr', strs.join(","))
|
||||
emits('update:modelValue', ids.slice(0))
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
const change = (ixs: number[]) => {
|
||||
|
||||
const {ids,data,strs} = getIdsByindexs(ixs)
|
||||
|
||||
const { ids, data, strs } = getIdsByindexs(ixs)
|
||||
_modelValueIndex.value = getIndexsByids(ids).indexs;
|
||||
_nowShowList.value = data.slice(0)
|
||||
nowValue.value = ids;
|
||||
|
||||
|
||||
/**
|
||||
* 等同v-model
|
||||
*/
|
||||
@@ -148,14 +148,14 @@ const change = (ixs: number[]) => {
|
||||
|
||||
|
||||
// 根据id返回索引
|
||||
const getIndexsByids = (ids:Array<string|number>):{indexs:Array<number>,data:TM_PICKER_X_ITEM[][],strs:string[]}=> {
|
||||
const getIndexsByids = (ids: Array<string | number>): { indexs: Array<number>, data: TM_PICKER_X_ITEM[][], strs: string[] } => {
|
||||
let index = 0;
|
||||
let val = ids.slice(0)
|
||||
let indexs = [] as number[]
|
||||
let data = [] as TM_PICKER_X_ITEM[][]
|
||||
let strs = [] as string[]
|
||||
|
||||
if(_list.value.length==0||ids.length==0) return {indexs:[],data:[],strs:[]}
|
||||
if (_list.value.length == 0 || ids.length == 0) return { indexs: [], data: [], strs: [] }
|
||||
|
||||
function getIndex(nodes: TM_PICKER_X_ITEM[]) {
|
||||
if (val.length <= index || val.length == 0) return;
|
||||
@@ -176,47 +176,47 @@ const getIndexsByids = (ids:Array<string|number>):{indexs:Array<number>,data:TM_
|
||||
}
|
||||
}
|
||||
getIndex(_list.value)
|
||||
return {indexs,data,strs}
|
||||
return { indexs, data, strs }
|
||||
}
|
||||
//根据索引返回ids
|
||||
const getIdsByindexs = (indexs:number[]):{ids:Array<string|number>,data:TM_PICKER_X_ITEM[][],strs:string[]} => {
|
||||
const getIdsByindexs = (indexs: number[]): { ids: Array<string | number>, data: TM_PICKER_X_ITEM[][], strs: string[] } => {
|
||||
let ids = [] as string[]
|
||||
let data = [] as TM_PICKER_X_ITEM[][]
|
||||
let index = 0;
|
||||
let val = indexs.slice(0)
|
||||
let strs = [] as string[]
|
||||
|
||||
if(_list.value.length==0||indexs.length==0) return {ids:[],data:[],strs:[]}
|
||||
|
||||
if (_list.value.length == 0 || indexs.length == 0) return { ids: [], data: [], strs: [] }
|
||||
function getIds(nodes: TM_PICKER_X_ITEM[]) {
|
||||
if (val.length <= index || val.length == 0) return;
|
||||
let currentsIndex = val[index]
|
||||
let id = ''
|
||||
let str = ''
|
||||
let children = [];
|
||||
if(nodes.length-1 >= currentsIndex){
|
||||
if (nodes.length - 1 >= currentsIndex) {
|
||||
id = nodes[currentsIndex][props.rangKey]
|
||||
str = nodes[currentsIndex][props.rangText]
|
||||
children = nodes[currentsIndex]?.children??[]
|
||||
}else{
|
||||
children = nodes[currentsIndex]?.children ?? []
|
||||
} else {
|
||||
id = nodes[0][props.rangKey]
|
||||
str = nodes[0][props.rangText]
|
||||
children = nodes[0]?.children??[]
|
||||
children = nodes[0]?.children ?? []
|
||||
}
|
||||
ids.push(id)
|
||||
data.push(nodes)
|
||||
strs.push(str)
|
||||
|
||||
if(children.length>0){
|
||||
if (children.length > 0) {
|
||||
index += 1
|
||||
getIds(children)
|
||||
}
|
||||
}
|
||||
getIds(_list.value)
|
||||
return {ids,data,strs};
|
||||
return { ids, data, strs };
|
||||
}
|
||||
|
||||
const getNowCurrent = ()=>{
|
||||
return getIdsByindexs(_modelValueIndex.value)
|
||||
const getNowCurrent = () => {
|
||||
return getIdsByindexs(_modelValueIndex.value)
|
||||
}
|
||||
// 获取相关数据。
|
||||
|
||||
@@ -233,11 +233,11 @@ onBeforeUnmount(() => {
|
||||
watch(() => props.modelValue, (newValue: Array<string | number>) => {
|
||||
if (newValue.join('') == nowValue.value.join('')) return;
|
||||
nowValue.value = newValue.slice(0);
|
||||
|
||||
let defauleindexs = nowValue.value.length==0?new Array(_maxDeep.value).fill(0):getIndexsByids(nowValue.value).indexs;
|
||||
|
||||
let defauleindexs = nowValue.value.length == 0 ? new Array(_maxDeep.value).fill(0) : getIndexsByids(nowValue.value).indexs;
|
||||
_modelValueIndex.value = defauleindexs;
|
||||
|
||||
const {data,strs} = getIdsByindexs(_modelValueIndex.value)
|
||||
const { data, strs } = getIdsByindexs(_modelValueIndex.value)
|
||||
_nowShowList.value = data.slice(0)
|
||||
emits('update:modelStr', strs.join(","))
|
||||
|
||||
@@ -248,7 +248,7 @@ watch(() => props.list, (newValue) => {
|
||||
oninitFun()
|
||||
}, { deep: true })
|
||||
|
||||
defineExpose({getIndexsByids,getIdsByindexs,getNowCurrent,onInit:oninitFun})
|
||||
defineExpose({ getIndexsByids, getIdsByindexs, getNowCurrent, onInit: oninitFun })
|
||||
|
||||
</script>
|
||||
<script lang="ts">
|
||||
@@ -263,14 +263,11 @@ export default {
|
||||
</script>
|
||||
<template>
|
||||
<view class="tmPickerView">
|
||||
<picker-item :rangKey="props.rangKey" :rangText="props.rangText"
|
||||
:font-size="props.fontSize" :cellUnits="_cellUnits" @changeDeep="change"
|
||||
:selectedIndex="_modelValueIndex" :list="_nowShowList"
|
||||
<picker-item :rangKey="props.rangKey" :rangText="props.rangText" :font-size="props.fontSize"
|
||||
:cellUnits="_cellUnits" @changeDeep="change" :selectedIndex="_modelValueIndex" :list="_nowShowList"
|
||||
class="tmPickerViewItem"></picker-item>
|
||||
</view>
|
||||
</template>
|
||||
<style scoped>
|
||||
.tmPickerView {
|
||||
|
||||
}
|
||||
.tmPickerView {}
|
||||
</style>
|
||||
Reference in new issue
Block a user