1 line
16 KiB
Plaintext
1 line
16 KiB
Plaintext
|
{"version":3,"file":"wd-picker-view.js","sources":["../../../../../../../node_modules/wot-design-uni/components/wd-picker-view/wd-picker-view.vue","../../../../../../../uniComponent:/RDovQXBwL1dvcmsvYWRkci9hY2RyLXVpL25vZGVfbW9kdWxlcy93b3QtZGVzaWduLXVuaS9jb21wb25lbnRzL3dkLXBpY2tlci12aWV3L3dkLXBpY2tlci12aWV3LnZ1ZQ"],"sourcesContent":["<template>\n <view :class=\"`wd-picker-view ${customClass}`\" :style=\"customStyle\">\n <view class=\"wd-picker-view__loading\" v-if=\"loading\">\n <wd-loading :color=\"loadingColor\" />\n </view>\n <view :style=\"`height: ${columnsHeight - 20}px;`\">\n <picker-view\n mask-class=\"wd-picker-view__mask\"\n indicator-class=\"wd-picker-view__roller\"\n :indicator-style=\"`height: ${itemHeight}px;`\"\n :style=\"`height: ${columnsHeight - 20}px;`\"\n :value=\"selectedIndex\"\n :immediate-change=\"immediateChange\"\n @change=\"onChange\"\n @pickstart=\"onPickStart\"\n @pickend=\"onPickEnd\"\n >\n <picker-view-column v-for=\"(col, colIndex) in formatColumns\" :key=\"colIndex\" class=\"wd-picker-view-column\">\n <view\n v-for=\"(row, rowIndex) in col\"\n :key=\"rowIndex\"\n :class=\"`wd-picker-view-column__item ${row['disabled'] ? 'wd-picker-view-column__item--disabled' : ''} ${\n selectedIndex[colIndex] == rowIndex ? 'wd-picker-view-column__item--active' : ''\n }`\"\n :style=\"`line-height: ${itemHeight}px;`\"\n >\n {{ row[labelKey] }}\n </view>\n </picker-view-column>\n </picker-view>\n </view>\n </view>\n</template>\n\n<script lang=\"ts\">\nexport default {\n name: 'wd-picker-view',\n options: {\n virtualHost: true,\n addGlobalClass: true,\n styleIsolation: 'shared'\n }\n}\n</script>\n<script lang=\"ts\" setup>\nimport { getCurrentInstance, ref, watch, nextTick } from 'vue'\nimport { deepClone, getType, isArray, isDef, isEqual, range } from '../common/util'\nimport { formatArray, pickerViewProps, type ColumnItem, type PickerViewExpose } from './types'\n\nconst props = defineProps(pickerViewProps)\nconst emit = defineEmits(['change', 'pickstart', 'pickend', 'update:modelValue'])\n\nconst formatColumns = ref<ColumnItem[][]>([]) // 格式化后的列数据\nconst itemHeight = ref<number>(35)\nconst selectedIndex = ref<Array<number>>([]) // 格式化之后,每列选中的下标集合\n\nwatch(\n [() => props.modelValue, () => props.columns],\n (newValue, oldValue) => {\n if (!isEqual(oldValue[1], newValue[1])) {\n formatColumns.value = formatArray(newValue[1], props.valueKey, props.labelKey)\n }\n if (!isEqual(oldValue[0], newValue[0]) && isDef(newValue[0])) {\n selectWithValue(newValue[0])\n }\n },\n {\n deep: true,\n immediate: true\n }\n)\n\nconst { proxy } = getCurrentInstance() as any\n\n/**\n * 根据传入的value,寻找对应的索引,并传递给原生选择器。\n * 需要保证formatColumns先设置,之后会修改selectedIndex。\n * @param {String|Number|Boolean|Array<String|Number|Boolean|Array<any>>}value\n */\nfunction selectWithValue(value: string | number | boolean | number[] | string[] | boolean[]) {\n if (formatColumns.value.length === 0) return\n\n // 使其默认选中首项\n if (value === '' || !isDef(value) || (isArray(value) && value.length === 0)) {\n value = formatColumns.value.map((col) => {\n return col[0][props.valueKey]\n })\n }\n const valueType = getType(value)\n const type = ['string', 'number', 'boolean', 'array']\n if (type.indexOf(valueType) === -1) console.error(`value must be one of ${type.toString()}`)\n\n /**\n * 1.单key转为Array<key>\n * 2.根据formatColumns的长度截取Array<String>,保证下面的遍历不溢出\n * 3.根据每列的key值找到选项中value为此key的下标并记录\n */\n value = isArray(value) ? value : [value as string]\n value = value.slice(0, formatColumns.value.length)\n\n let selected: number[] = deepClone(selectedIndex.value
|