init
This commit is contained in:
204
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.js
vendored
Normal file
204
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.js
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
require("../_utils/env.js");
|
||||
const uni_modules_nutuiUni_components__utils_pxCheck = require("../_utils/pxCheck.js");
|
||||
require("../../locale/locale.js");
|
||||
const uni_modules_nutuiUni_locale_useTranslate = require("../../locale/useTranslate.js");
|
||||
const uni_modules_nutuiUni_components__constants_event = require("../_constants/event.js");
|
||||
const uni_modules_nutuiUni_components__utils_props = require("../_utils/props.js");
|
||||
const uni_modules_nutuiUni_components_picker_usePicker = require("./use-picker.js");
|
||||
const pickerProps = {
|
||||
...uni_modules_nutuiUni_components__utils_props.commonProps,
|
||||
/**
|
||||
* @description 默认选中项
|
||||
*/
|
||||
modelValue: uni_modules_nutuiUni_components__utils_props.makeArrayProp([]),
|
||||
/**
|
||||
* @description 对象数组,配置每一列显示的数据
|
||||
*/
|
||||
columns: uni_modules_nutuiUni_components__utils_props.makeArrayProp([]),
|
||||
/**
|
||||
* @description 是否显示顶部导航
|
||||
*/
|
||||
showToolbar: uni_modules_nutuiUni_components__utils_props.truthProp,
|
||||
/**
|
||||
* @description 设置标题
|
||||
*/
|
||||
title: uni_modules_nutuiUni_components__utils_props.makeStringProp(""),
|
||||
/**
|
||||
* @description 确定按钮文案
|
||||
*/
|
||||
okText: uni_modules_nutuiUni_components__utils_props.makeStringProp(""),
|
||||
/**
|
||||
* @description 取消按钮文案
|
||||
*/
|
||||
cancelText: uni_modules_nutuiUni_components__utils_props.makeStringProp(""),
|
||||
/**
|
||||
* @description 是否开启3D效果
|
||||
*/
|
||||
threeDimensional: Boolean,
|
||||
/**
|
||||
* @description 惯性滚动时长
|
||||
*/
|
||||
swipeDuration: uni_modules_nutuiUni_components__utils_props.makeNumericProp(1e3),
|
||||
/**
|
||||
* @description 可见的选项个数
|
||||
*/
|
||||
visibleOptionNum: uni_modules_nutuiUni_components__utils_props.makeNumericProp(7),
|
||||
/**
|
||||
* @description 选项高度
|
||||
*/
|
||||
optionHeight: uni_modules_nutuiUni_components__utils_props.makeNumericProp(36),
|
||||
/**
|
||||
* @description 自定义 columns 中的字段
|
||||
*/
|
||||
fieldNames: uni_modules_nutuiUni_components__utils_props.makeObjectProp({})
|
||||
};
|
||||
const pickerEmits = {
|
||||
[uni_modules_nutuiUni_components__constants_event.UPDATE_MODEL_EVENT]: (val) => val instanceof Object,
|
||||
[uni_modules_nutuiUni_components__constants_event.CHANGE_EVENT]: (evt) => evt instanceof Object,
|
||||
[uni_modules_nutuiUni_components__constants_event.CONFIRM_EVENT]: (evt) => evt instanceof Object,
|
||||
[uni_modules_nutuiUni_components__constants_event.CANCEL_EVENT]: (evt) => evt instanceof Object
|
||||
};
|
||||
const __default__ = common_vendor.defineComponent({
|
||||
name: uni_modules_nutuiUni_components_picker_usePicker.componentName,
|
||||
options: {
|
||||
virtualHost: true,
|
||||
addGlobalClass: true,
|
||||
styleIsolation: "shared"
|
||||
}
|
||||
});
|
||||
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
|
||||
...__default__,
|
||||
props: pickerProps,
|
||||
emits: pickerEmits,
|
||||
setup(__props, { emit: __emit }) {
|
||||
const props = __props;
|
||||
const emit = __emit;
|
||||
const innerVisibleOptionNum = common_vendor.computed(() => {
|
||||
return Number(props.visibleOptionNum);
|
||||
});
|
||||
const innerOptionHeight = common_vendor.computed(() => {
|
||||
return Number(props.optionHeight);
|
||||
});
|
||||
const { translate } = uni_modules_nutuiUni_locale_useTranslate.useTranslate(uni_modules_nutuiUni_components_picker_usePicker.componentName);
|
||||
const {
|
||||
changeHandler,
|
||||
confirm,
|
||||
defaultValues,
|
||||
defaultIndexes,
|
||||
delayDefaultIndexes,
|
||||
columnsList,
|
||||
columnFieldNames,
|
||||
classes,
|
||||
cancel,
|
||||
confirmHandler
|
||||
} = uni_modules_nutuiUni_components_picker_usePicker.usePicker(props, emit);
|
||||
function componentWeapp() {
|
||||
const state = common_vendor.reactive({
|
||||
show: false,
|
||||
picking: false
|
||||
});
|
||||
const pickerViewStyles2 = common_vendor.computed(() => {
|
||||
const styles = {};
|
||||
styles.height = `${innerVisibleOptionNum.value * innerOptionHeight.value}px`;
|
||||
styles["--line-height"] = `${innerOptionHeight.value}px`;
|
||||
return styles;
|
||||
});
|
||||
const handleTileChange2 = (event) => {
|
||||
const indexes = event.detail.value;
|
||||
const prevIndexes = defaultIndexes.value;
|
||||
let changeIndex = 0;
|
||||
for (let i = 0; i < indexes.length; i++) {
|
||||
if (prevIndexes[i] !== indexes[i]) {
|
||||
changeIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
changeHandler(changeIndex, columnsList.value[changeIndex][indexes[changeIndex]]);
|
||||
};
|
||||
const confirmHandler2 = () => {
|
||||
if (state.picking) {
|
||||
setTimeout(() => {
|
||||
confirm();
|
||||
}, 0);
|
||||
} else {
|
||||
confirm();
|
||||
}
|
||||
};
|
||||
const handlePickStart2 = () => {
|
||||
state.picking = true;
|
||||
};
|
||||
const handlePickEnd2 = () => {
|
||||
state.picking = false;
|
||||
};
|
||||
return {
|
||||
...common_vendor.toRefs(state),
|
||||
pickerViewStyles: pickerViewStyles2,
|
||||
handleTileChange: handleTileChange2,
|
||||
confirmHandler: confirmHandler2,
|
||||
handlePickStart: handlePickStart2,
|
||||
handlePickEnd: handlePickEnd2
|
||||
};
|
||||
}
|
||||
const {
|
||||
confirmHandler: confirmHandlerMp,
|
||||
handleTileChange,
|
||||
handlePickStart,
|
||||
handlePickEnd,
|
||||
pickerViewStyles
|
||||
} = componentWeapp();
|
||||
function onConfirm() {
|
||||
confirmHandlerMp();
|
||||
}
|
||||
return (_ctx, _cache) => {
|
||||
return common_vendor.e({
|
||||
a: props.showToolbar
|
||||
}, props.showToolbar ? {
|
||||
b: common_vendor.t(props.cancelText || common_vendor.unref(translate)("cancel")),
|
||||
c: common_vendor.o(
|
||||
//@ts-ignore
|
||||
(...args) => common_vendor.unref(cancel) && common_vendor.unref(cancel)(...args)
|
||||
),
|
||||
d: common_vendor.t(props.title),
|
||||
e: common_vendor.t(props.okText || common_vendor.unref(translate)("confirm")),
|
||||
f: common_vendor.o(
|
||||
//@ts-ignore
|
||||
(...args) => onConfirm && onConfirm(...args)
|
||||
)
|
||||
} : {}, {
|
||||
g: common_vendor.f(common_vendor.unref(columnsList), (column, columnIndex, i0) => {
|
||||
return {
|
||||
a: common_vendor.f(column, (item, index, i1) => {
|
||||
return {
|
||||
a: common_vendor.t(item[common_vendor.unref(columnFieldNames).text]),
|
||||
b: item[common_vendor.unref(columnFieldNames).value] ? item[common_vendor.unref(columnFieldNames).value] : index
|
||||
};
|
||||
}),
|
||||
b: columnIndex
|
||||
};
|
||||
}),
|
||||
h: common_vendor.unref(uni_modules_nutuiUni_components__utils_pxCheck.pxCheck)(innerOptionHeight.value),
|
||||
i: common_vendor.s(common_vendor.unref(pickerViewStyles)),
|
||||
j: `height:${innerOptionHeight.value}px`,
|
||||
k: common_vendor.unref(delayDefaultIndexes),
|
||||
l: common_vendor.o(
|
||||
//@ts-ignore
|
||||
(...args) => common_vendor.unref(handleTileChange) && common_vendor.unref(handleTileChange)(...args)
|
||||
),
|
||||
m: common_vendor.o(
|
||||
//@ts-ignore
|
||||
(...args) => common_vendor.unref(handlePickStart) && common_vendor.unref(handlePickStart)(...args)
|
||||
),
|
||||
n: common_vendor.o(
|
||||
//@ts-ignore
|
||||
(...args) => common_vendor.unref(handlePickEnd) && common_vendor.unref(handlePickEnd)(...args)
|
||||
),
|
||||
o: common_vendor.n(common_vendor.unref(classes)),
|
||||
p: common_vendor.s(props.customStyle)
|
||||
});
|
||||
};
|
||||
}
|
||||
});
|
||||
wx.createComponent(_sfc_main);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/nutui-uni/components/picker/picker.js.map
|
||||
4
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.json
vendored
Normal file
4
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.json
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
1
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.wxml
vendored
Normal file
1
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.wxml
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<view class="{{o}}" style="{{p}}"><view wx:if="{{a}}" class="nut-picker__bar"><view class="nut-picker__cancel nut-picker__left nut-picker__button" bindtap="{{c}}">{{b}}</view><view class="nut-picker__title">{{d}}</view><view class="nut-picker__confirm nut-picker__right nut-picker__button" bindtap="{{f}}">{{e}}</view></view><slot name="top"/><block wx:if="{{r0}}"><picker-view style="{{i}}" indicator-style="{{j}}" value="{{k}}" immediate-change="{{true}}" mask-class="nut-picker__mask" bindchange="{{l}}" bindpickstart="{{m}}" bindpickend="{{n}}"><picker-view-column wx:for="{{g}}" wx:for-item="column" wx:key="b"><view wx:for="{{column.a}}" wx:for-item="item" wx:key="b" class="nut-picker-roller-item-tarotile" style="{{'line-height:' + h}}">{{item.a}}</view></picker-view-column></picker-view></block><slot/></view>
|
||||
231
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.wxss
vendored
Normal file
231
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/picker.wxss
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.nut-theme-dark .nut-picker-roller {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-theme-dark .nut-picker-roller-item {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-theme-dark .nut-picker-roller-item-tile {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-theme-dark .nut-picker-roller-item-tarotile {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-theme-dark .nut-picker-roller-mask {
|
||||
z-index: 1;
|
||||
background-image: linear-gradient(180deg, rgba(27, 27, 27, 0.9), rgba(27, 27, 27, 0.4)), linear-gradient(0deg, rgba(27, 27, 27, 0.9), rgba(27, 27, 27, 0.4));
|
||||
background-repeat: no-repeat;
|
||||
background-position: top, bottom;
|
||||
transform: translateZ(0);
|
||||
}
|
||||
.nut-picker__list {
|
||||
position: relative;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
text-align: center;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
}
|
||||
.nut-picker-roller {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
z-index: 1;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: var(--line-height);
|
||||
color: var(--nut-picker-item-text-color, var(--nut-title-color, #1a1a1a));
|
||||
transform: translateY(-50%);
|
||||
transform-style: preserve-3d;
|
||||
}
|
||||
.nut-picker-roller-item {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: var(--nut-picker-item-height, 36px);
|
||||
overflow: hidden;
|
||||
font-size: var(--nut-picker-item-text-font-size, 14px);
|
||||
line-height: var(--nut-picker-item-height, 36px);
|
||||
color: var(--nut-picker-item-text-color, var(--nut-title-color, #1a1a1a));
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
-webkit-backface-visibility: hidden;
|
||||
backface-visibility: hidden;
|
||||
}
|
||||
.nut-picker-roller-item-hidden {
|
||||
visibility: hidden;
|
||||
opacity: 0;
|
||||
}
|
||||
.nut-picker-roller-item-tile {
|
||||
display: block;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
font-size: var(--nut-picker-item-text-font-size, 14px);
|
||||
color: var(--nut-picker-item-text-color, var(--nut-title-color, #1a1a1a));
|
||||
text-align: center;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.nut-picker-roller-item-tarotile {
|
||||
display: block;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
font-size: var(--nut-picker-item-text-font-size, 14px);
|
||||
color: var(--nut-picker-item-text-color, var(--nut-title-color, #1a1a1a));
|
||||
text-align: center;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.nut-picker-roller-mask {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.4)), linear-gradient(0deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.4));
|
||||
background-repeat: no-repeat;
|
||||
background-position: top, bottom;
|
||||
}
|
||||
.nut-theme-dark .nut-picker {
|
||||
position: relative;
|
||||
background: var(--nut-dark-background, #131313);
|
||||
border-radius: 5px;
|
||||
}
|
||||
.nut-theme-dark .nut-picker__mask {
|
||||
background: none !important;
|
||||
}
|
||||
.nut-theme-dark .nut-picker__bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 46px;
|
||||
}
|
||||
.nut-theme-dark .nut-picker__title {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-theme-dark .nut-picker-content {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-theme-dark .nut-picker-item {
|
||||
color: var(--nut-dark-color, var(--nut-white, #fff));
|
||||
}
|
||||
.nut-picker {
|
||||
position: relative;
|
||||
background: #fff;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.nut-picker__bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 46px;
|
||||
}
|
||||
.nut-picker__left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 50px;
|
||||
height: 100%;
|
||||
padding: var(--nut-picker-bar-button-padding, 0 15px);
|
||||
font-size: var(--nut-picker-bar-cancel-font-size, 14px);
|
||||
color: var(--nut-picker-cancel-color, #808080);
|
||||
cursor: pointer;
|
||||
}
|
||||
.nut-picker__right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 50px;
|
||||
height: 100%;
|
||||
padding: var(--nut-picker-bar-button-padding, 0 15px);
|
||||
font-size: var(--nut-picker-bar-ok-font-size, 14px);
|
||||
color: var(--nut-picker-ok-color, var(--nut-primary-color, #fa2c19));
|
||||
cursor: pointer;
|
||||
}
|
||||
.nut-picker__column {
|
||||
position: relative;
|
||||
display: flex;
|
||||
}
|
||||
.nut-picker__column::before {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
width: 100%;
|
||||
height: var(--line-height);
|
||||
content: "";
|
||||
border: var(--nut-picker-item-active-line-border, 1px solid #eae7e7);
|
||||
border-right: 0;
|
||||
border-left: 0;
|
||||
transform: scale(0.9);
|
||||
transform: translateY(-50%);
|
||||
}
|
||||
.nut-picker__columnitem {
|
||||
flex-grow: 1;
|
||||
width: 0;
|
||||
height: 100%;
|
||||
cursor: grab;
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
.nut-picker__title {
|
||||
flex: 1;
|
||||
font-size: var(--nut-picker-bar-title-font-size, 16px);
|
||||
font-weight: var(--nut-picker-bar-title-font-weight, normal);
|
||||
color: var(--nut-picker-bar-title-color, var(--nut-title-color, #1a1a1a));
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.nut-picker__wrapper {
|
||||
display: block;
|
||||
}
|
||||
191
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/use-picker.js
vendored
Normal file
191
unpackage/dist/dev/mp-weixin/uni_modules/nutui-uni/components/picker/use-picker.js
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const uni_modules_nutuiUni_components__constants_event = require("../_constants/event.js");
|
||||
const uni_modules_nutuiUni_components__constants_prefix = require("../_constants/prefix.js");
|
||||
const uni_modules_nutuiUni_components__utils_common = require("../_utils/common.js");
|
||||
require("../_utils/env.js");
|
||||
const uni_modules_nutuiUni_components__utils_style = require("../_utils/style.js");
|
||||
const DEFAULT_FILED_NAMES = {
|
||||
text: "text",
|
||||
value: "value",
|
||||
children: "children",
|
||||
className: ""
|
||||
};
|
||||
const componentName = `${uni_modules_nutuiUni_components__constants_prefix.PREFIX}-picker`;
|
||||
function usePicker(props, emit) {
|
||||
const classes = common_vendor.computed(() => {
|
||||
return uni_modules_nutuiUni_components__utils_style.getMainClass(props, componentName);
|
||||
});
|
||||
const state = common_vendor.reactive({
|
||||
formattedColumns: props.columns
|
||||
});
|
||||
const columnFieldNames = common_vendor.computed(() => {
|
||||
return {
|
||||
...DEFAULT_FILED_NAMES,
|
||||
...props.fieldNames
|
||||
};
|
||||
});
|
||||
const defaultValues = common_vendor.ref([]);
|
||||
const columnsType = common_vendor.computed(() => {
|
||||
const firstColumn = state.formattedColumns[0];
|
||||
const fields = columnFieldNames.value;
|
||||
if (firstColumn) {
|
||||
if (Array.isArray(firstColumn))
|
||||
return "multiple";
|
||||
if (fields.children in firstColumn)
|
||||
return "cascade";
|
||||
}
|
||||
return "single";
|
||||
});
|
||||
const formatCascade = (columns, defaultValues2) => {
|
||||
const formatted = [];
|
||||
const fields = columnFieldNames.value;
|
||||
let cursor = {
|
||||
text: "",
|
||||
value: "",
|
||||
[fields.children]: columns
|
||||
};
|
||||
let columnIndex = 0;
|
||||
while (cursor && cursor[fields.children]) {
|
||||
const options = cursor[fields.children];
|
||||
const value = defaultValues2[columnIndex];
|
||||
let index = options.findIndex((columnItem) => columnItem[fields.value] === value);
|
||||
if (index === -1)
|
||||
index = 0;
|
||||
cursor = cursor[fields.children][index];
|
||||
columnIndex += 1;
|
||||
formatted.push(options);
|
||||
}
|
||||
return formatted;
|
||||
};
|
||||
const columnsList = common_vendor.computed(() => {
|
||||
switch (columnsType.value) {
|
||||
case "single":
|
||||
return [state.formattedColumns];
|
||||
case "multiple":
|
||||
return state.formattedColumns;
|
||||
case "cascade":
|
||||
return formatCascade(
|
||||
state.formattedColumns,
|
||||
defaultValues.value ? defaultValues.value : []
|
||||
);
|
||||
}
|
||||
return [];
|
||||
});
|
||||
const defaultIndexes = common_vendor.computed(() => {
|
||||
const fields = columnFieldNames.value;
|
||||
return columnsList.value.map((column, index) => {
|
||||
const targetIndex = column.findIndex((item) => item[fields.value] === defaultValues.value[index]);
|
||||
return targetIndex === -1 ? 0 : targetIndex;
|
||||
});
|
||||
});
|
||||
const delayDefaultIndexes = common_vendor.ref(columnsList.value.map(() => 0));
|
||||
common_vendor.watch(defaultIndexes, async (value) => {
|
||||
await common_vendor.nextTick$1();
|
||||
delayDefaultIndexes.value = value;
|
||||
}, { immediate: true });
|
||||
const columnRefs = common_vendor.ref([]);
|
||||
const columnRef = (el) => {
|
||||
if (el && columnRefs.value.length < columnsList.value.length)
|
||||
columnRefs.value.push(el);
|
||||
};
|
||||
const selectedOptions = common_vendor.computed(() => {
|
||||
const fields = columnFieldNames.value;
|
||||
return columnsList.value.map((column, index) => {
|
||||
return column.find((item) => item[fields.value] === defaultValues.value[index]) || column[0];
|
||||
});
|
||||
});
|
||||
const cancel = () => {
|
||||
emit(uni_modules_nutuiUni_components__constants_event.CANCEL_EVENT, {
|
||||
selectedValue: defaultValues.value,
|
||||
selectedOptions: selectedOptions.value
|
||||
});
|
||||
};
|
||||
const changeHandler = (columnIndex, option) => {
|
||||
const fields = columnFieldNames.value;
|
||||
if (option && Object.keys(option).length) {
|
||||
defaultValues.value = defaultValues.value ? defaultValues.value : [];
|
||||
if (columnsType.value === "cascade") {
|
||||
defaultValues.value[columnIndex] = option[fields.value] ? option[fields.value] : "";
|
||||
let index = columnIndex;
|
||||
let cursor = option;
|
||||
while (cursor && cursor[fields.children] && cursor[fields.children][0]) {
|
||||
defaultValues.value[index + 1] = cursor[fields.children][0][fields.value];
|
||||
index += 1;
|
||||
cursor = cursor[fields.children][0];
|
||||
}
|
||||
if (cursor && cursor[fields.children] && cursor[fields.children].length === 0)
|
||||
defaultValues.value = defaultValues.value.slice(0, index + 1);
|
||||
} else {
|
||||
defaultValues.value[columnIndex] = Object.prototype.hasOwnProperty.call(option, fields.value) ? option[fields.value] : "";
|
||||
}
|
||||
emit(uni_modules_nutuiUni_components__constants_event.CHANGE_EVENT, {
|
||||
columnIndex,
|
||||
selectedValue: defaultValues.value,
|
||||
selectedOptions: selectedOptions.value
|
||||
});
|
||||
}
|
||||
};
|
||||
const confirm = () => {
|
||||
const fields = columnFieldNames.value;
|
||||
if (defaultValues.value && !defaultValues.value.length) {
|
||||
columnsList.value.forEach((columns) => {
|
||||
defaultValues.value.push(columns[0][fields.value]);
|
||||
});
|
||||
}
|
||||
emit(uni_modules_nutuiUni_components__constants_event.CONFIRM_EVENT, {
|
||||
selectedValue: defaultValues.value,
|
||||
selectedOptions: selectedOptions.value
|
||||
});
|
||||
};
|
||||
const confirmHandler = () => {
|
||||
if (columnRefs.value.length > 0) {
|
||||
columnRefs.value.forEach((column) => {
|
||||
column.stopMomentum();
|
||||
});
|
||||
}
|
||||
confirm();
|
||||
};
|
||||
common_vendor.watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
if (!uni_modules_nutuiUni_components__utils_common.isEqualValue(value, defaultValues.value))
|
||||
defaultValues.value = uni_modules_nutuiUni_components__utils_common.cloneDeep(value);
|
||||
},
|
||||
{ deep: true, immediate: true }
|
||||
);
|
||||
common_vendor.watch(
|
||||
defaultValues,
|
||||
(value) => {
|
||||
if (!uni_modules_nutuiUni_components__utils_common.isEqualValue(value, props.modelValue))
|
||||
emit(uni_modules_nutuiUni_components__constants_event.UPDATE_MODEL_EVENT, value);
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
common_vendor.watch(
|
||||
() => props.columns,
|
||||
(value) => {
|
||||
state.formattedColumns = value;
|
||||
}
|
||||
);
|
||||
return {
|
||||
classes,
|
||||
...common_vendor.toRefs(state),
|
||||
columnsType,
|
||||
columnsList,
|
||||
columnFieldNames,
|
||||
cancel,
|
||||
changeHandler,
|
||||
confirmHandler,
|
||||
confirm,
|
||||
defaultValues,
|
||||
defaultIndexes,
|
||||
delayDefaultIndexes,
|
||||
columnRefs,
|
||||
columnRef,
|
||||
selectedOptions
|
||||
};
|
||||
}
|
||||
exports.componentName = componentName;
|
||||
exports.usePicker = usePicker;
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/nutui-uni/components/picker/use-picker.js.map
|
||||
Reference in New Issue
Block a user