@ecolovo/uniapp-components 1.0.10 → 2.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/README.md +202 -66
- package/components/aspect/aspect.vue +24 -15
- package/components/badge/badge.scss +20 -0
- package/components/badge/badge.vue +49 -40
- package/components/button/button.scss +15 -0
- package/components/button/button.vue +121 -177
- package/components/checkbox/checkbox.scss +10 -0
- package/components/checkbox/checkbox.vue +118 -146
- package/components/checkbox-group/checkbox-group.vue +79 -85
- package/components/checkbox-group2/checkbox-group2.vue +111 -107
- package/components/checkbox-group2/checkbox2.vue +104 -0
- package/components/data-list/data-list.scss +9 -0
- package/components/data-list/data-list.vue +70 -79
- package/components/date-picker/date-picker-view.vue +125 -124
- package/components/date-picker/date-picker.vue +145 -146
- package/components/dialog/dialog-content.vue +39 -47
- package/components/dialog/dialog.scss +11 -0
- package/components/dialog/dialog.vue +125 -138
- package/components/dropdown/dropdown.scss +11 -0
- package/components/dropdown/dropdown.vue +55 -97
- package/components/empty/empty.scss +14 -0
- package/components/empty/empty.vue +42 -41
- package/components/flex/flex.vue +45 -54
- package/components/form/form.vue +29 -24
- package/components/form-item/form-item.scss +11 -0
- package/components/form-item/form-item.vue +43 -40
- package/components/icon/icon.vue +70 -85
- package/components/image/image.vue +35 -38
- package/components/input/input.vue +65 -79
- package/components/input/password-input.vue +34 -42
- package/components/list-page/list-page.vue +73 -99
- package/components/load-more/load-more.scss +12 -0
- package/components/load-more/load-more.vue +29 -29
- package/components/loading/animations/loading-animation1.vue +8 -8
- package/components/loading/animations/loading-animation2.vue +8 -9
- package/components/loading/animations/loading-animation3.vue +11 -11
- package/components/loading/animations/loading-animation4.vue +8 -8
- package/components/loading/loading.vue +19 -20
- package/components/message-box/message-box.vue +59 -41
- package/components/number-dialog/number-dialog.scss +9 -0
- package/components/number-dialog/number-dialog.vue +209 -204
- package/components/number-input/number-input.scss +9 -0
- package/components/number-input/number-input.vue +233 -232
- package/components/numpad/numpad.scss +9 -0
- package/components/numpad/numpad.vue +133 -150
- package/components/page/page-body.scss +15 -0
- package/components/page/page-body.vue +137 -119
- package/components/page/page-footer.scss +13 -0
- package/components/page/page-footer.vue +31 -33
- package/components/page/page-header.scss +17 -0
- package/components/page/page-header.vue +89 -94
- package/components/page/page.scss +9 -0
- package/components/page/page.vue +105 -81
- package/components/picker/picker-popup.vue +218 -209
- package/components/picker/picker.vue +99 -104
- package/components/popover/popover-content.vue +54 -63
- package/components/popover/popover-mask.vue +63 -63
- package/components/popover/popover.scss +28 -0
- package/components/popover/popover.vue +49 -47
- package/components/popup/popup-content.vue +49 -53
- package/components/popup/popup.scss +11 -0
- package/components/popup/popup.vue +117 -132
- package/components/price/price.scss +20 -0
- package/components/price/price.vue +31 -42
- package/components/search/search.scss +12 -0
- package/components/search/search.vue +93 -117
- package/components/searching/searching.vue +33 -40
- package/components/selector/selector.vue +43 -48
- package/components/switch/switch.scss +12 -0
- package/components/switch/switch.vue +99 -96
- package/components/tab/tab.scss +19 -0
- package/components/tab/tab.vue +151 -145
- package/components/textarea/textarea.vue +104 -101
- package/composable/component-name.d.ts +2 -0
- package/composable/component-name.js +8 -0
- package/composable/component-name.ts +10 -0
- package/configs/index.d.ts +25 -10
- package/configs/index.js +14 -23
- package/configs/index.ts +82 -0
- package/easyCom.d.ts +9 -0
- package/easyCom.js +1 -2
- package/easyCom.ts +31 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.ts +1 -0
- package/init.d.ts +4 -7
- package/init.js +5 -4
- package/init.ts +34 -0
- package/package.json +14 -4
- package/styles/utils/css-var.scss +12 -15
- package/styles/utils/ellipsis.scss +0 -7
- package/styles/utils/z-index.scss +1 -1
- package/styles/var/component.scss +21 -245
- package/utils/date.d.ts +47 -0
- package/utils/date.js +23 -43
- package/utils/date.ts +153 -0
- package/utils/freezeDeep.d.ts +1 -0
- package/utils/freezeDeep.js +4 -14
- package/utils/freezeDeep.ts +9 -0
- package/utils/price.d.ts +24 -0
- package/utils/price.js +14 -8
- package/utils/price.ts +57 -0
- package/utils/round.d.ts +2 -0
- package/utils/round.js +2 -14
- package/utils/round.ts +11 -0
- package/utils/windowInfo.d.ts +24 -0
- package/utils/windowInfo.js +8 -36
- package/utils/windowInfo.ts +50 -0
- package/components/checkbox-group2/checkbox.vue +0 -109
- package/components/datetime-picker/datetime-picker-view.vue +0 -209
- package/components/datetime-picker/datetime-picker.vue +0 -235
- package/components/form/mixin.js +0 -13
- package/components/list-page/list-page.js +0 -10
- package/components/table/table.vue +0 -112
- package/components/time-picker/time-picker-view.vue +0 -127
- package/components/time-picker/time-picker.vue +0 -140
- package/components/uploader/download.js +0 -81
- package/components/uploader/file-uploader.vue +0 -52
- package/components/uploader/files.js +0 -225
- package/components/uploader/media-uploader.vue +0 -189
- package/components/uploader/mixin.js +0 -171
- package/components/uploader/uni.js +0 -38
- package/components/uploader/upload-button.vue +0 -29
- package/components/uploader/uploader copy.vue +0 -547
- package/components/uploader/uploader.vue +0 -117
- package/mixins/componentName.js +0 -32
- package/mixins/listPage.js +0 -1
- package/mixins/windowInfo.js +0 -1
- package/utils/fileSize.js +0 -39
- package/utils/floor.js +0 -20
package/components/tab/tab.vue
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view :class="[
|
|
2
|
+
<view :class="[...classNames, $style['Tab'], { [$style['Tab--evenly']]: evenly }]" :style="inlineStyle">
|
|
3
3
|
<scroll-view scroll-x :class="$style['Tab--tab-scroll']">
|
|
4
4
|
<view :class="$style['Tab--tab-wrapper']">
|
|
5
5
|
<view
|
|
6
6
|
v-for="(tab, index) in tabLabels"
|
|
7
7
|
:key="index"
|
|
8
|
-
:class="[[$style['Tab--tab']], { [$style['Tab--tab-active']]: index ===
|
|
8
|
+
:class="[[$style['Tab--tab']], { [$style['Tab--tab-active']]: index === selectedIndex }]"
|
|
9
9
|
@click="onChangeTab(index)"
|
|
10
10
|
>
|
|
11
11
|
<view :class="$style['Tab--tab-text']">{{ tab }}</view>
|
|
12
12
|
</view>
|
|
13
13
|
<view
|
|
14
14
|
v-if="indicator"
|
|
15
|
-
:class="[$style['Tab--indicator'], { [$style['Tab--
|
|
15
|
+
:class="[$style['Tab--indicator'], { [$style['Tab--indicator-animation']]: hasAnimation }]"
|
|
16
16
|
>
|
|
17
17
|
</view>
|
|
18
18
|
</view>
|
|
@@ -20,160 +20,166 @@
|
|
|
20
20
|
</view>
|
|
21
21
|
</template>
|
|
22
22
|
|
|
23
|
-
<script>
|
|
24
|
-
import
|
|
23
|
+
<script lang="ts" setup>
|
|
24
|
+
import { computed, getCurrentInstance, nextTick, onMounted, ref, useCssModule, watch } from 'vue';
|
|
25
|
+
import useClassNames from '../../composable/component-name';
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
name: 'Tab',
|
|
27
|
+
defineOptions({
|
|
28
28
|
options: {
|
|
29
29
|
virtualHost: true,
|
|
30
30
|
styleIsolation: 'shared',
|
|
31
31
|
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (!this.isTabsNotEmpty) return 0;
|
|
89
|
-
return this.isStringTabs
|
|
90
|
-
? Number(this.selectedIndex) || 0
|
|
91
|
-
: this.tabs.findIndex((item) => item.value === this.selectedIndex);
|
|
92
|
-
},
|
|
93
|
-
/** 指示器宽度 */
|
|
94
|
-
indicatorWidth() {
|
|
95
|
-
const rect = this.tabRects[this.tabIndex];
|
|
96
|
-
if (!rect) return 0;
|
|
97
|
-
return rect.width;
|
|
98
|
-
},
|
|
99
|
-
/** 指示器中心点 */
|
|
100
|
-
indicatorCenter() {
|
|
101
|
-
const rect = this.tabRects[this.tabIndex];
|
|
102
|
-
if (!rect) return 0;
|
|
103
|
-
return rect.left + rect.width / 2 - this.boundingLeft;
|
|
104
|
-
},
|
|
105
|
-
styleStr() {
|
|
106
|
-
return [
|
|
107
|
-
`--tab-count: ${this.tabs.length};`,
|
|
108
|
-
`--tab-text-width: ${this.indicatorWidth}px;`,
|
|
109
|
-
`--indicator-center: ${this.indicatorCenter}px;`,
|
|
110
|
-
].join(' ');
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
watch: {
|
|
114
|
-
tabs: {
|
|
115
|
-
handler() {
|
|
116
|
-
if (this.isStringTabs) {
|
|
117
|
-
this.selectedIndex = Math.min(this.selectedIndex, this.tabs.length - 1);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
if (this.isTabsNotEmpty && this.tabIndex < 0) {
|
|
121
|
-
this.selectedIndex = this.tabs[0].value;
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
immediate: true,
|
|
125
|
-
},
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const classNames = useClassNames('tab');
|
|
35
|
+
const $style = useCssModule();
|
|
36
|
+
|
|
37
|
+
type _TabItem = {
|
|
38
|
+
/** 标题 */
|
|
39
|
+
label: string;
|
|
40
|
+
/** 值 */
|
|
41
|
+
value: string | number;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
type _Props = {
|
|
45
|
+
/** 绑定值,当前所选 tab 的索引 */
|
|
46
|
+
modelValue?: number;
|
|
47
|
+
/** 值,当前所选 tab 的值,当 tabs 为字符串列表时,不使用该值 */
|
|
48
|
+
value?: string | number;
|
|
49
|
+
/** 页签配置 */
|
|
50
|
+
tabs?: string[] | _TabItem[];
|
|
51
|
+
/** 是否均分大小 */
|
|
52
|
+
evenly?: boolean;
|
|
53
|
+
/** 是否显示指示器 */
|
|
54
|
+
indicator?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const props = withDefaults(defineProps<_Props>(), {
|
|
58
|
+
modelValue: undefined,
|
|
59
|
+
value: undefined,
|
|
60
|
+
tabs: () => [],
|
|
61
|
+
evenly: true,
|
|
62
|
+
indicator: true,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const emit = defineEmits<{
|
|
66
|
+
(e: 'update:modelValue', payload: number): void;
|
|
67
|
+
(e: 'update:value', payload: string | number | undefined): void;
|
|
68
|
+
(e: 'change', payload: number): void;
|
|
69
|
+
}>();
|
|
70
|
+
|
|
71
|
+
/** 组件内部记录索引用的值 */
|
|
72
|
+
const innerIndex = ref<number>(0);
|
|
73
|
+
/** 组件左边距 */
|
|
74
|
+
const boundingLeft = ref(0);
|
|
75
|
+
/** 标签文本的尺寸信息 */
|
|
76
|
+
const tabTextRects = ref<UniApp.NodeInfo[]>([]);
|
|
77
|
+
/** 标签移动是否应用动画 */
|
|
78
|
+
const hasAnimation = ref(false);
|
|
79
|
+
|
|
80
|
+
/** 标签标题列表 */
|
|
81
|
+
const tabLabels = computed(() => props.tabs.map((item) => (typeof item === 'string' ? item : item.label)));
|
|
82
|
+
/** 当前选中的索引 */
|
|
83
|
+
const selectedIndex = computed<number>({
|
|
84
|
+
get: () => (props.modelValue === undefined ? innerIndex.value : props.modelValue),
|
|
85
|
+
set: (value) => {
|
|
86
|
+
emit('update:modelValue', value);
|
|
87
|
+
innerIndex.value = value;
|
|
126
88
|
},
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// 监听选项、索引、值的变化,以保证 tab 选择始终是对应的
|
|
92
|
+
watch(
|
|
93
|
+
[() => props.tabs, selectedIndex, () => props.value],
|
|
94
|
+
([nTabs, nIdx, nVal], [_t, _i, oVal]) => {
|
|
95
|
+
// 如果值改变了,查找对应的索引
|
|
96
|
+
if (nVal !== oVal && nVal !== undefined) {
|
|
97
|
+
nIdx = nTabs.findIndex((i) => (typeof i === 'string' ? nVal === i : nVal === i.value));
|
|
98
|
+
}
|
|
99
|
+
if (nIdx < 0) nIdx = 0;
|
|
100
|
+
const tab = nTabs[nIdx];
|
|
101
|
+
// 再度获取对应索引位置的值,如果是字符串类型标签,则为 undefined
|
|
102
|
+
nVal = typeof tab === 'string' ? undefined : tab?.value;
|
|
103
|
+
const idx = nIdx < 0 || nIdx >= nTabs.length ? 0 : nIdx;
|
|
104
|
+
if (selectedIndex.value !== idx) {
|
|
105
|
+
// 更新索引和值
|
|
106
|
+
selectedIndex.value = nIdx < 0 || nIdx >= nTabs.length ? 0 : nIdx;
|
|
107
|
+
emit('change', idx);
|
|
108
|
+
}
|
|
109
|
+
emit('update:value', nVal);
|
|
146
110
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
111
|
+
{ immediate: true, deep: true }
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
/** 指示器宽度 */
|
|
115
|
+
const indicatorWidth = computed(() => {
|
|
116
|
+
const rect = tabTextRects.value[selectedIndex.value];
|
|
117
|
+
if (!rect) return 0;
|
|
118
|
+
return rect.width;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
/** 指示器中心点 */
|
|
122
|
+
const indicatorCenter = computed(() => {
|
|
123
|
+
const rect = tabTextRects.value[selectedIndex.value];
|
|
124
|
+
if (!rect || !rect.width) return 0;
|
|
125
|
+
return (rect.left || 0) + rect.width / 2 - boundingLeft.value;
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const inlineStyle = computed(() => {
|
|
129
|
+
return [
|
|
130
|
+
`--tab-count: ${props.tabs.length};`,
|
|
131
|
+
`--tab-text-width: ${indicatorWidth.value}px;`,
|
|
132
|
+
`--indicator-center: ${indicatorCenter.value}px;`,
|
|
133
|
+
].join(' ');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const vm = getCurrentInstance();
|
|
137
|
+
|
|
138
|
+
onMounted(() => {
|
|
139
|
+
uni.createSelectorQuery()
|
|
140
|
+
.in(vm)
|
|
141
|
+
.select('.' + $style['Tab--tab-wrapper'])
|
|
142
|
+
.boundingClientRect((rect) => {
|
|
143
|
+
boundingLeft.value = (rect as UniApp.NodeInfo).left || 0;
|
|
144
|
+
})
|
|
145
|
+
.exec();
|
|
146
|
+
|
|
147
|
+
// 选项发生变化,重新计算各个选项的尺寸信息
|
|
148
|
+
watch(
|
|
149
|
+
() => props.tabs,
|
|
150
|
+
() => {
|
|
151
|
+
hasAnimation.value = false;
|
|
152
|
+
nextTick(() => {
|
|
153
|
+
uni.createSelectorQuery()
|
|
154
|
+
.in(vm)
|
|
155
|
+
.selectAll('.' + $style['Tab--tab-text'])
|
|
156
|
+
.boundingClientRect((rects) => {
|
|
157
|
+
tabTextRects.value = rects as UniApp.NodeInfo[];
|
|
158
|
+
nextTick(() => {
|
|
159
|
+
hasAnimation.value = true;
|
|
160
|
+
});
|
|
161
|
+
})
|
|
162
|
+
.exec();
|
|
163
|
+
});
|
|
160
164
|
},
|
|
161
|
-
|
|
165
|
+
{ immediate: true, deep: true }
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
/** 改变标签响应 */
|
|
170
|
+
const onChangeTab = (index: number) => {
|
|
171
|
+
selectedIndex.value = index;
|
|
172
|
+
// emit('change', selectedIndex.value);
|
|
162
173
|
};
|
|
163
174
|
</script>
|
|
164
175
|
|
|
165
176
|
<style lang="scss" module>
|
|
166
|
-
@use '../../styles/
|
|
177
|
+
@use '../../styles/utils' as *;
|
|
178
|
+
@use './tab' as *;
|
|
167
179
|
|
|
168
180
|
// 定义外部变量
|
|
169
|
-
$component-name: 'tab';
|
|
170
|
-
$component-vars: $tab;
|
|
171
181
|
%external-vars {
|
|
172
|
-
@include UTILS__DEFINE_COMPONENT_VARS();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
:host {
|
|
176
|
-
display: block;
|
|
182
|
+
@include UTILS__DEFINE_COMPONENT_VARS($tab, 'tab');
|
|
177
183
|
}
|
|
178
184
|
|
|
179
185
|
.Tab {
|
|
@@ -226,9 +232,9 @@ $component-vars: $tab;
|
|
|
226
232
|
border-radius: 10rpx;
|
|
227
233
|
background: UTILS__LOCAL_VAR(indicator-color);
|
|
228
234
|
transform: translateX(-50%);
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
235
|
+
left: var(--indicator-center, 0);
|
|
236
|
+
width: UTILS__LOCAL_VAR(indicator-width, var(--tab-text-width, 0));
|
|
237
|
+
&.Tab--indicator-animation {
|
|
232
238
|
transition: left 0.3s, width 0.3s;
|
|
233
239
|
}
|
|
234
240
|
}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<view :class="
|
|
2
|
+
<view :class="[...classNames, $style['Textarea']]">
|
|
3
3
|
<template v-if="!isReadonly">
|
|
4
4
|
<textarea
|
|
5
|
-
:value="
|
|
5
|
+
:value="modelValue"
|
|
6
6
|
:maxlength="maxlength"
|
|
7
7
|
:auto-height="autoHeight"
|
|
8
8
|
:class="$style['Textarea--input']"
|
|
9
|
-
@input="
|
|
10
|
-
@blur="
|
|
9
|
+
@input="onInput"
|
|
10
|
+
@blur="trimValue"
|
|
11
11
|
>
|
|
12
12
|
</textarea>
|
|
13
|
-
<view v-if="!
|
|
13
|
+
<view v-if="!modelValue" :class="$style['Textarea--placeholder']">
|
|
14
14
|
<slot name="placeholder">
|
|
15
15
|
<icon-cpn icon="textarea-edit" :class="$style['Textarea--icon']" />
|
|
16
16
|
<text> {{ placeholder }} </text>
|
|
@@ -19,125 +19,123 @@
|
|
|
19
19
|
<view :class="$style['Textarea--counter']"> 已输入 {{ count }}/{{ maxlength }} </view>
|
|
20
20
|
</template>
|
|
21
21
|
<!-- 只读文本展示 -->
|
|
22
|
-
<view v-else-if="
|
|
23
|
-
<view :class="{ [$style['Textarea--fold']]: fold && isFolded }"> {{
|
|
22
|
+
<view v-else-if="modelValue" :class="$style['Textarea--readonly']">
|
|
23
|
+
<view :class="{ [$style['Textarea--fold']]: fold && isFolded }"> {{ modelValue }} </view>
|
|
24
24
|
<view v-if="fold && hasFoldButton" :class="$style['Textarea--fold-button']" @click="isFolded = !isFolded">
|
|
25
25
|
<text v-if="isFolded"> <icon-cpn icon="arrow-down" /> 展开 </text>
|
|
26
26
|
<text v-else> <icon-cpn icon="arrow-up" /> 收起 </text>
|
|
27
27
|
</view>
|
|
28
28
|
<!-- 隐藏文字,用于计算是否显示收起展开按钮 -->
|
|
29
|
-
<view v-if="fold" :class="[$style['Textarea--hidden-text'], $style['Textarea--fold']]">
|
|
30
|
-
|
|
29
|
+
<view v-if="fold" :class="[$style['Textarea--hidden-text'], $style['Textarea--fold']]">
|
|
30
|
+
{{ modelValue }}
|
|
31
|
+
</view>
|
|
32
|
+
<view v-if="fold" :class="$style['Textarea--hidden-text']"> {{ modelValue }} </view>
|
|
31
33
|
</view>
|
|
32
34
|
<!-- 空文本展示 -->
|
|
33
35
|
<view v-else :class="[$style['Textarea--readonly'], $style['Textarea--empty']]"> 未填写 </view>
|
|
34
36
|
</view>
|
|
35
37
|
</template>
|
|
36
38
|
|
|
37
|
-
<script>
|
|
38
|
-
import
|
|
39
|
-
import
|
|
39
|
+
<script lang="ts" setup>
|
|
40
|
+
import { computed, getCurrentInstance, inject, nextTick, ref, useCssModule, watch } from 'vue';
|
|
41
|
+
import useClassNames from '../../composable/component-name';
|
|
40
42
|
import IconCpn from '../icon/icon.vue';
|
|
41
43
|
|
|
42
|
-
|
|
43
|
-
name: 'Textarea',
|
|
44
|
+
defineOptions({
|
|
44
45
|
options: {
|
|
45
46
|
virtualHost: true,
|
|
46
47
|
styleIsolation: 'shared',
|
|
47
48
|
},
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
.in(this)
|
|
121
|
-
.selectAll('.' + this.$style['Textarea--hidden-text'])
|
|
122
|
-
.boundingClientRect((rects) => {
|
|
123
|
-
this.hasFoldButton = rects.length === 2 && rects[1].height > rects[0].height;
|
|
124
|
-
})
|
|
125
|
-
.exec();
|
|
126
|
-
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const classNames = useClassNames('textarea');
|
|
52
|
+
const $style = useCssModule();
|
|
53
|
+
|
|
54
|
+
type _Props = {
|
|
55
|
+
/** 绑定值 */
|
|
56
|
+
modelValue?: string;
|
|
57
|
+
/** 最大输入文本长度 */
|
|
58
|
+
maxlength?: number;
|
|
59
|
+
/** 占位文本 */
|
|
60
|
+
placeholder?: string;
|
|
61
|
+
/** 是否自动调整高度 */
|
|
62
|
+
autoHeight?: boolean;
|
|
63
|
+
/** 是否只读 */
|
|
64
|
+
readonly?: boolean;
|
|
65
|
+
/** 当只读时,如果文字过多,是否折叠 */
|
|
66
|
+
fold?: boolean;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const props = withDefaults(defineProps<_Props>(), {
|
|
70
|
+
modelValue: '',
|
|
71
|
+
maxlength: 300,
|
|
72
|
+
placeholder: '请输入',
|
|
73
|
+
autoHeight: true,
|
|
74
|
+
readonly: false,
|
|
75
|
+
fold: true,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const emit = defineEmits<{
|
|
79
|
+
(e: 'update:modelValue', val: string): void;
|
|
80
|
+
}>();
|
|
81
|
+
|
|
82
|
+
/** 表单是否只读 */
|
|
83
|
+
const isFormReadonly = inject(
|
|
84
|
+
'ecolovo/form/readonly',
|
|
85
|
+
computed(() => false)
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
/** 是否有收起展开按钮 */
|
|
89
|
+
const hasFoldButton = ref(false);
|
|
90
|
+
/** 当前是否处于收起状态 */
|
|
91
|
+
const isFolded = ref(true);
|
|
92
|
+
|
|
93
|
+
/** 是否只读 */
|
|
94
|
+
const isReadonly = computed(() => props.readonly || isFormReadonly.value);
|
|
95
|
+
|
|
96
|
+
/** 已输入字符长度 */
|
|
97
|
+
const count = computed(() => props.modelValue.length);
|
|
98
|
+
|
|
99
|
+
const vm = getCurrentInstance();
|
|
100
|
+
|
|
101
|
+
/** 计算是否需要显示收起展开按钮 */
|
|
102
|
+
const shouldShowFold = () => {
|
|
103
|
+
uni.createSelectorQuery()
|
|
104
|
+
.in(vm)
|
|
105
|
+
.selectAll('.' + $style['Textarea--hidden-text'])
|
|
106
|
+
.boundingClientRect((rects) => {
|
|
107
|
+
if (!Array.isArray(rects)) return;
|
|
108
|
+
hasFoldButton.value = rects.length === 2 && (rects[1]?.height || 0) > (rects[0]?.height || 0);
|
|
109
|
+
})
|
|
110
|
+
.exec();
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
watch(
|
|
114
|
+
() => isReadonly.value,
|
|
115
|
+
(newVal) => {
|
|
116
|
+
if (newVal && props.fold) {
|
|
117
|
+
nextTick(() => {
|
|
118
|
+
shouldShowFold();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
127
121
|
},
|
|
122
|
+
{ immediate: true }
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
/** 输入响应 */
|
|
126
|
+
const onInput = (e: Event) => {
|
|
127
|
+
emit('update:modelValue', (e as CustomEvent).detail.value);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** 去除头尾空白字符 */
|
|
131
|
+
const trimValue = (e: Event) => {
|
|
132
|
+
emit('update:modelValue', (e as CustomEvent).detail.value.trim());
|
|
128
133
|
};
|
|
129
134
|
</script>
|
|
130
135
|
|
|
131
136
|
<style lang="scss" module>
|
|
132
137
|
@use '../../styles/index' as *;
|
|
133
138
|
|
|
134
|
-
:host {
|
|
135
|
-
display: block;
|
|
136
|
-
}
|
|
137
|
-
:host(.display-inline) {
|
|
138
|
-
display: inline;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
139
|
.Textarea {
|
|
142
140
|
flex: 1;
|
|
143
141
|
position: relative;
|
|
@@ -173,7 +171,12 @@ export default {
|
|
|
173
171
|
overflow: hidden;
|
|
174
172
|
}
|
|
175
173
|
.Textarea--fold {
|
|
176
|
-
|
|
174
|
+
overflow: hidden;
|
|
175
|
+
text-overflow: ellipsis;
|
|
176
|
+
display: -webkit-box;
|
|
177
|
+
-webkit-line-clamp: 5;
|
|
178
|
+
line-clamp: 5;
|
|
179
|
+
-webkit-box-orient: vertical;
|
|
177
180
|
}
|
|
178
181
|
.Textarea--fold-button {
|
|
179
182
|
text-align: right;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { kebabCase, pascalCase } from 'case-anything';
|
|
2
|
+
import { componentPrefix } from '../configs';
|
|
3
|
+
const useClassNames = (componentName) => {
|
|
4
|
+
const pascalCaseClass = pascalCase(componentPrefix) + pascalCase(componentName);
|
|
5
|
+
const kebabCaseClass = kebabCase(pascalCaseClass);
|
|
6
|
+
return [pascalCaseClass, kebabCaseClass];
|
|
7
|
+
};
|
|
8
|
+
export default useClassNames;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { kebabCase, pascalCase } from 'case-anything';
|
|
2
|
+
import { componentPrefix } from '../configs';
|
|
3
|
+
|
|
4
|
+
const useClassNames = (componentName: string): [string, string] => {
|
|
5
|
+
const pascalCaseClass = pascalCase(componentPrefix) + pascalCase(componentName);
|
|
6
|
+
const kebabCaseClass = kebabCase(pascalCaseClass);
|
|
7
|
+
return [pascalCaseClass, kebabCaseClass];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export default useClassNames;
|
package/configs/index.d.ts
CHANGED
|
@@ -2,21 +2,36 @@
|
|
|
2
2
|
declare let componentPrefix: string;
|
|
3
3
|
/** 首页路径 */
|
|
4
4
|
declare let homePath: string;
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 设置组件前缀
|
|
7
|
+
* @param prefix 组件前缀
|
|
8
|
+
*/
|
|
9
|
+
declare function setComponentPrefix(prefix?: string): void;
|
|
10
|
+
/**
|
|
11
|
+
* 设置首页路径
|
|
12
|
+
* @param path 首页路径
|
|
13
|
+
*/
|
|
14
|
+
declare function setHomePath(path?: string): void;
|
|
15
|
+
interface IconInfo {
|
|
16
|
+
/** 字体文件名 */
|
|
17
|
+
fontFamily: string;
|
|
18
|
+
/** 图标前缀 */
|
|
19
|
+
prefix: string;
|
|
20
|
+
/** 图标名称 */
|
|
21
|
+
name: string;
|
|
22
|
+
}
|
|
9
23
|
/** iconfont 图标 map */
|
|
10
|
-
declare
|
|
11
|
-
interface IconFontJson {
|
|
24
|
+
declare const iconMap: Map<string, IconInfo>;
|
|
25
|
+
export interface IconFontJson {
|
|
12
26
|
font_family: string;
|
|
13
27
|
css_prefix_text: string;
|
|
14
|
-
glyphs: {
|
|
28
|
+
glyphs: {
|
|
29
|
+
font_class: string;
|
|
30
|
+
}[];
|
|
15
31
|
}
|
|
16
32
|
/**
|
|
17
33
|
* 添加一组图标,传入 iconfont.json 文件内容
|
|
18
34
|
* @param iconJson iconfont.json 文件内容
|
|
19
35
|
*/
|
|
20
|
-
declare
|
|
21
|
-
|
|
22
|
-
export { componentPrefix, homePath, IconFontJson, setComponentPrefix, setHomePath, iconMap, addIcons };
|
|
36
|
+
declare function addIcons(iconJson: IconFontJson): void;
|
|
37
|
+
export { componentPrefix, homePath, setComponentPrefix, setHomePath, iconMap, addIcons };
|