uview-pro 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +6 -0
- package/components/u-action-sheet/u-action-sheet.vue +205 -0
- package/components/u-alert-tips/u-alert-tips.vue +241 -0
- package/components/u-avatar/u-avatar.vue +220 -0
- package/components/u-avatar-cropper/u-avatar-cropper.vue +329 -0
- package/components/u-avatar-cropper/weCropper.d.ts +54 -0
- package/components/u-avatar-cropper/weCropper.js +1267 -0
- package/components/u-avatar-cropper/weCropper.ts +1254 -0
- package/components/u-back-top/u-back-top.vue +156 -0
- package/components/u-badge/u-badge.vue +189 -0
- package/components/u-button/u-button.vue +562 -0
- package/components/u-calendar/u-calendar.vue +725 -0
- package/components/u-car-keyboard/u-car-keyboard.vue +236 -0
- package/components/u-card/u-card.vue +240 -0
- package/components/u-cell-group/u-cell-group.vue +56 -0
- package/components/u-cell-item/u-cell-item.vue +245 -0
- package/components/u-checkbox/u-checkbox.vue +310 -0
- package/components/u-checkbox-group/u-checkbox-group.vue +134 -0
- package/components/u-circle-progress/u-circle-progress.vue +210 -0
- package/components/u-col/u-col.vue +135 -0
- package/components/u-collapse/u-collapse.vue +82 -0
- package/components/u-collapse-item/u-collapse-item.vue +190 -0
- package/components/u-column-notice/u-column-notice.vue +264 -0
- package/components/u-count-down/u-count-down.vue +333 -0
- package/components/u-count-to/u-count-to.vue +297 -0
- package/components/u-divider/u-divider.vue +141 -0
- package/components/u-dropdown/u-dropdown.vue +311 -0
- package/components/u-dropdown-item/u-dropdown-item.vue +135 -0
- package/components/u-empty/u-empty.vue +111 -0
- package/components/u-field/u-field.vue +469 -0
- package/components/u-form/u-form.vue +162 -0
- package/components/u-form-item/u-form-item.vue +476 -0
- package/components/u-full-screen/u-full-screen.vue +80 -0
- package/components/u-gap/u-gap.vue +48 -0
- package/components/u-grid/u-grid.vue +101 -0
- package/components/u-grid-item/u-grid-item.vue +136 -0
- package/components/u-icon/u-icon.vue +389 -0
- package/components/u-image/types.ts +48 -0
- package/components/u-image/u-image.vue +218 -0
- package/components/u-index-anchor/u-index-anchor.vue +101 -0
- package/components/u-index-list/u-index-list.vue +376 -0
- package/components/u-input/u-input.vue +462 -0
- package/components/u-keyboard/u-keyboard.vue +188 -0
- package/components/u-lazy-load/u-lazy-load.vue +288 -0
- package/components/u-line/u-line.vue +71 -0
- package/components/u-line-progress/u-line-progress.vue +128 -0
- package/components/u-link/u-link.vue +87 -0
- package/components/u-loading/u-loading.vue +111 -0
- package/components/u-loadmore/u-loadmore.vue +205 -0
- package/components/u-mask/u-mask.vue +137 -0
- package/components/u-message-input/u-message-input.vue +315 -0
- package/components/u-modal/u-modal.vue +284 -0
- package/components/u-navbar/u-navbar.vue +314 -0
- package/components/u-no-network/image.ts +2 -0
- package/components/u-no-network/u-no-network.vue +311 -0
- package/components/u-notice-bar/u-notice-bar.vue +274 -0
- package/components/u-number-box/u-number-box.vue +344 -0
- package/components/u-number-keyboard/u-number-keyboard.vue +170 -0
- package/components/u-parse/libs/CssHandler.js +100 -0
- package/components/u-parse/libs/MpHtmlParser.js +580 -0
- package/components/u-parse/libs/config.js +80 -0
- package/components/u-parse/libs/handler.wxs +22 -0
- package/components/u-parse/libs/trees.vue +505 -0
- package/components/u-parse/u-parse.vue +645 -0
- package/components/u-picker/u-picker.vue +808 -0
- package/components/u-popup/u-popup.vue +404 -0
- package/components/u-radio/u-radio.vue +272 -0
- package/components/u-radio-group/u-radio-group.vue +116 -0
- package/components/u-rate/u-rate.vue +349 -0
- package/components/u-read-more/u-read-more.vue +199 -0
- package/components/u-row/u-row.vue +95 -0
- package/components/u-row-notice/u-row-notice.vue +273 -0
- package/components/u-search/u-search.vue +298 -0
- package/components/u-section/u-section.vue +175 -0
- package/components/u-select/u-select.vue +387 -0
- package/components/u-skeleton/u-skeleton.vue +230 -0
- package/components/u-slider/u-slider.vue +293 -0
- package/components/u-steps/u-steps.vue +200 -0
- package/components/u-sticky/u-sticky.vue +189 -0
- package/components/u-subsection/u-subsection.vue +388 -0
- package/components/u-swipe-action/u-swipe-action.vue +289 -0
- package/components/u-swiper/u-swiper.vue +305 -0
- package/components/u-switch/u-switch.vue +146 -0
- package/components/u-tabbar/u-tabbar.vue +347 -0
- package/components/u-table/u-table.vue +104 -0
- package/components/u-tabs/u-tabs.vue +322 -0
- package/components/u-tabs-swiper/u-tabs-swiper.vue +426 -0
- package/components/u-tag/u-tag.vue +270 -0
- package/components/u-td/u-td.vue +76 -0
- package/components/u-th/u-th.vue +70 -0
- package/components/u-time-line/u-time-line.vue +39 -0
- package/components/u-time-line-item/u-time-line-item.vue +88 -0
- package/components/u-toast/types.ts +4 -0
- package/components/u-toast/u-toast.vue +238 -0
- package/components/u-top-tips/u-top-tips.vue +118 -0
- package/components/u-tr/u-tr.vue +24 -0
- package/components/u-upload/u-upload.vue +600 -0
- package/components/u-verification-code/u-verification-code.vue +194 -0
- package/components/u-waterfall/u-waterfall.vue +186 -0
- package/iconfont.css +910 -0
- package/index.scss +23 -0
- package/index.ts +166 -0
- package/libs/config/config.ts +26 -0
- package/libs/config/zIndex.ts +37 -0
- package/libs/css/color.scss +155 -0
- package/libs/css/common.scss +176 -0
- package/libs/css/style.components.scss +7 -0
- package/libs/css/style.h5.scss +8 -0
- package/libs/css/style.mp.scss +72 -0
- package/libs/css/style.nvue.scss +3 -0
- package/libs/css/style.vue.scss +175 -0
- package/libs/function/$parent.ts +22 -0
- package/libs/function/addUnit.ts +13 -0
- package/libs/function/color.ts +37 -0
- package/libs/function/colorGradient.ts +123 -0
- package/libs/function/debounce.ts +28 -0
- package/libs/function/deepClone.ts +39 -0
- package/libs/function/deepMerge.ts +34 -0
- package/libs/function/getParent.ts +59 -0
- package/libs/function/getRect.ts +26 -0
- package/libs/function/guid.ts +42 -0
- package/libs/function/md5.ts +397 -0
- package/libs/function/parent.ts +21 -0
- package/libs/function/queryParams.ts +60 -0
- package/libs/function/random.ts +16 -0
- package/libs/function/randomArray.ts +11 -0
- package/libs/function/route.ts +118 -0
- package/libs/function/sys.ts +15 -0
- package/libs/function/test.ts +229 -0
- package/libs/function/throttle.ts +31 -0
- package/libs/function/timeFormat.ts +54 -0
- package/libs/function/timeFrom.ts +48 -0
- package/libs/function/toast.ts +14 -0
- package/libs/function/trim.ts +21 -0
- package/libs/function/type2icon.ts +36 -0
- package/libs/hooks/useEmitter.ts +77 -0
- package/libs/hooks/useParent.ts +29 -0
- package/libs/request/index.ts +237 -0
- package/libs/store/index.ts +88 -0
- package/libs/util/area.ts +1 -0
- package/libs/util/async-validator.js +1356 -0
- package/libs/util/city.ts +1 -0
- package/libs/util/emitter.ts +112 -0
- package/libs/util/mitt.ts +118 -0
- package/libs/util/parent.ts +20 -0
- package/libs/util/province.ts +1 -0
- package/package.json +98 -0
- package/readme.md +165 -0
- package/theme.scss +38 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-code-wrap">
|
|
3
|
+
<!-- 此组件功能由js完成,无需写html逻辑 -->
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import { ref, watch, onMounted, onBeforeUnmount } from 'vue';
|
|
9
|
+
|
|
10
|
+
defineOptions({ name: 'u-verification-code' });
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* verificationCode 验证码输入框
|
|
14
|
+
* @description 考虑到用户实际发送验证码的场景,可能是一个按钮,也可能是一段文字,提示语各有不同,所以本组件不提供界面显示,只提供提示语,由用户将提示语嵌入到具体的场景
|
|
15
|
+
* @tutorial https://www.uviewui.com/components/verificationCode.html
|
|
16
|
+
* @property {Number|String} seconds 倒计时所需的秒数(默认60)
|
|
17
|
+
* @property {String} startText 开始前的提示语,见官网说明(默认获取验证码)
|
|
18
|
+
* @property {String} changeText 倒计时期间的提示语,必须带有字母"x",见官网说明(默认X秒重新获取)
|
|
19
|
+
* @property {String} endText 倒计时结束的提示语,见官网说明(默认重新获取)
|
|
20
|
+
* @property {Boolean} keepRunning 是否在H5刷新或各端返回再进入时继续倒计时(默认false)
|
|
21
|
+
* @property {String} uniqueKey 区分多个页面或多个倒计时组件本地存储的key
|
|
22
|
+
* @event change 倒计时期间,每秒触发一次
|
|
23
|
+
* @event start 开始倒计时触发
|
|
24
|
+
* @event end 结束倒计时触发
|
|
25
|
+
* @example <u-verification-code :seconds="seconds" @end="end" @start="start" ref="uCode" />
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const emit = defineEmits(['change', 'start', 'end']);
|
|
29
|
+
|
|
30
|
+
const props = defineProps({
|
|
31
|
+
/** 倒计时总秒数 */
|
|
32
|
+
seconds: {
|
|
33
|
+
type: [String, Number],
|
|
34
|
+
default: 60
|
|
35
|
+
},
|
|
36
|
+
/** 尚未开始时提示 */
|
|
37
|
+
startText: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: '获取验证码'
|
|
40
|
+
},
|
|
41
|
+
/** 正在倒计时中的提示 */
|
|
42
|
+
changeText: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: 'X秒重新获取'
|
|
45
|
+
},
|
|
46
|
+
/** 倒计时结束时的提示 */
|
|
47
|
+
endText: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: '重新获取'
|
|
50
|
+
},
|
|
51
|
+
/** 是否在H5刷新或各端返回再进入时继续倒计时 */
|
|
52
|
+
keepRunning: {
|
|
53
|
+
type: Boolean,
|
|
54
|
+
default: false
|
|
55
|
+
},
|
|
56
|
+
/** 区分多个页面或多个倒计时组件本地存储的key */
|
|
57
|
+
uniqueKey: {
|
|
58
|
+
type: String,
|
|
59
|
+
default: ''
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
/** 当前倒计时秒数 */
|
|
64
|
+
const secNum = ref(Number(props.seconds));
|
|
65
|
+
/** 定时器句柄 */
|
|
66
|
+
let timer: ReturnType<typeof setInterval> | null = null;
|
|
67
|
+
/** 是否可以执行验证码操作 */
|
|
68
|
+
const canGetCode = ref(true);
|
|
69
|
+
|
|
70
|
+
// 监听 seconds 变化,重置倒计时秒数
|
|
71
|
+
watch(
|
|
72
|
+
() => props.seconds,
|
|
73
|
+
n => {
|
|
74
|
+
secNum.value = Number(n);
|
|
75
|
+
},
|
|
76
|
+
{ immediate: true }
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
onMounted(() => {
|
|
80
|
+
checkKeepRunning();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
onBeforeUnmount(() => {
|
|
84
|
+
setTimeToStorage();
|
|
85
|
+
if (timer) clearTimeout(timer);
|
|
86
|
+
timer = null;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 检查是否需要继续上一次的倒计时
|
|
91
|
+
* @description 用于H5刷新或各端返回再进入时继续倒计时
|
|
92
|
+
*/
|
|
93
|
+
function checkKeepRunning() {
|
|
94
|
+
// 获取上一次退出页面(H5还包括刷新)时的时间戳,如果没有上次的保存,此值可能为空
|
|
95
|
+
const lastTimestamp = Number(uni.getStorageSync(props.uniqueKey + '_$uCountDownTimestamp'));
|
|
96
|
+
if (!lastTimestamp) return changeEvent(props.startText);
|
|
97
|
+
// 当前秒的时间戳
|
|
98
|
+
const nowTimestamp = Math.floor(+new Date() / 1000);
|
|
99
|
+
// 判断当前的时间戳,是否小于上一次的本该按设定结束,却提前结束的时间戳
|
|
100
|
+
if (props.keepRunning && lastTimestamp && lastTimestamp > nowTimestamp) {
|
|
101
|
+
// 剩余尚未执行完的倒计秒数
|
|
102
|
+
secNum.value = lastTimestamp - nowTimestamp;
|
|
103
|
+
// 清除本地保存的变量
|
|
104
|
+
uni.removeStorageSync(props.uniqueKey + '_$uCountDownTimestamp');
|
|
105
|
+
// 开始倒计时
|
|
106
|
+
start();
|
|
107
|
+
} else {
|
|
108
|
+
// 如果不存在需要继续上一次的倒计时,执行正常的逻辑
|
|
109
|
+
changeEvent(props.startText);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 开始倒计时
|
|
115
|
+
* @description 防止快速点击获取验证码的按钮而导致内部产生多个定时器导致混乱
|
|
116
|
+
*/
|
|
117
|
+
function start() {
|
|
118
|
+
if (timer) {
|
|
119
|
+
clearInterval(timer);
|
|
120
|
+
timer = null;
|
|
121
|
+
}
|
|
122
|
+
emit('start');
|
|
123
|
+
canGetCode.value = false;
|
|
124
|
+
// 一开始时就提示,否则要等setInterval的1秒后才会有提示
|
|
125
|
+
changeEvent(props.changeText.replace(/x|X/, String(secNum.value)));
|
|
126
|
+
setTimeToStorage();
|
|
127
|
+
timer = setInterval(() => {
|
|
128
|
+
if (--secNum.value) {
|
|
129
|
+
// 用当前倒计时的秒数替换提示字符串中的"x"字母
|
|
130
|
+
changeEvent(props.changeText.replace(/x|X/, String(secNum.value)));
|
|
131
|
+
} else {
|
|
132
|
+
clearInterval(timer!);
|
|
133
|
+
timer = null;
|
|
134
|
+
changeEvent(props.endText);
|
|
135
|
+
secNum.value = Number(props.seconds);
|
|
136
|
+
emit('end');
|
|
137
|
+
canGetCode.value = true;
|
|
138
|
+
}
|
|
139
|
+
}, 1000);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 重置,可以让用户再次获取验证码
|
|
144
|
+
*/
|
|
145
|
+
function reset() {
|
|
146
|
+
canGetCode.value = true;
|
|
147
|
+
if (timer) clearInterval(timer);
|
|
148
|
+
timer = null;
|
|
149
|
+
secNum.value = Number(props.seconds);
|
|
150
|
+
changeEvent(props.endText);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* 触发 change 事件
|
|
155
|
+
* @param text 当前提示文本
|
|
156
|
+
*/
|
|
157
|
+
function changeEvent(text: string) {
|
|
158
|
+
emit('change', text);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* 保存时间戳,为了防止倒计时尚未结束,H5刷新或者各端的右上角返回上一页再进来
|
|
163
|
+
*/
|
|
164
|
+
function setTimeToStorage() {
|
|
165
|
+
if (!props.keepRunning || !timer) return;
|
|
166
|
+
// 记录当前的时间戳,为了下次进入页面,如果还在倒计时内的话,继续倒计时
|
|
167
|
+
// 倒计时尚未结束,结果大于0;倒计时已经开始,就会小于初始值,如果等于初始值,说明没有开始倒计时,无需处理
|
|
168
|
+
if (secNum.value > 0 && secNum.value <= Number(props.seconds)) {
|
|
169
|
+
// 获取当前时间戳(+ new Date()为特殊写法),除以1000变成秒,再去除小数部分
|
|
170
|
+
const nowTimestamp = Math.floor(+new Date() / 1000);
|
|
171
|
+
// 将本该结束时候的时间戳保存起来 => 当前时间戳 + 剩余的秒数
|
|
172
|
+
uni.setStorage({
|
|
173
|
+
key: props.uniqueKey + '_$uCountDownTimestamp',
|
|
174
|
+
data: nowTimestamp + Number(secNum.value)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
defineExpose({
|
|
179
|
+
start,
|
|
180
|
+
reset,
|
|
181
|
+
canGetCode
|
|
182
|
+
});
|
|
183
|
+
</script>
|
|
184
|
+
|
|
185
|
+
<style lang="scss" scoped>
|
|
186
|
+
@import '../../libs/css/style.components.scss';
|
|
187
|
+
|
|
188
|
+
.u-code-wrap {
|
|
189
|
+
width: 0;
|
|
190
|
+
height: 0;
|
|
191
|
+
position: fixed;
|
|
192
|
+
z-index: -1;
|
|
193
|
+
}
|
|
194
|
+
</style>
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="u-waterfall">
|
|
3
|
+
<view id="u-left-column" class="u-column">
|
|
4
|
+
<slot name="left" :leftList="leftList"></slot>
|
|
5
|
+
</view>
|
|
6
|
+
<view id="u-right-column" class="u-column">
|
|
7
|
+
<slot name="right" :rightList="rightList"></slot>
|
|
8
|
+
</view>
|
|
9
|
+
</view>
|
|
10
|
+
</template>
|
|
11
|
+
<script setup lang="ts">
|
|
12
|
+
import { ref, computed, watch, onMounted, getCurrentInstance } from 'vue';
|
|
13
|
+
import { $u } from '../..';
|
|
14
|
+
|
|
15
|
+
defineOptions({ name: 'u-waterfall' });
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* waterfall 瀑布流
|
|
19
|
+
* @description 这是一个瀑布流形式的组件,内容分为左右两列,结合uView的懒加载组件效果更佳。相较于某些只是奇偶数左右分别,或者没有利用vue作用域插槽的做法,uView的瀑布流实现了真正的 组件化,搭配LazyLoad 懒加载和loadMore 加载更多组件,让您开箱即用,眼前一亮。
|
|
20
|
+
* @tutorial https://www.uviewui.com/components/waterfall.html
|
|
21
|
+
* @property {Array} flow-list 用于渲染的数据
|
|
22
|
+
* @property {String | Number} add-time 单条数据添加到队列的时间间隔,单位ms,见上方注意事项说明(默认200)
|
|
23
|
+
* @example <u-waterfall :flowList="flowList"></u-waterfall>
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits(['update:modelValue']);
|
|
27
|
+
|
|
28
|
+
const props = defineProps({
|
|
29
|
+
/** 瀑布流数据 */
|
|
30
|
+
modelValue: {
|
|
31
|
+
type: Array as () => any[],
|
|
32
|
+
required: true,
|
|
33
|
+
default: () => []
|
|
34
|
+
},
|
|
35
|
+
/** 每次向结构插入数据的时间间隔,单位ms */
|
|
36
|
+
addTime: {
|
|
37
|
+
type: [Number, String],
|
|
38
|
+
default: 200
|
|
39
|
+
},
|
|
40
|
+
/** id值,用于清除某一条数据时,根据此idKey名称找到并移除 */
|
|
41
|
+
idKey: {
|
|
42
|
+
type: String,
|
|
43
|
+
default: 'id'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const leftList = ref<any[]>([]);
|
|
48
|
+
const rightList = ref<any[]>([]);
|
|
49
|
+
const tempList = ref<any[]>([]);
|
|
50
|
+
const instance = getCurrentInstance();
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 破坏 flowList 变量的引用,否则 watch 的结果新旧值是一样的
|
|
54
|
+
*/
|
|
55
|
+
const copyFlowList = computed(() => cloneData(props.modelValue));
|
|
56
|
+
|
|
57
|
+
watch(copyFlowList, (nVal, oVal) => {
|
|
58
|
+
// 取差值,即这一次数组变化新增的部分
|
|
59
|
+
const startIndex = Array.isArray(oVal) && oVal.length > 0 ? oVal.length : 0;
|
|
60
|
+
// 拼接上原有数据
|
|
61
|
+
tempList.value = tempList.value.concat(cloneData(nVal.slice(startIndex)));
|
|
62
|
+
splitData();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
onMounted(() => {
|
|
66
|
+
tempList.value = cloneData(copyFlowList.value);
|
|
67
|
+
splitData();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 复制而不是引用对象和数组
|
|
72
|
+
*/
|
|
73
|
+
function cloneData(data: any) {
|
|
74
|
+
return JSON.parse(JSON.stringify(data));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 异步分配数据到左右列
|
|
79
|
+
*/
|
|
80
|
+
async function splitData() {
|
|
81
|
+
if (!tempList.value.length) return;
|
|
82
|
+
const leftRect = await $u.getRect('#u-left-column', instance);
|
|
83
|
+
const rightRect = await $u.getRect('#u-right-column', instance);
|
|
84
|
+
// 如果左边小于或等于右边,就添加到左边,否则添加到右边
|
|
85
|
+
const item = tempList.value[0];
|
|
86
|
+
// 解决多次快速上拉后,可能数据会乱的问题,因为经过上面的两个await节点查询阻塞一定时间,加上后面的定时器干扰
|
|
87
|
+
// 数组可能变成[],导致此item值可能为undefined
|
|
88
|
+
if (!item) return;
|
|
89
|
+
if (leftRect.height < rightRect.height) {
|
|
90
|
+
leftList.value.push(item);
|
|
91
|
+
} else if (leftRect.height > rightRect.height) {
|
|
92
|
+
rightList.value.push(item);
|
|
93
|
+
} else {
|
|
94
|
+
// 这里是为了保证第一和第二张添加时,左右都能有内容
|
|
95
|
+
// 因为添加第一张,实际队列的高度可能还是0,这时需要根据队列元素长度判断下一个该放哪边
|
|
96
|
+
if (leftList.value.length <= rightList.value.length) {
|
|
97
|
+
leftList.value.push(item);
|
|
98
|
+
} else {
|
|
99
|
+
rightList.value.push(item);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// 移除临时列表的第一项
|
|
103
|
+
tempList.value.splice(0, 1);
|
|
104
|
+
// 如果临时数组还有数据,继续循环
|
|
105
|
+
if (tempList.value.length) {
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
splitData();
|
|
108
|
+
}, Number(props.addTime));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 清空数据列表
|
|
114
|
+
*/
|
|
115
|
+
function clear() {
|
|
116
|
+
leftList.value = [];
|
|
117
|
+
rightList.value = [];
|
|
118
|
+
// 同时清除父组件列表中的数据
|
|
119
|
+
emit('update:modelValue', []);
|
|
120
|
+
tempList.value = [];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* 清除某一条指定的数据,根据 id 实现
|
|
125
|
+
*/
|
|
126
|
+
function remove(id: string | number) {
|
|
127
|
+
let index = leftList.value.findIndex(val => val[props.idKey] == id);
|
|
128
|
+
if (index !== -1) {
|
|
129
|
+
// 如果index不等于-1,说明已经找到了要找的id,根据index索引删除这一条数据
|
|
130
|
+
leftList.value.splice(index, 1);
|
|
131
|
+
} else {
|
|
132
|
+
// 同理于上方面的方法
|
|
133
|
+
index = rightList.value.findIndex(val => val[props.idKey] == id);
|
|
134
|
+
if (index !== -1) rightList.value.splice(index, 1);
|
|
135
|
+
}
|
|
136
|
+
// 同时清除父组件的数据中的对应id的条目
|
|
137
|
+
index = props.modelValue.findIndex((val: any) => val[props.idKey] == id);
|
|
138
|
+
if (index !== -1) emit('update:modelValue', props.modelValue.splice(index, 1));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 修改某条数据的某个属性
|
|
143
|
+
*/
|
|
144
|
+
function modify(id: string | number, key: string, value: any) {
|
|
145
|
+
let index = leftList.value.findIndex(val => val[props.idKey] == id);
|
|
146
|
+
if (index !== -1) {
|
|
147
|
+
// 如果index不等于-1,说明已经找到了要找的id,修改对应key的值
|
|
148
|
+
leftList.value[index][key] = value;
|
|
149
|
+
} else {
|
|
150
|
+
// 同理于上方面的方法
|
|
151
|
+
index = rightList.value.findIndex(val => val[props.idKey] == id);
|
|
152
|
+
if (index !== -1) rightList.value[index][key] = value;
|
|
153
|
+
}
|
|
154
|
+
// 修改父组件的数据中的对应id的条目
|
|
155
|
+
index = props.modelValue.findIndex((val: any) => val[props.idKey] == id);
|
|
156
|
+
if (index !== -1) {
|
|
157
|
+
// 首先复制一份value的数据
|
|
158
|
+
const data = cloneData(props.modelValue);
|
|
159
|
+
// 修改对应索引的key属性的值为value
|
|
160
|
+
data[index][key] = value;
|
|
161
|
+
// 修改父组件通过v-model绑定的变量的值
|
|
162
|
+
emit('update:modelValue', data);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
</script>
|
|
166
|
+
|
|
167
|
+
<style lang="scss" scoped>
|
|
168
|
+
@import '../../libs/css/style.components.scss';
|
|
169
|
+
|
|
170
|
+
.u-waterfall {
|
|
171
|
+
@include vue-flex;
|
|
172
|
+
flex-direction: row;
|
|
173
|
+
align-items: flex-start;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.u-column {
|
|
177
|
+
@include vue-flex;
|
|
178
|
+
flex: 1;
|
|
179
|
+
flex-direction: column;
|
|
180
|
+
height: auto;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.u-image {
|
|
184
|
+
width: 100%;
|
|
185
|
+
}
|
|
186
|
+
</style>
|