1 line
17 KiB
Plaintext
1 line
17 KiB
Plaintext
{"version":3,"file":"wd-picker.js","sources":["../../../../../../../node_modules/wot-design-uni/components/wd-picker/wd-picker.vue","../../../../../../../uniComponent:/RDovQXBwL1dvcmsvYWRkci9hY2RyLXVpL25vZGVfbW9kdWxlcy93b3QtZGVzaWduLXVuaS9jb21wb25lbnRzL3dkLXBpY2tlci93ZC1waWNrZXIudnVl"],"sourcesContent":["<template>\n <view\n :class=\"`wd-picker ${disabled ? 'is-disabled' : ''} ${size ? 'is-' + size : ''} ${cell.border.value ? 'is-border' : ''} ${\n alignRight ? 'is-align-right' : ''\n } ${error ? 'is-error' : ''} ${customClass}`\"\n :style=\"customStyle\"\n >\n <view class=\"wd-picker__field\" @click=\"showPopup\">\n <slot v-if=\"useDefaultSlot\"></slot>\n <view v-else class=\"wd-picker__cell\">\n <view\n v-if=\"label || useLabelSlot\"\n :class=\"`wd-picker__label ${customLabelClass} ${isRequired ? 'is-required' : ''}`\"\n :style=\"labelWidth ? 'min-width:' + labelWidth + ';max-width:' + labelWidth + ';' : ''\"\n >\n <template v-if=\"label\">{{ label }}</template>\n <slot v-else name=\"label\"></slot>\n </view>\n <view class=\"wd-picker__body\">\n <view class=\"wd-picker__value-wraper\">\n <view :class=\"`wd-picker__value ${ellipsis && 'is-ellipsis'} ${customValueClass} ${showValue ? '' : 'wd-picker__placeholder'}`\">\n {{ showValue ? showValue : placeholder || translate('placeholder') }}\n </view>\n <wd-icon v-if=\"!disabled && !readonly\" custom-class=\"wd-picker__arrow\" name=\"arrow-right\" />\n </view>\n <view v-if=\"errorMessage\" class=\"wd-picker__error-message\">{{ errorMessage }}</view>\n </view>\n </view>\n </view>\n <wd-popup\n v-model=\"popupShow\"\n position=\"bottom\"\n :hide-when-close=\"false\"\n :close-on-click-modal=\"closeOnClickModal\"\n :z-index=\"zIndex\"\n :safe-area-inset-bottom=\"safeAreaInsetBottom\"\n @close=\"onCancel\"\n custom-class=\"wd-picker__popup\"\n >\n <view class=\"wd-picker__wraper\">\n <view class=\"wd-picker__toolbar\" @touchmove=\"noop\">\n <view class=\"wd-picker__action wd-picker__action--cancel\" @click=\"onCancel\">\n {{ cancelButtonText || translate('cancel') }}\n </view>\n <view v-if=\"title\" class=\"wd-picker__title\">{{ title }}</view>\n <view :class=\"`wd-picker__action ${isLoading ? 'is-loading' : ''}`\" @click=\"onConfirm\">\n {{ confirmButtonText || translate('done') }}\n </view>\n </view>\n <wd-picker-view\n ref=\"pickerViewWd\"\n :custom-class=\"customViewClass\"\n v-model=\"pickerValue\"\n :columns=\"displayColumns\"\n :loading=\"isLoading\"\n :loading-color=\"loadingColor\"\n :columns-height=\"columnsHeight\"\n :value-key=\"valueKey\"\n :label-key=\"labelKey\"\n :immediate-change=\"immediateChange\"\n @change=\"pickerViewChange\"\n @pickstart=\"onPickStart\"\n @pickend=\"onPickEnd\"\n :column-change=\"columnChange\"\n />\n </view>\n </wd-popup>\n </view>\n</template>\n\n<script lang=\"ts\">\nexport default {\n name: 'wd-picker',\n options: {\n virtualHost: true,\n addGlobalClass: true,\n styleIsolation: 'shared'\n }\n}\n</script>\n\n<script lang=\"ts\" setup>\nimport { getCurrentInstance, onBeforeMount, ref, watch, computed, onMounted, nextTick } from 'vue'\nimport { deepClone, defaultDisplayFormat, getType, isArray, isDef, isFunction } from '../common/util'\nimport { useCell } from '../composables/useCell'\nimport { type ColumnItem, formatArray, type PickerViewInstance } from '../wd-picker-view/types'\nimport { FORM_KEY, type FormItemRule } from '../wd-form/types'\nimport { useParent } from '../composables/useParent'\nimport { useTranslate } from '../composables/useTranslate'\nimport { pickerProps, type PickerExpose } from './types'\nconst { translate } = useTranslate('picker')\n\nconst props = defineProps(pickerProps)\nconst emit = defineEmits(['confirm', 'open', 'cancel', 'update:modelValue'])\n\nconst pickerViewWd = ref<PickerViewInstance | null>(null)\nconst cell = useCell()\n\nconst innerLoading = ref<boolean>(false) // 内部控制是否loading\n\n// 弹出层是否显示\nconst popupShow = ref<boolean>(false)\n// 选定后展示的选中项\nconst showValue = ref<string>('')\nconst pickerValue = ref<string | number | boolean | string[] | number[] | boolean[]>('')\nconst displayColumns = ref<Array<string | number | ColumnItem | Array<string | number | ColumnItem>>>([]) // 传入 pickerView 的columns\nconst resetColumns = ref<Array<string | number | ColumnItem | Array<string | number | ColumnItem>>>([]) // 保存之前的 columns,当取消时,将数据源回滚,避免多级联动数据源不正确的情况\nconst isPicking = ref<boolean>(false) // 判断pickview是否还在滑动中\nconst hasConfirmed = ref<boolean>(false) // 判断用户是否点击了确认按钮\n\nconst isLoading = computed(() => {\n return props.loading || innerLoading.value\n})\n\nwatch(\n () => props.displayFormat,\n (fn) => {\n if (fn && !isFunction(fn)) {\n console.error('The type of displayFormat must be Function')\n }\n if (pickerViewWd.value && pickerViewWd.value.getSelectedIndex().length !== 0) {\n handleShowValueUpdate(props.modelValue)\n }\n },\n {\n immediate: true,\n deep: true\n }\n)\n\nwatch(\n () => props.modelValue,\n (newValue) => {\n pickerValue.value = newValue\n // 获取初始选中项,并展示初始选中文案\n handleShowValueUpdate(newValue)\n },\n {\n deep: true,\n immediate: true\n }\n)\n\nwatch(\n () => props.columns,\n (newValue) => {\n displayColumns.value = deepClone(newValue)\n resetColumns.value = deepClone(newValue)\n // 获取初始选中项,并展示初始选中文案\n handleShowValueUpdate(props.modelValue)\n },\n {\n deep: true,\n immediate: true\n }\n)\n\nwatch(\n () => props.columnChange,\n (newValue) => {\n if (newValue && !isFunction(newValue)) {\n console.error('The type of columnChange must be Function')\n }\n },\n {\n deep: true,\n immediate: true\n }\n)\n\nconst { parent: form } = useParent(FORM_KEY)\n\n// 表单校验错误信息\nconst errorMessage = computed(() => {\n if (form && props.prop && form.errorMessages && form.errorMessages[props.prop]) {\n return form.errorMessages[props.prop]\n } else {\n return ''\n }\n})\n\n// 是否展示必填\nconst isRequired = computed(() => {\n let formRequired = false\n if (form && form.props.rules) {\n const rules = form.props.rules\n for (const key in rules) {\n if (Object.prototype.hasOwnProperty.call(rules, key) && key === props.prop && Array.isArray(rules[key])) {\n formRequired = rules[key].some((rule: FormItemRule) => rule.required)\n }\n }\n }\n return props.required || props.rules.some((rule) => rule.required) || formRequired\n})\n\nconst { proxy } = getCurrentInstance() as any\n\nonMounted(() => {\n handleShowValueUpdate(props.modelValue)\n})\n\nonBeforeMount(() => {\n displayColumns.value = deepClone(props.columns)\n resetColumns.value = deepClone(props.columns)\n})\n\n/**\n * 值变更时更新显示内容\n * @param value\n */\nfunction handleShowValueUpdate(value: string | number | Array<string | number>) {\n // 获取初始选中项,并展示初始选中文案\n if ((isArray(value) && value.length > 0) || (isDef(value) && !isArray(value) && value !== '')) {\n if (pickerViewWd.value) {\n nextTick(() => {\n setShowValue(pickerViewWd.value!.getSelects())\n })\n } else {\n setShowValue(getSelects(value)!)\n }\n } else {\n showValue.value = ''\n }\n}\n\n/**\n * @description 根据传入的value,picker组件获取当前cell展示值。\n * @param {String|Number|Array<String|Number|Array<any>>}value\n */\nfunction getSelects(value: string | number | Array<string | number | Array<any>>) {\n const formatColumns = formatArray(props.columns, props.valueKey, props.labelKey)\n if (props.columns.length === 0) return\n\n // 使其默认选中首项\n if (value === '' || !isDef(value) || (isArray(value) && value.length === 0)) {\n return\n }\n const valueType = getType(value)\n const type = ['string', 'number', 'boolean', 'array']\n if (type.indexOf(valueType) === -1) return []\n /**\n * 1.单key转为Array<key>\n * 2.根据formatColumns的长度截取Array<String>,保证下面的遍历不溢出\n * 3.根据每列的key值找到选项中value为此key的下标并记录\n */\n value = isArray(value) ? value : [value]\n value = value.slice(0, formatColumns.length)\n\n if (value.length === 0) {\n value = formatColumns.map(() => 0)\n }\n let selected: number[] = []\n value.forEach((target, col) => {\n let row = formatColumns[col].findIndex((row) => {\n return row[props.valueKey].toString() === target.toString()\n })\n row = row === -1 ? 0 : row\n selected.push(row)\n })\n\n const selects = selected.map((row, col) => formatColumns[col][row])\n // 单列选择器,则返回单项\n if (selects.length === 1) {\n return selects[0]\n }\n return selects\n}\n\n// 对外暴露方法,打开弹框\nfunction open() {\n showPopup()\n}\n// 对外暴露方法,关闭弹框\nfunction close() {\n onCancel()\n}\n/**\n * 展示popup\n */\nfunction showPopup() {\n if (props.disabled || props.readonly) return\n\n emit('open')\n popupShow.value = true\n pickerValue.value = props.modelValue\n displayColumns.value = resetColumns.value\n}\n\n/**\n * 点击取消按钮触发。关闭popup,触发cancel事件。\n */\nfunction onCancel() {\n popupShow.value = false\n emit('cancel')\n}\n/**\n * 点击确定按钮触发。展示选中值,触发cancel事件。\n */\nfunction onConfirm() {\n if (isLoading.value) return\n\n // 如果当前还在滑动且未停止下来,则锁住先不确认,等滑完再自动确认,避免pickview值未更新\n if (isPicking.value) {\n hasConfirmed.value = true\n return\n }\n\n const { beforeConfirm } = props\n if (beforeConfirm && isFunction(beforeConfirm)) {\n beforeConfirm(\n pickerValue.value,\n (isPass: boolean) => {\n isPass && handleConfirm()\n },\n proxy.$.exposed\n )\n } else {\n handleConfirm()\n }\n}\nfunction handleConfirm() {\n if (isLoading.value || props.disabled) {\n popupShow.value = false\n return\n }\n\n const selects = pickerViewWd.value!.getSelects()\n const values = pickerViewWd.value!.getValues()\n // 获取当前的数据源,并设置给 resetColumns,用于取消时可以回退数据源\n const columns = pickerViewWd.value!.getColumnsData()\n popupShow.value = false\n resetColumns.value = deepClone(columns)\n emit('update:modelValue', values)\n\n setShowValue(selects)\n emit('confirm', {\n value: values,\n selectedItems: selects\n })\n}\n/**\n * 初始change事件\n * @param event\n */\nfunction pickerViewChange({ value }: any) {\n pickerValue.value = value\n}\n/**\n * 设置展示值\n * @param items\n */\nfunction setShowValue(items: ColumnItem | ColumnItem[]) {\n // 避免值为空时调用自定义展示函数\n if ((isArray(items) && !items.length) || !items) return\n\n const { valueKey, labelKey } = props\n showValue.value = (props.displayFormat || defaultDisplayFormat)(items, { valueKey, labelKey })\n}\nfunction noop() {}\nfunction onPickStart() {\n isPicking.value = true\n}\nfunction onPickEnd() {\n isPicking.value = false\n\n if (hasConfirmed.value) {\n hasConfirmed.value = false\n onConfirm()\n }\n}\n\n/**\n * 外部设置是否loading\n * @param loading 是否loading\n */\nfunction setLoading(loading: boolean) {\n innerLoading.value = loading\n}\n\ndefineExpose<PickerExpose>({\n close,\n open,\n setLoading\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/wd-picker.vue'\nwx.createComponent(Component)"],"names":["useTranslate","ref","useCell","computed","watch","isFunction","deepClone","useParent","FORM_KEY","getCurrentInstance","onMounted","onBeforeMount","isArray","isDef","nextTick","formatArray","getType","row","defaultDisplayFormat"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAA,cAAe;AAAA,EACb,MAAM;AAAA,EACN,SAAS;AAAA,IACP,aAAa;AAAA,IACb,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,EAClB;AACF;;;;;AAYA,UAAM,EAAE,UAAA,IAAcA,cAAA,aAAa,QAAQ;AAE3C,UAAM,QAAQ;AACd,UAAM,OAAO;AAEP,UAAA,eAAeC,kBAA+B,IAAI;AACxD,UAAM,OAAOC,cAAAA;AAEP,UAAA,eAAeD,kBAAa,KAAK;AAGjC,UAAA,YAAYA,kBAAa,KAAK;AAE9B,UAAA,YAAYA,kBAAY,EAAE;AAC1B,UAAA,cAAcA,kBAAiE,EAAE;AACjF,UAAA,iBAAiBA,kBAA+E,CAAA,CAAE;AAClG,UAAA,eAAeA,kBAA+E,CAAA,CAAE;AAChG,UAAA,YAAYA,kBAAa,KAAK;AAC9B,UAAA,eAAeA,kBAAa,KAAK;AAEjC,UAAA,YAAYE,cAAAA,SAAS,MAAM;AACxB,aAAA,MAAM,WAAW,aAAa;AAAA,IAAA,CACtC;AAEDC,kBAAA;AAAA,MACE,MAAM,MAAM;AAAA,MACZ,CAAC,OAAO;AACN,YAAI,MAAM,CAACC,yBAAW,EAAE,GAAG;AACzB,kBAAQ,MAAM,4CAA4C;AAA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