acdr-ui/dist/dev/mp-weixin/node-modules/wot-design-uni/components/wd-picker-view/wd-picker-view.js.map

1 line
16 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{"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)\n value.forEach((target, col) => {\n let row = formatColumns.value[col].findIndex((row) => {\n return row[props.valueKey].toString() === target.toString()\n })\n row = row === -1 ? 0 : row\n selected = correctSelectedIndex(col, row, selected)\n })\n /** 根据formatColumns的长度去除selectWithIndex无用的部分。\n * 始终保持value、selectWithIndex、formatColumns长度一致\n */\n selectedIndex.value = selected.slice(0, value.length)\n}\n\n/**\n * 修正选中项的值\n * @param value 当前picker选择器选中的值\n * @param origin 原始选中的值\n */\nfunction correctSelected(value: number[]) {\n let selected = deepClone(value)\n value.forEach((row, col) => {\n row = range(row, 0, formatColumns.value[col].length - 1)\n selected = correctSelectedIndex(col, row, selected)\n })\n return selected\n}\n\n/**\n * 修正选中项指定列行的值\n * @param columnIndex 列下标\n * @param rowIndex 行下标\n * @param selected 选中值列表\n */\nfunction correctSelectedIndex(columnIndex: number, rowIndex: number, selected: number[]) {\n const col = formatColumns.value[columnIndex]\n if (!col || !col[rowIndex]) {\n throw Error(`The value to select with Col:${columnIndex} Row:${rowIndex} is incorrect`)\n }\n const select: number[] = deepClone(selected)\n select[columnIndex] = rowIndex\n\n // 被禁用的无法选中,选中距离它最近的未被禁用的\n if (col[rowIndex].disabled) {\n // 寻找值为0或最最近的未被禁用的节点的索引\n const prev = col\n .slice(0, rowIndex)\n .reverse()\n .findIndex((s) => !s.disabled)\n const next = col.slice(rowIndex + 1).findIndex((s) => !s.disabled)\n if (prev !== -1) {\n select[columnIndex] = rowIndex - 1 - prev\n } else if (next !== -1) {\n select[columnIndex] = rowIndex + 1 + next\n } else if (select[columnIndex] === undefined) {\n select[columnIndex] = 0\n }\n }\n return select\n}\n\n/**\n * 选择器选中项变化时触发\n * @param param0\n */\nfunction onChange({ detail: { value } }: { detail: { value: number[] } }) {\n value = value.map((v: any) => {\n return Number(v || 0)\n })\n const index = getChangeDiff(value)\n // 先将picker选择器的值赋给selectedIndex然后重新赋予修正后的值防止两次操作修正结果一致时pikcer视图不刷新\n selectedIndex.value = deepClone(value)\n nextTick(() => {\n // 重新赋予修正后的值\n selectedIndex.value = correctSelected(value)\n if (props.columnChange) {\n // columnsChange 可能有异步操作,需要添加 resolve 进行回调通知形参小于4个则为同步\n if (props.columnChange.length < 4) {\n props.columnChange(proxy.$.exposed, getSelects(), index || 0, () => {})\n handleChange(index || 0)\n } else {\n props.columnChange(proxy.$.exposed, getSelects(), index || 0, () => {\n // 如果selectedIndex只有一列返回此项如果是多项返回所有选中项。\n handleChange(index || 0)\n })\n }\n } else {\n // 如果selectedIndex只有一列返回此项如果是多项返回所有选中项。\n handleChange(index || 0)\n }\n })\n}\n\n/**\n * 获取选中项变化的列的下标\n * @param now 当前选中项值\n * @param origin 旧选中项值\n */\nfunction getChangeColumn(now: number[], origin: number[]) {\n if (!now || !origin) return -1\n const index = now.findIndex((row, index) => row !== origin[index])\n return index\n}\n\nfunction getChangeDiff(value: number[]) {\n value = value.slice(0, formatColumns.value.length)\n\n // 保留选中前的\n const origin: number[] = deepClone(selectedIndex.value)\n // 存储赋值旧值,便于外部比较\n let selected: number[] = deepClone(selectedIndex.value)\n\n value.forEach((row, col) => {\n row = range(row, 0, formatColumns.value[col].length - 1)\n if (row === origin[col]) return\n selected = correctSelectedIndex(col, row, selected)\n })\n\n // 值变化的列\n const diffCol = getChangeColumn(selected, origin)\n if (diffCol === -1) return\n\n // 获取变化的的行\n const diffRow = selected[diffCol]\n\n // 如果selectedIndex只有一列返回选中项的索引如果是多项返回选中项所在的列。\n return selected.length === 1 ? diffRow : diffCol\n}\n\n/**\n * 列更新\n * @param index 列下标\n */\nfunction handleChange(index: number) {\n const value = getValues()\n\n // 避免多次触发change\n if (isEqual(value, props.modelValue)) return\n\n emit('update:modelValue', value)\n // 延迟一下,避免组件刚渲染时调用者的事件未初始化好\n setTimeout(() => {\n emit('change', {\n picker: proxy.$.exposed,\n value,\n index\n })\n }, 0)\n}\n\n/**\n * @description 获取所有列选中项,返回值为一个数组\n */\nfunction getSelects() {\n const selects = selectedIndex.value.map((row, col) => formatColumns.value[col][row])\n // 单列选择器,则返回单项\n if (selects.length === 1) {\n return selects[0]\n }\n return selects\n}\n\n/**\n * 获取所有列的选中值\n * 如果values只有一项则将第一项返回\n */\nfunction getValues() {\n const { valueKey } = props\n const values = selectedIndex.value.map((row, col) => {\n return formatColumns.value[col][row][valueKey]\n })\n\n if (values.length === 1) {\n return values[0]\n }\n return values\n}\n\n/**\n * 获取所有列选中项的label返回值为一个数组\n */\nfunction getLabels() {\n const { labelKey } = props\n return selectedIndex.value.map((row, col) => formatColumns.value[col][row][labelKey])\n}\n\n/**\n * 获取某一列的选中项下标\n * @param {Number} columnIndex 列的下标\n * @returns {Number} 下标\n */\nfunction getColumnIndex(columnIndex: number) {\n return selectedIndex.value[columnIndex]\n}\n\n/**\n * 获取某一列的选项\n * @param {Number} columnIndex 列的下标\n * @returns {Array<{valueKey,labelKey}>} 当前列的集合\n */\nfunction getColumnData(columnIndex: number) {\n return formatColumns.value[columnIndex]\n}\n\n/**\n * 设置列数据\n * @param columnIndex 列下标\n * @param data // 列数据\n * @param rowIndex // 行下标\n */\nfunction setColumnData(columnIndex: number, data: Array<string | number | ColumnItem | Array<string | number | ColumnItem>>, rowIndex: number = 0) {\n formatColumns.value[columnIndex] = formatArray(data, props.valueKey, props.labelKey).reduce((acc, val) => acc.concat(val), [])\n selectedIndex.value = correctSelectedIndex(columnIndex, rowIndex, selectedIndex.value)\n}\n\n/**\n * 获取列数据\n */\nfunction getColumnsData() {\n return deepClone(formatColumns.value)\n}\n\n/**\n * 获取选中数据\n */\nfunction getSelectedIndex() {\n return selectedIndex.value\n}\n\nfunction onPickStart() {\n emit('pickstart')\n}\n\nfunction onPickEnd() {\n emit('pickend')\n}\n\ndefineExpose<PickerViewExpose>({\n getSelects,\n getValues,\n setColumnData,\n getColumnsData,\n getColumnData,\n getColumnIndex,\n getLabels,\n getSelectedIndex\n})\n</script>\n<style lang=\"scss\" scoped>\n@import './index.scss';\n</style>\n","import Component from 'D:/App/Work/addr/acdr-ui/node_modules/wot-design-uni/components/wd-picker-view/wd-picker-view.vue'\nwx.createComponent(Component)"],"names":["ref","watch","isEqual","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